Перейти из форума на сайт.

НовостиФайловые архивы
ПоискАктивные темыТоп лист
ПравилаКто в 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 "    -d    Set 'output_dimension' of [WxH], like: -d 240x180. Aspect always preserved. "
    echo ""
    echo "    -f    Use 'ffmpeg' for encoding."
    echo ""
    echo "    -F    Set full path to 'ffmpeg' binary."
    echo ""
    echo "    -fmt    Set video codec format: -fmt mpeg4 or -fmt x264. x264 is a default value."
    echo ""
    echo "    -i    Turn 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 "    -I    Turn on processing of a desired catalogue with your movies. Nested folders are left intact."
    echo "        In this case filenames are NOT restricted."
    echo ""
    echo "    -m    Use 'mencoder' for encoding."
    echo ""
    echo "    -M    Set full path to 'mencoder' binary."
    echo ""
    echo "    -O    Set desired catalogue for encoded results. It's highly recommended to keep them seperate from the sources."
    echo ""
    echo "    -q    Set quantity of a 'thumbnails' per source movie. Default value is 3."
    echo ""
    echo "    -s    Set 'time shift' - interval in seconds between cuts."
    echo ""
    echo "    -t    Set the duration of cuts in seconds."
    echo ""
    echo "    -T    Set 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 | Исправлено: Skif_off, 20:58 09-03-2022
Открыть новую тему     Написать ответ в эту тему

На первую страницук этому сообщениюк последнему сообщению

Компьютерный форум Ru.Board » Компьютеры » Программы » MPlayer | MPlayer2 | MPV | MEncoder


Реклама на форуме Ru.Board.

Powered by Ikonboard "v2.1.7b" © 2000 Ikonboard.com
Modified by Ru.B0ard
© Ru.B0ard 2000-2024

BitCoin: 1NGG1chHtUvrtEqjeerQCKDMUi6S6CG4iC

Рейтинг.ru