1

This is my ffmpeg process:

exec("/usr/local/bin/ffmpeg -y -i source.avi dest.mp4 >/dev/null 2>/dev/null &

Now, I wish to execute a PHP file after the conversion is complete. Logically, this is what I have:

exec("/usr/local/bin/ffmpeg -y -i source.avi dest.mp4 >/dev/null 2>/dev/null ; php proceed.php &

This doesn't work though, since then PHP will hold up the process to wait till the ffmpeg conversion is complete. What I want is basically to call proceed.php after the conversion completes, both of which are done in the background.

If anyone can provide the Windows server solution, that will be awesome too.

4

2 回答 2

3

编写一个执行 ffmpeg 和 php 进程的外部 (bash/php) 脚本,然后执行&此操作。

对于 Windows,请在 SO 上打开一个新问题。

于 2013-09-12T16:13:41.300 回答
2

为了补充 Evert 发布的内容,这里是我用于 FFMPEG bash 脚本的示例......它远未完成(例如,如果程序崩溃,它不会发出警报)但它是开始的地方:

#!/bin/sh

## Set our paths
FFMPEG_PATH=/usr/local/bin
SITE_PATH=path_to_file
VIDEO_PATH=$SITE_PATH/public_html/videos

## Make sure we have permissions to do this stuff
chown -R wwwrun:www $VIDEO_PATH/$2
chmod -R 765 $VIDEO_PATH/$2

## Set the options for mp4 compression
options="-vcodec libx264 -b 512k -ar 22050 -flags +loop+mv4 -cmp 256 \
       -partitions +parti4x4+parti8x8+partp4x4+partp8x8+partb8x8 \
       -me_method hex -subq 7 -trellis 1 -refs 5 -bf 3 \
       -flags2 +bpyramid+wpred+mixed_refs+dct8x8 -coder 1 -me_range 16 \
       -g 250 -keyint_min 25 -sc_threshold 40 -i_qfactor 0.71 -qmin 10\
       -qmax 51 -qdiff 4"

## Start the conversion.
$FFMPEG_PATH/ffmpeg -y -i $VIDEO_PATH/$2/original/$1 -an -pass 1 -threads 2 $options $VIDEO_PATH/$2/$2.mp4 2> $VIDEO_PATH/$2/pass_one.log
$FFMPEG_PATH/ffmpeg -y -i $VIDEO_PATH/$2/original/$1 -acodec libfaac -ab 96k -pass 2 -threads 2 $options $VIDEO_PATH/$2/$2.mp4 2> $VIDEO_PATH/$2/pass_two.log

## Create the thumbnail for the video
. $SITE_PATH/bin/create_thumbnail $2 00:00:15 2> $VIDEO_PATH/$2/generate_thumbnails.log

## Clean up the log files that were created
## find /log_path/ -name *log* -exec rm {} \;

## Update datbase and send email that we're done here.
php $SITE_PATH/public_html/admin/includes/video_status.php converting_finished $2

这一切都是从一个 PHP 文件中调用的(连同其他一些代码):

proc_close(proc_open(server_path.'/bin/convert_video_mp4 '.mysql_result($next_video, 0, "uid").'.'.mysql_result($next_video, 0, "original_ext").' '.mysql_result($next_video, 0, "uid").' &', array(), $foo));

PS - 我知道 mysql 扩展即将推出,我有一段时间没有使用或更新此代码,所以请更新到您的规范

于 2013-09-12T16:43:26.653 回答