#!/bin/sh # This needs a short video file (test.mp4), it will decode it to # raw video (warning: this will use A LOT of disk space!) then # it will try to encode it with a variety of codecs, to compare # their speed, CPU usage, and overall efficiency. # I wrote this script when I was trying to find out what would # be a good "mezzanine codec" to transfer 1080p/30fps video over # gigabit Ethernet as efficiently as possible, where "efficiency" # here means: low CPU usage on the sending side and low latency. # I ended up using HDMI out and an HDMI capture dongle (😅) but # further testing seemed to show that H264 ultrafast/zerolatency # could actually deliver even better results than the codecs I # tested here. 🤷 init() { ffmpeg -i test.mp4 -c:v rawvideo -c:a copy test.nut } test_codec() { KEY=$(echo "$*" | sha256sum | cut -c1-8) CODEC=$1 shift ARGS="$@" LOG=test-$KEY.log OUT=test-$KEY.nut [ -f $OUT ] && return ffprobe -v error -show_entries format=duration -of default=noprint_wrappers=1 test.nut > $LOG printf "CODEC=%s\nARGS=\"%s\"\n\n" "$CODEC" "$*" >> $LOG pv -cN input test.nut \ | /bin/time -a -f "TIME_REAL=%e\nTIME_USER=%U\nTIME_SYS=%S\nCPU_PERCENT=%P\n" -o $LOG ffmpeg -i - -an -c:v $CODEC $ARGS -f nut - \ | pv -cN output > $OUT stat test.nut --format "SIZE_INPUT=%s" >> $LOG stat $OUT --format "SIZE_OUTPUT=%s" >> $LOG echo cat $LOG } test_codec ffv1 test_codec ffvhuff test_codec prores test_codec mjpeg test_codec mjpeg -qscale:v 1 test_codec mjpeg -qscale:v 2 test_codec mpeg1video test_codec mpeg1video -qscale:v 1 test_codec mpeg1video -qscale:v 2 test_codec mpeg2video test_codec mpeg2video -qscale:v 1 test_codec mpeg2video -qscale:v 2