What h.264 format loads on android AND IOS?

后端 未结 3 629
清酒与你
清酒与你 2020-12-04 08:10

Theoretically both IOS and ANDROID will play h.264 files, but I can\'t figure out a setting to encode them so they actually work cross platform. Does anybody know how to enc

3条回答
  •  旧时难觅i
    2020-12-04 08:25

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

    Supplemental answer

    This answer is a supplement to the accepted answer explaining some of the 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's 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 of the details I wasn't sure about.

    Here it is again in a cut-and-paste format. (I also had to add the -strict -2 parameter 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 Study

    Most of this information I found at the following links:

    • ffmpeg Documentation
    • x264 FFmpeg Options Guide
    • FFMPEG An Intermediate Guide/Flags Flags

    See also

    • Android VideoView example

提交回复
热议问题