Script to reduce the size of video files using FFMPEG.
Idea of this script: https://coderunner.io/shrink-videos-with-ffmpeg-and-preserve-metadata/
- H.264:
- CRF (Constant Rate Factor). Basically translates as "try to keep this quality overall", and will use more or less bits at different parts of the video, depending on the content. (the bitrate is variable*).
- Output codec. Possible options are H.264 or H.265 codecs. When using H.265 video is reduced half of its size maintaining the same video quality.
- Rest of video properties. They are not modified.
- Videos with different codecs:
- They are copied to another folder without being modified
- Install Python (3.7 version recommended)
- [Optional] Configure virtualenv:
- Install virtual env:
python3.7 -m venv venv
- Activate it:
source venv/bin/activate
- Install virtual env:
- Install FFmpeg and add it to system PATH
- Install FFprobe (This is installed on ffmpeg installation by default)
- Look at script options:
python main.py -h
- Execute it:
python main.py [VIDEOS_FOLDER] [--ANOTHER_OPTIONS]
You can create an isolated Python environment to install required libraries with virtualenv:
- Create a virtualenv:
python -m venv [VENV_FOLDER]
- Activate virtualenv:
source [VENV_FOLDER]/bin/activate
Original video metadata will be copied to the new modified video:
- Container metadata. All the original container metadata is copied using ffmpeg
-map_metadata
option - FILE dates. Access and modification file dates.
What happens if I have h.264 videos and another videos which use different codecs in the same folder?
Non-h.264 videos will be copied to the destination_folder/other_codecs by default without being modified
That video will be copied to the failures
folder so that you can analyze why later
http://download.das-werkstatt.com/pb/mthk/info/video/comparison_video_codecs_containers.html
-
Different methods to compare video quality after modifying videos https://superuser.com/questions/338725/compare-two-video-files-to-find-out-which-has-best-quality
-
Compare video quality with FFMPEG https://github.com/stoyanovgeorge/ffmpeg/wiki/How-to-Compare-Video
https://trac.ffmpeg.org/wiki/Encode/H.264
https://slhck.info/video/2017/02/24/crf-guide.html https://slhck.info/video/2017/03/01/rate-control.html
https://github.com/stoyanovgeorge/ffmpeg/wiki/Variable-Frame-Rate
Using ffmpeg: ffmpeg -i [VIDEO] -vf vfrdet -f null -
Result example:
[Parsed_vfrdet_0 @ 0x56518fa3f380] VFR:0.400005 (15185/22777) min: 1801 max: 3604)
A non-zero value for VFR indicates a VFR stream. The first value in brackets (15185) is the number of frames with a duration different than the expected duration implied by the detected frame rate of the stream. The 2nd value (22777) is number of frames having the expected duration. The VFR value (0.400005) is the ratio of the first number to the sum of both.
If there were frames with variable delta, than it will also show min and max delta encountered.