ffmpeg重复视频片段
#!/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
#
# 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 "
exit
fi
if [ "x${loops}" == "x" ]; then
echo "USAGE: ${0} inputFile numloops "
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
页:
[1]