Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- CUTINTO=$3
- SOURCE=$1
- OUTPUT=$2
- SKIPFRAME=$4
- FRAMES=$(ffprobe -v error -count_frames -select_streams v:0 -show_entries stream=nb_read_frames -of default=nokey=1:noprint_wrappers=1 $SOURCE)
- WIDTH=$(ffprobe -v error -select_streams v:0 -show_entries stream=width -of default=nokey=1:noprint_wrappers=1 $SOURCE)
- HEIGHT=$(ffprobe -v error -select_streams v:0 -show_entries stream=height -of default=nokey=1:noprint_wrappers=1 $SOURCE)
- VERT=$5
- ORD=$6
- if [ "$VERT" == "vertical" ];
- then
- CUT=$((WIDTH/CUTINTO))
- else
- CUT=$((HEIGHT/CUTINTO))
- fi
- echo "cut is $CUT"
- i=0
- N=4
- j=0
- while [ "$i" -lt "$CUTINTO" ];
- do
- if [ "$ORD" == "normal" ];
- then
- STARTTIME=$((SKIPFRAME*i))
- else
- STARTTIME=$((SKIPFRAME*(CUTINTO-i-1)))
- fi
- START=$((CUT*i))
- ENDTIME=$((FRAMES-(CUTINTO-1)*SKIPFRAME+STARTTIME))
- echo "$STARTTIME $ENDTIME"
- ((j=j%N)); ((j++==0)) && wait
- if [ "$VERT" == "vertical" ];
- then
- ffmpeg -loglevel error -i $SOURCE -an -vf "crop=$CUT:$HEIGHT:$START:0, trim=end_frame=$ENDTIME, trim=start_frame=$STARTTIME" tmp$i.mp4 &
- else
- ffmpeg -loglevel error -i $SOURCE -an -vf "crop=$WIDTH:$CUT:0:$START, trim=end_frame=$ENDTIME, trim=start_frame=$STARTTIME" tmp$i.mp4 &
- fi
- i=$((i+1))
- done
- wait
- ls
- function merge {
- from=$1
- to=$2
- if [ "$from" -eq "$to" ];
- then
- echo "tmp$from.mp4" 1>&2
- echo "tmp$from.mp4"
- else
- mid1=$(((from+to)/2))
- mid2=$((mid1+1))
- m1="$(merge $from $mid1)"
- m2="$(merge $mid2 $to)"
- echo "$m1 $m2" 1>&2
- out="t$m1"
- if [ "$VERT" == "vertical" ];
- then
- ffmpeg -i $m1 -i $m2 -an -loglevel error -filter_complex "[0:v][1:v]hstack" $out
- else
- ffmpeg -i $m1 -i $m2 -an -loglevel error -filter_complex "[0:v][1:v]vstack" $out
- fi
- mv $out $m1
- rm $m2
- echo $m1
- fi
- }
- merge 0 $((CUTINTO-1))
- mv tmp0.mp4 $OUTPUT
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement