Created
January 6, 2020 06:57
-
-
Save RicherMans/5bad80bd9c57d1ee0f6ee70c0960d7ef to your computer and use it in GitHub Desktop.
download_video_parallel.sh
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# @Author: richman | |
# @Date: 2018-03-15 | |
# @Last Modified by: richman | |
# @Last Modified time: 2018-03-30 | |
if [[ $# < 1 ]]; then | |
echo "Input .csv file .e.g balanced_train_segments.csv" | |
exit | |
fi | |
inp=$1 | |
njobs=${2:-4} | |
SAMPLE_RATE=16000 | |
fetch_clip() { | |
echo $1 | |
# echo "Fetching $1 ($2 to $3)..." | |
outname="$1_$2_$3" | |
if [ -f "${outname}.mp4" ]; then | |
# echo "Already have it." | |
return | |
fi | |
youtube-dl https://youtube.com/watch?v=$1 \ | |
--quiet -f 'bestvideo[ext=mp4]+bestaudio[ext=wav]/mp4' --no-warnings --output "$outname.%(ext)s" | |
if [ $? -eq 0 ]; then | |
downloaded_file=$(find . -name "$outname*") | |
# If we don't pipe `yes`, ffmpeg seems to steal a | |
# character from stdin. I have no idea why. | |
ffmpeg -loglevel quiet -i "$downloaded_file" -ar $SAMPLE_RATE \ | |
-ss "$2" -to "$3" "./${outname}_out.mp4" | |
mv "./${outname}_out.mp4" "./${outname}.mp4" | |
fi | |
} | |
export SAMPLE_RATE | |
export -f fetch_clip | |
grep "^[^#;]" $inp | parallel --resume --joblog job.log --eta -j $njobs --colsep=, fetch_clip {1} {2} {3} > /dev/null |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment