meta data for this page
  •  

This is an old revision of the document!


H.264 params

CRF (Constant Rate Factor), 0..51 (0-lossless)

  • 17..23 very good, no blocking efect during fast movement
  • 23 - default

FFMpeg params

Resize

to half of size (using video filter https://ffmpeg.org/ffmpeg-filters.html#scale

-vf scale=w=iw/2:h=ih/2

Examples

Change container

ffmpeg -i input.ts -vcodec copy -sameq -acodec copy -f matroska output.ts

Recompress

ffmpeg -i input.mp4 -b 1000000 output.mp4
ffmpeg -i input.mp4 -vcodec libx264 -crf 20 output.mp4

ffmpeg -i input.mp4 -c:v libx264 -crf 23 output.mp4
ffmpeg -i input.ts -c:a copy -c:v libx264 -crf 18 -preset veryfast NL.mp4

Limit CPU usage to 150% (2 CPUs)

cpulimit -z -e ffmpeg -l 150

Cut

Cut input from 11:20 to 1:45:50:

Example below (option order -i and -ss) will decode input from beginning frame by frame and starts processing at 11:20 and stops at 1:45:50.

ffmpeg -i input.mp4 -ss 11:20 -to 1:45:50 -c:a copy -c:v copy  output.mp4

Next example (option order -ss and then -i) will seek to position 11:20 using keyframes and start processing for 1:34:30.

ffmpeg -ss 11:20 -i input.mp4 -to 1:34:30 -c:a copy -c:v copy  output.mp4

This is faster solution.

In both examples video codes is “copy” so seeking works using I-frames, so there is no speed difference. Additionally with “copy”, it is possibilty to select time range without keyframes, so only audio will be copied and video will start from next valid key frame.

Copy chosen streams:

ffmpeg -i test.ts -to 5:47 -map 0:0 -map0:1 -map 0:4 -c copy cut.mkv

Copy chosen streams and recompress video stream:

ffmpeg -i test.ts -to 5:47 -map 0:0 -map0:1 -map 0:4 -c copy -c:v libx264 -crf 25 cut.mkv

Copy chosen streams and resize to 50%, recompress video stream:

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

vidia

https://www.maketecheasier.com/convert-video-to-mp4-handbrake-linux/