Textdoc
Zipdoc
Writeurl
ListPrompter
Loading…
#!/bin/bash createRandomTimeCode(){ local sec=$(( $RANDOM % 60 + 0 )); local min=$(( $RANDOM % 60 + 0 )); local hou=$(( $RANDOM % 2 + 0 )); local timecode=$( printf '%d:%d:%d' $hou $min $sec ); echo "$timecode" } #======================================================= #======================================================= ## SCRIPT TO CREATE VIDEO MOSAIC 3x3 ## INPUT PARAMETERS inputFilename="The_Scarlet_Empress_1934_a_film_directed_by_Josef_von_Sternberg_with_Marlene_Dietrich_John_Lodge_Louise_Dresser_Sam_Jaffe-1378964146886.mp4" metadataTitle="The.Scarlet.Empress.1934" scaleSize_x=436 scaleSize_y=320 fileType="webm" EXTRACTCLIPS=true COMBINECLIPS=false CREATEMOSAIC=true RANDOM_TIMECODES=false MOSAIC_3x3=true MOSAIC_3x1=false RANDOM=12375 LOG_FILENAME="log_file.txt" TESTRANDOM=false #$(mktemp) #RANDOM Each time this parameter is referenced, a random integer between 0 and 32767 is generated. The sequence of random numbers may be # initialized by assigning a value to RANDOM. If RANDOM is unset, it loses its special properties, even if it is subsequently reset. #======================================================= #======================================================= #0. TEST RANDOM if $TESTRANDOM; then echo -e "=====================" >> $LOG_FILENAME currentDate=`date` echo -e "$currentDate" >> $LOG_FILENAME echo -e "TESTRANDOM" >> $LOG_FILENAME for (( i=0; i<=10; i++ )) do timejump="$(createRandomTimeCode)" echo -e " " >> $LOG_FILENAME echo -e "$i" >> $LOG_FILENAME echo "$timejump" >> $LOG_FILENAME done echo -e "=====================" >> $LOG_FILENAME fi #======================================================= #======================================================= #1. EXTRACT CLIPS if $EXTRACTCLIPS; then libVid="libvpx" #libVid="libvpx-vp9" out_Filenames=("input1" "input2" "input3" "input4" "input5" "input6" "input7" "input8" "input9") out_Timejumps=("00:00:58" "00:04:58" "00:04:49" "00:10:56" "00:20:29" "00:21:18" "00:23:41" "00:24:10" "00:28:18") out_Timelength=("00:00:05" "00:00:05" "00:00:05" "00:00:05" "00:00:05" "00:00:05" "00:00:05" "00:00:05" "00:00:05") out_bitRates=("2M" "2M" "2M" "2M" "2M" "2M" "2M" "2M" "2M") out_subtitles=("null" "null" "null" "null" "null" "null" "null" "null" "null") #subtitles=subs.srt ####### ss_Timejump="00:00:01" scaleSize=$( printf '%dx%d' $scaleSize_x $scaleSize_y ) totalNumber=${#out_Filenames[*]} number_timejumps=${#out_Timejumps[*]} number_timelengths=${#out_Timelength[*]} number_bitrates=${#out_bitRates[*]} number_subs=${#out_subtitles[*]} #LOG info echo -e "=====================" >> $LOG_FILENAME currentDate=`date` echo -e "$currentDate" >> $LOG_FILENAME echo -e "new_log_file" >> $LOG_FILENAME echo -e "$metadataTitle" >> $LOG_FILENAME echo -e "$scaleSize" >> $LOG_FILENAME for (( i=0; i<=$(( $totalNumber -1 )); i++ )) do if $RANDOM_TIMECODES; then timejump="$(createRandomTimeCode)" else if [ "${i}" -gt "${number_timejumps}" ]; then timejump="$(createRandomTimeCode)"; else timejump="${out_Timejumps[$i]}"; fi fi if [ "${i}" -gt "${number_timelengths}" ]; then timelength="00:00:01"; else timelength="${out_Timelength[$i]}"; fi if [ "${i}" -gt "${number_bitrates}" ]; then bitrate="1M"; else bitrate="${out_bitRates[$i]}"; fi if [ "${i}" -gt "${number_subs}" ]; then subs="null"; else subs="${out_subtitles[$i]}"; fi #LOG info echo -e "=====================" echo -e "${out_Filenames[$i]}" echo -e "$timejump" echo -e "$timelength" echo -e "${out_Filenames[$i]}" >> $LOG_FILENAME echo -e "$timejump" >> $LOG_FILENAME echo -e "$timelength" >> $LOG_FILENAME echo -e "=====================" >> $LOG_FILENAME echo -e "=====================" #CLIP EXTRACTION ffmpeg -ss "$timejump" -i "$inputFilename" -c:v "$libVid" -b:v "$bitrate" -s "$scaleSize" -ss "$ss_Timejump" -t "$timelength" -vf "$subs" -sn -an -metadata title="$metadataTitle" -f "$fileType" -y -pass 1 /dev/null ffmpeg -ss "$timejump" -i "$inputFilename" -c:v "$libVid" -b:v "$bitrate" -s "$scaleSize" -ss "$ss_Timejump" -t "$timelength" -vf "$subs" -sn -an -metadata title="$metadataTitle" -f "$fileType" -y -pass 2 "${out_Filenames[$i]}.$fileType" done fi #======================================================= #======================================================= #2. COMBINE CLIPS if $COMBINECLIPS; then #ffmpeg -f concat -safe 0 -i list.txt output.mp4 #list.txt #file 'input1.webm' #file 'input2.webm' ffmpeg -f concat -safe 0 -i lista.txt inputa.webm ffmpeg -f concat -safe 0 -i listb.txt inputb.webm #ffmpeg -f concat -safe 0 -i listc.txt inputc.webm #ffmpeg -f concat -safe 0 -i listd.txt inputd.webm #ffmpeg -f concat -safe 0 -i liste.txt inpute.webm #ffmpeg -f concat -safe 0 -i listf.txt inputf.webm #ffmpeg -f concat -safe 0 -i listg.txt inputg.webm #ffmpeg -f concat -safe 0 -i listh.txt inputh.webm #ffmpeg -f concat -safe 0 -i listi.txt inputi.webm fi #======================================================= #======================================================= #3. CREATE MOSAIC if $CREATEMOSAIC; then mosaic_bitRate="1.5M" #mosaic_libVid="libvpx" mosaic_libVid="libvpx-vp9" #CALCULATE WINDOW SIZE let scaleSize_x2=$scaleSize_x*2 let scaleSize_x3=$scaleSize_x*3 let scaleSize_x4=$scaleSize_x*4 let scaleSize_y2=$scaleSize_y*2 let scaleSize_y3=$scaleSize_y*3 let scaleSize_y4=$scaleSize_y*4 totalSize_3x3=$( printf '%dx%d' $scaleSize_x3 $scaleSize_y3 ) totalSize_3x1=$( printf '%dx%d' $scaleSize_x $scaleSize_y3 ) scaleSize=$( printf '%dx%d' $scaleSize_x $scaleSize_y ) #MOSAIC PARAMETERS parameters_3x3="nullsrc=size=$totalSize_3x3 [base]; [0:v] setpts=PTS-STARTPTS, scale=$scaleSize [upperleft]; [1:v] setpts=PTS-STARTPTS, scale=$scaleSize [uppercenter]; [2:v] setpts=PTS-STARTPTS, scale=$scaleSize [upperright]; [3:v] setpts=PTS-STARTPTS, scale=$scaleSize [centerleft]; [4:v] setpts=PTS-STARTPTS, scale=$scaleSize[centercenter]; [5:v] setpts=PTS-STARTPTS, scale=$scaleSize [centerright]; [6:v] setpts=PTS-STARTPTS, scale=$scaleSize [lowerleft]; [7:v] setpts=PTS-STARTPTS, scale=$scaleSize [lowercenter]; [8:v] setpts=PTS-STARTPTS, scale=$scaleSize [lowerright]; [base][upperleft] overlay=shortest=1 [tmp1]; [tmp1][uppercenter] overlay=shortest=1:x=$scaleSize_x [tmp2]; [tmp2][upperright] overlay=shortest=1:x=$scaleSize_x2 [tmp3]; [tmp3][centerleft] overlay=shortest=1:y=$scaleSize_y [tmp4]; [tmp4][centercenter] overlay=shortest=1:x=$scaleSize_x:y=$scaleSize_y [tmp5]; [tmp5][centerright] overlay=shortest=1:x=$scaleSize_x2:y=$scaleSize_y [tmp6]; [tmp6][lowerleft] overlay=shortest=1:y=$scaleSize_y2 [tmp7]; [tmp7][lowercenter] overlay=shortest=1:x=$scaleSize_x:y=$scaleSize_y2 [tmp8]; [tmp8][lowerright] overlay=shortest=1:x=$scaleSize_x2:y=$scaleSize_y2" parameters_3x1="nullsrc=size=$totalSize_3x1 [base]; [0:v] setpts=PTS-STARTPTS, scale=$scaleSize [upper]; [1:v] setpts=PTS-STARTPTS, scale=$scaleSize [center]; [2:v] setpts=PTS-STARTPTS, scale=$scaleSize [lower]; [base][upper] overlay=shortest=1 [tmp1]; [tmp1][center] overlay=shortest=1:y=$scaleSize_y [tmp2]; [tmp2][lower] overlay=shortest=1:y=$scaleSize_y2" if $MOSAIC_3x3; then #3x3 TOPL="input1.webm" TOPC="input2.webm" TOPR="input3.webm" MIDL="input4.webm" MIDC="input5.webm" MIDR="input6.webm" BOTL="input7.webm" BOTC="input8.webm" BOTR="input9.webm" #CREATE MOSAIC 3x3 1 ffmpeg -i "$TOPL" -i "$TOPC" -i "$TOPR" -i "$MIDL" -i "$MIDC" -i "$MIDR" -i "$BOTL" -i "$BOTC" -i "$BOTR" -filter_complex "$parameters_3x3" -c:v "$mosaic_libVid" -b:v "$mosaic_bitRate" -sn -f "$fileType" -an -metadata title="$metadataTitle" -y -pass 1 "/dev/null" ffmpeg -i "$TOPL" -i "$TOPC" -i "$TOPR" -i "$MIDL" -i "$MIDC" -i "$MIDR" -i "$BOTL" -i "$BOTC" -i "$BOTR" -filter_complex "$parameters_3x3" -c:v "$mosaic_libVid" -b:v "$mosaic_bitRate" -sn -f "$fileType" -an -metadata title="$metadataTitle" -metadata comment="$metadataTitle" -y -pass 2 "$metadataTitle.mosaic_3x3.1.$fileType" TOPL="input10.webm" TOPC="input11.webm" TOPR="input12.webm" MIDL="input13.webm" MIDC="input14.webm" MIDR="input15.webm" BOTL="input16.webm" BOTC="input17.webm" BOTR="input18.webm" #CREATE MOSAIC 3x3 2 ffmpeg -i "$TOPL" -i "$TOPC" -i "$TOPR" -i "$MIDL" -i "$MIDC" -i "$MIDR" -i "$BOTL" -i "$BOTC" -i "$BOTR" -filter_complex "$parameters_3x3" -c:v "$mosaic_libVid" -b:v "$mosaic_bitRate" -sn -f "$fileType" -an -metadata title="$metadataTitle" -y -pass 1 "/dev/null" ffmpeg -i "$TOPL" -i "$TOPC" -i "$TOPR" -i "$MIDL" -i "$MIDC" -i "$MIDR" -i "$BOTL" -i "$BOTC" -i "$BOTR" -filter_complex "$parameters_3x3" -c:v "$mosaic_libVid" -b:v "$mosaic_bitRate" -sn -f "$fileType" -an -metadata title="$metadataTitle" -metadata comment="$metadataTitle" -y -pass 2 "$metadataTitle.mosaic_3x3.2.$fileType" fi if $MOSAIC_3x1; then #3x1 TOP="input19.webm" MID="input20.webm" BOT="input21.webm" #CREATE MOSAIC 3x1 ffmpeg -i "$TOP" -i "$MID" -i "$BOT" -filter_complex "$parameters_3x1" -c:v "$mosaic_libVid" -b:v "$mosaic_bitRate" -sn -f "$fileType" -an -metadata title="$metadataTitle" -y -pass 1 "/dev/null" ffmpeg -i "$TOP" -i "$MID" -i "$BOT" -filter_complex "$parameters_3x1" -c:v "$mosaic_libVid" -b:v "$mosaic_bitRate" -sn -f "$fileType" -an -metadata title="$metadataTitle" -y -pass 2 "$metadataTitle.mosaic_3x1.1.$fileType" fi fi