1

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.

golmschenk
  • 11,736
  • 20
  • 78
  • 137
  • Hi , Just from curiosity, why not call the application with system call. Won't it work ? – ransh Apr 15 '15 at 17:43
  • @ransh: Sorry, my final "EDIT" paragraph explains why, though for people who haven't developed for the iPhone it doesn't, I suppose I should explain the reasoning. iPhone software is sandboxed (for various reasons), and so cannot make system calls or install their own software to the system. So in my case (and people in similarly restricted situations), the program has to be self contained. – golmschenk Apr 15 '15 at 18:04

1 Answers1

4

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

golmschenk
  • 11,736
  • 20
  • 78
  • 137
Paul
  • 1,262
  • 8
  • 16
  • Thanks for the response. I have already looked through most of those tutorials, but I don't see anything about the streaming in them. Do you have any example with that? Thanks. – golmschenk Apr 26 '13 at 12:48
  • From your perspective "streaming" is the same as writing data to an output file. libavformat provides a transparent API for input / output operations (check avio.h header). – Paul Apr 26 '13 at 13:01
  • Alright. I suppose that makes sense. An example of it being done would still be useful, but this is important to know nonetheless. – golmschenk Apr 26 '13 at 13:03
  • 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. – Paul Apr 26 '13 at 13:14