What h.264 format loads on Android and IOS?

Theoretically, both IOS and ANDROID will play h.264 files, but I cannot figure out how to encode them so that they really work on a cross platform. Does anyone know how to encode for Android and IOS using a single file?

ps I know all about html5 video and backup sources, I just don’t want to encode and post a new video for every device that comes off the pike.

+29
android iphone html5-video ffmpeg
Jun 15 '11 at 20:50
source share
3 answers

This uses the ffmpeg command line, which we use to transcode to MPEG-4 h.264 in our production environment. We tested the output on several Android devices, as well as on iOS. You can use this as a starting point by simply tweaking things like frame size / frame rate and qfactor.

ffmpeg -y -i #{input_file} -s 432x320 -b 384k -vcodec libx264 -flags +loop+mv4 -cmp 256 -partitions +parti4x4+parti8x8+partp4x4+partp8x8 -subq 6 -trellis 0 -refs 5 -bf 0 -flags2 +mixed_refs -coder 0 -me_range 16 -g 250 -keyint_min 25 -sc_threshold 40 -i_qfactor 0.71 -qmin 10 -qmax 51 -qdiff 4 -acodec libfaac -ac 1 -ar 16000 -r 13 -ab 32000 -aspect 3:2 #{output_file} 

Some of the important parameters that affect Android compatibility are:

 -coder 0 Uses CAVLAC rather than CABAC entropy encoding (CABAC not supported on Android) -trellis 0 Should be shut off, requires CABAC -bf 0 Turns off B-frames, not supported on Android or other h.264 Baseline Profile devices -subq 6 Determines what algorithms are used for subpixel motion searching. 7 applies to B-frames, not supported on Android. -refs 5 Determines how many frames are referenced prior to the current frame. Increasing this number could affect compatibility 

After encoding our video using this ffmpeg recipe, we also transfer the video through qt-faststart . This step repeats the video for streaming. We send it via HTTP to the embedded VideoView in our Android application. No streaming issues on any Android device we know about.

Update 2013-06-17: I just wanted to add a note that it is best to use a “base” profile for H.264 encoding for maximum compatibility on all Android devices. The H.264 profile is not explicitly specified in the command line above, but ffmpeg has a -profile command line flag which is useful if you use its presets . You should probably not be confused with -profile . I encoded the video for my tablet ASUS Transformer 300 (Android 4.2) using the "main" and not the "basic" profile (via Handbrake). The "main" profile gave problems with the synchronization of sound with video during playback.

+51
Jun 15 2018-11-11T00:
source share

I used this to make an Android and iOS app with embedded videos. Movies playable in both versions. ( Android example ) ( iOS example )

Additional answer

This answer is in addition to the accepted answer explaining some parameters.

 ffmpeg -y # Overwrite output files without asking. -i input_filename # input file name -s 432x320 # size of output file -b:v 384k # bitrate for video -vcodec libx264 # use H.264 video codec -flags +loop+mv4 # use loop filter and four motion vector by macroblock -cmp 256 # ??? Full pel motion estimation compare function -partitions +parti4x4+parti8x8+partp4x4+partp8x8 #??? -subq 6 # determines algorythms for subpixel motion searching and partition decision -trellis 0 # optimal rounding choices -refs 5 # number of frames referenced prior to current frame -bf 0 # turn of B-frames, something to do with H.264 and Baseline Profile -flags2 +mixed_refs # ??? gave me an error so I just deleted it -coder 0 # turn of the CABAC entropy encoder -me_range 16 # max range of the motion search -g 250 # GOP length (250 is the recommended default) -keyint_min 25 # Minimum GOP length (25 is the recommended default) -sc_threshold 40 # adjusts sensitivity of x264 scenecut detection (default is 40) -i_qfactor 0.71 # Qscale difference between I-frames and P-frames (0.71 is the recommended default) -qmin 10 -qmax 51 # min and max quantizer (10 and 51 are the recommended defaults) -qdiff 4 # max QP step (4 is recommended default) -c:a aac # Set the audio codec to use AAC -ac 1 # number of audio channels -ar 16000 # audio sampling frequency -r 13 # frames per second -ab 32000 # audio bitrate -aspect 3:2 # sample aspect ratio output_filename # name of the output file 

Feel free to edit this if you can fill in some details that I did not know about.

Here it is again in cut and paste format. (I also had to add the -strict -2 option to get aac to work on my computer.)

 ffmpeg -y -i input_file.avi -s 432x320 -b:v 384k -vcodec libx264 -flags +loop+mv4 -cmp 256 -partitions +parti4x4+parti8x8+partp4x4+partp8x8 -subq 6 -trellis 0 -refs 5 -bf 0 -coder 0 -me_range 16 -g 250 -keyint_min 25 -sc_threshold 40 -i_qfactor 0.71 -qmin 10 -qmax 51 -qdiff 4 -c:a aac -ac 1 -ar 16000 -r 13 -ab 32000 -aspect 3:2 -strict -2 output_file.mp4 

Further research

I found most of this information at the following links:

see also

  • Android VideoView Example
+2
Dec 10 '16 at 7:08
source share

See supported multimedia formats for Android , which says that h.264 is only supported in Android 3.0+. Earlier versions of Android h.263 support. EDIT . As mportuesisf mentions below, I misinterpreted the linked table. Ignore this answer.

-one
Jun 15 2018-11-11T00:
source share



All Articles