Skip to content

Instantly share code, notes, and snippets.

@r-aamir
Last active September 4, 2022 17:09
Show Gist options
  • Save r-aamir/d1c89f589d120da75686223ad3c9f056 to your computer and use it in GitHub Desktop.
Save r-aamir/d1c89f589d120da75686223ad3c9f056 to your computer and use it in GitHub Desktop.
A benchmark of ffmpeg libx264 encoding with a range of CRF and presets
#!/bin/bash
infile="Test-15s.mov"
datafile="Test-15s.csv"
crfs=("18" "19" "20" "21" "22" "23" "24" "25" "26" "27")
presets=("ultrafast" "superfast" "veryfast" "faster" "fast" "medium" "slow" "slower" "veryslow")
echo 'CRF,Preset,Time (Secs),Size (MB)' >> "$datafile"
for crf in "${crfs[@]}"; do
for preset in "${presets[@]}"; do
outfile=Out_CRF_"$crf"_Preset_"$preset".mp4
time_start=$(date +%s)
ffmpeg -i "$infile" -map 0 -c copy -c:v libx264 -crf "$crf" -preset "$preset" "$outfile"
time_end=$(date +%s)
# Dividing by 1 forces the scale to be used.
time=$(echo "scale = 2; ($time_end - $time_start)/1" | bc)
size_bytes=$(ls -l "$outfile" | awk '{ print $5 }')
size_mb=$(echo "scale = 2; $size_bytes / 1000000" | bc)
echo $crf,$preset,$time,$size_mb >> "$datafile"
done
done
@r-aamir
Copy link
Author

r-aamir commented Oct 30, 2021

Download the file

  • make it executable chmod 700 ffmpeg-libx264
  • can double click to run the script file
  • can also run script from terminal ./ffmpeg-libx264

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment