kewlbear/FFmpeg-iOS

How to encode to H.264?

Closed this issue · 3 comments

We need to upload the encoded video to be displayed in a web browser, so we're trying to encode it to H.264. Here's our code:

let result = ffmpeg(["ffmpeg",
                             "-hide_banner", "-loglevel", "error", /// quiet
                             "-i", inPath.absoluteString, /// input file
                             "-filter:v", "scale=\(scale)", /// scale to the desired size
                             "-c:v", "libx264", /// use H.264 codec
                             "-c:a", "copy", /// copy audio stream "as is"
                             outPath.absoluteString])

However, we get the error message:

�[1;35m[vost#0:0 @ 0x117d857a0] �[0m�[4;31mUnknown encoder 'libx264'
�[0m

Is there another way to achieve this?

As a side-note, I would also like to get rid of these messages, if possible:

HookMain: setjmp=0
FFmpeg_exit=1, will longjmp
HookMain: setjmp=1

since they are cluttering my console.

For others: I was able to set the codec to H.265 at least, using this line:

"-vcodec", "hevc_videotoolbox", "-b:v", "6000k", "-tag:v", "hvc1",

see https://forums.developer.apple.com/forums/thread/667873

But this does not seem to be supported on Firefox:

https://caniuse.com/hevc

ChatGPT gave me the answer. You can use:

"-c:v", "h264_videotoolbox", // use H.264 codec with hardware acceleration