如何设置ffmpeg队列?

Tra*_*rea 3 queue bash cron ffmpeg batch-processing

我试图在我的服务器上编码很多视频,但FFMPEG是资源密集型的,所以我想设置某种形式的排队.我的网站的其余部分使用PHP,但我不知道我是否应该使用PHP,Python,BASH等.我在想我可能需要使用CRON,但我不确定如何告诉ffmpeg启动一个新任务(从列表中)完成之后的任务.

Gil*_*not 7

我们将在bash脚本中使用FIFO(先进先出).脚本需要在之前运行cron(或任何脚本,任何调用它的终端FIFO)以向ffmpeg此脚本发送命令:

#!/bin/bash

pipe=/tmp/ffmpeg

trap "rm -f $pipe" EXIT

# creating the FIFO    
[[ -p $pipe ]] || mkfifo $pipe

while true; do
    # can't just use "while read line" if we 
    # want this script to continue running.
    read line < $pipe

    # now implementing a bit of security,
    # feel free to improve it.
    # we ensure that the command is a ffmpeg one.
    [[ $line =~ ^ffmpeg ]] && bash <<< "$line"
done
Run Code Online (Sandbox Code Playgroud)

现在(当脚本运行时),我们可以ffmpeg使用以下语法将任何命令发送到命名管道:

echo "ffmpeg -version" > /tmp/ffmpeg
Run Code Online (Sandbox Code Playgroud)

并通过错误检查:

if [[ -p /tmp/ffmpeg ]]; then
    echo "ffmpeg -version" > /tmp/ffmpeg
else
    echo >&2 "ffmpeg FIFO isn't open :/"
fi
Run Code Online (Sandbox Code Playgroud)

他们将自动排队.