FFMPEG : Redirecting MP4 muxed data to socket

2019-05-11 08:13发布

I am using FFMPEG library to mux H.264 and AAC frames to MP4 file. I can do that both using command line and C program.

Now, instead of writing the muxed MP4 data in to file I want to write these muxed data directly on to socket or pipe. Command line options for that will be appreciated. My actual goal is to write a C program though.

I tried using protocols tcp and udp but they are not working with Mp4 format. They are working with the matroska format.

Following is working.

ffmpeg -i Cartoon.mjpeg -f matroska -r 25 -vcodec copy tcp://10.99.19.224:8888

Following is not and gives error as below.

ffmpeg -i Cartoon.mjpeg -f mp4 -r 25 -vcodec copy tcp://10.99.19.224:8888

Could not write header for output file #0 (incorrect codec parameters ?): Operation not permitted

Any help or advice? Thank you in advance.

标签: ffmpeg mp4
2条回答
虎瘦雄心在
2楼-- · 2019-05-11 08:54

If you look at all the ffmpeg output, there is a line:

[mp4 @ 0033d660] muxer does not support non seekable output

The mp4 container needs to go back at the beggining of the file to write additional information. A thing that your network socket can not do. So it is not possible to use mp4 container here.

查看更多
干净又极端
3楼-- · 2019-05-11 08:57

Just got one way to output the muxed MP4 output directly on the socket using fragments. I know there are limitations of using fragments but this can be useful.

https://www.ffmpeg.org/ffmpeg-formats.html#Example-1

So following command line is working for me now. I am able to play the MP4 file received from the 8888 port. ffprobe also confirms that its really an MP4 file.

ffmpeg -i Stingray.264 -f mp4 -movflags isml+frag_keyframe -vcodec copy tcp://10.99.19.224:8888

Now I will have to write the C program to do this pragmatically.

查看更多
登录 后发表回答