美丽心灵公益论坛

查看: 1582|回复: 0

ffmpeg重复视频片段

[复制链接]
累计签到:57 天
连续签到:1 天

981

主题

461

回帖

8037

积分

版主

Rank: 7Rank: 7Rank: 7

积分
8037
发表于 2022-4-8 02:39:57| 字数 1,738 来自手机 | 显示全部楼层 |阅读模式

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

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

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
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Archiver|手机版|小黑屋|免责及版权声明|关于|美丽心灵公益论坛

GMT+8, 2025-12-12 16:36 , Processed in 0.057854 second(s), 26 queries .

Powered by Discuz! X3.4

!copyright!

快速回复 返回顶部 返回列表