Search code examples
iosobjective-cvideoffmpegmjpeg

Encode mjpeg files from within an iOS app


I'm trying to encode a video file with the mjpeg codec on iOS. Basically, I'm trying to replicate what this command does

ffmpeg -i recording.mp4 -vsync vfr -q:v 9 recording.mjpeg

from within an app.

Is there an easy way to do this?

I'm looking at using the low level ffmpeg API to do this like in this example, but I was wondering if somebody knows of a simpler way.

I have also access to the individual video frames in CMSampleBufferRef format, in case that makes it easier. AVAssetWriter doesn't seem to support mjpeg, which is unfortunate, as that would make things super simple.


Solution

  • I ended up using the code shown in the transcoding.c example, but replacing the encoding codec by AV_CODEC_ID_MJPEG.