.



on-line?
? ?
Ru.Board » » » MPlayer | MPlayer2 | MPV | MEncoder

: gyra, Maz

   •

     

Nuck



Member
| | | |

 
#!/bin/sh
 
###############################################################
# Licensed under Creative Commons by-nc-sa                    #
# http://creativecommons.org/licenses/by-nc-sa/3.0/deed.en_GB #
# created by sda (sda00@himki.net)                            #
###############################################################
 
export TMPDIR="/tmp"
export RESULTDIR="./movies_splitted"
export INPUTDIR="./"
export ffmpeg="ffmpeg"
export mencoder="mencoder"
export FORMAT="x264" # there's only 2 supported at the moment: x264 and mpeg4
export output_qty="3"
export output_timing="30"
export output_dimension="240x180"
# export use_ffmpeg="1"
export encoder_time_shift="1200"
 
 
case $1 in
--help)
echo -e '\E[37;44m'"\033[1mNAME\033[0m"
echo "movie_splitter - is a script aimed to be handy in making multiple cuttings out of a movies."
echo " It uses 'mencoder' or 'ffmpeg' (or both of them) and capable to make encoding"
echo " in 'x264' or 'mpeg4' video codec."
echo ""
echo -e '\E[37;44m'"\033[1mSYNOPSIS\033[0m"
echo "movie_splitter [options]"
echo ""
echo -e '\E[37;44m'"\033[1mOPTIONS\033[0m"
echo "You're welcome to tune them as you like... "
echo ""
echo "-dSet 'output_dimension' of [WxH], like: -d 240x180. Aspect always preserved. "
echo ""
echo "-fUse 'ffmpeg' for encoding."
echo ""
echo "-FSet full path to 'ffmpeg' binary."
echo ""
echo "-fmtSet video codec format: -fmt mpeg4 or -fmt x264. x264 is a default value."
echo ""
echo "-iTurn on 'single file mode' by setting a full path to a desired movie."
echo "In this case filename should not contain spaces and other 'special' characters."
echo ""
echo "-ITurn on processing of a desired catalogue with your movies. Nested folders are left intact."
echo "In this case filenames are NOT restricted."
echo ""
echo "-mUse 'mencoder' for encoding."
echo ""
echo "-MSet full path to 'mencoder' binary."
echo ""
echo "-OSet desired catalogue for encoded results. It's highly recommended to keep them seperate from the sources."
echo ""
echo "-qSet quantity of a 'thumbnails' per source movie. Default value is 3."
echo ""
echo "-sSet 'time shift' - interval in seconds between cuts."
echo ""
echo "-tSet the duration of cuts in seconds."
echo ""
echo "-TSet catalogue for temporary files. The default is /tmp."
echo ""
echo "Hope you like it :). Though it's pretty raw and definitely should be improved."
exit 0
 
;;
esac
 
 
for ARGS in $* ; do
 
case $ARGS in
-f)
export use_ffmpeg="1"
;;
-m)
export use_mencoder="1"
;;
-F)
export ffmpeg=$(echo $* | awk -F\-F '{ print $2 }' | awk '{ print $1 }')
;;
-M)
export mencoder=$(echo $* | awk -F\-M '{ print $2 }' | awk '{ print $1 }')
;;
-O)
export RESULTDIR=$(echo $* | awk -F\-O '{ print $2 }' | awk '{ print $1 }')
;;
-i)
export input_file=$(echo $* | awk -F\-i '{ print $2 }' | awk -F\ \- '{ print $1 }')
;;
-I)
export INPUTDIR=$(echo $* | awk -F\-I '{ print $2 }' | awk '{ print $1 }')
;;
-T)
export TMPDIR=$(echo $* | awk -F\-T '{ print $2 }' | awk '{ print $1 }')
;;
-fmt)
export FORMAT=$(echo $* | awk -F\-fmt '{ print $2 }' | awk '{ print $1 }')
;;
-q)
export output_qty=$(echo $* | awk -F\-q '{ print $2 }' | awk '{ print $1 }')
;;
-t)
export output_timing=$(echo $* | awk -F\-t '{ print $2 }' | awk '{ print $1 }')
;;
-d)
export output_dimension=$(echo $* | awk -F\-d '{ print $2 }' | awk '{ print $1 }')
;;
-s)
export encoded_time_shift=$(echo $* | awk -F\-s '{ print $2 }' | awk '{ print $1 }')
;;
 
esac
 
done
 
 
mkdir -p $TMPDIR
mkdir -p $RESULTDIR
 
 
if [ -d $RESULTDIR ] ; then echo "RESULTDIR created as $RESULTDIR"
else echo "Check your permissions for a proper $RESULTDIR. Going to exit." && read a1 && exit 0
fi
 
if [ -d $TMPDIR ] ; then echo "TMPDIR created as $TMPDIR"
else echo "Check your permissions for a proper $TMPDIR. Going to exit." && read a1 && exit 0
fi
 
if [ -n "$(eval which ${ffmpeg})" ]; then echo "Good... ffmpeg is here"
else echo "ffmpeg is missing" && touch "$TMPDIR/noffmpeg"
fi
 
if [ -n "$(eval which ${mencoder})" ]; then echo "Good... mencoder is here"
else echo "mencoder is missing" && touch "$TMPDIR/nomencoder"
fi
 
if [ -e "$TMPDIR/noffmpeg" -a -e "$TMPDIR/nomencoder" ]  
then echo "Can't locate 'ffmpeg' or 'mplayer'. Check your setup" && read a1 && exit 0
fi
 
if [ "$FORMAT" = "x264" ]
then export vcodec_ffmpeg="libx264" && export vcodec_mencoder="x264"
fi
 
if [ "$FORMAT" = "mpeg4" ]
then export vcodec_ffmpeg="mpeg4" && export vcodec_mencoder="lavc"
fi
 
export mencoder_dimension=$(echo $output_dimension | awk -Fx '{ print $1 }' )
 
 
get_time_ffmpeg_function ()
{
export movie_total_time=$(expr $(find $input_file -exec ${ffmpeg} -i {} \; 2>&1 | grep -i duration |\
       awk -F: '{ print $2 }') '*' 3600 \
'+' $(find $input_file -exec ${ffmpeg} -i {} \; 2>&1 | grep -i duration | awk -F: '{ print $3 }') '*' 60 \
'+' $(find $input_file -exec ${ffmpeg} -i {} \; 2>&1 | grep -i duration | awk -F: '{ print $4 }' |\
awk -F\. '{ print $1 }' ))
}
 
 
 
split_by_ffmpeg_single ()
{
a1=0
 
get_time_ffmpeg_function
 
while [ "$a1" -lt "$output_qty" ]
do

$( ${ffmpeg} -ss $(expr $movie_total_time '/' $output_qty '*' $a1) \
-t $output_timing -i $(find $input_file) -f avi \
-s $output_dimension -vcodec $vcodec_ffmpeg -sameq -bf 2 -ab 128k -ac 2 -y \
"$input_file"_ffmpeg_"$a1".avi )
 
mv $INPUTDIR/*_ffmpeg_*.avi $RESULTDIR/
 
a1=$(expr $a1 '+' 1)
 
done
 
find $RESULTDIR/ -size 0c -exec rm {} \;
find $RESULTDIR/ -size 4108c -exec rm {} \;
 
}
 
split_by_ffmpeg_multiple ()
{
a1=0
while [ "$a1" -lt "$output_qty" ]
do
$(find $INPUTDIR -maxdepth 1 -exec ${ffmpeg} -ss $(expr $encoder_time_shift '*' $a1) \
-t $output_timing -i {} -f avi \
-s $output_dimension -vcodec $vcodec_ffmpeg -sameq -bf 2 -ab 128k -ac 2 -y \
{}_ffmpeg_"$a1".avi \; )  
 
mv $INPUTDIR/*_ffmpeg_*.avi $RESULTDIR/
 
a1=$(expr $a1 '+' 1)
 
done
 
find $RESULTDIR/ -size 0c -exec rm {} \;
# find $RESULTDIR/ -size 4108c -exec rm {} \;
 
}
 
 
 
split_by_mencoder_multiple ()
{
a1=0
while [ "$a1" -lt "$output_qty" ]
do
find $INPUTDIR -maxdepth 1 -exec ${mencoder} {} -ss $(expr "$a1" '*' "$encoder_time_shift") -endpos $output_timing \
-oac copy -ovc $vcodec_mencoder -vf scale=$mencoder_dimension:-2 \
-forceidx -zoom \
-o {}_mencoder_"$a1".avi \;  
 
mv $INPUTDIR/*_mencoder_*.avi $RESULTDIR/
 
a1=$(expr $a1 '+' 1)
 
done
 
find $RESULTDIR/ -size 0c -exec rm {} \;
# find $RESULTDIR/ -size 4108c -exec rm {} \;
 
}
 
 
split_by_mencoder_single ()
{
a1=0
while [ "$a1" -lt "$output_qty" ]
do
find $input_file -exec ${mencoder} {} -ss $(expr "$a1" '*' "$encoder_time_shift") -endpos $output_timing \
-oac copy -ovc $vcodec_mencoder -vf scale=$mencoder_dimension:-2 \
-forceidx -zoom \
-o {}_mencoder_"$a1".avi \;  
 
mv $INPUTDIR/*_mencoder_*.avi $RESULTDIR/
 
a1=$(expr $a1 '+' 1)
 
done
 
find $RESULTDIR/ -size 0c -exec rm {} \;
# find $RESULTDIR/ -size 4108c -exec rm {} \;
 
}
 
 
 
 
if [ "$use_ffmpeg" = "1" -a "$input_file" != "" ] ; then
split_by_ffmpeg_single
fi
 
if [ "$use_ffmpeg" = "1" -a "$input_file" = "" ] ; then
split_by_ffmpeg_multiple
fi
 
if [ "$use_mencoder" = "1" -a "$input_file" = "" ] ; then
split_by_mencoder_multiple
fi
 
if [ "$use_mencoder" = "1" -a "$input_file" != "" ] ; then
split_by_mencoder_single
fi
 
 
if [ -e "$TMPDIR/noffmpeg" ]
then rm "$TMPDIR/noffmpeg"
fi
 
if [ -e "$TMPDIR/nomencoder" ]
then rm "$TMPDIR/nomencoder"  
fi
 
 

: 360 | . 29-10-2001 | : 12:54 25-06-2003 | : Maz, 15:57 22-11-2019
     


Ru.Board » » » MPlayer | MPlayer2 | MPV | MEncoder


Ru.Board.

Powered by Ikonboard "v2.1.7b" © 2000 Ikonboard.com
Modified by Ru.Board
© Ru.Board 2000-2020

BitCoin: 1NGG1chHtUvrtEqjeerQCKDMUi6S6CG4iC

.ru