Skip to content

Instantly share code, notes, and snippets.

@bear-jordan
Created June 22, 2024 17:46
Show Gist options
  • Save bear-jordan/bc3e1f248ecbcabd6cfcd43b2654be1d to your computer and use it in GitHub Desktop.
Save bear-jordan/bc3e1f248ecbcabd6cfcd43b2654be1d to your computer and use it in GitHub Desktop.
Script to clip vhs webm to specified length
#!/bin/bash
# This script increases the playback speed of a web so that the total clip time
# is a user-specified number of seconds.
#
# Args:
# - input_file: path to input webm
# - output_duration_sec: how long the output should be in seconds
# - output_file: path to output webm
#
# Returns:
# - None
if [ "$#" -ne 3 ]; then
Echo "Usage: clip-vhs input_file output_duration output_file"
exit 1
fi
INPUT="$1"
OUTPUT_DURATION_SEC="$2"
OUTPUT="$3"
DURATION=$(ffprobe -v error -show_entries format=duration -of default=noprint_wrappers=1:nokey=1 "$INPUT")
FACTOR=$(echo "$DURATION / $OUTPUT_DURATION_SEC" | bc -l)
ffmpeg -i "$INPUT" -filter_complex "[0:v]setpts=PTS/$FACTOR[v]" -map "[v]" "$OUTPUT"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment