C# WCF Video Streaming from growing file? -
been pulling hair out on should have been quick , easy task.
i have self-hosted wcf service in need implement real-time video transcoding, transcoding isn't problem such, using ffmpeg local temp file.
quick sample of code looks like;
public stream streammedia(int a) { string input = @"\media\" + + ".mkv"; string output = @"\temp\transcoded\" + + datetime.now.ticks.tostring() + ".wmv"; processstartinfo pi = new processstartinfo("ffmpeg.exe"); pi.arguments = "-i " + input + " -y -ab 64k -vcodec wmv2 -b 800k -mbd 2 -cmp 2 -subcmp 2 -s 320x180 -f asf " + output; process p = new process; p.startinfo = pi; p.start(); thread.sleep(2500); return new filestream(output, filemode.open, fileaccess.read, fileshare.readwrite); }
the problem facing returned stream gives me written file when returned - resulting in rather short video file :)
i've played around obvious here, no matter return what's available there , then.
what need happen stream returned no respect actual current lenght of output file - there other code involved makes sure data never sent client faster ffmpeg manages encode, need open-ended stream.
any takers?
one solution create custom stream class wrap around file disk; but, there's concurrency issue, meaning need locking mechanism writing process (video transcoder) share file filestream.
is possible transcoder create multi-volume output? if so, lucky , work (almost) no pain @ all, streaming of volume n, transcoder writes volume n + 1, , you'll not have file access concurrency issues.
happy coding! - adrian
Comments
Post a Comment