Skip to content

Instantly share code, notes, and snippets.

@odds-get-evened
Last active September 17, 2022 19:28
Show Gist options
  • Save odds-get-evened/1db3847e6f10bd3314497fd596168cf9 to your computer and use it in GitHub Desktop.
Save odds-get-evened/1db3847e6f10bd3314497fd596168cf9 to your computer and use it in GitHub Desktop.
download and trim YouTube vids
#!/bin/bash
# youtube-dl --format mp4 UF8uR6Z6KLc
# ffmpeg -i video.mp4 -ss 00:03:32 -to 00:05:32 clip.mp4
# youtube video id
vid="$1";
echo "[youtube-dl] download video from youtube in .mp4 format...";
youtube-dl --format mp4 $vid -o '%(title)s.%(ext)s';
if [ "$2" == --trim ]
then
# from which point to which point you want to trim
# start e.g. 00:03:32
# end e.g. 00:05:32
start="$3";
end="$4";
# get the name of the video file
file_name=`youtube-dl --get-filename -o '%(title)s' $vid`;
# file extension
ext="mp4";
# path to working directory
path=`pwd`;
# video clip name and path to store location
clip="$path/${file_name}_clip.${ext}";
echo "[ffmpeg] cutting out the section file you need";
ffmpeg -i "$path/$file_name.$ext" -ss $start -to $end "$clip";
fi
echo "done...";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment