Skip to content

Instantly share code, notes, and snippets.

@jmccardle
Created September 5, 2018 00:32
Show Gist options
  • Save jmccardle/78ac6fe1a0cbb5b539b6b37e92474b17 to your computer and use it in GitHub Desktop.
Save jmccardle/78ac6fe1a0cbb5b539b6b37e92474b17 to your computer and use it in GitHub Desktop.
#!/bin/bash
# ffmpeg video editing workflow script
set -e #exit immediately on errors
original_file=`basename "$1"`
cd `dirname "$1"`
if [ -z "$original_file" ]
then
echo "av_editing.sh - ffmpeg video editing workflow"
echo " Strips out audio for editing, then recombines it."
echo " Use: $0 <filename>"
exit 1
fi
#http://stackoverflow.com/questions/965053/ddg#965072
extension="${original_file##*.}"
noext_name="${original_file%.*}"
# Strip audio into separate file
audio_fn="$noext_name".wav
video_fn="$noext_name"_noaudio."$extension"
ffmpeg -i "$original_file" "$audio_fn"
ffmpeg -i "$original_file" -c copy -an "$video_fn"
# Open audio file in Audacity
audacity "$audio_fn"
# Press Enter to continue (or input audio file name)
new_audio_file="$noext_name"_edit.wav #default
printf "Press Enter or give filename to recombine (default: %b)\n" "$new_audio_file"
read waitcmd
#if given, use the filename instead
if [ -n "$waitcmd" ]
then
new_audio_file="$waitcmd"
fi
# Combine new audio file to video only
final_fn="$noext_name"_final."$extension"
ffmpeg -i "$video_fn" -i "$new_audio_file" -c:v copy -c:a aac -strict experimental "$final_fn"
# Clean-up temp files
rm "$video_fn"
rm "$audio_fn"
rm "$new_audio_file"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment