Body: <p>I transcoding mpeg2 data to h264 via libx264 codec and need to create the following GOP structure:</p>
  
  <blockquote>
    <p>I(IDR) P I P</p>
  </blockquote>
  
  <p>I try to perform it with the following command:</p>
  
  <blockquote>
    <p>ffmpeg -i INPUT -vcodec libx264 -g 4 -bf 0 -refs 1 -acodec copy 
    OUT.mpg</p>
  </blockquote>
  
  <p>Check results via ffprobe:</p>
  
  <blockquote>
    <p>ffprobe -i OUT.mpg -show_entries frame=key_frame,pict_type
    -select_streams v -of compact=p=0</p>
  </blockquote>
  
  <p>And received the following output:</p>
  
  <blockquote>
    <p>key_frame=1|pict_type=I<br> key_frame=0|pict_type=P<br>
    key_frame=0|pict_type=P <br> key_frame=0|pict_type=P<br></p>
  </blockquote>
  
  <p>As you can see the GOP structure is:</p>
  
  <blockquote>
    <p>I(IDR) P P P</p>
  </blockquote>
  
  <p>I think -refs 1 key has no effect. <br>
  Please explain how correct transcode it to necessary GOP I(IDR)PIP ?</p>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2017-02-01T11:24:29.410Z
Comments.Text: You may have to use x264 standalone encoder with qpfile option.
Comments.UserDisplayName: Gyan
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2017-02-01T17:07:18.333Z
Comments.Text: `-refs 1`  means use (at most) 1 reference frame. P frames can reference P frames, so it will not affect GOP structure. You do set the GOP structure to 4 `-g 4` and get a 4 frame GOP. So I'm not sure if i"m understanding the issue since `-g 2` should be obvious.
Comments.UserDisplayName: SlimSCSI
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2017-02-01T20:00:21.230Z
Comments.Text: Thanks to All for answers and explanations. But with -g 2. All I-frames will be IDR and we will receive I(IDR) P structure, but necessary structure is I(IDR) P I P. The third I-frame shouldn't be IDR.
Comments.UserDisplayName: Ivan Kolesnikov
Tags: <ffmpeg><transcoding><h.264><gop>
Title: FFmpeg transcoding libx264 set only one P-frame
UserDisplayName: Ivan Kolesnikov
ThreadText: # FFmpeg transcoding libx264 set only one P-frame
  
  (Asked by: username_0 on 2017-02-01)
  
  I transcoding mpeg2 data to h264 via libx264 codec and need to create the following GOP structure:
  
  > I(IDR) P I P
  
  I try to perform it with the following command:
  
  > ffmpeg -i INPUT -vcodec libx264 -g 4 -bf 0 -refs 1 -acodec copy
  > OUT.mpg
  
  Check results via ffprobe:
  
  > ffprobe -i OUT.mpg -show\_entries frame=key\_frame,pict\_type
  > -select\_streams v -of compact=p=0
  
  And received the following output:
  
  > key\_frame=1|pict\_type=I  
  >  key\_frame=0|pict\_type=P  
  > key\_frame=0|pict\_type=P   
  >  key\_frame=0|pict\_type=P
  
  As you can see the GOP structure is:
  
  > I(IDR) P P P
  
  I think -refs 1 key has no effect.   
  Please explain how correct transcode it to necessary GOP I(IDR)PIP ?
  
  **Tags:** ffmpeg, transcoding, h.264, gop
  
  > **Comments:**
  > **username_1**: You may have to use x264 standalone encoder with qpfile option.  
  > **username_2**: `-refs 1`  means use (at most) 1 reference frame. P frames can reference P frames, so it will not affect GOP structure. You do set the GOP structure to 4 `-g 4` and get a 4 frame GOP. So I'm not sure if i"m understanding the issue since `-g 2` should be obvious.  
  > **username_0**: Thanks to All for answers and explanations. But with -g 2. All I-frames will be IDR and we will receive I(IDR) P structure, but necessary structure is I(IDR) P I P. The third I-frame shouldn't be IDR.  
  
  ---
  
  ## 0 answers
  
  