1
votes

I am trying to generate a periodic intra refresh h264 stream with only P frames using ffmpeg and x264 but I always get an I frame at the start.

Is there a way with x264 to create a P frame only stream?

Commands I am using:

ffmpeg -f lavfi -re -i testsrc=duration=5:size=1920x1080:rate=30000/1001 -s 1920x1080 -pix_fmt yuv420p -f rawvideo out.yuv
x264 --input-res 1920x1080 --intra-refresh out.yuv --b-pyramid none -b 0 --ref 0  -o out.264

Verification:

    ffprobe -show_frames out.264 |grep pict_type=I

Or just looking at the x264 output e.g.

yuv [info]: 1920x1080p 0:0 @ 25/1 fps (cfr)
x264 [info]: using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX FMA3 BMI2 AVX2
x264 [info]: profile High, level 4.0, 4:2:0, 8-bit
x264 [info]: frame I:1     Avg QP:13.63  size: 12189
x264 [info]: frame P:149   Avg QP:13.59  size:   874
x264 [info]: mb I  I16..4: 78.7% 18.6%  2.7%
x264 [info]: mb P  I16..4:  2.3%  0.1%  0.0%  P16..4:  3.2%  0.3%  0.0%  0.0%  0.0%    skip:94.1%
x264 [info]: 8x8 transform intra:7.6% inter:91.5%
x264 [info]: coded y,uvDC,uvAC intra: 1.3% 18.9% 3.6% inter: 0.1% 1.1% 0.1%
x264 [info]: i16 v,h,dc,p: 86%  6%  1%  7%
x264 [info]: i8 v,h,dc,ddl,ddr,vr,hd,vl,hu: 42% 22% 36%  0%  0%  0%  0%  0%  0%
x264 [info]: i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 29% 30% 32%  3%  1%  3%  0%  3%  0%
x264 [info]: i8c dc,h,v,p: 28%  7% 55%  9%
x264 [info]: Weighted P-Frames: Y:0.0% UV:0.0%
x264 [info]: kb/s:189.96

encoded 150 frames, 66.76 fps, 189.96 kb/s
1
Are you expecting the first frame to be dependent on future frames?Gyan
If you mean decoding the first full frame then yes. The sample I am trying to recreate is from a broadcast feed and it looks like it relies entirely on the intra P slices and recovery points before it can deliver a full frameAndrew
If you start decoding of your stream from middle and not from the start than it also wouldn't have IDR-frames (like in broadcast feed example, in which you also connect in the middle of stream).nobody555
x264 will emit output starting with a I-slice. I suggest you streamcopy the output using ffmpeg but set -ss X and -copyinkf so that the I-frame is not copied.Gyan

1 Answers

0
votes

Thanks to @Gyan and @nobody555 this works:

ffmpeg -f lavfi -re -i testsrc=duration=60:size=1920x1080:rate=30000/1001 -s 1920x1080 -pix_fmt yuv420p -f rawvideo -|x264 --input-res 1920x1080 --intra-refresh -o - -|ffmpeg -r "30000/1001" -fflags +genpts -i - -c copy -movflags frag_keyframe+empty_moov -f mp4 -|ffmpeg -i - -ss 200ms -c copy -f mpegts out.ts -y