3
votes

I have added this (https://github.com/kewlbear/FFmpeg-iOS-build-script) version of ffmpeg to my project. I can't see the entry point to the library in the headers included.

How do I get access to the same text command based system that the stand alone application has, or an equivalent?

I would also be happy if someone could point me towards documentation that allows you to use FFmpeg without the command line interface.

This is what I am trying to execute (I have it working on windows and android using the CLI version of ffmpeg)

ffmpeg -framerate 30 -i snap%03d.jpg -itsoffset 00:00:03.23333 -itsoffset 00:00:05 -i soundEffect.WAV -c:v libx264 -vf fps=30 -pix_fmt yuv420p result.mp4
3
so what is your use case here for the ios app ? and you just want ffmpeg to convert (wav) files to video(mp4) files with cropped audio from the audio file ??Gokul G
Its converting a series of still images to a video file, and adding audio to it.deek0146

3 Answers

5
votes

Actually you can build ffmpeg library including the ffmpeg binary's code (ffmpeg.c). Only thing to care about is to rename the function main(int argc, char **argv), for example, to ffmpeg_main(int argc, char **argv) - then you can call it with arguments just like you're executing ffmpeg binary. Note that argv[0] should contain program name, just "ffmpeg" should work.

The same approach was used in the library VideoKit for Android.

0
votes

To do what you want, you have to use your compiled FFmpeg library in your code.

What you are looking for is exactly the code providing by FFmpeg documentation libavformat/output-example.c (that mean AVFormat and AVCodec FFmpeg's libraries in general).

Stackoverflow is not a "do it for me please" platform. So I prefer explaining here what you have to do, and I will try to be precise and to answer all your questions.

I assume that you already know how to link your compiled (static or shared) library to your Xcode project, this is not the topic here.

So, let's talk about this code. It creates a video (containing video stream and audio stream randomly generated) based on a duration. You want to create a video based on a picture list and sound file. Perfect, there are only three main modifications you have to do:

  • The end condition is not reaching a duration, but reaching the end of your file list (In code there is already a #define STREAM_NB_FRAMES you can use to iterate over all you frames).
  • Replace the dummy void fill_yuv_image by your own method that load and decode image buffer from file.
  • Replace the dummy void write_audio_frame by your own method that load and decode the audio buffer from your file.

(you can find "how to load audio file content" example on documentation starting at line 271, easily adaptable for video content regarding documentation)

In this code, comparing to your CLI, you can figure out that:

  • const char *filename; in the main should be you output file "result.mp4".
  • #define STREAM_FRAME_RATE 25 (replace it by 30).
  • For MP4 generation, video frames will be encoded in H.264 by default (in this code, the GOP is 12). So no need to precise libx264.
  • #define STREAM_PIX_FMT PIX_FMT_YUV420P represents your desired yuv420p decoding format.

Now, with these official examples and related documentation, you can achieve what you desire. Be careful that there is some differences between FFmpeg's version in these examples and current FFmpeg's version. For example:

st = av_new_stream(oc, 1); // line 60

Could be replaced by:

st = avformat_new_stream(oc, NULL);
st->id = 1;

Or:

if (avcodec_open(c, codec) < 0) { // line 97

Could be replaced by:

if (avcodec_open2(c, codec, NULL) < 0) {

Or again:

dump_format(oc, 0, filename, 1); // line 483

Could be replaced by:

av_dump_format(oc, 0, filename, 1);

Or CODEC_ID_NONE by AV_CODEC_ID_NONE... etc.

Ask your questions, but you got all the keys! :)

0
votes

MobileFFMpeg is an easy to use pod for the purpose. Instructions on how to use MobileFFMpeg at: https://stackoverflow.com/a/59325680/1466453

MobileFFMpeg gives a very simple method for translating ffmpeg commands to your IOS objective-c program.

Virtually all ffmpeg commands and switches are supported. However you have to get the pod with appropriate license. e.g min-gpl will not give you features of libiconv. libiconv is convered in vidoe, gpl and full-gpl licenses.

Please highlight if you have specific issues regarding use of MobileFFMpeg