How much can I compress a video stream by?

I just went through this myself, here's my documentation when using a command-line script called ffmpeg. You can reduce by ~97% without loss in quality.

The method below compresses a video file, and repairs broken video indices. This makes it unnecessary to split videos at 3GB when recording large files. The output will be ~3% of the file size of the input. This is because it's using x265/HEVC encoding, which is a new type of encoding designed for 4k video, enabling much higher quality outputs at the same level of compression as h264.

This was tested using an input video generated with SpinView using mp4 encoding at 70% quality, and a CRF setting of 22. .

CRF settings for a 1280x1024 mouse video are below. Lower CRF settings are higher quality & less compressed videos, which also take longer to encode.

CRF 00: Lossless compression, ~20% file size reduction CRF 16: ~800 MB/hour CRF 22: ~250 MB/hour (higher quality, recommended for sLEAP/BORIS) CRF 28: ~100 MB/hour (standard compression for 4k video) CRF 34: ~ 50 MB/hour (visible compression artifacts)


1) Download FFmpeg, which is a very small footprint command line compression package, use the static build https://www.ffmpeg.org/download.html#build-windows

Extract the zipped download, and grab the ffmpeg file (~60 MB) and place it into the folder that contains the videos you'll be compressing.

2) Open a command line interface and cd into the current folder (on Windows, Shift+RClick the window background and select 'Open command window here', as seen here: https://youtu.be/MPV7JXTWPWI?t=242)

3) Paste the following into the command line, and replace 'input' with your file name, no quotes needed:

.\ffmpeg -i input -c:v libx265 -crf 22 -c:a copy output.mp4

For example: .\ffmpeg -i test.avi -c:v libx265 -crf 22 -c:a copy test.mp4

To increase quality if necessary, lower the crf from 22 to ~18 (0 is lossless), every 6 doubles the file size.

Further documentation here: https://trac.ffmpeg.org/wiki/Encode/H.265

For batch processing: (Windows:) ls | Where { $.Extension -eq ".avi" } | ForEach { .\ffmpeg -i $.FullName -c:v libx265 -crf 22 -c:a copy $_.Name.Replace(".avi", ".mp4") }

-- from Tomo --

(Batch processing in Linux/Mac:) for i in *.avi; do ffmpeg -i "$i" -crf 18 -c:a copy -pix_fmt yuv420p "${i%.*}.mp4"; done

-- from Tomo (end) --

https://stackoverflow.com/questions/5784661/how-do-you-convert-an-entire-directory-with-ffmpeg

Vertical/horizontal concatenate videos: https://stackoverflow.com/questions/11552565/vertically-or-horizontally-stack-mosaic-several-videos-using-ffmpeg

How to count exact number of frames: ffmpeg -i input.mp4 -map 0:v:0 -c copy -f null -

How to cut/trim specific range of frames and re-encode: (0-indexed)

ffmpeg -i input -vf trim=start_frame=n:end_frame=m -af atrim=start=s:end=t -fflags +genpts output

n and m are the frame numbers of the video in and out points. s and t are the timecodes for the corresponding audio.

/r/AskTechnology Thread