Answers.Body: <p>I was able to produce the same size as Youtube by varying the <code>qp</code> option for x264. The value that worked to approximately the same size was qp=20.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2023-01-24T16:44:02.107Z
Answers.LastActivityDate: 2023-01-24T16:44:02.107Z
Answers.UserDisplayName: er0
Body: <p>I am unable to re-encode an H.264 video that I downloaded from Youtube back to its original size. The MediaInfo is pasted below. The size of the video stream is 20 MB.</p>
  <p>I decoded the video into raw YUV (using ffmpeg and JM separately, ensuring that I get an identical file). Then I re-encoded it using the x264 library with a variety of configs. The encoded H.264 videos that I generated are around 40 MB in size.</p>
  <p>This is the commandline that I used:
  <code>x264 -o out.h264 --input-res 1280x720 --preset slow autl.yuv</code></p>
  <p>Any ideas on what options I might be missing that YouTube would have used to encode the video?</p>
  <p>Mediainfo:</p>
  <pre><code>General
  Complete name                            : autl.h264
  Format                                   : AVC
  Format/Info                              : Advanced Video Codec
  File size                                : 19.9 MiB
  Writing library                          : x264 core 155 r2901 7d0ff22
  
  Video
  Format                                   : AVC
  Format/Info                              : Advanced Video Codec
  Format profile                           : Main@L3.1
  Format settings                          : CABAC / 3 Ref Frames
  Format settings, CABAC                   : Yes
  Format settings, Reference frames        : 3 frames
  Width                                    : 1 280 pixels
  Height                                   : 720 pixels
  Display aspect ratio                     : 16:9
  Frame rate mode                          : Variable
  Color space                              : YUV
  Chroma subsampling                       : 4:2:0
  Bit depth                                : 8 bits
  Scan type                                : Progressive
  Writing library                          : x264 core 155 r2901 7d0ff22
  Color range                              : Limited
  Color primaries                          : BT.709
  Transfer characteristics                 : BT.709
  Matrix coefficients                      : BT.709
  </code></pre>
  
Tags: <encoding><youtube><h.264><libx264><x264>
Title: Encoding to the same H.264 size as YouTube
UserDisplayName: er0
ThreadText: # Encoding to the same H.264 size as YouTube
  
  (Asked by: username_0 on 2023-01-23)
  
  I am unable to re-encode an H.264 video that I downloaded from Youtube back to its original size. The MediaInfo is pasted below. The size of the video stream is 20 MB.
  
  I decoded the video into raw YUV (using ffmpeg and JM separately, ensuring that I get an identical file). Then I re-encoded it using the x264 library with a variety of configs. The encoded H.264 videos that I generated are around 40 MB in size.
  
  This is the commandline that I used:
  `x264 -o out.h264 --input-res 1280x720 --preset slow autl.yuv`
  
  Any ideas on what options I might be missing that YouTube would have used to encode the video?
  
  Mediainfo:
  
  ```
  General
  Complete name                            : autl.h264
  Format                                   : AVC
  Format/Info                              : Advanced Video Codec
  File size                                : 19.9 MiB
  Writing library                          : x264 core 155 r2901 7d0ff22
  
  Video
  Format                                   : AVC
  Format/Info                              : Advanced Video Codec
  Format profile                           : Main@L3.1
  Format settings                          : CABAC / 3 Ref Frames
  Format settings, CABAC                   : Yes
  Format settings, Reference frames        : 3 frames
  Width                                    : 1 280 pixels
  Height                                   : 720 pixels
  Display aspect ratio                     : 16:9
  Frame rate mode                          : Variable
  Color space                              : YUV
  Chroma subsampling                       : 4:2:0
  Bit depth                                : 8 bits
  Scan type                                : Progressive
  Writing library                          : x264 core 155 r2901 7d0ff22
  Color range                              : Limited
  Color primaries                          : BT.709
  Transfer characteristics                 : BT.709
  Matrix coefficients                      : BT.709
  
  ```
  
  **Tags:** encoding, youtube, h.264, libx264, x264
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_0 on 2023-01-24. Score: 1 | Accepted answer
  
  I was able to produce the same size as Youtube by varying the `qp` option for x264. The value that worked to approximately the same size was qp=20.
  
  
  ---
  
  