Advertisement
Guest User

Untitled

a guest
Mar 8th, 2014
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.58 KB | None | 0 0
  1. ####################### Script for file 001.MOV
  2. ####################### Goals: 4
  3. ####################### This script is PHP generated for processing sport videos. It overlays a
  4. ####################### score bar (updated depending on number of goals and team names) and a
  5. ####################### splash screen with information about the game.
  6. ####################### Splitting requires that the key frame be calculated for each partial temp
  7. ####################### file so getKeyFrame must be called within the script and not precalculated.
  8. #!/bin/sh
  9. infile='001.MOV'
  10. workingdir='/tmp/ram'
  11. mkdir $workingdir/scores
  12. minutein0='0'
  13. secondin0='7'
  14. ms0=008333
  15. intime0=$minutein0':'$secondin0'.'$ms0
  16. logo0='/tmp/ram/scores/p1.00.png'
  17. logo1='/tmp/ram/scores/p1.01.png'
  18. cp scores/p1.00.png $workingdir/scores/
  19. cp scores/p1.01.png $workingdir/scores/
  20. logo2='/tmp/ram/scores/p1.02.png'
  21. cp scores/p1.02.png $workingdir/scores/
  22. logo3='/tmp/ram/scores/p1.12.png'
  23. cp scores/p1.12.png $workingdir/scores/
  24. logo4='/tmp/ram/scores/p1.13.png'
  25. cp scores/p1.13.png $workingdir/scores/
  26. cp input/$infile $workingdir/
  27. #Split Files
  28. 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
  29. ms1=$(./getKeyFrame 3 /tmp/ram/smallfile0e.mp4 2>/dev/null)
  30. if [ ${#ms1} -eq 0 ]
  31. then
  32. ms1=$(./getKeyFrame 4 /tmp/ram/smallfile0e.mp4)
  33. minutein1='0'
  34. secondin1='4'
  35. else
  36. minutein1='0'
  37. secondin1='3'
  38. fi
  39. intime1=$minutein1':'$secondin1'.'$ms1
  40. 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
  41. ms2=$(./getKeyFrame 11 /tmp/ram/smallfile1e.mp4 2>/dev/null)
  42. if [ ${#ms2} -eq 0 ]
  43. then
  44. ms2=$(./getKeyFrame 12 /tmp/ram/smallfile1e.mp4)
  45. minutein2='0'
  46. secondin2='12'
  47. else
  48. minutein2='0'
  49. secondin2='11'
  50. fi
  51. intime2=$minutein2':'$secondin2'.'$ms2
  52. 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
  53. ms3=$(./getKeyFrame 414 /tmp/ram/smallfile2e.mp4 2>/dev/null)
  54. if [ ${#ms3} -eq 0 ]
  55. then
  56. ms3=$(./getKeyFrame 415 /tmp/ram/smallfile2e.mp4)
  57. minutein3='6'
  58. secondin3='55'
  59. else
  60. minutein3='6'
  61. secondin3='54'
  62. fi
  63. intime3=$minutein3':'$secondin3'.'$ms3
  64. 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
  65. #Limpar RAM (ficheiro original)
  66. rm /tmp/ram/$infile
  67. #Coloca overlay nos vídeos repartidos
  68. 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
  69. 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
  70. 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
  71. 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
  72. 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
  73. #Limpar RAM (smallfiles)
  74. rm $workingdir/smallfile*
  75. #Aplica fade out final
  76. iss=$(mediainfo $workingdir/overlaid4.mp4 | grep -m 1 Duration | awk '{print $3}' | grep 's')
  77. if [ $iss > 0 ]
  78. then
  79. s=$(mediainfo /tmp/ram/overlaid4.mp4 | grep -m 1 Duration | awk '{print substr( $3, 0, 3 )}' | tr -d 's')
  80. f=`expr $s \* 30`
  81. frames=`expr $f - 100`
  82. else
  83. mn=$(mediainfo /tmp/ram/overlaid4.mp4 | grep -m 1 Duration | awk '{print substr( $3, 0, 3 )}' | tr -d 'mn')
  84. s=$(mediainfo /tmp/ram/overlaid4.mp4 | grep -m 1 Duration | awk '{print substr( $4, 0, 3 )}' | tr -d 's')
  85. mtosec=`expr $mn \* 60`
  86. sum=`expr $s + $mtosec`
  87. f=`expr $sum \* 30`
  88. frames=`expr $f - 100`
  89. fi
  90. 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
  91. mv $workingdir/outfade.mp4 $workingdir/overlaid4.mp4
  92. #Limpar RAM (clear config)
  93. rm $workingdir/config
  94. #Agrega os fragmentos num vídeo só
  95. echo "file '/tmp/ram/overlaid0.mp4'" >> /tmp/ram/config
  96. echo "file '/tmp/ram/overlaid1.mp4'" >> /tmp/ram/config
  97. echo "file '/tmp/ram/overlaid2.mp4'" >> /tmp/ram/config
  98. echo "file '/tmp/ram/overlaid3.mp4'" >> /tmp/ram/config
  99. echo "file '/tmp/ram/overlaid4.mp4'" >> /tmp/ram/config
  100. ffmpeg -y -f concat -i /tmp/ram/config -c copy /tmp/ram/out.mp4 </dev/null >/dev/null 2>/var/log/ffmpeg.log
  101. #Aplica imagem inicial
  102. cp scores/parte*png /tmp/ram/scores/
  103. 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
  104. mv /tmp/ram/lo.mp4 /tmp/ram/out.mp4
  105. mv $workingdir/out.mp4 results/001.MOV.mp4
  106. rm $workingdir/*
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement