Last active
December 12, 2015 08:49
-
-
Save k0a1a/4747287 to your computer and use it in GitHub Desktop.
once you Bash it, you can't unBash it
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
## final_cunt.sh is simple, algorithmic CLI video-editor | |
## requires mencoder and GNU user-land | |
## usage: final_cunt.sh [infile] | |
####### settings ######## | |
## length of a piece in seconds | |
P_LEN='3' | |
## gap between the pieces in seconds | |
P_GAP='60' | |
## output filename | |
OUTPUT='output_final_cunted.avi' | |
######################### | |
FILE=$1 | |
[ -f "$FILE" ] || (echo -e '\n\ninput file does not exist!\n\n'; exit 1) | |
LEN=$(mplayer -vo null -ao null -frames 0 -identify "$FILE" 2>/dev/null | grep "^ID_LENGTH" | sed -e 's/ID_LENGTH=//g') | |
SEC=${LEN/\.*} | |
## make TMP dir | |
TMP=tmp_$(date +%s) | |
[ -a $TMP ] || mkdir ./$TMP | |
## calculate the number of samples | |
PIECES=$(($SEC / ($P_LEN+$P_GAP))) | |
echo 'file info:' | |
echo 'length:' $SEC | |
echo 'pieces:' $PIECES | |
## chopping function | |
function chop() { | |
POS=$1 | |
SKIP=$(($POS*($P_LEN+$P_GAP))) | |
echo 'piece #' $POS | |
echo 'skip to' $SKIP | |
mencoder -ovc copy -oac copy -ss $SKIP -endpos $P_LEN -o $TMP/$POS.avi "$FILE" &> /dev/null | |
} | |
## chopping loop | |
for i in $(seq $PIECES); do chop $i; done | |
## put all chunks together | |
echo -e 'stitching the chops..' | |
CHUNKS=$(ls $TMP | sort -n | awk -v T=$TMP '{ print T"/"$1}') | |
mencoder -forceidx -ovc copy -oac copy -o ./$OUTPUT $CHUNKS &>/dev/null && \ | |
echo -e '\n\n\nDone!\nEnjoy your file:' $(pwd)/$OUTPUT || \ | |
echo -e '\n\nerror!\n\n' | |
rm -Rf $TMP | |
## uncomment to play file once it's ready | |
mplayer $(pwd)/$OUTPUT | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment