Using named pipes/streams to convert and output to a stream contains no stream duration

915 Views Asked by At

I have an integration with an API that sends us an FLV with an H.264 codec. I use FFMpeg (FFMpegCore, a C# library that interacts with FFMpeg) to convert the container to a fragmented MP4 container. The result is then streamed to resp.OutputStream, and the file's downloaded.

However, the result contains no stream duration and Windows Media Player is unable to navigate the file.

The stream is handled via the following code:

FFMpegArguments
.FromPipe(new StreamPipeSource(inputStream))
.WithVideoCodec("copy")
.ForceFormat("mp4")
.WithArgument(new FragArgument())
.OutputToPipe(new StreamPipeSink(resp.OutputStream))
.ProcessSynchronously(false);

Which roughly equates to the following command:

type "Input.flv" | ffmpeg -i - -vcodec copy -f mp4 -movflags frag_keyframe+empty_moov pipe:1 > Output.mp4

(FragArgument is something I created myself which simply adds -movflags frag_keyframe+empty_moov to the command)

The outputted stream has a duration of 0. Media players such as VLC seem to be able to calculate the durations, but the client is unable to use VLC media player, instead having to use Windows Media Player, which is able to play the file but does not properly record the duration.

I'm quite new to handling video streams, but the lack of a duration seems to be something the muxer does, according to this stack overflow answer

I think I can get a stream duration if I output as a non-fragmented mp4 to a local file, then stream that to the server. However, the extra step would increase the download time, and I would have to worry about deleting the file afterwards, which I am trying to avoid doing.

How do I get my stream to include the correct durations without first saving to a file?

0

There are 0 best solutions below