Skip to content

Instantly share code, notes, and snippets.

@ironicbadger
Created February 23, 2023 03:44
Show Gist options
  • Save ironicbadger/1744d232a1ab6ca4e03f3a1c2b539645 to your computer and use it in GitHub Desktop.
Save ironicbadger/1744d232a1ab6ca4e03f3a1c2b539645 to your computer and use it in GitHub Desktop.
This script sets the input and output video file paths, the codec name and profile, the encoding preset and tune, the output video resolution and frame rate, the number of encoding threads, and the number of encoding iterations. It then uses the ffmpeg command to encode the input video file using the specified codec and encoding settings, and measures the time taken using the time command. Finally, it calculates the average encoding time per iteration and prints the benchmark results.
To run this script, simply save it as a shell script file (e.g., quick_sync_benchmark.sh), make it executable (e.g., chmod +x quick_sync_benchmark.sh), and then run it (e.g., ./quick_sync_benchmark.sh). Note that you will need to have the ffmpeg command-line tool and the Intel Quick Sync Media Encoding driver installed on your Linux system in order for this script to work.
#!/bin/bash
# Set the input video file path
INPUT_VIDEO_FILE="input.mp4"
# Set the output video file path
OUTPUT_VIDEO_FILE="output.mp4"
# Set the codec name and profile
CODEC_NAME="h264_qsv"
CODEC_PROFILE="main"
# Set the encoding preset and tune
ENCODING_PRESET="veryfast"
ENCODING_TUNE="film"
# Set the output video resolution and frame rate
OUTPUT_RESOLUTION="1280x720"
OUTPUT_FRAME_RATE="30"
# Set the number of encoding threads
ENCODING_THREADS="1"
# Set the number of encoding iterations
ENCODING_ITERATIONS="10"
# Run the encoding command and measure the time taken
ENCODING_TIME=$( { time ffmpeg -y -i "$INPUT_VIDEO_FILE" -c:v $CODEC_NAME -profile:v $CODEC_PROFILE -preset:v $ENCODING_PRESET -tune:v $ENCODING_TUNE -s $OUTPUT_RESOLUTION -r $OUTPUT_FRAME_RATE -threads $ENCODING_THREADS "$OUTPUT_VIDEO_FILE" >/dev/null 2>&1; } 2>&1 )
# Calculate the average encoding time per iteration
AVERAGE_ENCODING_TIME=$(echo "scale=3; $ENCODING_TIME / $ENCODING_ITERATIONS" | bc)
# Print the benchmark results
echo "Encoding completed in $ENCODING_TIME seconds."
echo "Average encoding time per iteration: $AVERAGE_ENCODING_TIME seconds."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment