我根据来自我的安全摄像头的图像制作延时视频。相机按日期将 JPG 分类到文件夹中,然后按小时分类到子文件夹中。
这会展平、重命名并将结果推送到 avconv。
#!/bin/bash
SOURCE_DIR="/home/ftp/camera/$1"
TIMELAPSE_DIR="/home/ftp/camera/timelapse-batch"
FRAME_DELAY=50
ls -1 $SOURCE_DIR |
while read DAY;
do
echo "=================================================================";
echo "| >>> Processing $SOURCE_DIR/$DAY";
cd $SOURCE_DIR/$DAY;
echo "| >>> Flattening...";
find $SOURCE_DIR/$DAY -mindepth 2 -type f -exec mv -t $SOURCE_DIR/$DAY -i '{}' +
echo "| >>> Frame Count: $(ls -1 | wc -l)";
echo "| >>> Converting...";
echo "-----------------------------------------------------------------";
#gets list of images, renames them to a format that avconv expects, then runs avconv
ls |
grep jpg |
awk -v name=$1 'BEGIN{a=0}{printf "mv %s " name "%04d.JPG\n" , $0, a++}' |
bash && avconv -y -r $FRAME_DELAY -i $1%4d.JPG -r $FRAME_DELAY -vcodec libx264 -q:v 4 -vf scale=iw:ih $TIMELAPSE_DIR/$DAY"_"$1.mp4;
echo "-----------------------------------------------------------------";
echo "| >>> Done!";
echo "=================================================================";
echo -e "\n\n\n\n";
done