doc:appunti:linux:video:ffmpeg
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 [2019/11/27 10:41] – [AVC (x264) is better than ASP (xvid4)] niccolo | doc:appunti:linux:video:ffmpeg [2024/07/25 08:12] (current) – [AVC (x264) is better than ASP (xvid4)] niccolo | ||
|---|---|---|---|
| Line 264: | Line 264: | ||
| </ | </ | ||
| - | ====== Final rendering (re-encoding) ====== | ||
| - | The video stream recorded by the Xiaomi Yi camera is **1920x1080 pixels** at a variable bitrate of **12.0 Mb/s**. Because we watch it on a simple TV set capable only of 1366x768 pixels, we we re-encode it with the following settings: | + | ====== Re-encoding |
| - | ^ Video codec | MPEG-4 AVC (x264) | + | We had some video clips recorded with an **SJCAM Sj8 Pro** camera with a **bad color balance and saturation** due some bad tables [[..:..:hardware: |
| - | ^ Video filter | + | |
| - | ^ Basic x264 | Preset: | + | |
| - | ^ Video encoding | + | |
| - | ^ Audio codec | Lame MP3 | | + | |
| - | ^ Audio bitrate | + | |
| - | We can use **Avidemux** to make the final rendering (re-encoding). For a **comman line only** solution you can consider ffmpeg to perfomr the re-encoding and **mkvmerge** (contained into the **mkvtoolnix** Debian package) to merge all into a Matroska container. | + | The video clips were **extracted from the original MP4 container** as **[[wp> |
| - | ==== AVC (x264) is better than ASP (xvid4) ==== | + | <code bash> |
| + | #!/bin/sh | ||
| + | # | ||
| + | # Re-encode video clips in MPEG transport stream (MPEG-TS) format applying | ||
| + | # some saturation and gamma correction. | ||
| + | # | ||
| + | # saturation: | ||
| + | # gamma_{r|g|b} | ||
| + | |||
| + | INPUT=" | ||
| + | OUTPUT=" | ||
| + | EQ_FILTER=" | ||
| + | |||
| + | # Produces MPEG segments like the ones produced by the SJCAM SJ8Pro: | ||
| + | ffmpeg -i " | ||
| + | -vf " | ||
| + | -codec:v libx264 \ | ||
| + | -preset veryslow -profile:v main -level:v 4.2 -pix_fmt yuvj420p \ | ||
| + | -x264-params ' | ||
| + | -keyint_min 8 -brand avc1 -f 3gp \ | ||
| + | -bsf:v h264_mp4toannexb -f mpegts \ | ||
| + | " | ||
| + | </ | ||
| + | |||
| + | The gamma correction for the three RGB channels was determined with the GIMP, using the //Colors// => //Levels// => //Pick the gray point for all channels// tool. The use of MPEG-TS clips allowed the montage of the final video by just concatenating them. | ||
| + | |||
| + | ===== AVC (x264) is better than ASP (xvid4) | ||
| See this page: **[[https:// | See this page: **[[https:// | ||
| Line 293: | Line 313: | ||
| * **Tuning**: Use the **film** option for real life scenes. | * **Tuning**: Use the **film** option for real life scenes. | ||
| * **Profile**: | * **Profile**: | ||
| - | * **IDC Level**: Leave this parameter to **Auto**, setting it to higer values does not increase the quality, but impose | + | * **IDC Level**: Leave this parameter to **Auto**, setting it to higer values does not increase the video quality, but imposes |
| ====== More on ffmpeg Command Line ====== | ====== More on ffmpeg Command Line ====== | ||
| Line 385: | Line 405: | ||
| </ | </ | ||
| - | the CSV format can be controlled by several options, e.g. if you want to know the key for each filed use: | + | the CSV format can be controlled by several options, e.g. if you want to print each field as a **key=val** pair, use: |
| < | < | ||
| Line 471: | Line 491: | ||
| </ | </ | ||
| + | ====== Problem in MKV Remux ====== | ||
| - | ====== Doppiaggio | + | It seems there is a bug in ffmpeg **[[https:// |
| - | Per doppiare un video sostitutendo o mixando l' | + | This was the first try command line: |
| - | + | ||
| - | Per alcuni suggerimenti vedere il paragrafo sull' | + | |
| - | ===== Estrazione traccia audio originale ===== | + | |
| - | + | ||
| - | La traccia audio originale verrà usata come riferimento per allineare i brani musicali da abbinare al video. | + | |
| - | + | ||
| - | **ATTENZIONE** alla conversione del file in formato WAV: controllare con '' | + | |
| < | < | ||
| - | ffmpeg -i video.mp4 -vn -c:a copy audio.m4a | + | # The resulting video is broken. |
| - | ffmpeg | + | ffmpeg -i input_file1.mkv -i input_file2.mkv \ |
| + | | ||
| + | -map ' | ||
| + | | ||
| + | output_file.mkv | ||
| </ | </ | ||
| - | ===== Conversione dei brani audio ===== | + | The workaround was to extract each individual stream, and mux then together: |
| - | + | ||
| - | Per importare in Ardour i brani musicali vanno convertiti in WAV quelli non direttamente supportati (es. i file MP3 e le tracce M4A solitamente estratte dai video MP4). Per questo si può utilizzare **sox** (dall' | + | |
| < | < | ||
| - | sox file.mp3 file.wav | + | ffmpeg -i input_file1.mkv -map 0:v:0 -codec:v copy input-v_env.mkv |
| + | ffmpeg -i input_file1.mkv -map 0:a:0 -codec:a copy input-a_ita.mkv | ||
| + | ffmpeg -i input_file2.mkv -map 0:a:0 -codec:a copy input-a_eng.mkv | ||
| + | ffmpeg -i input_file2.mkv -map 0:s:0 -codec:s copy input-s_eng.mkv | ||
| + | ffmpeg \ | ||
| + | -i input-v_env.mkv \ | ||
| + | -i input-a_ita.mkv \ | ||
| + | -i input-a_eng.mkv \ | ||
| + | -i input-s_eng.mkv \ | ||
| + | -codec:v copy -codec:a copy -codec:s copy \ | ||
| + | -map ' | ||
| + | output_file.mkv | ||
| </ | </ | ||
| - | ===== Manipolazione | + | ====== ffmpeg: leggere la sequenza |
| - | Con Ardour si inizia un **nuovo progetto**, impostare **48 kHz, 32 bit float, stereo**, che sono i parametri che vanno per la maggiore nei video MP4 in alta risoluzione. Quando il progetto | + | Nella directory |
| - | Con Ardour si **importano** le varie **tracce musicali** (menu //Session// => //Import//). Conviene scegliere il **mapping one track per file**, altrimenti il canale destro e sinistro vengono importati | + | In teoria è sufficiente concatenare i file in un solo file destinazione e quindi trattarlo come un normale file audio/video. Tuttavia è possibile indicare i singoli |
| - | Attenzione al **fader** di ogni traccia: se per caso viene spostato con il mouse, fare **Ctrl-click** per resettarlo al **valore predefinito di 0 dB**. | + | <code bash> |
| + | SOURCE=" | ||
| + | ffmpeg | ||
| + | </ | ||
| - | {{..:ardour: | + | ====== ffmpeg: impostare un ritardo sui sottotitoli durante il muxing ====== |
| - | Ogni **traccia** può essere manipolata separatamente | + | Se un flusso di sottotitoli |
| - | === Spostare === | + | <code bash> |
| + | ffmpeg -i video-stream.mkv -i audio-stream.mkv -itsoffset 44.5 -i subtitles-stream.mkv ... | ||
| + | </ | ||
| - | === Tagliare un pezzo === | + | In generale dovrebbe essere possibile scoprire l' |
| - | * Strumento forbici | + | < |
| - | * Zoom opportuno | + | [mpeg @ 0x55f98bb2c6c0] New subtitle stream 0:7 at pos: |
| - | * Click sul punto: taglia immediatamente la traccia | + | </code> |
| - | * Strumento selezione, click sul pezzo da togliere, menu //Region// => //Remove// | + | |
| - | === Bloccare una singola regione | + | ====== Parameters for final rendering ====== |
| - | | + | See the page **[[ffmpeg_final_rendering]]**. |
| - | === Fade in/ | + | ====== |
| - | + | ||
| - | * Con lo strumento "Grab mode" cliccare una regione | + | |
| - | * Trascinare il quadretto che appare all' | + | |
| - | + | ||
| - | === | + | |
| - | * //Session// => //Export// => //Export to Audio File(s)// | + | Vedere la pagina dedicata: **[[ardour_dubbing]]**. |
| - | * **File formats**: impostare **WAV 16 bit, 48 KHz**. Eventualmente si può abilitare il **Normalize**, | + | |
| - | * **Time Span**: Controllare che sia pari alla lunghezza originale. Se c'è qualcosa di troppo aggiustare il tag **end** nella barra **Location markers**. | + | |
| - | * **Channels**: | + | |
doc/appunti/linux/video/ffmpeg.1574847664.txt.gz · Last modified: by niccolo
