meta data for this page
Differences
This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
linux:multimedia:movie [2016/08/18 11:25] niziak [Examples] |
linux:multimedia:movie [2021/02/07 11:21] (current) niziak |
||
---|---|---|---|
Line 1: | Line 1: | ||
+ | ====== Movie ====== | ||
- | ==== mpeg2 ==== | + | ===== Extract frames ===== |
+ | * Extract keyframes | ||
+ | * **-hide_banner** we are using this parameter to hide ffmpeg compilation information | ||
+ | * **-vsync vfr**: This is a parameter that tells the filter to use a variable bitrate video synchronization. If we do not use this parameter ffmpeg will fail to find only the keyframes and shoud extract other frames that can be not processed correctly. | ||
+ | <code bash>ffmpeg -i VIDEO0068.mp4 -vf "select=eq(pict_type\,I)" -vsync vfr thumb%04d.bmp -hide_banner</code> | ||
+ | * Extract one frame per second | ||
+ | <code bash>ffmpeg -i video.webm -vf fps=1 thumb%04d.jpg -hide_banner</code> | ||
+ | * Extract one frame per 10 seconds | ||
+ | <code bash>ffmpeg -i video.webm -vf fps=1/10 thumb%04d.jpg -hide_banner</code> | ||
+ | * Extract with different quality / to bmp | ||
+ | <code bash>ffmpeg -i video.webm -vf fps=1 -quality 90 thumb%04d.jpg -hide_banner</code> | ||
+ | <code bash>ffmpeg -i video.webm -vf fps=1 thumb%04d.bmp -hide_banner</code> | ||
+ | * Extract only one frame | ||
+ | <code bash>ffmpeg -i video.webm -ss 00:00:07.000 -vframes 1 thumb.jpg</code> | ||
+ | |||
+ | ===== Chroma subsampling ===== | ||
+ | [[https://en.wikipedia.org/wiki/Chroma_subsampling]] | ||
+ | {{ :linux:multimedia:sampling.jpg?200|}} | ||
+ | {{ :linux:multimedia:316-f6-chroma-subsampling-secondary_1.png?200|}} | ||
+ | * j:a:b - j - horizontal sampling reference (usually 4). **a** number of chroma samples (Cr, Cb) in the first row of **j** pixels. **b** number of changes of chroma samples between firs and second row of **j** pixels. | ||
+ | * 4:4:4 - (H265, H264) - no chroma subsampling - for every 4 pixels of luma, there are 4 pixels of colour | ||
+ | * 4:2:2 - 50Mbit - (H264) for every 4 pixels of luma, there are 2 pixels of colour. Keying can produce bad edges. | ||
+ | * 4:2:0 - 35MBit - (DVD, DV, JPEG, MPEG1, Blueray) - only alternatign lines are sampled for chroma. Chroma vertical resolution is halved. | ||
+ | |||
+ | |||
+ | ===== Stabilisation ===== | ||
+ | |||
+ | ==== To remove Little shaking in 1-pass ==== | ||
+ | |||
+ | <code bash>ffmpeg -threads 8 -i $1 -vf deshake -c:a copy -c:v utvideo yuv420p $1-deshake.mkv</code> | ||
+ | NOTE: No multithreading. | ||
+ | |||
+ | ==== To completely process shaky video in 2-pass| ==== | ||
+ | |||
+ | FFMpeg already contains plugins **vidstabdetect** and **vidstabtransform** [[http://public.hronopik.de/vid.stab/download.php]]. | ||
+ | But latest version (supports multithreading) can be downloaded as statically linked binary from: [[https://www.johnvansickle.com/ffmpeg/]] | ||
+ | |||
+ | <code bash> | ||
+ | ffmpeg -i $1 -vf vidstabdetect=shakiness=10:accuracy=15:result="tracefile.trf":show=1 -c:a copy -c:v utvideo ${PIX_FMT} ${OFILE}-vidstab1.mkv | ||
+ | ffmpeg -i $1 -vf vidstabtransform=input="tracefile.trf" -c:a copy -c:v utvideo ${PIX_FMT} ${OFILE}-vidstab2.mkv | ||
+ | </code> | ||
+ | NOTE: output from pass1 is also written as video to see motion vectors. | ||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | ===== Lossless ===== | ||
+ | |||
+ | Use UT Video codec as better alternative to HUFYUV: [[https://en.wikipedia.org/wiki/Ut_Video_Codec_Suite]] | ||
+ | * Download for Windows: https://www.videohelp.com/software/Ut-Video-Codec-Suite | ||
+ | * Supported by ffmpeg | ||
+ | <code bash>ffmpeg -i $1 -vf deshake -c:a copy -c:v utvideo -pix_fmt yuv422p $1-deshake.mkv</code> | ||
+ | |||
+ | Comparison of file size: | ||
+ | ^ pixfmt ^ huffyuv ^ utvideo ^ | ||
+ | | 444p | | 4104M | | ||
+ | | 422p | 4077M | 3204M | | ||
+ | | 420p | | 2556M | | ||
+ | |||
+ | The same video encoded using **utvideo** @422p is 78% of **huffyuv**. | ||
+ | ===== MPEG2 ===== | ||
Highest quality (qscale 4-5 is far enough) | Highest quality (qscale 4-5 is far enough) | ||
<code>-c:v mpeg2video -qscale:v 2</code> | <code>-c:v mpeg2video -qscale:v 2</code> | ||
+ | ==== DVD ==== | ||
+ | DVD's VOBS can be simply concatenated to one big file: | ||
+ | <code bash>cat ./VIDEO_TS/*.VOB | ffmpeg -i - <out_name>.<out_format></code> | ||
- | ==== H.264 params ==== | + | <code bash> |
+ | #!/bin/bash -eu | ||
+ | |||
+ | VOBS="" | ||
+ | while read VOB; do | ||
+ | echo ${VOB} | ||
+ | if [ -n "${VOBS}" ]; then | ||
+ | VOBS="${VOBS}|" | ||
+ | fi | ||
+ | VOBS="${VOBS}${VOB}" | ||
+ | done < <(ls -1 *.VOB) | ||
+ | |||
+ | ffmpeg -i "concat:${VOBS}" -map 0:0 -map 0:1 -map 0:2 -c copy out.ts | ||
+ | </code> | ||
+ | More: [[https://newspaint.wordpress.com/2016/07/27/ripping-a-video-from-dvd-using-ffmpeg/]] | ||
+ | |||
+ | |||
+ | ===== H.264 params ===== | ||
CRF (Constant Rate Factor), 0..51 (0-lossless) | CRF (Constant Rate Factor), 0..51 (0-lossless) | ||
* 17..23 very good, no blocking efect during fast movement | * 17..23 very good, no blocking efect during fast movement | ||
Line 12: | Line 94: | ||
<code>-c:v libx264 -b:v 1024k</code> | <code>-c:v libx264 -b:v 1024k</code> | ||
- | ==== FFMpeg params ==== | + | ===== FFMpeg params ===== |
2.5Mbps bitrate with tolerance 300k | 2.5Mbps bitrate with tolerance 300k | ||
<code>-b 2500k -bt 300k</code> | <code>-b 2500k -bt 300k</code> | ||
- | === Resize === | + | ==== Resize ==== |
to half of size (using video filter [[https://ffmpeg.org/ffmpeg-filters.html#scale]] | to half of size (using video filter [[https://ffmpeg.org/ffmpeg-filters.html#scale]] | ||
<code>-vf scale=w=iw/2:h=ih/2</code> | <code>-vf scale=w=iw/2:h=ih/2</code> | ||
- | === Audio recompress === | + | ==== Audio recompress ==== |
1 channel audio (mono), audio quality 7 [[https://trac.ffmpeg.org/wiki/Encode/MP3]] | 1 channel audio (mono), audio quality 7 [[https://trac.ffmpeg.org/wiki/Encode/MP3]] | ||
<code>-ac 1 -c:a libmp3lame -q:a 7</code> | <code>-ac 1 -c:a libmp3lame -q:a 7</code> | ||
- | ==== Examples ==== | + | ===== Examples ===== |
- | === Change container === | + | ==== Change container ==== |
<code>ffmpeg -i input.ts -vcodec copy -sameq -acodec copy -f matroska output.ts</code> | <code>ffmpeg -i input.ts -vcodec copy -sameq -acodec copy -f matroska output.ts</code> | ||
- | === Copy video and compress audio === | + | ==== Copy video and compress audio ==== |
Create mono mp3 audio stream: | Create mono mp3 audio stream: | ||
<code bash>ffmpeg -i input_file.avi -c:v copy -ac 1 -c:a libmp3lame -q:a 7 output.avi</code> | <code bash>ffmpeg -i input_file.avi -c:v copy -ac 1 -c:a libmp3lame -q:a 7 output.avi</code> | ||
- | === Recompress === | + | ==== Remove audio ==== |
+ | <code bash>ffmpeg -i example.mkv -c copy -an example-nosound.mkv</code> | ||
+ | |||
+ | ==== Recompress ==== | ||
<code> | <code> | ||
ffmpeg -i input.mp4 -b 1000000 output.mp4 | ffmpeg -i input.mp4 -b 1000000 output.mp4 | ||
Line 46: | Line 131: | ||
<code>cpulimit -z -e ffmpeg -l 150</code> | <code>cpulimit -z -e ffmpeg -l 150</code> | ||
- | === Cut === | + | ==== Cut ==== |
Cut input from 11:20 to 1:45:50: | Cut input from 11:20 to 1:45:50: | ||
Line 70: | Line 155: | ||
Copy chosen streams and resize to 50%, recompress video stream: | Copy chosen streams and resize to 50%, recompress video stream: | ||
- | <code>ffmpeg -i test.ts -to 5:47 -map 0:0 -map0:1 -map 0:4 -c copy -c:v libx264 -crf 25 -vf scale=w=iw/2:h=ih/2 cut.mkv</code> | + | <code bash>ffmpeg -i test.ts -to 5:47 -map 0:0 -map0:1 -map 0:4 -c copy -c:v libx264 -crf 25 -vf scale=w=iw/2:h=ih/2 cut.mkv</code> |
+ | ==== Deinterlace ==== | ||
+ | <code bash> ffmpeg -i test.ts -vf yadif -vcodec ... -acodec ... test.mp4</code> | ||
vidia | vidia | ||
Line 78: | Line 165: | ||
https://www.maketecheasier.com/convert-video-to-mp4-handbrake-linux/ | https://www.maketecheasier.com/convert-video-to-mp4-handbrake-linux/ | ||
+ | ===== Issues ===== | ||
+ | * **deprecated pixel format used, make sure you did set range correctly** | ||
+ | * when using **yuv420p** pixel format | ||