How to pipe a new command after ffmpeg background process completes?

我只是一个虾纸丫 提交于 2020-01-16 02:55:29

问题


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.


回答1:


Write an external (bash/php) script that executes both the ffmpeg and php process, and tack & after that.

For windows, please open a new question on SO.




回答2:


To add on to what Evert had posted, here is an example of what I use for my FFMPEG bash script... it's far from done (it doesn't alert if the program crashes, for instance) but it's somewhere to start:

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

And this all gets called from a PHP file that does (along with some other code):

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 - I know mysql extension are on their way out, I haven't been using or updating this code in a while, so please update to your specifications



来源:https://stackoverflow.com/questions/18769220/how-to-pipe-a-new-command-after-ffmpeg-background-process-completes

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!