doc:appunti:linux:video:ffmpeg_final_rendering
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| doc:appunti:linux:video:ffmpeg_final_rendering [2024/07/31 09:53] – [Two pass encoding] niccolo | doc: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 |
| - | ^ Video filter | + | ^ Video filter |
| - | ^ Basic x264 | Preset: **slow** (or less), Tuning: **film**, Profile: **High**, IDC Level: **Auto** | | + | ^ Basic x264 |
| - | ^ Video encoding | + | ^ Video encoding |
| - | ^ Pixel format | + | ^ Pixel format |
| - | ^ Bits per sample | + | ^ Bits per sample |
| - | ^ Color range | We use the **full | + | ^ Color range |
| - | ^ Audio codec | < | + | ^ Audio codec |
| - | ^ Audio bitrate | + | ^ Audio bitrate |
| 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: | -metadata: | ||
| -filter:v " | -filter:v " | ||
| - | -vcodec ' | + | -vcodec ' |
| + | | ||
| + | | ||
| -b:v 4M -maxrate:v 6M -bufsize:v 6M \ | -b:v 4M -maxrate:v 6M -bufsize:v 6M \ | ||
| -acodec copy \ | -acodec copy \ | ||
| Line 41: | Line 43: | ||
| Notice that we selected a target bitrate of **4 Mbps** and a maximum bitrate of **6 Mbps**. Sepcifying both the //bitrate// and the //max bitrate tolerance// requires also to specify a //buffer size//; '' | Notice that we selected a target bitrate of **4 Mbps** and a maximum bitrate of **6 Mbps**. Sepcifying both the //bitrate// and the //max bitrate tolerance// requires also to specify a //buffer size//; '' | ||
| + | |||
| + | ===== A warning about the H.264 profile level ===== | ||
| + | |||
| + | It turned out that **Kodi 19.4** (running on a Raspberry Pi 4 with **Raspbian GNU/Linux 11 Bullseye** o.s.) has some problems playing H.264 video files depending on the video format profile used for the encoding. The video actually starts to play, but nothing is seen on the screen; sometimes the screen goes totally green. Similarly a **Google TV** with Kodi 21.0 has problems with the same files, showing stuttering and video artifacts. | ||
| + | |||
| + | Here it is a table of playing capabilities based on experimental testing: | ||
| + | |||
| + | ^ Format profile | ||
| + | | High@L5 | ||
| + | | High@L4 | ||
| + | | High@L4.1 | ||
| + | | High@5 | ||
| + | | High@5 | ||
| ===== 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# |
| <code bash> | <code bash> | ||
| Line 51: | Line 66: | ||
| -i full32bit-veryslow-crf18-fullcolor.mkv \ | -i full32bit-veryslow-crf18-fullcolor.mkv \ | ||
| -metadata title=" | -metadata title=" | ||
| - | -vcodec ' | + | -vcodec ' |
| -profile:v ' | -profile:v ' | ||
| -b:v 6M -maxrate:v 9M -bufsize:v 18M \ | -b:v 6M -maxrate:v 9M -bufsize:v 18M \ | ||
| Line 58: | Line 73: | ||
| -pass 1 \ | -pass 1 \ | ||
| -f matroska -y /dev/null | -f matroska -y /dev/null | ||
| + | # First pass produces two files: ffmpeg2pass-0.log and ffmpeg2pass-0.log.mbtree. | ||
| ffmpeg \ | ffmpeg \ | ||
| -i full32bit-veryslow-crf18-fullcolor.mkv \ | -i full32bit-veryslow-crf18-fullcolor.mkv \ | ||
| -metadata title=" | -metadata title=" | ||
| - | -vcodec ' | + | -vcodec ' |
| -profile:v ' | -profile:v ' | ||
| -b:v 6M -maxrate:v 9M -bufsize:v 18M \ | -b:v 6M -maxrate:v 9M -bufsize:v 18M \ | ||
| Line 71: | Line 86: | ||
| </ | </ | ||
| - | The transcoding works on the video only, suppressing any audio stream (**%%-an%%** option). Using the **keyint=64** option will produce a keyframe every 64 frame (about | + | The transcoding works on the video only, suppressing any audio stream (**%%-an%%** option). Using the **keyint=64** option will produce a keyframe every 64 frames |
| - | + | ||
| - | ===== A warning about the H.264 profile level ===== | + | |
| - | + | ||
| - | It turned out that **Kodi 19.4** (running on a Raspberry Pi 4 with **Raspbian GNU/Linux 11 Bullseye** o.s.) has some problems playing H.264 video files depending on the video format profile used for the encoding. The video actually starts to play, but nothing is seen on the screen; sometimes the screen goes totally green. Similarly a **Google TV** with Kodi 21.0 has problems with the same files, showing stuttering and video artifacts. | + | |
| - | + | ||
| - | Here it is a table of playing capabilities based on experimental testing: | + | |
| - | + | ||
| - | ^ Format profile | + | |
| - | | High@L5 | + | |
| - | | High@L4 | + | |
| - | | High@L4.1 | + | |
| - | | High@5 | + | |
| - | | High@5 | + | |
| ===== Pixel format considerations ===== | ===== Pixel format considerations ===== | ||
| - | We used the **yuvj420p | + | We use the **yuv420p |
| - | 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? | {{subsampling.png? | ||
| - | 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.1722412417.txt.gz · Last modified: by niccolo
