how to set option of ffmpeg with libx264, I,P,B order?

3.2k views Asked by At

I'm looking for a option of ffmpeg with libx264. I want to operate it, like a hardware encoder with ordering of the fixed frame type.

IBBPBBPBBPBBPBB..IBBPBBPBBPBBP..IBBPBBP...

Please, give me a advice.

    #!/bin/bash

    INFILE=$1
    IFILE=$1.ts

    OPT_CRF="-g 120 -c:v libx264 -crf 18 -bf 2"
    VAL_CBR="20000k"
    OPT_COMMON="-c:v libx264 -b:v $VAL_CBR -minrate $VAL_CBR -maxrate $VAL_CBR -g 60"

    ffmpeg -i $IFILE -vf crop=1920:1088:0:16 $OPT_COMMON -acodec copy ${INFILE}.1.ts
    ffmpeg -i $IFILE -vf crop=1920:1088:1920:16 $OPT_COMMON -an ${INFILE}.2.ts
    ffmpeg -i $IFILE -vf crop=1920:1088:0:1104 $OPT_COMMON -an ${INFILE}.3.ts
    ffmpeg -i $IFILE -vf crop=1920:1088:1920:1104 $OPT_COMMON -an ${INFILE}.4.ts
1

There are 1 answers

0
nobody555 On BEST ANSWER

If you want to force fixed P/B pattern than you should disable B-frames adaptive algorithm and specify max consecutive B-frames number by using old style global options, for example "-b_strategy 0 -bf 2" for PBBPBBPBBP... pattern. If you also want also fixed I-frames intervals than you need to disable scenecut detection algorithm also, for example "-sc_threshold 0 -g 50" for fixed 50 frames interval between I-frames. With new enough ffmpeg you can also use private libx264 options using -x264opts or -x264-params params.

So for fully fixed frame types pattern you may use any of below command lines (they should be equal):

ffmpeg -i $INFILE -c:v libx264 -b:v $BITRATE -sc_threshold 0 -g 50 -b_strategy 0 -bf 2 $OUTFILE

or

ffmpeg -i $INFILE -c:v libx264 -b:v $BITRATE -x264-params scenecut=0:keyint=50:b-adapt=0:bframes=2 $OUTFILE