Search code examples
androidffmpegcodecexoplayervitamio

Android - Best solution to convert recorded H.264 Main Profile videos to H.264 Baseline Profile


I found MediaPlayer cannot play videos which are encoded by H.264 Main Profile and I tried ExoPlayer and Vitamio but none of them solved my problem. finally I found the best solution is converting videos to H.264 Baseline Profile. FFmpeg is almost 9MB and it's so heavy for my project, so I don't like to use it for converting videos to that profile by commands. My friend suggested converting videos on the server-side but we both know it has bad performance. What should I do? What is the best solution to this problem?


Solution

  • Android technically only supports H.264 Baseline, but many of the newer (usually high end devices) will play H.264 Main Profile, too. The Nexus 4,5,6,7 and 10 all do, for example. So, you have a few options... You either just use H.264 Main and don't care about older devices that don't support it, or you convert on the server side. Doing the conversion on the device is a bad idea. If it doesn't support H.264 Baseline, it was probably done for performance reasons and doing the conversion on the device and then decoding is going to crush the CPU.

    Worth noting, ExoPlayer will use the same device codecs as MediaPlayer because it is just a wrapper around MediaCodec. Vitamio is a wrapper around ffmpeg and it might be possible to provide a H.264 Main codec with a custom ffmpeg build, but again, if it isn't there in the first place, performance was probably an issue.