[fix] add bitrate and switch to concat
This commit is contained in:
parent
813be866ea
commit
ce402fa9b2
53
makevideo.sh
53
makevideo.sh
@ -2,15 +2,16 @@
|
|||||||
usage(){
|
usage(){
|
||||||
cat << EOF
|
cat << EOF
|
||||||
|
|
||||||
$(basename $0) -d <directory> -s <rate> -p <prefix> -v <video_dir> -s <size>
|
$(basename $0) -d <directory> -s <accelerate> -p <prefix> -v <video_dir> -s <size>
|
||||||
|
|
||||||
——————————————————————————————————————————————————————————————————————————————————
|
——————————————————————————————————————————————————————————————————————————————————
|
||||||
Opt | Variable | Type | Definition | Default value
|
Opt | Variable | Type | Definition | Default value
|
||||||
——————————————————————————————————————————————————————————————————————————————————
|
——————————————————————————————————————————————————————————————————————————————————
|
||||||
-d directory path Directory path of images to convert ./pics
|
-d directory path Directory path of images to convert ./pics
|
||||||
-r rate int Convert only 1/N images 1
|
-a accelerate int Convert only 1/N images 1
|
||||||
-p prefix str Images filename prefix. ''
|
-p prefix str Images filename prefix. ''
|
||||||
-v video_dir path Directory path to store video file. ./videos
|
-v video_dir path Directory path to store video file. ./videos
|
||||||
|
-b bitrate str Video bitrate 1500k
|
||||||
-s size str Images geometry. '1024x768'
|
-s size str Images geometry. '1024x768'
|
||||||
——————————————————————————————————————————————————————————————————————————————————
|
——————————————————————————————————————————————————————————————————————————————————
|
||||||
|
|
||||||
@ -21,26 +22,33 @@ panic(){ echo $@; exit 2;}
|
|||||||
|
|
||||||
directory="./pics"
|
directory="./pics"
|
||||||
prefix=""
|
prefix=""
|
||||||
rate="1"
|
accelerate="1"
|
||||||
size='1024x768'
|
size='1024x768'
|
||||||
video_dir="./videos"
|
video_dir="./videos"
|
||||||
|
bitrate="1500k"
|
||||||
|
|
||||||
while getopts "hd:s:p:v:" o; do
|
while getopts "a:b:d:hs:p:r:v:" o; do
|
||||||
case "${o}" in
|
case "${o}" in
|
||||||
h)
|
a)
|
||||||
usage
|
accelerate=${OPTARG}
|
||||||
;;
|
|
||||||
r)
|
|
||||||
rate=${OPTARG}
|
|
||||||
;;
|
;;
|
||||||
d)
|
d)
|
||||||
directory=${OPTARG}
|
directory=${OPTARG}
|
||||||
;;
|
;;
|
||||||
|
h)
|
||||||
|
usage
|
||||||
|
;;
|
||||||
p)
|
p)
|
||||||
prefix=${OPTARG}
|
prefix=${OPTARG}
|
||||||
;;
|
;;
|
||||||
|
b)
|
||||||
|
bitrate=${OPTARG}
|
||||||
|
;;
|
||||||
|
s)
|
||||||
|
size=${OPTARG}
|
||||||
|
;;
|
||||||
v)
|
v)
|
||||||
video_dir=$( realpath ${OPTARG} 2>/dev/null )
|
video_dir=${OPTARG}
|
||||||
;;
|
;;
|
||||||
\?)
|
\?)
|
||||||
panic "Unknown option at position $OPTIND. Exiting."
|
panic "Unknown option at position $OPTIND. Exiting."
|
||||||
@ -55,12 +63,21 @@ which ffmpeg &>/dev/null || panic "No ffmpeg found. Exiting."
|
|||||||
directory="$( realpath ${directory} 2>/dev/null )/"
|
directory="$( realpath ${directory} 2>/dev/null )/"
|
||||||
[ -n "${directory}" ] && [ -d "${directory}" ] || panic "'${directory}' is not a valid directory. Exiting."
|
[ -n "${directory}" ] && [ -d "${directory}" ] || panic "'${directory}' is not a valid directory. Exiting."
|
||||||
|
|
||||||
# Safe test prefix
|
# Safe test accelerate
|
||||||
[ -n "$( ls ${directory}/${prefix}* 2>/dev/null)" ] || panic "${directory}/${prefix}\* doesn't match any file. Exiting."
|
[ ${accelerate} -gt 0 ] || panic "Invalid rate '${rate}'"
|
||||||
|
|
||||||
|
# Safe test prefix
|
||||||
|
let c=0
|
||||||
|
tmpfile=$( mktemp )
|
||||||
|
for file in ${directory}/${prefix}* ; do
|
||||||
|
|
||||||
|
let $(( c++ ))
|
||||||
|
[[ $(( $c % ${accelerate} )) -eq 0 ]] || [[ $rate -eq 1 ]] && echo "file '$file'" >> $tmpfile
|
||||||
|
|
||||||
|
done
|
||||||
|
|
||||||
|
[ 0 -eq $c ] && panic "No file found"
|
||||||
|
|
||||||
# Safe test rate
|
|
||||||
[ ${rate} -gt 0 ] || panic "Invalid rate '${rate}'"
|
|
||||||
pts=$( echo 1/$rate | bc -l )
|
|
||||||
|
|
||||||
# Safe test video_dir
|
# Safe test video_dir
|
||||||
video_dir="$( realpath ${video_dir} 2>/dev/null )/"
|
video_dir="$( realpath ${video_dir} 2>/dev/null )/"
|
||||||
@ -71,11 +88,11 @@ video_dir="$( realpath ${video_dir} 2>/dev/null )/"
|
|||||||
[ "N" == ${REPLY^^} ] && panic "The video directory must exist. Exiting."
|
[ "N" == ${REPLY^^} ] && panic "The video directory must exist. Exiting."
|
||||||
mkdir -p ${video_dir} 2>/dev/null || panic "Failed to create '${video_dir}'. Exiting"
|
mkdir -p ${video_dir} 2>/dev/null || panic "Failed to create '${video_dir}'. Exiting"
|
||||||
}
|
}
|
||||||
[ -n "$( ls ${directory}/${prefix}* 2>/dev/null)" ] || panic "${directory}/${prefix}\* doesn't match any file. Exiting."
|
|
||||||
|
|
||||||
# Set video file name
|
# Set video file name
|
||||||
date=$(date +%s)
|
date=$(date +%s)
|
||||||
video_file="${video_dir}$date.mp4"
|
video_file="${video_dir}$date.mp4"
|
||||||
echo -e "\nSaving to video file $video_file.\n"
|
echo -e "\nSaving to video file $video_file\n"
|
||||||
|
|
||||||
ffmpeg -hide_banner -loglevel quiet -stats -pattern_type glob -i "pics/*.jpg" -filter:v "setpts=(${pts})*PTS" -pix_fmt yuv420p -s "${size}" -vcodec libx264 "${video_file}"
|
ffmpeg -hide_banner -loglevel quiet -stats -f concat -safe 0 -i "${tmpfile}" -pix_fmt yuv420p -s "${size}" -vcodec libx264 -b ${bitrate} "${video_file}"
|
||||||
|
rm -f $tmpfile
|
||||||
|
Loading…
Reference in New Issue
Block a user