Answers.Body: <p>You'll have to manually set encoding parameters.</p>
  
  <pre><code>ffmpeg -i input.mkv -filter:v "pad=3840:2160:0:280,setsar=1" -crf 18 -preset faster -c:a copy my_output_video.mkv
  </code></pre>
  
  <p>The CRF option sets the tradeoff for size/quality. Lower values produce better quality but larger files. The preset will increase speed, but for same quality, the file size will be larger.</p>
  
  <p>The setsar filter has been added as a precaution in case your player reads the SAR stored in the file and stretches the video based on that value.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-09-03T07:56:45.743Z
Answers.LastActivityDate: 2018-09-03T07:56:45.743Z
Answers.UserDisplayName: Gyan
Answers.Body: <p>You can do transformations with <code>-c:v libx264 -crf 0</code> X264 has lossless mode, which it enters with <code>-crf 0</code>. They implemented real lossless video encoding, this is not widely known - but it works perfectly.</p>
  
  <p>I use it all the time.</p>
  
  <p>Be ready - it takes GBs - especially for videos of real-life (not graphics etc...)</p>
  
  <p>Doing screen recording for programs and graphis in <code>-crf 0</code> - is perfect - it compresses them really great and uses relatively small CPU power.</p>
  
  <p>You also can control compression complexity it uses, with the presets (<code>fast</code>, <code>veryslow</code> ... etc). And you also can recomress lossles into more compressed lossless.</p>
  
  <p>Everything for lossless is the same as for all x264's, except that it is the real lossless.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-10-12T19:39:52.580Z
Answers.Text: The OP intends to play the files on a TV, and most h/w or s/w decoders don't support Hi444 profile which is what `crf/qp 0` requires.
Answers.UserDisplayName: Gyan
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-10-13T23:11:48.293Z
Answers.Text: @Gyan Yep, what you say is true. Except I said "transformations". The idea I represent - person does not know how to play with lossless processing. He can develop workflow in lossless form in stages, and then all that can be moved into on-the-fly bulk processing into lossy.
  Also lossless can be directly compared. Like I had two days before. If input file has 11.8 GB, letterboxed file also would be 11.8 GB - you see right away that all information is preserved.
  & Lossless can always be encoded into lossy.
Answers.UserDisplayName: Anton Latukha
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-10-10T22:30:13.530Z
Answers.LastActivityDate: 2019-10-10T22:36:27.557Z
Answers.LastEditDate: 2019-10-10T22:36:27.557Z
Answers.UserDisplayName: Anton Latukha
Answers.Body: <h5>Here is my solution with explanation</h5>
  <pre><code>ffmpeg -i input.mkv -filter:v &quot;pad=3840:2160:0:280,setsar=1&quot; -c:a copy -c:v libx265 -x265-params lossless=1 my_output_video.mkv
  ----------111111111----------------2222-3333-4-555----------------------------------------------------------6666666666666666666
  
  Legend
  1 - input filename
  2 - Target X dimension
  3 - Target Y
  4 - Bar's target X pos. Best: Floor( (Target X - Current X) / 2) . If the value is 0, no vertical baps will be present.
  5 - Bar's target Y pos. Best: Floor( (Target Y - Current Y) / 2) . If the value is 0, no horizontal baps will be present.
  6 - output filename
  
  Notes
  -c:a copy is to maintain lossless-ness
  -x265-params lossless=1 option is for lossless encoding. Adding -crf 0 is not required.
  -c:v libx265 - added to reduce output video quality while maintaining lossless-ness
  Floor() - means to floor DOWN where applicable (ideally, no non-integer calculations occur)
  </code></pre>
  <p>My example command to add bars from 1660x780 to 1920x1080,</p>
  <pre><code>ffmpeg -i input.mp4 -filter:v &quot;pad=1920:1080:130:150,setsar=1&quot; -crf 0 -c:v libx265 -x265-params lossless=1 my_output_video.mp4
  </code></pre>
  <h5>Sources,</h5>
  <ul>
  <li><a href="https://video.stackexchange.com/a/24756">https://video.stackexchange.com/a/24756</a></li>
  <li><a href="https://video.stackexchange.com/a/28659">https://video.stackexchange.com/a/28659</a></li>
  <li><a href="http://underpop.online.fr/f/ffmpeg/help/pad.htm.gz" rel="nofollow noreferrer">http://underpop.online.fr/f/ffmpeg/help/pad.htm.gz</a></li>
  <li><a href="https://superuser.com/a/1667833">https://superuser.com/a/1667833</a></li>
  <li><a href="https://forum.videohelp.com/threads/382367-X265-Lossless-not-really-lossless-and-I-can-prove-it" rel="nofollow noreferrer">https://forum.videohelp.com/threads/382367-X265-Lossless-not-really-lossless-and-I-can-prove-it</a></li>
  <li><a href="https://trac.ffmpeg.org/wiki/Encode/H.265" rel="nofollow noreferrer">https://trac.ffmpeg.org/wiki/Encode/H.265</a></li>
  </ul>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-01-01T21:51:36.487Z
Answers.LastActivityDate: 2022-01-04T14:25:55.023Z
Answers.LastEditDate: 2022-01-04T14:25:55.023Z
Answers.UserDisplayName: TAbdiukov
Body: <p>I have a file of resolution 3840x1632, but my TV stretches the picture vertically to fill up all 2160 pixels of height.  Is it possible to use ffmpeg to add blank / black height, while preserving the video and audio quality?</p>
  
  <p>Tried doing this, which seemed to work (took about 2 hours, the same length of the video), but greatly reduced the file size/video quality):</p>
  
  <pre><code>ffmpeg -i input.mkv -filter:v "pad=3840:2160:0:280" -c:a copy my_output_video.mkv
  </code></pre>
  
  <p>Is there a switch to say "keep everything else the same"?</p>
  
  <p>Thank you!</p>
  
Tags: <ffmpeg><encoding><compression><lossless>
Title: Using ffmpeg to add height (as black bars) to video file without quality loss
UserDisplayName: Rosella
ThreadText: # Using ffmpeg to add height (as black bars) to video file without quality loss
  
  (Asked by: username_0 on 2018-09-03)
  
  I have a file of resolution 3840x1632, but my TV stretches the picture vertically to fill up all 2160 pixels of height. Is it possible to use ffmpeg to add blank / black height, while preserving the video and audio quality?
  
  Tried doing this, which seemed to work (took about 2 hours, the same length of the video), but greatly reduced the file size/video quality):
  
  ```
  ffmpeg -i input.mkv -filter:v "pad=3840:2160:0:280" -c:a copy my_output_video.mkv
  
  ```
  
  Is there a switch to say "keep everything else the same"?
  
  Thank you!
  
  **Tags:** ffmpeg, encoding, compression, lossless
  
  
  ---
  
  ## 3 answers
  
  ### Answer by username_1 on 2018-09-03. Score: 2
  
  You'll have to manually set encoding parameters.
  
  ```
  ffmpeg -i input.mkv -filter:v "pad=3840:2160:0:280,setsar=1" -crf 18 -preset faster -c:a copy my_output_video.mkv
  
  ```
  
  The CRF option sets the tradeoff for size/quality. Lower values produce better quality but larger files. The preset will increase speed, but for same quality, the file size will be larger.
  
  The setsar filter has been added as a precaution in case your player reads the SAR stored in the file and stretches the video based on that value.
  
  
  ---
  
  ### Answer by username_2 on 2019-10-10. Score: 1
  
  You can do transformations with `-c:v libx264 -crf 0` X264 has lossless mode, which it enters with `-crf 0`. They implemented real lossless video encoding, this is not widely known - but it works perfectly.
  
  I use it all the time.
  
  Be ready - it takes GBs - especially for videos of real-life (not graphics etc...)
  
  Doing screen recording for programs and graphis in `-crf 0` - is perfect - it compresses them really great and uses relatively small CPU power.
  
  You also can control compression complexity it uses, with the presets (`fast`, `veryslow` ... etc). And you also can recomress lossles into more compressed lossless.
  
  Everything for lossless is the same as for all x264's, except that it is the real lossless.
  
  > **Comments:**
  > **username_1**: The OP intends to play the files on a TV, and most h/w or s/w decoders don't support Hi444 profile which is what `crf/qp 0` requires.  
  > **username_2**: @username_1 Yep, what you say is true. Except I said "transformations". The idea I represent - person does not know how to play with lossless processing. He can develop workflow in lossless form in stages, and then all that can be moved into on-the-fly bulk processing into lossy. Also lossless can be directly compared. Like I had two days before. If input file has 11.8 GB, letterboxed file also would be 11.8 GB - you see right away that all information is preserved. & Lossless can always be encoded into lossy.  
  
  ---
  
  ### Answer by username_3 on 2022-01-01. Score: 0
  
  ##### Here is my solution with explanation
  
  ```
  ffmpeg -i input.mkv -filter:v "pad=3840:2160:0:280,setsar=1" -c:a copy -c:v libx265 -x265-params lossless=1 my_output_video.mkv
  ----------111111111----------------2222-3333-4-555----------------------------------------------------------6666666666666666666
  
  Legend
  1 - input filename
  2 - Target X dimension
  3 - Target Y
  4 - Bar's target X pos. Best: Floor( (Target X - Current X) / 2) . If the value is 0, no vertical baps will be present.
  5 - Bar's target Y pos. Best: Floor( (Target Y - Current Y) / 2) . If the value is 0, no horizontal baps will be present.
  6 - output filename
  
  Notes
  -c:a copy is to maintain lossless-ness
  -x265-params lossless=1 option is for lossless encoding. Adding -crf 0 is not required.
  -c:v libx265 - added to reduce output video quality while maintaining lossless-ness
  Floor() - means to floor DOWN where applicable (ideally, no non-integer calculations occur)
  
  ```
  
  My example command to add bars from 1660x780 to 1920x1080,
  
  ```
  ffmpeg -i input.mp4 -filter:v "pad=1920:1080:130:150,setsar=1" -crf 0 -c:v libx265 -x265-params lossless=1 my_output_video.mp4
  
  ```
  
  ##### Sources,
  
  * <https://video.stackexchange.com/a/24756>
  * <https://video.stackexchange.com/a/28659>
  * <http://underpop.online.fr/f/ffmpeg/help/pad.htm.gz>
  * <https://superuser.com/a/1667833>
  * <https://forum.videohelp.com/threads/382367-X265-Lossless-not-really-lossless-and-I-can-prove-it>
  * <https://trac.ffmpeg.org/wiki/Encode/H.265>
  
  
  ---
  
  