Advertisement
Guest User

Untitled

a guest
Oct 19th, 2017
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.79 KB | None | 0 0
  1. #!/bin/bash
  2. CUTINTO=$3
  3. SOURCE=$1
  4. OUTPUT=$2
  5. SKIPFRAME=$4
  6. FRAMES=$(ffprobe -v error -count_frames -select_streams v:0 -show_entries stream=nb_read_frames -of default=nokey=1:noprint_wrappers=1 $SOURCE)
  7. WIDTH=$(ffprobe -v error -select_streams v:0 -show_entries stream=width -of default=nokey=1:noprint_wrappers=1 $SOURCE)
  8. HEIGHT=$(ffprobe -v error -select_streams v:0 -show_entries stream=height -of default=nokey=1:noprint_wrappers=1 $SOURCE)
  9. VERT=$5
  10. ORD=$6
  11. if [ "$VERT" == "vertical" ];
  12. then
  13.     CUT=$((WIDTH/CUTINTO))
  14. else
  15.     CUT=$((HEIGHT/CUTINTO))
  16. fi
  17. echo "cut is $CUT"
  18.  
  19. i=0
  20. N=4
  21. j=0
  22. while [ "$i" -lt "$CUTINTO" ];
  23. do
  24.     if [ "$ORD" == "normal" ];
  25.     then
  26.         STARTTIME=$((SKIPFRAME*i))
  27.     else
  28.         STARTTIME=$((SKIPFRAME*(CUTINTO-i-1)))
  29.     fi
  30.     START=$((CUT*i))
  31.     ENDTIME=$((FRAMES-(CUTINTO-1)*SKIPFRAME+STARTTIME))
  32.     echo "$STARTTIME $ENDTIME"
  33.     ((j=j%N)); ((j++==0)) && wait
  34.     if [ "$VERT" == "vertical" ];
  35.     then
  36.         ffmpeg -loglevel error -i $SOURCE -an -vf "crop=$CUT:$HEIGHT:$START:0, trim=end_frame=$ENDTIME, trim=start_frame=$STARTTIME" tmp$i.mp4 &
  37.     else
  38.         ffmpeg -loglevel error -i $SOURCE -an -vf "crop=$WIDTH:$CUT:0:$START, trim=end_frame=$ENDTIME, trim=start_frame=$STARTTIME" tmp$i.mp4 &
  39.     fi
  40.     i=$((i+1))
  41. done
  42. wait
  43. ls
  44.  
  45. function merge {
  46.     from=$1
  47.     to=$2
  48.     if [ "$from" -eq "$to" ];
  49.     then
  50.         echo "tmp$from.mp4" 1>&2
  51.         echo "tmp$from.mp4"
  52.     else
  53.         mid1=$(((from+to)/2))
  54.         mid2=$((mid1+1))
  55.         m1="$(merge $from $mid1)"
  56.         m2="$(merge $mid2 $to)"
  57.         echo "$m1 $m2" 1>&2
  58.         out="t$m1"
  59.         if [ "$VERT" == "vertical" ];
  60.         then
  61.             ffmpeg -i $m1 -i $m2 -an -loglevel error -filter_complex "[0:v][1:v]hstack" $out
  62.         else
  63.             ffmpeg -i $m1 -i $m2 -an -loglevel error -filter_complex "[0:v][1:v]vstack" $out
  64.         fi
  65.         mv $out $m1
  66.         rm $m2
  67.         echo $m1
  68.     fi
  69. }
  70.  
  71. merge 0 $((CUTINTO-1))
  72. mv tmp0.mp4 $OUTPUT
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement