3

サーバーで多くのビデオをエンコードしようとしていますが、FFMPEGはリソースを大量に消費するため、何らかの形式のキューイングを設定したいと思います。私のサイトの残りの部分はPHPを使用していますが、PHP、Python、BASHなどを使用する必要があるかどうかわかりません。CRONを使用する必要があるかもしれないと思っていましたが、ffmpegに開始するように指示する方法が正確にはわかりません。前のタスクを終了した後の(リストからの)新しいタスク。

4

2 に答える 2

8

We will use FIFO (First In First Out) in a bash script. The script needs to run before cron (or any script, any terminal that call the FIFO) to send ffmpeg commands to this script :

#!/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

Now (when the script is running), we can send any ffmpeg commands to the named pipe by using the syntax :

echo "ffmpeg -version" > /tmp/ffmpeg

And with error checking:

if [[ -p /tmp/ffmpeg ]]; then
    echo "ffmpeg -version" > /tmp/ffmpeg
else
    echo >&2 "ffmpeg FIFO isn't open :/"
fi

They will be queuing automatically.

于 2012-10-02T21:05:26.343 に答える
1

これをありがとう。この手法を正確に適用して、ffmpegキューを作成しました。ただし、小さな変更を1つ行いました。何らかの理由で、このキューは2つのアイテムに対してのみ機能しました。最初のアイテムが終わったとき、私は3番目のアイテムを送ることができるだけでした。

それに応じてスクリプトを変更しました。

while true; do

# added tweak to fix hang
exec 3<> $pipe

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

私はこれに基づいています: https ://stackoverflow.com/questions/15376562/cant-write-to-named-pipe

これを将来使用するために共有する必要があると思っただけです。

于 2015-05-01T12:57:36.980 に答える