[Libav-user] Problems with H.264 encoding for MP4 files on macOS

Richard Kern kernrj at gmail.com
Sun Jan 29 22:27:45 EET 2017


On January 29, 2017 at 2:25:25 PM, films (postsoup-at-yahoo.com at ffmpeg.org)
wrote:

Hi Folks.

I am trying to write .mp4 files with H.264 and AAC from generated images
and audio. My app is linked to libAVFormat, libAVCodec etc plus some
necessary OSX frameworks

If I let libAVFormat select the codecs for a file named xxxxx.mp4 using
av_guess_format() it selects the MPEG4 and AAC encoders and everything is
working **fine**

However, I really need to use the H.264 codec instead of the MPEG4 video
codec, so I have tried overriding the guessed codec by simply adding this
after the av_guess_format stage.

fmt->video_codec = AV_CODEC_ID_H264;

However, having done that, libAVCodec appears to be failing when it calls
through to the OSX VideoToolbox.framework.

[h264_videotoolbox @ 0x106806800] Error: cannot create compression session:
-12908
[h264_videotoolbox @ 0x106806800] Try -allow_sw 1. The hardware encoder may
be busy, or not supported.

In constrast, if I simply try using the ffmpeg binary app (built from the
same libraries) to encode a source file into a .mp4 without specifying any
parameters, it selects x264 and AAC and encodes without hitting any errors.


In the ffmpeg trace, I see lots of
[libx264 ....

rather than the

[h264_videotoolbox ...
I see in my own code.

I have not been able to get past this issue and I wondered if anyone can
shed any light.  Is the [libx264 .... encoding used by ffmpeg different to
the [h264_videotoolbox ... attempt and fail in my app.

If this is true then I guess I need to find a way to specify use of x264
instead of h264_videotoolbox.
If thats the same thing then I need to understand why its failing in my
direct calls, but working ok when ffmpeg calls it.

I ran the app on a completely different mac to eliminate any hardware
dependancy in the VideoToolbox.framework and it doesn't throw the error but
it only turns out one really nasty video frame and the rest of the output
is blank.

I am quite happy with software based x264 and don't need hardware
acceleration through VideoToolbox.framework. How can I disable this ?
Compiling the libraries with -disable-videotoolbox in configure didn't make
any diffference.

You can download/compile/install x264 from source then re-run configure in
FFmpeg. If you see “libx264” listed under “Enabled encoders” once configure
completes, build/install and x264 will be available.

What Apple computer are you using? Which OS X version? Error “-12908” means
the hardware encoder doesn’t exist, but this could be a bug.



There doesn't appear to be much in the way of updated documentation or
example code for this sort of thing.
Can anyone advise ?

Many thanks.



_______________________________________________
Libav-user mailing list
Libav-user at ffmpeg.org
http://ffmpeg.org/mailman/listinfo/libav-user
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://ffmpeg.org/pipermail/libav-user/attachments/20170129/aac178a0/attachment.html>


More information about the Libav-user mailing list