Skip to content

Instantly share code, notes, and snippets.

@rahuldeo2047
Created September 17, 2017 12:45
Show Gist options
  • Save rahuldeo2047/b8dd24b6ece0655f8f7ebccd14f80b36 to your computer and use it in GitHub Desktop.
Save rahuldeo2047/b8dd24b6ece0655f8f7ebccd14f80b36 to your computer and use it in GitHub Desktop.
download audio and images from web and create youtube downloadable videos
#!/bin/bash
basePath="/home/rahuldeo/Downloads/AudioArchive/Gita/Hindi/"
#/home/rahuldeo/Downloads/AudioArchive/Gita/Hindi/"
array_verse=(39 71 43 42 27 42 30 28 34 40 52 16 29 24 19 19 24 74)
#array_chapter=(1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18)
array_title=("Doha" "Transliteration" "Anvaya" "Translation")
#baseWebPath="http://www.bhagavad-gita.org/"
for chapter in $(seq 1 1) #9 18
do
printf "Chapter $chapter ... "
multipleFiles=""
outFile=""
for verse in $(seq 1 ${array_verse[$chapter-1]})
do
file=$(printf "video/gita-chapter-%02d-verse-%02d.avi" "$chapter" "$verse")
#$(printf "video/verse-%02d-%02d-%01d.png" "$chapter" "$verse" "$img")
outFile=$(printf "mergedvideo/gita-chapter-%02d.avi" "$chapter")
multipleFiles="$multipleFiles$basePath$file "
done
#avimerge -o ../result.mp4 -i ./gita-chapter-01-verse-01.avi ./gita-chapter-01-verse-02.avi
cmd="melt $multipleFiles -consumer avformat:$basePath$outFile acodec=libmp3lame vcodec=libx264"
#cmd="avimerge -o $basePath$outFile -i $multipleFiles"
#echo $cmd
$cmd
#convert
#exit 0
done
#convert $basePath"/png/verse-01-01-1.png" ./png/verse-01-01-2.png ./png/verse-01-01-3.png ./png/verse-01-01-4.png -gravity center -append -alpha remove ./out1.png
exit 0
ffmpeg -i "concat:./gita-chapter-01-verse-01.avi|./gita-chapter-01-verse-02.avi" -c copy ../test.mp4
ffmpeg -f concat -safe 0 -i /home/rahuldeo/WORKS/scripts/videotomergelist1.txt -c copy ../test.mp4
ffmpeg -f concat -safe 0 -i mylist.txt -c copy output
#melt {input-sequence} -consumer avformat:{output-name} acodec=libmp3lame vcodec=libx264
#melt ./gita-chapter-01-verse-01.avi ./gita-chapter-01-verse-02.avi -consumer avformat:../gita-chapter-01.avi acodec=libmp3lame vcodec=libx264
: <<'end_long_comment'
ffmpeg -i ./gita-chapter-01-verse-01.avi -i ./gita-chapter-01-verse-02.avi -vf "scale=trunc(iw/2)*2:trunc(ih/2)*2" -f lavfi -i color=black -filter_complex \
"[0:v]format=pix_fmts=yuva420p,fade=t=out:st=4:d=1:alpha=1,setpts=PTS-STARTPTS[va0];\
[1:v]format=pix_fmts=yuva420p,fade=t=in:st=0:d=1:alpha=1,setpts=PTS-STARTPTS+4/TB[va1];\
[2:v]scale=960x720,trim=duration=9[over];\
[over][va0]overlay[over1];\
[over1][va1]overlay=format=yuv420[outv]" \
-vcodec libx264 -map [outv] ../test.mp4
ffmpeg -i ./gita-chapter-01-verse-01.avi -i ./gita-chapter-01-verse-02.avi -vf "scale=trunc(iw/2)*2:trunc(ih/2)*2" -an \
-filter_complex \
" [0:v]trim=start=0:end=9,setpts=PTS-STARTPTS[firstclip];
[1:v]trim=start=1,setpts=PTS-STARTPTS[secondclip];
[0:v]trim=start=9:end=10,setpts=PTS-STARTPTS[fadeoutsrc];
[1:v]trim=start=0:end=1,setpts=PTS-STARTPTS[fadeinsrc];
[fadeinsrc]format=pix_fmts=yuva420p,
fade=t=in:st=0:d=1:alpha=1[fadein];
[fadeoutsrc]format=pix_fmts=yuva420p,
fade=t=out:st=0:d=1:alpha=1[fadeout];
[fadein]fifo[fadeinfifo];
[fadeout]fifo[fadeoutfifo];
[fadeoutfifo][fadeinfifo]overlay[crossfade];
[firstclip][crossfade][secondclip]concat=n=3[output];
[0:a][1:a] acrossfade=d=1 [audio]
" \
-map "[output]" -map "[audio]" ../result.mp4
ffmpeg -i ./gita-chapter-01-verse-01.avi -i ./gita-chapter-01-verse-02.avi -an \
-filter_complex \
" scale=trunc(iw/2)*2:trunc(ih/2)*2
[0:v]trim=start=0:end=9,setpts=PTS-STARTPTS[firstclip];
[1:v]trim=start=1,setpts=PTS-STARTPTS[secondclip];
[0:v]trim=start=9:end=10,setpts=PTS-STARTPTS[fadeoutsrc];
[1:v]trim=start=0:end=1,setpts=PTS-STARTPTS[fadeinsrc];
[fadeinsrc]format=pix_fmts=yuva420p,
fade=t=in:st=0:d=1:alpha=1[fadein];
[fadeoutsrc]format=pix_fmts=yuva420p,
fade=t=out:st=0:d=1:alpha=1[fadeout];
[fadein]fifo[fadeinfifo];
[fadeout]fifo[fadeoutfifo];
[fadeoutfifo][fadeinfifo]overlay[crossfade];
[firstclip][crossfade][secondclip]concat=n=3[output];
[0:a][1:a] acrossfade=d=1 [audio]
" \
-map "[output]" -map "[audio]" ../result.mp4
ffmpeg -i ./gita-chapter-01-verse-01.avi -i ./gita-chapter-01-verse-02.avi -an \
-filter_complex \
" [0:v]trim=start=0:end=9,setpts=PTS-STARTPTS[firstclip];
[1:v]trim=start=1,setpts=PTS-STARTPTS[secondclip];
[0:v]trim=start=9:end=10,setpts=PTS-STARTPTS[fadeoutsrc];
[1:v]trim=start=0:end=1,setpts=PTS-STARTPTS[fadeinsrc];
[fadeinsrc]format=pix_fmts=yuva420p,
fade=t=in:st=0:d=1:alpha=1[fadein];
[fadeoutsrc]format=pix_fmts=yuva420p,
fade=t=out:st=0:d=1:alpha=1[fadeout];
[fadein]fifo[fadeinfifo];
[fadeout]fifo[fadeoutfifo];
[fadeoutfifo][fadeinfifo]overlay[crossfade];
[firstclip][crossfade][secondclip]concat=n=3[output];
[0:a][1:a] acrossfade=d=1 [audio]
" \
-map "[output]" -map "[audio]" ../result.mp4
ffmpeg -i ./gita-chapter-01-verse-01.avi -i ./gita-chapter-01-verse-02.avi ../result.mp4
ffmpeg -i ./gita-chapter-01-verse-01.avi -i ./gita-chapter-01-verse-02.avi -filter_complex \
"[0:v]setpts=PTS-STARTPTS[v1]; [1:v]format=yuva420p,fade=in:st=0:d=1:alpha=1,setpts=PTS-STARTPTS+(4/TB)[v2]; [2:v]format=yuva420p,fade=in:st=0:d=1:alpha=1,setpts=PTS-STARTPTS+(8/TB)[v3]; [3:v]format=yuva420p,fade=in:st=0:d=1:alpha=1,setpts=PTS-STARTPTS+(12/TB)[v4]; [4:v]format=yuva420p,fade=in:st=0:d=1:alpha=1,setpts=PTS-STARTPTS+(16/TB)[v5]; [v1][v2]overlay[12]; [12][v3]overlay[123]; [123][v4]overlay[1234]; [1234][v5]overlay,format=yuv420p[v];[1][2]acrossfade=d=1[a12]; [a12][3]acrossfade=d=1[a123]; [a123][4]acrossfade=d=1[a1234]; [a1234][5]acrossfade=d=1[a];" \
-map [v] -map [a] ../result.mp4
ffmpeg -i ./gita-chapter-01-verse-01.avi -i ./gita-chapter-01-verse-02.avi -filter_complex \
"[0:v]scale=640:480:force_original_aspect_ratio=decrease,pad=640:480:(ow-iw)/2:(oh-ih)/2[v0]; \
[v0][0:a][1:v][1:a]concat=n=2:v=1:a=1[v][a]" \
-map "[v]" -map "[a]" -c:v libx264 -c:a aac -movflags +faststart ../result.mp4
ffmpeg -i 1.mp4 -acodec libvo_aacenc -vcodec libx264 -s 1920x1080 -r 60 -strict experimental 1.mp4
avimerge -o ../result.mp4 -i ./gita-chapter-01-verse-01.avi ./gita-chapter-01-verse-02.avi
'end_long_comment'
#!/bin/bash
array_verse=(39 71 43 42 27 42 30 28 34 40 52 16 29 24 19 19 24 74)
#array_chapter=(1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18)
array_title=("Doha" "Transliteration" "Anvaya" "Translation")
baseWebPath="http://www.bhagavad-gita.org/"
for chapter in $(seq 1 18) #${array_chapter[@]}"
do
for verse in $(seq 1 ${array_verse[$chapter-1]}) #" ${array_verse[@]}"
do
mp3file=$(printf "AudioArchive/Gita/Hindi/verses/%02d-%02d.mp3" "$chapter" "$verse")
htmlfile=$(printf "Gita/verse-%02d-%02d.html" "$chapter" "$verse")
#for img in $(seq 1 4)
#do
# pngfile=$(printf "Gita/png2/verse-%02d-%02d-%01d.png" "$chapter" "$verse" "$img")
# not working pngfile2=$(printf "Gita/png2/verse-%02d-%02d-%s.png" "$chapter" "$verse" ${array_title[$img-1]})
webPath="http://www.bhagavad-gita.org/"$mp3file
localPath="/home/rahuldeo/Downloads/"$mp3file
echo $webPath, $localPath
curl $webPath --create-dirs -o $localPath
#done
exit 0
done
#echo " "
done
http://www.bhagavad-gita.org/AudioArchive/Gita/
#!/bin/bash
#ffmpeg -loop 1 -i im6.png -c:v libx264 -t 4 -pix_fmt yuv420p -vf scale=1280:720 cover.mp4
#ffmpeg -i cover.mp4 -vf drawtext="fontfile=/path/to/font.ttf: text='sankshipt shrimad bhagwat geeta': fontcolor=white: fontsize=60: box=1: boxcolor=black@0.5: boxborderw=5: x=(w-text_w)/2: y=h/100*mod(t\*t\*t\,100)" -codec:a copy output.mp4
basePath="/home/rahuldeo/Downloads/AudioArchive/Gita/Hindi/"
array_verse=(39 71 43 42 27 42 30 28 34 40 52 16 29 24 19 19 24 74)
#array_chapter=(1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18)
#H=(1241 1241 1241 1241 1241 1241 1240 1240 1241 1241 1241 1241 1241 1241 1241 1241 1240 1241)
H=(1240 1240 1240 1240 1240 1240 1240 1240 1240 1240 1240 1240 1240 1240 1240 1240 1240 1240)
W=(1436 898 682 581 844 1330 633 814 675 889 1256 878 1523 1557 1260 1298 1181 1270)
#HW=(1241x1436 1241x898 1241x682 1241x581 1241x844 1241x1330 1240x633 1240x814 1241x675 1241x889 1241x1256 1241x878 1241x1523 1241x1557 1241x1260 1241x1298 1240x1181 1241x1270)
# 1 2 3 4 5 6 7 8
HW=(1240x720 1240x600! 1240x682 1240x600! 1240x844 1240x600! 1240x632 1240x600! 1240x674 1240x888 1240x1256 1240x878 1240x720! 1240x1556 1240x1260 1240x1298 1240x1180 1240x1270)
#ffmpeg -i input.jpg -vf scale=w=320:h=240:force_original_aspect_ratio=decrease output_320.png
array_title=("Doha" "Transliteration" "Anvaya" "Translation")
#baseWebPath="http://www.bhagavad-gita.org/"
HWindex=0
for chapter in $(seq 6 6) #1 18
do
dataC=""
printf "Chapter $chapter ... "
for verse in $(seq 1 ${array_verse[$chapter-1]})
do
#mp3file=$(printf "AudioArchive/Gita/Hindi/verses/%02d-%02d.mp3" "$chapter", "$verse")
#htmlfile=$(printf "Gita/verse-%02d-%02d.html" "$chapter", "$verse")
multipleFiles=""
outFile=""
for img in $(seq 1 4)
do
file=$(printf "png/verse-%02d-%02d-%01d.png" "$chapter" "$verse" "$img")
outFile=$(printf "out/verse-%02d-%02d.png" "$chapter" "$verse")
multipleFiles="$multipleFiles $basePath$file"
done
cmd="convert $multipleFiles -gravity center -append -alpha remove -resize ${HW[$HWindex]} -border 20 "$basePath"$outFile" #
#echo $cmd
$cmd
#cmd="
#-vf scale=1280:-2
#cmd="ffmpeg -i $basePath$outFile -filter:v "crop=out_w:out_h:x:y" $basePath$outFile"
cmd="ffmpeg -v error -y -i $basePath$outFile -vf scale=${H[$HWindex]}:-2,setdar=16:9 $basePath$outFile"
$cmd
#data=$(echo $(identify -verbose $basePath"$outFile" | grep -E "Geometry" | grep -Eo '[0-9]{1,4}') $outFile)
#dataC="$dataC \n $data"
# echo -e "$dataC"
printf "."
cmd=$(ffmpeg -v error -i $(printf $basePath"verses/%02d-%02d.mp3" "$chapter" "$verse") -i $basePath"$outFile" $(printf $basePath"video/gita-chapter-%02d-verse-%02d.avi" "$chapter" "$verse"))
#echo $cmd
$cmd
#bash squarize.bash $basePath"out1.png"
#convert
#exit 0
done
HWindex=$HWindex+1
echo " $chapter . Done"
#printf " "
#echo -e "$dataC" > ./data.txt
# Get max size of the image
#size="$(awk -v max=0 '{if($1>max){want=$1; max=$1}}END{print want} ' ./data.txt)x$(awk -v max=0 '{if($2>max){want=$2; max=$2}}END{print want} ' ./data.txt)"
#echo " $chapter = $size"
done
# 1 39 = 1241 x 1436
# 2 71 = 1241 x 898
# 3 43 = 1241 x 682
# 4 42 = 1241 x 581
# 5 27 = 1241 x 844
# 6 42 = 1241 x 1330
# 7 30 = 1240 x 633
# 8 28 = 1240 x 814
# 9 34 = 1241 x 675
# 10 40 = 1241 x 889
# 11 52 = 1241 x 1256
# 12 16 = 1241 x 878
# 13 29 = 1241 x 1523
# 14 24 = 1241 x 1557
# 15 19 = 1241 x 1260
# 16 19 = 1241 x 1298
# 17 24 = 1240 x 1181
# 18 74 = 1241 x 1270
#convert $basePath"/png/verse-01-01-1.png" ./png/verse-01-01-2.png ./png/verse-01-01-3.png ./png/verse-01-01-4.png -gravity center -append -alpha remove ./out1.png
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment