Answers.Body: <p>The default encoder for mpegts is mpeg2video (producing a H.262 bitstream). This is an ancient encoder for an ancient codec and it is not capable of supporting a 1k or 0.5k video. Even modern codecs with significantly better compression ratios cannot get this low at 15fps. MPEG2 is also not optimized for low bitrate in the first place.</p>
  <p>The output files have the same size because it is overshooting your target bitrate. If you want to set a hard limit then you have to add <code>-maxrate</code> and <code>-bufsize</code> in addition to <code>-b:v</code>. But you'll be disappointed. The encoder isn't able to do anything with such a low bitrate. If you force a hard upper limit you will see:</p>
  <pre><code>cropbox:~$ ffmpeg -v error -f lavfi -i &quot;testsrc2=s=640x360:r=15&quot; -c:v mpeg2video -b:v 500 -maxrate 500 -bufsize 1000 -f null -
  [mpeg2video @ 0x5b52cea9ec80] rc buffer underflow
  [mpeg2video @ 0x5b52cea9ec80] max bitrate possibly too small or try trellis with large lmax or increase qmax
  [mpeg2video @ 0x5b52cea9ec80] rc buffer underflow
  [mpeg2video @ 0x5b52cea9ec80] max bitrate possibly too small or try trellis with large lmax or increase qmax
  [mpeg2video @ 0x5b52cea9ec80] rc buffer underflow
  [mpeg2video @ 0x5b52cea9ec80] max bitrate possibly too small or try trellis with large lmax or increase qmax
  [mpeg2video @ 0x5b52cea9ec80] rc buffer underflow
  [mpeg2video @ 0x5b52cea9ec80] max bitrate possibly too small or try trellis with large lmax or increase qmax
  ...
  </code></pre>
  <p>Encoders aren't able to make anything useful from such a low bitrate, even modern ones. You can see the difference yourself by running these test commands (top left to bottom right: original 640x360@15 test sample, AVC, HEVC, AV1, all with a 1 second open GOP and 40kbps CBR):</p>
  <pre><code>ffmpeg -f lavfi -i &quot;testsrc2=640x360:r=15:d=30&quot; -c:v libx264 -x264-params &quot;vbv-bufsize=40:vbv-maxrate=40:open-gop=1:keyint=15&quot; avc.mkv
  ffmpeg -f lavfi -i &quot;testsrc2=640x360:r=15:d=30&quot; -c:v libx265 -x265-params &quot;strict-cbr=1:bitrate=40:vbv-bufsize=40:keyint=15&quot; hevc.mkv
  ffmpeg -f lavfi -i &quot;testsrc2=640x360:r=15:d=30&quot; -c:v libsvtav1 -svtav1-params &quot;rc=2:tbr=40:pred-struct=1:irefresh-type=1:keyint=15&quot; av1.mkv
  ffplay -f lavfi -i &quot;testsrc2=640x360:r=15:d=30,pad=iw+4:ih+4[orig];movie=avc.mkv,pad=iw+4:ih+4[avc];movie=hevc.mkv,pad=iw+4:ih+4[hevc];movie=av1.mkv,pad=iw+4:ih+4[av1];[orig][avc][hevc][av1]xstack=4:grid=2x2,fps=15[out0]&quot;
  </code></pre>
  <p>If this looks so horrible even with advanced modern formats, how could an ancient format like MPEG2 <em>possibly</em> operate at 80 times lower bitrate than any of these were using?</p>
  <p>Even when encoding a 640x360@15 pure black image, none of those encoders were able to get below 2kbps (and mpeg2video requires 62kbps for that!). As Gyan said in a comment, the overhead of the syntax elements alone is probably higher than 1kbps.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2024-05-05T03:35:43.943Z
Answers.LastActivityDate: 2024-05-05T09:03:30.037Z
Answers.LastEditDate: 2024-05-05T09:03:30.037Z
Answers.UserDisplayName: veppy
Body: <p>I am trying to lower the bitrate of a video using ffmpeg to 1000 bits/s and 500 bits/s using the commands</p>
  <pre><code>ffmpeg -i __temp__.mp4  -vf &quot;scale=-2:360&quot; -b:v 1000 out_1000.ts
  ffmpeg -i __temp__.mp4  -vf &quot;scale=-2:360&quot; -b:v 500 out_500.ts
  </code></pre>
  <p>but the output files seem to have the same size:</p>
  <pre><code>-rw-rw-r-- 1 alex alex 8160140 Nov  2 13:11 out_1000.ts
  -rw-rw-r-- 1 alex alex 8160140 Nov  2 13:11 out_500.ts
  </code></pre>
  <ul>
  <li>Size of original video: 8344903</li>
  <li>Framerate: 15 fps</li>
  </ul>
  <p>What is going on?</p>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2023-11-02T16:09:26.957Z
Comments.Text: 1000 bits/s is absurdly low - maybe not even enough to form all the syntax elements of a coded bitstream. Maybe you meant `1000k`.
Comments.UserDisplayName: Gyan
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2023-11-03T06:29:25.027Z
Comments.Text: Yes I know it is low. I meant 1000, not 1000k.
Comments.UserDisplayName: Alex
Tags: <ffmpeg>
Title: Why does setting the bitrate with ffmpeg has no affect on the filesize?
UserDisplayName: Alex
ThreadText: # Why does setting the bitrate with ffmpeg has no affect on the filesize?
  
  (Asked by: username_0 on 2023-11-02)
  
  I am trying to lower the bitrate of a video using ffmpeg to 1000 bits/s and 500 bits/s using the commands
  
  ```
  ffmpeg -i __temp__.mp4  -vf "scale=-2:360" -b:v 1000 out_1000.ts
  ffmpeg -i __temp__.mp4  -vf "scale=-2:360" -b:v 500 out_500.ts
  
  ```
  
  but the output files seem to have the same size:
  
  ```
  -rw-rw-r-- 1 username_0 username_0 8160140 Nov  2 13:11 out_1000.ts
  -rw-rw-r-- 1 username_0 username_0 8160140 Nov  2 13:11 out_500.ts
  
  ```
  
  * Size of original video: 8344903
  * Framerate: 15 fps
  
  What is going on?
  
  **Tags:** ffmpeg
  
  > **Comments:**
  > **username_1**: 1000 bits/s is absurdly low - maybe not even enough to form all the syntax elements of a coded bitstream. Maybe you meant `1000k`.  
  > **username_0**: Yes I know it is low. I meant 1000, not 1000k.  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_2 on 2024-05-05. Score: 1
  
  The default encoder for mpegts is mpeg2video (producing a H.262 bitstream). This is an ancient encoder for an ancient codec and it is not capable of supporting a 1k or 0.5k video. Even modern codecs with significantly better compression ratios cannot get this low at 15fps. MPEG2 is also not optimized for low bitrate in the first place.
  
  The output files have the same size because it is overshooting your target bitrate. If you want to set a hard limit then you have to add `-maxrate` and `-bufsize` in addition to `-b:v`. But you'll be disappointed. The encoder isn't able to do anything with such a low bitrate. If you force a hard upper limit you will see:
  
  ```
  cropbox:~$ ffmpeg -v error -f lavfi -i "testsrc2=s=640x360:r=15" -c:v mpeg2video -b:v 500 -maxrate 500 -bufsize 1000 -f null -
  [mpeg2video @ 0x5b52cea9ec80] rc buffer underflow
  [mpeg2video @ 0x5b52cea9ec80] max bitrate possibly too small or try trellis with large lmax or increase qmax
  [mpeg2video @ 0x5b52cea9ec80] rc buffer underflow
  [mpeg2video @ 0x5b52cea9ec80] max bitrate possibly too small or try trellis with large lmax or increase qmax
  [mpeg2video @ 0x5b52cea9ec80] rc buffer underflow
  [mpeg2video @ 0x5b52cea9ec80] max bitrate possibly too small or try trellis with large lmax or increase qmax
  [mpeg2video @ 0x5b52cea9ec80] rc buffer underflow
  [mpeg2video @ 0x5b52cea9ec80] max bitrate possibly too small or try trellis with large lmax or increase qmax
  ...
  
  ```
  
  Encoders aren't able to make anything useful from such a low bitrate, even modern ones. You can see the difference yourself by running these test commands (top left to bottom right: original 640x360@15 test sample, AVC, HEVC, AV1, all with a 1 second open GOP and 40kbps CBR):
  
  ```
  ffmpeg -f lavfi -i "testsrc2=640x360:r=15:d=30" -c:v libx264 -x264-params "vbv-bufsize=40:vbv-maxrate=40:open-gop=1:keyint=15" avc.mkv
  ffmpeg -f lavfi -i "testsrc2=640x360:r=15:d=30" -c:v libx265 -x265-params "strict-cbr=1:bitrate=40:vbv-bufsize=40:keyint=15" hevc.mkv
  ffmpeg -f lavfi -i "testsrc2=640x360:r=15:d=30" -c:v libsvtav1 -svtav1-params "rc=2:tbr=40:pred-struct=1:irefresh-type=1:keyint=15" av1.mkv
  ffplay -f lavfi -i "testsrc2=640x360:r=15:d=30,pad=iw+4:ih+4[orig];movie=avc.mkv,pad=iw+4:ih+4[avc];movie=hevc.mkv,pad=iw+4:ih+4[hevc];movie=av1.mkv,pad=iw+4:ih+4[av1];[orig][avc][hevc][av1]xstack=4:grid=2x2,fps=15[out0]"
  
  ```
  
  If this looks so horrible even with advanced modern formats, how could an ancient format like MPEG2 *possibly* operate at 80 times lower bitrate than any of these were using?
  
  Even when encoding a 640x360@15 pure black image, none of those encoders were able to get below 2kbps (and mpeg2video requires 62kbps for that!). As username_1 said in a comment, the overhead of the syntax elements alone is probably higher than 1kbps.
  
  
  ---
  
  