How to check if ffmpeg is done encoding a video wi

2019-04-02 20:36发布

I need the specific code to check with PHP if it is done encoding a video with ffmpeg. I just need a simple true/false check. True if the encoding is done, and false if it is not done. Also the language is PHP, and I do have ffmpeg-php installed.

More info: I am on Linux.

Code is below

convertToFlv( $input, $output );

function convertToFlv( $input, $output ) {

echo "Converting $input to $output";

$command = "ffmpeg -y -i $input -acodec libfaac -ar 44100 -ab 96k -vcodec libx264 -level 41 -crf 20 -bufsize 20000k -maxrate 25000k -g 250 -r 20 -s 640x480 -coder 1 -flags +loop -cmp +chroma -partitions +parti4x4+partp8x8+partb8x8 -flags2 +brdo+dct8x8+bpyramid -me umh -subq 7 -me_range 16 -keyint_min 25 -sc_threshold 40 -i_qfactor 0.71 -rc_eq 'blurCplx^(1-qComp)' -bf 16 -b_strategy 1 -bidir_refine 1 -refs 6 -deblockalpha 0 -deblockbeta 0 $output";

shell_exec( $command );

}

标签: php ffmpeg
3条回答
爱情/是我丢掉的垃圾
2楼-- · 2019-04-02 20:46

The simple answer is to check if the process is still running, which means either filtering the output of ps or keeping track of the PID of the ffmpeg process and checking via pcntl_waitpid.

查看更多
Luminary・发光体
3楼-- · 2019-04-02 20:58

You could add another line of code after the ffmpeg in the php exec() to run a php page in the command line.

Just end your ffmpeg line with a ";" and type "php" followed by the absolute location of your php script to run. You could add a get variable with the id of the video you are waiting to be converted:

$cmd = "ffmpeg -i[SOURCE FILE] [OUTPUT FILE]; php /public_html/etc/ffmpegComplete.php?videoID=101";

exec( $cmd );
查看更多
爷的心禁止访问
4楼-- · 2019-04-02 21:03

Maybe you could give us a clue how you are starting the encoding off? And what OS you are running on?

Assuming that you are doing it the right way on a Unix/POSIX/Linux system - i.e. you've created a new process in a seperate process group and can't read the return value directly, then why don't you just wrap the ffmpeg binary in a simple sh script - something like:

#!/bin/bash

OUTDIR=/var/www/html/video

/usr/local/bin/ffmpeg -s sqcif -i $1 ${OUTDIR}/${2}.mpeg`

RETURNED=$?

echo ${RETURNED} >${OUTDIR}/${2}.completion

...then you can see when the script has finished, and whether it ran successfully.

查看更多
登录 后发表回答