Use libstagefright Decoder in Legacy FFmpeg

This article explains how to enable and use the legacy libstagefright hardware-accelerated decoder in older versions of FFmpeg. You will learn the requirements for compiling FFmpeg with Stagefright support, the command-line syntax to invoke the decoder, and how to verify its installation on Android-based legacy systems.

Prerequisites and Compilation

The libstagefright library is Android’s media playback engine. To use it within FFmpeg, you must use a legacy version of FFmpeg (typically version 3.4 or older, as it was deprecated and subsequently removed in later releases) and compile it specifically for the Android platform using the Android NDK.

To enable the decoder during compilation, you must pass the appropriate flag to the configure script:

./configure --enable-libstagefright --enable-jni

Ensure your build environment has the Android NDK paths correctly configured, as the compiler needs access to the Android system libraries to bind with the Stagefright framework.

Verifying Decoder Availability

Once compiled, you can verify that the Stagefright decoders are available in your FFmpeg binary by running the following command on your target Android device:

ffmpeg -decoders | grep stagefright

If successfully compiled, you should see output listing the available Stagefright decoders, such as:

V...D. libstagefright_h264   H.264 Android Stagefright (codec: h264)

Using the Decoder in Command Line

To force FFmpeg to use the Stagefright hardware decoder instead of the default software decoder (like native h264), you must explicitly specify the codec using the -c:v or -codec:v flag before the input file.

Here is the standard command structure:

ffmpeg -c:v libstagefright_h264 -i input.mp4 output.mkv

Command Breakdown:

Modern Alternatives

If you are working on newer Android systems or modern versions of FFmpeg, libstagefright is no longer supported. It has been replaced by MediaCodec. For modern implementations, use the MediaCodec decoder wrapper instead:

ffmpeg -c:v h264_mediacodec -i input.mp4 output.mkv