Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ####################### Script for file 001.MOV
- ####################### Goals: 4
- ####################### This script is PHP generated for processing sport videos. It overlays a
- ####################### score bar (updated depending on number of goals and team names) and a
- ####################### splash screen with information about the game.
- ####################### Splitting requires that the key frame be calculated for each partial temp
- ####################### file so getKeyFrame must be called within the script and not precalculated.
- #!/bin/sh
- infile='001.MOV'
- workingdir='/tmp/ram'
- mkdir $workingdir/scores
- minutein0='0'
- secondin0='7'
- ms0=008333
- intime0=$minutein0':'$secondin0'.'$ms0
- logo0='/tmp/ram/scores/p1.00.png'
- logo1='/tmp/ram/scores/p1.01.png'
- cp scores/p1.00.png $workingdir/scores/
- cp scores/p1.01.png $workingdir/scores/
- logo2='/tmp/ram/scores/p1.02.png'
- cp scores/p1.02.png $workingdir/scores/
- logo3='/tmp/ram/scores/p1.12.png'
- cp scores/p1.12.png $workingdir/scores/
- logo4='/tmp/ram/scores/p1.13.png'
- cp scores/p1.13.png $workingdir/scores/
- cp input/$infile $workingdir/
- #Split Files
- ffmpeg -y -i /tmp/ram/$infile -t $intime0 -c copy $workingdir/smallfile0b.mp4 -ss $intime0 -c copy $workingdir/smallfile0e.mp4 </dev/null >/dev/null 2>/var/log/ffmpeg.log
- ms1=$(./getKeyFrame 3 /tmp/ram/smallfile0e.mp4 2>/dev/null)
- if [ ${#ms1} -eq 0 ]
- then
- ms1=$(./getKeyFrame 4 /tmp/ram/smallfile0e.mp4)
- minutein1='0'
- secondin1='4'
- else
- minutein1='0'
- secondin1='3'
- fi
- intime1=$minutein1':'$secondin1'.'$ms1
- ffmpeg -y -i $workingdir/smallfile0e.mp4 -t $intime1 -c copy $workingdir/smallfile1b.mp4 -ss $intime1 -c copy $workingdir/smallfile1e.mp4 </dev/null >/dev/null 2>/var/log/ffmpeg.log
- ms2=$(./getKeyFrame 11 /tmp/ram/smallfile1e.mp4 2>/dev/null)
- if [ ${#ms2} -eq 0 ]
- then
- ms2=$(./getKeyFrame 12 /tmp/ram/smallfile1e.mp4)
- minutein2='0'
- secondin2='12'
- else
- minutein2='0'
- secondin2='11'
- fi
- intime2=$minutein2':'$secondin2'.'$ms2
- ffmpeg -y -i $workingdir/smallfile1e.mp4 -t $intime2 -c copy $workingdir/smallfile2b.mp4 -ss $intime2 -c copy $workingdir/smallfile2e.mp4 </dev/null >/dev/null 2>/var/log/ffmpeg.log
- ms3=$(./getKeyFrame 414 /tmp/ram/smallfile2e.mp4 2>/dev/null)
- if [ ${#ms3} -eq 0 ]
- then
- ms3=$(./getKeyFrame 415 /tmp/ram/smallfile2e.mp4)
- minutein3='6'
- secondin3='55'
- else
- minutein3='6'
- secondin3='54'
- fi
- intime3=$minutein3':'$secondin3'.'$ms3
- ffmpeg -y -i $workingdir/smallfile2e.mp4 -t $intime3 -c copy $workingdir/smallfile3b.mp4 -ss $intime3 -c copy $workingdir/smallfile3e.mp4 </dev/null >/dev/null 2>/var/log/ffmpeg.log
- #Limpar RAM (ficheiro original)
- rm /tmp/ram/$infile
- #Coloca overlay nos vídeos repartidos
- ffmpeg -y -i $workingdir/smallfile0b.mp4 -acodec copy -vcodec libx264 -crf 20 -vf "movie="$logo0" [watermark]; [in][watermark] overlay=0:0 [out]" $workingdir/overlaid0.mp4 </dev/null >/dev/null 2>/var/log/ffmpeg.log
- ffmpeg -y -i $workingdir/smallfile1b.mp4 -acodec copy -vcodec libx264 -crf 20 -vf "movie="$logo1" [watermark]; [in][watermark] overlay=0:0 [out]" $workingdir/overlaid1.mp4 </dev/null >/dev/null 2>/var/log/ffmpeg.log
- ffmpeg -y -i $workingdir/smallfile2b.mp4 -acodec copy -vcodec libx264 -crf 20 -vf "movie="$logo2" [watermark]; [in][watermark] overlay=0:0 [out]" $workingdir/overlaid2.mp4 </dev/null >/dev/null 2>/var/log/ffmpeg.log
- ffmpeg -y -i $workingdir/smallfile3b.mp4 -acodec copy -vcodec libx264 -crf 20 -vf "movie="$logo3" [watermark]; [in][watermark] overlay=0:0 [out]" $workingdir/overlaid3.mp4 </dev/null >/dev/null 2>/var/log/ffmpeg.log
- ffmpeg -y -i $workingdir/smallfile3e.mp4 -acodec copy -vcodec libx264 -crf 20 -vf "movie="$logo4" [watermark]; [in][watermark] overlay=0:0 [out]" $workingdir/overlaid4.mp4 </dev/null >/dev/null 2>/var/log/ffmpeg.log
- #Limpar RAM (smallfiles)
- rm $workingdir/smallfile*
- #Aplica fade out final
- iss=$(mediainfo $workingdir/overlaid4.mp4 | grep -m 1 Duration | awk '{print $3}' | grep 's')
- if [ $iss > 0 ]
- then
- s=$(mediainfo /tmp/ram/overlaid4.mp4 | grep -m 1 Duration | awk '{print substr( $3, 0, 3 )}' | tr -d 's')
- f=`expr $s \* 30`
- frames=`expr $f - 100`
- else
- mn=$(mediainfo /tmp/ram/overlaid4.mp4 | grep -m 1 Duration | awk '{print substr( $3, 0, 3 )}' | tr -d 'mn')
- s=$(mediainfo /tmp/ram/overlaid4.mp4 | grep -m 1 Duration | awk '{print substr( $4, 0, 3 )}' | tr -d 's')
- mtosec=`expr $mn \* 60`
- sum=`expr $s + $mtosec`
- f=`expr $sum \* 30`
- frames=`expr $f - 100`
- fi
- ffmpeg -y -i $workingdir/overlaid4.mp4 -acodec copy -vcodec libx264 -crf 20 -vf "fade=out:"$frames":90" $workingdir/outfade.mp4 </dev/null >/dev/null 2>/var/log/ffmpeg.log
- mv $workingdir/outfade.mp4 $workingdir/overlaid4.mp4
- #Limpar RAM (clear config)
- rm $workingdir/config
- #Agrega os fragmentos num vídeo só
- echo "file '/tmp/ram/overlaid0.mp4'" >> /tmp/ram/config
- echo "file '/tmp/ram/overlaid1.mp4'" >> /tmp/ram/config
- echo "file '/tmp/ram/overlaid2.mp4'" >> /tmp/ram/config
- echo "file '/tmp/ram/overlaid3.mp4'" >> /tmp/ram/config
- echo "file '/tmp/ram/overlaid4.mp4'" >> /tmp/ram/config
- ffmpeg -y -f concat -i /tmp/ram/config -c copy /tmp/ram/out.mp4 </dev/null >/dev/null 2>/var/log/ffmpeg.log
- #Aplica imagem inicial
- cp scores/parte*png /tmp/ram/scores/
- ffmpeg -y -i $workingdir/out.mp4 -r 29.97 -loop 1 -i $workingdir/scores/parte1.png -vcodec libx264 -crf 20 -filter_complex "[1:v] fade=out:st=3:d=1:alpha=1 [ov]; [0:v][ov] overlay=0:0 [v]" -map "[v]" -map 0:a -c:v libx264 -c:a copy -shortest $workingdir/lo.mp4 </dev/null >/dev/null 2>/var/log/ffmpeg.log
- mv /tmp/ram/lo.mp4 /tmp/ram/out.mp4
- mv $workingdir/out.mp4 results/001.MOV.mp4
- rm $workingdir/*
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement