ffmpeg重复视频片段

电脑技术 电脑技术 1216 人阅读 | 0 人回复 | 2022-04-08

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?立即注册

x
#!/bin/bash

#
# USAGE: loop-video fileInThisDirectory howManyLoops outputFile
#
# Example:
#    $ cd ~/Documents/Videos
#    $ ls
#    TEN-CU-E03-Vid03_1280x800.mp4 TEN-CU-E03-Vid05_1280x800.mp4
#    TEN-CU-E03-Vid04_1280x800.mp4
#    $ for f in *.mp4; do ~/bin/loop-video.sh "$f" 8; done
#    ...
#    Finished
#    $ ls
#    TEN-CU-E03-Vid03_1280x800.mp4         TEN-CU-E03-Vid04_1280x800_8_loops.mp4
#    TEN-CU-E03-Vid03_1280x800_8_loops.mp4 TEN-CU-E03-Vid05_1280x800.mp4
#    TEN-CU-E03-Vid04_1280x800.mp4         TEN-CU-E03-Vid05_1280x800_8_loops.mp4
#
# Example:
#    $ ~/bin/loop-video.sh TEN-CU-E03-Vid03_1280x800.mp4
#    USAGE /Users/nhyde/bin/loop-video.sh inputFile numloops [outputFile]
#
#    TEN-CU-E03-Vid03_1280x800.mp4 can be looped 4 times per GB
#         4GB         8GB
#        -----       -----
#        16 times      32 times
#


input="${1}"
loops="${2}"
output="${3}"

tmpfile=$(uuidgen).txt

function printLoopsPerGb {
    filename="${1}"
    if [ "x${filename}" != "x" ]; then
        kb=$(du -k "${filename}" | cut -f1)
        gb=1000000
        loops_per_gb=$(expr $gb / $kb)
        echo "${filename} can be looped ${loops_per_gb} times per GB"
        echo "     4GB           8GB"
        echo "    -----         -----"
        echo "    $(expr $loops_per_gb \* 4) times        $(expr $loops_per_gb \* 8) times"
    fi
}

if [ "x${input}" == "x" ]; then
    echo "USAGE: ${0} inputFile numloops [outputFile]"
    exit
fi

if [ "x${loops}" == "x" ]; then
    echo "USAGE: ${0} inputFile numloops [outputFile]"
    echo
    printLoopsPerGb ${1}
    exit
fi

if [ "x${output}" == "x" ]; then
    output="${input%.mp4}_${loops}_loops.mp4"
fi

echo "Looping ${input} ${loops} times into ${output}"

# try/catch-esque block
{
    for i in `seq 1 $loops`; do printf "file '%s'\n" "${input}" >> $tmpfile; done
    ffmpeg -f concat -i "${tmpfile}" -c copy "${output}"
    rm $tmpfile
} || {
    rm $tmpfile
}
echo
echo Finished
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

热门推荐