User Tools

Site Tools


doc:appunti:linux:video:ffmpeg_final_rendering

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
doc:appunti:linux:video:ffmpeg_final_rendering [2024/07/31 09:56] – niccolodoc:appunti:linux:video:ffmpeg_final_rendering [2026/11/20 10:28] (current) – [Pixel format considerations] niccolo
Line 11: Line 11:
 Our main source of videos is the Xiaomi Yi action camera, which records full HD videos **1920x1080 pixels** at a variable bitrate of **12.0 Mb/s**. So we re-encode the final montage with the following settings: Our main source of videos is the Xiaomi Yi action camera, which records full HD videos **1920x1080 pixels** at a variable bitrate of **12.0 Mb/s**. So we re-encode the final montage with the following settings:
  
-^ Video codec       | MPEG-4 AVC (x264)  | +^ Video codec       | MPEG-4 AVC (x264)  | 
-^ Video filter      | swresize, 1366x768, Bilinear  | +^ Video filter      | swresize, 1366x768, Bilinear  | 
-^ Basic x264        | Preset: **slow** (or less), Tuning: **film**, Profile: **High**, IDC Level: **Auto** | +^ Basic x264        | Preset: **slow** (or less), Tuning: **film**, Profile: **High**, IDC Level: **Auto** | 
-^ Video encoding    | Average Bitrate (Two Pass), Average Bitrate 4096 kb/s (about 1.8 Gb per hour)  | +^ Video encoding    | Average Bitrate (Two Pass), Average Bitrate 4096 kb/s (about 1.8 Gb per hour)  | 
-^ Pixel format      | Our source videos use **yuvj420p pixel format**, so we use the same for the final rendering (see the considerations below).  | +^ Pixel format      | Our source videos are reported to use the **yuvj420p** pixel format, which is a yuv420p with full-range color (J is for JPEG). Pixel format yuvj420p was deprecated by ffmpeg so we will use **yuv420p** instead, forcing the color range to **pc** (full) instead of the default //tv// (limited). The result, however, will be identified as yuvj420p, which creates a bit of confusion.  | 
-^ Bits per sample   | Our source videos use **8 bits per raw sample**, so we stay on this.  | +^ Bits per sample   | Our source videos use **8 bits per raw sample**, so we stay on this.  | 
-^ Color range       | We use the **full range** of colors. The **j** letter in the //yuvj420p// pixel format means that YUV values are stored as full 0-255 range (8 bits), as in JPEG. This is better than the so called //studio swing//, with Y in the 16-235 range and UV in the 16-240 range.  | +^ Color range       | We want to use the **full color** range, which means storing YUV values ​​in the full range 0-255 (8 bits). This can be achieved using the obsolete //yuvj420p// pixel format, where the //j// stands for JPEG, or alternatively using the options **%%-pix_fmt yuv420p -color_range pc%%**. The other limited color range, also called //tv// or //studio swing//, stores the Y value in the range 16-235 and UV in the range 16-240.  | 
-^ Audio codec       | <del>Lame MP3</del> Vorbis  | +^ Audio codec       | <del>Lame MP3</del> Vorbis  | 
-^ Audio bitrate     | CBR 192 (or higher)  |+^ Audio bitrate     | CBR 192 (or higher)  |
  
 We can use **Avidemux** to make the final rendering (re-encoding). For a **command line only** solution you can consider **ffmpeg** to perfomr the re-encoding and to make the merge (mux) all into a Matroska container. We can use **Avidemux** to make the final rendering (re-encoding). For a **command line only** solution you can consider **ffmpeg** to perfomr the re-encoding and to make the merge (mux) all into a Matroska container.
Line 34: Line 34:
     -metadata:s:a:1 title="Audio in presa diretta" \     -metadata:s:a:1 title="Audio in presa diretta" \
     -filter:v "scale=1366x768" -aspect "16:9" \     -filter:v "scale=1366x768" -aspect "16:9" \
-    -vcodec 'libx264' -pix_fmt 'yuvj420p' -preset 'veryslow' -tune 'film' -profile:v 'high' -level:v 5 \+    -vcodec 'libx264' \ 
 +        -pix_fmt 'yuv420p' -color_range 'pc' -preset 'veryslow' -tune 'film' \ 
 +        -profile:v 'high' -level:v 5 \
     -b:v 4M -maxrate:v 6M -bufsize:v 6M \     -b:v 4M -maxrate:v 6M -bufsize:v 6M \
     -acodec copy \     -acodec copy \
Line 57: Line 59:
 =====  Two pass encoding ===== =====  Two pass encoding =====
  
-Here it is a recipe of **two-pass encoding** from an high quality //master// produced with Olive Video Editor. The target video will be a **6 Mbit** stream, **1920x1080@30**. The profile level selected is **High@L4.1**, so that the video will play nicely with Kodi 19.4 on the Raspberry Pi 4:+Here it is a recipe of **two-pass encoding** from an high quality //master// produced with [[olive_editor_tools#export_media|Olive Video Editor]]. The target video will be a **6 Mbit** stream, **1920x1080@30**. The profile level selected is **High@L4.1**, so that the video will play nicely with Kodi 19.4 on the Raspberry Pi 4:
  
 <code bash> <code bash>
Line 64: Line 66:
     -i full32bit-veryslow-crf18-fullcolor.mkv \     -i full32bit-veryslow-crf18-fullcolor.mkv \
     -metadata title="$TITLE" -metadata:s:v:0 title="$TITLE" \     -metadata title="$TITLE" -metadata:s:v:0 title="$TITLE" \
-    -vcodec 'libx264' -pix_fmt 'yuvj420p' -preset 'veryslow' -tune 'film' \+    -vcodec 'libx264' -pix_fmt 'yuv420p' -color_range 'pc' -preset 'veryslow' -tune 'film' \
     -profile:v 'high' -level:v 4.1 \     -profile:v 'high' -level:v 4.1 \
     -b:v 6M -maxrate:v 9M -bufsize:v 18M \     -b:v 6M -maxrate:v 9M -bufsize:v 18M \
Line 75: Line 77:
     -i full32bit-veryslow-crf18-fullcolor.mkv \     -i full32bit-veryslow-crf18-fullcolor.mkv \
     -metadata title="$TITLE" -metadata:s:v:0 title="$TITLE" \     -metadata title="$TITLE" -metadata:s:v:0 title="$TITLE" \
-    -vcodec 'libx264' -pix_fmt 'yuvj420p' -preset 'veryslow' -tune 'film' \+    -vcodec 'libx264' -pix_fmt 'yuv420p' -color_range 'pc' -preset 'veryslow' -tune 'film' \
     -profile:v 'high' -level:v 4.1 \     -profile:v 'high' -level:v 4.1 \
     -b:v 6M -maxrate:v 9M -bufsize:v 18M \     -b:v 6M -maxrate:v 9M -bufsize:v 18M \
Line 88: Line 90:
 =====  Pixel format considerations ===== =====  Pixel format considerations =====
  
-We used the **yuvj420p pixel format**. What does it means?+We use the **yuv420p pixel format** with **full color range** (also called //pc color range//). What does it means?
  
-First of all consider the **420** code; this means tat for each matrix of 4x2 pixels the stream encode all the values for the luminance, only 2 values for the chrominance on the X axis and zero values for the chrominance on the Y axis. This figure explains clearly the 4:4:4, 4:2:2 and 4:2:0 subsampling methods:+First of all consider the **420** code; this means that for each matrix of 4x2 pixels the stream encode all the values for the luminance, only 2 values for the chrominance on the X axis and zero values for the chrominance on the Y axis. This figure explains clearly the 4:4:4, 4:2:2 and 4:2:0 subsampling methods:
  
 {{subsampling.png?400|Chroma Subsampling}} {{subsampling.png?400|Chroma Subsampling}}
  
-Is file size is not a concern, we might ask ourselves whether a pixel format with less loss of chroma information would be preferable. Obviously is useless to add more chroma information if the final rendering has the same resolution of the original video, but if we are **scaling down** the video resolution we may **retain chroma information** using a different pixel format.+If file size is not a concern, we might ask ourselves whether a pixel format with less loss of chroma information would be preferable. Obviously is useless to add more chroma information if the final rendering has the same resolution of the original video, but if we are **scaling down** the video resolution we may **retain chroma information** using a different pixel format.
  
 The fact is that **in movies 4:2:0 is almost lossless visually**, which is why it can be found used in Blu-ray discs and a lot of modern video cameras. There is virtually no advantage to using 4:4:4 for consuming video content. The fact is that **in movies 4:2:0 is almost lossless visually**, which is why it can be found used in Blu-ray discs and a lot of modern video cameras. There is virtually no advantage to using 4:4:4 for consuming video content.
doc/appunti/linux/video/ffmpeg_final_rendering.1722412612.txt.gz · Last modified: by niccolo