Skip to content

Instantly share code, notes, and snippets.

@Luocy7
Created August 7, 2023 01:25
Show Gist options
  • Save Luocy7/1f6061447315cd9e334f32b8526b3d32 to your computer and use it in GitHub Desktop.
Save Luocy7/1f6061447315cd9e334f32b8526b3d32 to your computer and use it in GitHub Desktop.
cut relive video advertising off use gum and ffmpeg
WORK_DIR=$(gum input --placeholder "Work dir path, default:.")
INPUT_FILE_PATH=$(gum file "$WORK_DIR")
if [ ! -d "$WORK_DIR" ] || [ ! -f "$INPUT_FILE_PATH" ]; then
echo "path not exist"
exit
fi
OUTPUT_FILE=$(gum input --placeholder "Output file name, like: output.mp4")
OUTPUT_FILE="${OUTPUT_FILE:-output.mp4}"
OUTPUT_FILE_PATH=$WORK_DIR/$OUTPUT_FILE
cut_duration=7.1
input_duration=$(ffprobe -i "$INPUT_FILE_PATH" -show_format -v quiet | sed -n 's/duration=//p')
end_time=$((input_duration-cut_duration))
end_time=$(printf "%02d:%02d:%03f" end_time/3600 end_time%3600/60 end_time%60)
ffmpeg -t "$end_time" -accurate_seek -i "$INPUT_FILE_PATH" -codec copy -avoid_negative_ts 1 "$OUTPUT_FILE_PATH" -y
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment