FFmpeg can use OpenH264 (named libopenh264
in FFmpeg) to decode in addition to the native FFmpeg H.264 decoder (named h264
). There are also several supported hardware assisted H.264 decoders, but I'm not going to go into detail about those.
OpenH264 vs FFmpeg H.264 decoder
The documentation states that OpenH264 supports decoding of Constrained Baseline profile, so its usefulness may be limited. However it was able to decode a Main and a High profile video I tested. The actual capabilities appear to be undocumented, so it is unclear if it has partial or full support for Main and High profiles.
The native FFmpeg H.264 decoder has threading capabilities (frame and slice) but OpenH264 does not. So the FFmpeg H.264 decoder is much faster than OpenH264.
OpenH264 is licensed BSD 2-Clause "Simplified" License. FFmpeg H.264 decoder is LGPL 2.1 or later.
ffmpeg
CLI tool examples
It appears you're working with the FFmpeg libraries, but here are some examples using ffmpeg
.
To choose the decoder you want use the -c:v
input option. Below are two decoding benchmark examples using the null muxer. The -map
option is also used so only the (first) video stream is decoded and to ignore other, non-video streams such as audio.
Native FFmpeg H.264 decoder
$ ffmpeg -benchmark -i input.mp4 -map 0:v:0 -f null -
bench: utime=23.557s
bench: maxrss=57752kB
real 0m3.834s
user 0m23.573s
sys 0m0.213s
libopenh264
$ ffmpeg -benchmark -c:v libopenh264 -i input.mp4 -map 0:v:0 -f null -
bench: utime=20.927s
bench: maxrss=37404kB
real 0m21.002s
user 0m20.940s
sys 0m0.060s
Benchmark time
Note the benchmark option outputs user CPU time, not the elapsed real time. If you want real time as well add the time
command before the ffmpeg
command (if you're on Linux). I added the outputs from time
in the example (the last three lines) for comparison purposes.
To verify the desired decoder is being used
View the console output. For example using the native H.264 decoder:
Stream mapping:
Stream #0:0 -> #0:0 (h264 (native) -> wrapped_avframe (native))
Using libopenh264:
Stream mapping:
Stream #0:0 -> #0:0 (h264 (libopenh264) -> wrapped_avframe (native))
h264
decoder to decode. – Sappanwoodx264
is encoder only, openOpenH264
both encoder and decoder. So you either decode with built-in ffmpeg h264 decoder or with libopenh264 decoder. Decoding with x264 is currently not possible. – Siloum