使用 ffmpeg 在启动时以 5 分钟为一个片段录制屏幕(12.04)

使用 ffmpeg 在启动时以 5 分钟为一个片段录制屏幕(12.04)

因此,我对此进行了相当多的尝试,但在这一点上,我遇到了下一步该怎么做的障碍。

我有这个脚本,它可以通过 ssh 隧道记录显示:0.0

#!/bin/dash
# Sleep to try not to break everything YAY
sleep 30
# Export the main display
export DISPLAY=0.0
#Start an infinite loop
while true; do
        # Set variable now to todays date and the time right now in Hours-Minutes-Seconds_Month-Day-Year
        now=$(date +'%H-%M-%S_%m-%d-%Y')
        # Start recording using ffmpeg at 5fps with a time limit of 300 seconds(Five Minutes) to file $now
        ffmpeg -f x11grab -s 1024x768 -r 5 -t 300 -i :0.0 /home/swuser/Videos/$now.mp4
done

我已经尝试过将它用于一个 upstart 作业,但是它会在启动时挂起,除非我给它一个睡眠条件,在这种情况下它不会记录(我假设它无法找到显示:0.0,即使睡眠是在导出之前)并且脚本会继续运行,什么也不做,只是ffmpeg一遍又一遍地结束。

作为参考,我正在运行ffmpeg 0.10.12-7:0.10.12-1~precise1

任何帮助是极大的赞赏!!

答案1

我最终使用该.profile文件并将我的代码更改为以下内容:

.profile

if [ "$RECORDISRUNNING" != "1" ]; then
    export RECORDISRUNNING=1
    /home/swuser/sleep.sh &
fi

sleep.sh

#!/bin/sh
# sleep for 30 seconds then call record.sh
sleep 30
/home/swuser/scripts/record.sh &

record.sh

#!/bin/sh
# Check to see if there is a display, and if not, exit with error code of 1
if [ -z "$DISPLAY" ]; then
exit 1
fi
# Export the main display
export DISPLAY=0.0
# Set variable now to todays date and the time right now in Hours-Minutes-Seconds_Month-Day-Year
now=$(date +'%H-%M-%S_%m-%d-%Y')
# Start recording using ffmpeg at 5fps with a time limit of 300 seconds(Five Minutes) to file $now
ffmpeg -f x11grab -s 1024x768 -r 5 -t 300 -i :0.0 /home/swuser/Videos/$now.mp4
# Call the script again (to continually record in 300 second increments)
/home/swuser/scripts/record.sh &

这就是全部内容了。

相关内容