Skip to content

Instantly share code, notes, and snippets.

@ultramango
Created February 18, 2018 14:53
Show Gist options
  • Save ultramango/5aefbc0655c530d8e971d4efc4ecc5ea to your computer and use it in GitHub Desktop.
Save ultramango/5aefbc0655c530d8e971d4efc4ecc5ea to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
# Create test video
# Arguments:
# 1 - video size (in pixels, optional)
# 2 - duration (in seconds, optional)
# 3 - frame rate (fps, optional)
# 4 - no sound (0 - sound /default/, 1 - no sound)
# Returns:
# test file full path
create_test_video() {
local videoformat="mp4" # hardcoded for the moment
# Default parameter: https://stackoverflow.com/questions/9332802/how-to-write-a-bash-script-that-takes-optional-input-arguments
local videosize=${1:-"3840x1920"} # Other video size: 2560x1280
local duration=${2:-"1"}
local framerate=${3:-"29.97"}
local nosound=${4:-"0"}
local filename=$(mktemp --suffix=.${videoformat}) # Mind the dot (extension)
# Well... we assume it will not fail
local soundopt=""
if [ ${nosound} -eq 0 ]; then
soundopt="-f lavfi -i sine=frequency=1000:sample_rate=48000:duration=${duration}"
fi
ffmpeg -loglevel quiet -y -f lavfi -i testsrc=duration=${duration}:size=${videosize}:rate=30 ${soundopt} -f ${videoformat} ${filename}
echo "${filename}"
}
echo "Creating test video..."
testvideo=$(create_test_video "3840x1920")
# csv file
test_output="test_result.csv"
echo "quality,file_size" > $test_output
# Check quality parameter
for ((i=1; i<=35; i++))
do
echo "Quality parameter (lower is better, valid: 2-31): $i"
frames_dir="frames_q$i"
mkdir -p $frames_dir
ffmpeg -y -i $testvideo -q:v $i $frames_dir/image%05d.jpg > /dev/null 2>&1
file_size=$(stat --printf="%s" $frames_dir/image00001.jpg)
echo "$i,$file_size" >> $test_output
rm -rf $frames_dir
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment