golmschenk golmschenk - 1 year ago 257
C Question

C - FFmpeg streaming from a C program?

I'm looking to replicate an FFmpeg command-line command in my C code. Specifically I would like to be able to run:

ffmpeg -re -i video.mp4 -f mpegts udp://localhost:7777

One thing I've noticed when looking at people's code who have used the libraries of FFmpeg in their own code is that they often have a few hundred lines of code for a single command similar to an FFmpeg command-line command. I'm guessing this is just because they are doing something very specific, because if I can run that short command on my command line and get what I want it should probably only take about ten lines of code to do the same thing in my C code. This should only take about that much work right? Why would it take much more?

I'm having a bit of difficulty finding explanations on how to use the streaming capabilities of the FFmpeg libraries that aren't overly complex because they're for a very specific purpose. Can anyone explain how I might go about writing the code for the above command? Or at the very least point me to some documentation explaining how to write such a script/program? Thank you much!

EDIT: I do hope to run this from an iPhone app eventually so I won't just be able to straight up call FFmpeg from my program. I'll need to use the libraries used by FFmpeg.

Answer Source

FFmpeg's internal libraries (libavcode, libavformat and a few more) have a pretty complex code structure. You will need time to understand how basic things work, then you should try to write some simple test applications, and only then you will be able to replicate given command.

There are quite a few tutorials available how to use FFmeg's libraries (some of them use obsolete API), please also check a demo code in “doc/examples” directory.

Hope it helps !

From Comments:
Check examples/muxing.c sources from the latest FFmpeg version. Try to provide an URL instead of output file. Check documentation/sources for avformat_alloc_output_context2() function. Then you should get the basic idea how to add streaming support

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download