Answers.Body: <p>Most video encoders apply temporal compression i.e. most frames only store the difference in image content relative to other frames, thus saving storage space, while a few frames store the whole image. The frames with whole pictures are called key frames since they are required in order to reconstruct the whole picture of frames which only store differences. IDR frame in H264 stream denotes a keyframe.</p>
  
  <p>Your code tells ffmpeg to generate a H264 video stream using the x264 encoder, and the options below are used by the encoder to decide keyframe placement.</p>
  
  <pre><code>-x264opts "keyint=24:min-keyint=24:no-scenecut"
  </code></pre>
  
  <p><code>keyint=24</code> tells x264 to forcibly generate a keyframe 24 frames after the last keyframe.</p>
  
  <p><code>min-keyint=24</code> sets the minimum keyframe distance. The encoder may decide to place a keyframe on its own even if <code>keyint</code> # of frames haven't elapsed if it comes across an image which is more efficient to store as a complete picture rather than as a set of differences. <code>min-keyint</code> tells the encoder to never do this if the distance isn't at least <code>24</code>. Since in this case keyint is the same value as min-keyint, all KFs will be 24 frames apart.</p>
  
  <p><code>no-scenecut</code> - scenecut is the value used by the encoder to calculate if it should force a keyframe if min-keyint allows it to. It can range from 0-100. <code>no-scenecut</code> tells the encoder to skip this evaluation.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-03-02T14:33:45.817Z
Answers.Text: What is the point of having `no-scenecut` when `keyint` = `min-keyint`? Aren’t they equivalent?
Answers.UserDisplayName: Géry Ogam
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-03-02T14:49:56.133Z
Answers.Text: From what I remember, it saves the frame comparison analysis effort.
Answers.UserDisplayName: Gyan
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-05-27T15:38:03.560Z
Answers.Text: In my case the command above returns instantly. Any idea?
Answers.UserDisplayName: user1315621
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-08-20T10:24:52.133Z
Answers.LastActivityDate: 2018-08-20T10:24:52.133Z
Answers.UserDisplayName: Gyan
Answers.Body: <blockquote>
  <p>What is the point of having no-scenecut when keyint = min-keyint</p>
  </blockquote>
  <p>There is the code in x264 (validate_parameters function):</p>
  <pre><code>if( h-&gt;param.i_keyint_min == X264_KEYINT_MIN_AUTO )
      h-&gt;param.i_keyint_min = X264_MIN( h-&gt;param.i_keyint_max / 10, (int)fps );
  </code></pre>
  <p>It will disallow equality of the keyint and keyint_min.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-11-18T14:55:03.167Z
Answers.Text: That's correct, but the piece of code you copied is not the relevant one. The line that performs the clipping is [this one](https://github.com/mirror/x264/blob/b093bbe7d9bc642c8f24067cbdcc73bb43562eab/encoder/encoder.c#LL1111C5-L1111C95): `h->param.i_keyint_min = x264_clip3( h->param.i_keyint_min, 1, h->param.i_keyint_max/2+1 );`
Answers.UserDisplayName: mcont
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-01-05T20:02:03.230Z
Answers.LastActivityDate: 2022-01-05T20:02:03.230Z
Answers.UserDisplayName: misterx527
Answers.Body: <p>The frames in your H.264 video are grouped into units called <code>GOP</code>s (Group Of Pictures). Inside these <code>GOP</code>s frames are classified into three types:</p>
  
  <ul>
  <li><code>I-frame</code>: frame that stores the whole picture</li>
  <li><code>P-frame</code>: frame that stores only the changes between the current picture and previous ones</li>
  <li><code>B-frame</code>: frame that stores differences with previous or future pictures</li>
  </ul>
  
  <p>Additionally, I-frames can be classified as <code>IDR</code> frames and <code>non-IDR</code> frames. The difference is that frames following an <code>IDR</code> frame cannot reference any frame that comes before the <code>IDR</code> frame, while in the case of a <code>non-IDR</code> frame there are no limitations.</p>
  
  <p>Every <code>GOP</code> starts with an I-frame, also called a <code>keyframe</code>, but may contain <em>more than one</em>. To create further confusion, a <code>GOP</code> can start with an <code>IDR</code> frame <em>or</em> with a <code>non-IDR</code> frame. This means that frames in the <code>GOP</code> can sometimes refer to previous <code>GOP</code>s (in this case the <code>GOP</code> is said to be "open"), and sometimes not (in this case it's closed).</p>
  
  <p>It's common to see the structure of a <code>GOP</code> represented as in this example: <code>IBBBPBBBPBBBI</code>. Here the length of the the <code>GOP</code> is 12 frames, with 3 B-frames between each P-frame.</p>
  
  <p>Now your questions:</p>
  
  <ul>
  <li><code>keyint</code> specifies the <em>maximum</em> length of the <code>GOP</code>, so the maximum interval between each keyframe, which remember that can be either an IDR frame or a non-IDR frame. I'm not completely sure but I think that by default ffmpeg will require every I-frame to be an IDR frame, so in practice you can use the terms IDR frame and I-frame interchangeably</li>
  <li><code>min-keyint</code> specifies the <em>minimum</em> length of the <code>GOP</code>. This is because the encoder might decide that it makes sense to add a keyframe before the <code>keyint</code> value, so you can put a limit </li>
  <li><code>no-scenecut</code>. When the encoder determines that there's been a scene cut, it may decide to insert an additional I-frame. The issue is that I-frames are very expensive if compared to other frame types, so when encoding for streaming you want to disable it.</li>
  </ul>
  
  <p>A couple of other related parameters:</p>
  
  <ul>
  <li><code>bframes</code> specifies the number of consecutive B-frames</li>
  <li><code>ref</code> specifies the number of references frames that are used when encoding. It means that when encoding a picture, <code>ref</code> previous frames are looked at for encoding the current frame</li>
  </ul>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-08-20T19:25:28.813Z
Answers.Text: In the OP's command, these are x264 options, so keyint and min-keyint relate to IDR placement, not non-RAP I frames.
Answers.UserDisplayName: Gyan
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-08-20T20:46:02.357Z
Answers.Text: Thanks for the amazing response... I have learnt so much.
Answers.UserDisplayName: George
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-08-20T20:48:52.447Z
Answers.Text: My question now is how did you learn all of these, how do I learn too?
Answers.UserDisplayName: George
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-10-14T12:57:00.820Z
Answers.Text: I wish i could give more votes to this one. Amazing answer and very informative. Thank you.
Answers.UserDisplayName: Somebody
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-08-20T17:31:24.727Z
Answers.LastActivityDate: 2018-08-20T17:31:24.727Z
Answers.UserDisplayName: mcont
Body: <p>I am absolutely new to video processing, I am building a video streaming site and worked with ffmpeg to generate the formats I need for ShakaPackager.</p>
  
  <p>Sadly I don't understand some of the options being provided, especially <code>keyInt</code>, <code>min-keyint</code> and <code>no-scenecut</code>.</p>
  
  <p>Below you will find the code I use to generate the required formats for my videos.</p>
  
  <pre><code>ffmpeg -y -i ${1} -c:a aac -ac 2 -ab 256k -ar 48000 -c:v libx264 -x264opts "keyint=24:min-keyint=24:no-scenecut" -b:v 1500k -maxrate 1500k -bufsize 1000k -vf "scale=-2:720" "${2}/${3}720.mp4"
  </code></pre>
  
  <p>I did a bit of research and they talked about <code>IDR-frames</code> I don't even understand those, maybe my needs go way more than that?</p>
  
Tags: <video><ffmpeg><audio>
Title: What is KeyInt and min-keyint and no-scenecut
UserDisplayName: George
ThreadText: # What is KeyInt and min-keyint and no-scenecut
  
  (Asked by: username_0 on 2018-08-20)
  
  I am absolutely new to video processing, I am building a video streaming site and worked with ffmpeg to generate the formats I need for ShakaPackager.
  
  Sadly I don't understand some of the options being provided, especially `keyInt`, `min-keyint` and `no-scenecut`.
  
  Below you will find the code I use to generate the required formats for my videos.
  
  ```
  ffmpeg -y -i ${1} -c:a aac -ac 2 -ab 256k -ar 48000 -c:v libx264 -x264opts "keyint=24:min-keyint=24:no-scenecut" -b:v 1500k -maxrate 1500k -bufsize 1000k -vf "scale=-2:720" "${2}/${3}720.mp4"
  
  ```
  
  I did a bit of research and they talked about `IDR-frames` I don't even understand those, maybe my needs go way more than that?
  
  **Tags:** video, ffmpeg, audio
  
  
  ---
  
  ## 3 answers
  
  ### Answer by username_5 on 2018-08-20. Score: 32 | Accepted answer
  
  The frames in your H.264 video are grouped into units called `GOP`s (Group Of Pictures). Inside these `GOP`s frames are classified into three types:
  
  * `I-frame`: frame that stores the whole picture
  * `P-frame`: frame that stores only the changes between the current picture and previous ones
  * `B-frame`: frame that stores differences with previous or future pictures
  
  Additionally, I-frames can be classified as `IDR` frames and `non-IDR` frames. The difference is that frames following an `IDR` frame cannot reference any frame that comes before the `IDR` frame, while in the case of a `non-IDR` frame there are no limitations.
  
  Every `GOP` starts with an I-frame, also called a `keyframe`, but may contain *more than one*. To create further confusion, a `GOP` can start with an `IDR` frame *or* with a `non-IDR` frame. This means that frames in the `GOP` can sometimes refer to previous `GOP`s (in this case the `GOP` is said to be "open"), and sometimes not (in this case it's closed).
  
  It's common to see the structure of a `GOP` represented as in this example: `IBBBPBBBPBBBI`. Here the length of the the `GOP` is 12 frames, with 3 B-frames between each P-frame.
  
  Now your questions:
  
  * `keyint` specifies the *maximum* length of the `GOP`, so the maximum interval between each keyframe, which remember that can be either an IDR frame or a non-IDR frame. I'm not completely sure but I think that by default ffmpeg will require every I-frame to be an IDR frame, so in practice you can use the terms IDR frame and I-frame interchangeably
  * `min-keyint` specifies the *minimum* length of the `GOP`. This is because the encoder might decide that it makes sense to add a keyframe before the `keyint` value, so you can put a limit
  * `no-scenecut`. When the encoder determines that there's been a scene cut, it may decide to insert an additional I-frame. The issue is that I-frames are very expensive if compared to other frame types, so when encoding for streaming you want to disable it.
  
  A couple of other related parameters:
  
  * `bframes` specifies the number of consecutive B-frames
  * `ref` specifies the number of references frames that are used when encoding. It means that when encoding a picture, `ref` previous frames are looked at for encoding the current frame
  
  > **Comments:**
  > **username_1**: In the OP's command, these are x264 options, so keyint and min-keyint relate to IDR placement, not non-RAP I frames.  
  > **username_0**: Thanks for the amazing response... I have learnt so much.  
  > **username_0**: My question now is how did you learn all of these, how do I learn too?  
  > **username_6**: I wish i could give more votes to this one. Amazing answer and very informative. Thank you.  
  
  ---
  
  ### Answer by username_1 on 2018-08-20. Score: 7
  
  Most video encoders apply temporal compression i.e. most frames only store the difference in image content relative to other frames, thus saving storage space, while a few frames store the whole image. The frames with whole pictures are called key frames since they are required in order to reconstruct the whole picture of frames which only store differences. IDR frame in H264 stream denotes a keyframe.
  
  Your code tells ffmpeg to generate a H264 video stream using the x264 encoder, and the options below are used by the encoder to decide keyframe placement.
  
  ```
  -x264opts "keyint=24:min-keyint=24:no-scenecut"
  
  ```
  
  `keyint=24` tells x264 to forcibly generate a keyframe 24 frames after the last keyframe.
  
  `min-keyint=24` sets the minimum keyframe distance. The encoder may decide to place a keyframe on its own even if `keyint` # of frames haven't elapsed if it comes across an image which is more efficient to store as a complete picture rather than as a set of differences. `min-keyint` tells the encoder to never do this if the distance isn't at least `24`. Since in this case keyint is the same value as min-keyint, all KFs will be 24 frames apart.
  
  `no-scenecut` - scenecut is the value used by the encoder to calculate if it should force a keyframe if min-keyint allows it to. It can range from 0-100. `no-scenecut` tells the encoder to skip this evaluation.
  
  > **Comments:**
  > **username_2**: What is the point of having `no-scenecut` when `keyint` = `min-keyint`? Aren’t they equivalent?  
  > **username_1**: From what I remember, it saves the frame comparison analysis effort.  
  > **username_3**: In my case the command above returns instantly. Any idea?  
  
  ---
  
  ### Answer by username_4 on 2022-01-05. Score: 0
  
  > What is the point of having no-scenecut when keyint = min-keyint
  
  There is the code in x264 (validate\_parameters function):
  
  ```
  if( h->param.i_keyint_min == X264_KEYINT_MIN_AUTO )
      h->param.i_keyint_min = X264_MIN( h->param.i_keyint_max / 10, (int)fps );
  
  ```
  
  It will disallow equality of the keyint and keyint\_min.
  
  > **Comments:**
  > **username_5**: That's correct, but the piece of code you copied is not the relevant one. The line that performs the clipping is [this one](https://github.com/mirror/x264/blob/b093bbe7d9bc642c8f24067cbdcc73bb43562eab/encoder/encoder.c#LL1111C5-L1111C95): `h->param.i_keyint_min = x264_clip3( h->param.i_keyint_min, 1, h->param.i_keyint_max/2+1 );`  
  
  ---
  
  