When i run the ffmpeg command directly in the command line it is working. But when i used the php command is breaking and getting error (At least one output file must be specified)
Code directly in command line
ffmpeg -i "F:/Sites/raaga_deploy36/mp4/arul/ghajini_rahath-96.mp4" -y -c copy -bsf h264_mp4toannexb -flags global_header -map 0 -f segment -segment_time 10 -segment_list "F:/Sites/raaga_deploy36/mp4/m3u8/ghajini_rahath-96.m3u8" -segment_format mpegts "F:/Sites/raaga_deploy36/mp4/m3u8/ghajini_rahath-96-segment_%05d.ts"
Code from PHP
$mfile=escapeshellarg($dir.$file);
$cfile=escapeshellarg($dir1.$fname.".m3u8");
$cfile_sg=escapeshellarg($dir1.$fname."-segment_%05d.ts");
$cmd="ffmpeg -i ".$mfile."-y -c copy -bsf h264_mp4toannexb -flags global_header -map 0 -f segment -segment_time 10 -segment_list ".$cfile.".m3u8 -segment_format mpegts ".$cfile_sg;
$res=shell_exec( $cmd );
Output in the command line
ffmpeg -i "C:/sites/hls/mp4/arul/ghajini_orum-128.mp4
"-y -c copy -bsf h264_mp4toannexb -flags global_header -map 0 -f segment -segmen
t_time 10 -segment_list "C:/sites/hls/mp4/m3u8/ghajini_orum-128.m3u8".m3u8 -segm
ent_format mpegts "C:/sites/hls/mp4/m3u8/ghajini_orum-128-segment_ 05d.ts"
since the commands (line) are breaking here it is not working.
please see the link below
http://dv.raaga.com/new_ig/m3u_convert_err.jpg
Thanks
Thanigaivelan
Related
I have problems with FFmpeg and Intel QuickSync. If I start my ffmpeg command from shell it works correctly. But if I want to start the same ffmpeg command from an cronjob I get Failure with quicksync
My command is:
/bin/ffmpeg -vsync passthrough -copytb 1 -hwaccel qsv -probesize 5000000 -analyzeduration 16000000 -c:v hevc_qsv -recv_buffer_size 67108864 -i source -filter_complex "[v:0]hwdownload,format=pix_fmts=nv12[format:0]; [format:0]cvdelogo=filename=file:buffer_queue_size=150:detect_interval=25:score_min=0.4:scale_min=0.75:scale_max=1.25:padding_left=10:padding_right=10:padding_top=10:padding_bottom=10[cvdelogo]; [cvdelogo]split=outputs=1[hwupload:0]; [hwupload:0]hwupload=extra_hw_frames=10[map:v:0]" -map [map:v:0] -c:v h264_qsv -flags:v +global_header+cgop -preset:v veryfast -g 250 -b:v:0 6200k -maxrate:v:0 6200k -bufsize:v:0 6200k -map a:0 -c:a copy -f hls -hls_flags delete_segments -hls_time 10 -hls_list_size 6 output.m3u8
If I run that on terminal everything works. But if I want to start it from php with shell_exec command over an cronjob I get this failure:
[AVHWDeviceContext # 0x2cc7b80] Failed to initialise VAAPI connection: -1 (unknown libva error). Error creating a QSV device
I don't know why FFmpeg is not founding the vaapi device from cronjob, pls help me out of this issue.
Thanks
cpulimit -l 180 ffmpeg-static/ffmpeg -ss 0 -t 8.96 -i '/var/www/html/Videos2/Character Jack/Happy/happy birthday scene.mp4' -filter_complex '[0] drawtext=textfile=scene2.txt:fontsize=199.68:fontfile=/var/www/html/fonts/Arial.ttf:x=288:y=409:fontcolor_expr=ffffff%{eif\: clip(1+(255*t/4)\, 0\, 255)\:x\:2}' -pass 1 -f h264 -y - > /dev/null &&
cpulimit -l 180 ffmpeg-static/ffmpeg -ss 0 -t 8.96 -i '/var/www/html/Videos2/Character Jack/Happy/happy birthday scene.mp4' -i '/var/www/html/Userfiles/Users/blaze/Projects/earl3x/audio/scene2_music.x.mp3' -filter_complex '[1] volume=0.95 [au1]; [0][au1] amix=inputs=2:duration=shortest' -c:v copy -c:a libmp3lame -pix_fmt yuv420p -preset ultrafast -shortest -movflags faststart -y -pass 2 /var/www/html/Userfiles/Users/blaze/example/earl4x/scene2.mp4
What i'm trying to achieve ?
encoding text elements / graphics on the first pass
and encoding Sound (audio) on the second pass
the first pass and second pass runs fine ( with no errors at all)
and the output has no artifact.
however the text is totally no where to be found!
what it seems like is that , the second pass had no idea there was a first pass with text encoded in it.
what will be the right way to run / format the command ?
thanks
i solved this.
i had to go through another method
-generate the video with with draw text ( dont parse the -pass 1 parameter)
just run your output normally
-put you output url as the input url of the next command (use -y and remember no passes)
add the audio file as the second input parameter
-output a final file
note things could get really muddy if you have a series of complex combinations
so i have to figure out an algorithm specific to my case that worked.
The drawtext has to be applied both times. What pass 1 is generate the video, analyze video and then discard it, so drawtext has to be present for pass 2 as well.
ffmpeg -ss 0 -t 8.96 -i '/var/www/html/Videos2/Character Jack/Happy/happy birthday scene.mp4' \
-filter_complex \
'[0] drawtext=textfile=scene2.txt:fontsize=199.68:fontfile=/var/www/html/fonts/Arial.ttf: \
x=288:y=409: \
fontcolor_expr=ffffff%{eif\: clip(1+(255*t/4)\, 0\, 255)\:x\:2}' \
-pass 1 -c:v libx264 -f null -
2nd pass:
ffmpeg -ss 0 -t 8.96 -i '/var/www/html/Videos2/Character Jack/Happy/happy birthday scene.mp4' \
-i '/var/www/html/Userfiles/Users/blaze/Projects/earl3x/audio/scene2_music.x.mp3' \
-filter_complex \
'[0] drawtext=textfile=scene2.txt:fontsize=199.68:fontfile=/var/www/html/fonts/Arial.ttf: \
x=288:y=409: \
fontcolor_expr=ffffff%{eif\: clip(1+(255*t/4)\, 0\, 255)\:x\:2}[v];
[1]volume=0.95 [au1]; [0][au1] amix=inputs=2:duration=shortest[a]' -map "[v]" -map "[a]" \
-pass 2 -c:v libx264 -c:a libmp3lame -pix_fmt yuv420p -preset ultrafast -shortest \
-movflags +faststart -y \
/var/www/html/Userfiles/Users/blaze/example/earl4x/scene2.mp4
I want to execute the following command
exec("c:\Program Files\Handbrake\HandBrakeCLI -i D:/wamp/www/upload_google_drive/output.flv -e x264 -a 1 -E faac -6 dpl2 -R Auto -D 0.0 -f mp4 -I -m -x level=30:bframes=0:weightp=0:cabac=0:ref=1:vbv-maxrate=768:vbv-bufsize=2000:analyse=all:me=umh:no-fast-pskip=1:subme=6:8x8dct=0:trellis=0 -b 250 -B 64 -R 48 -X 480 -w 480 -l 320 -2 -o D:/wamp/www/upload_google_drive/w2.mp4 2>&1",$output);
in php but after executing i am gettting the following error message:
Array ( [0] => 'c:\Program' is not recognized as an internal or
external command, [1] => operable program or batch file. )
It's because you have a space in the path. You will have to put the path between "
Like so:
exec("\"c:\Program Files\Handbrake\HandBrakeCLI\" -i D:/wamp/www/upload_google_drive/output.flv -e x264 -a 1 -E faac -6 dpl2 -R Auto -D 0.0 -f mp4 -I -m -x level=30:bframes=0:weightp=0:cabac=0:ref=1:vbv-maxrate=768:vbv-bufsize=2000:analyse=all:me=umh:no-fast-pskip=1:subme=6:8x8dct=0:trellis=0 -b 250 -B 64 -R 48 -X 480 -w 480 -l 320 -2 -o D:/wamp/www/upload_google_drive/w2.mp4 2>&1",$output);
I think your problem is the space in the file name between 'Program' and 'Files'
Since I don't know which language 'exec' is from I can't offer the exact solution, but if i were you I'd try adding quotes around
c:\Program Files\Handbrake\HandBrakeCLI
so maybe
exec("'c:\Program Files\Handbrake\HandBrakeCLI' -i D:/wamp/www/upload_google_drive/output.flv -e x264 -a 1 -E faac -6 dpl2 -R Auto -D 0.0 -f mp4 -I -m -x level=30:bframes=0:weightp=0:cabac=0:ref=1:vbv-maxrate=768:vbv-bufsize=2000:analyse=all:me=umh:no-fast-pskip=1:subme=6:8x8dct=0:trellis=0 -b 250 -B 64 -R 48 -X 480 -w 480 -l 320 -2 -o D:/wamp/www/upload_google_drive/w2.mp4 2>&1",$output);
The path "Program Files" contains a space so you need to wrap it around with single quotes '
c:\Program Files
Eg:
exec('"c:\Program Files\Handbrake\HandBrakeCLI -i D:/wamp/www/upload_google_drive/output.flv -e x264 -a 1 -E faac -6 dpl2 -R Auto -D 0.0 -f mp4 -I -m -x level=30:bframes=0:weightp=0:cabac=0:ref=1:vbv-maxrate=768:vbv-bufsize=2000:analyse=all:me=umh:no-fast-pskip=1:subme=6:8x8dct=0:trellis=0 -b 250 -B 64 -R 48 -X 480 -w 480 -l 320 -2 -o D:/wamp/www/upload_google_drive/w2.mp4 2>&1"',$output);
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.
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.
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
I am using a ffmpeg command to cut a video with exec function in php. But it is not creating a video file and doesn't show any errors. I used exec as below
exec("ffmpeg -i input.flv -ss 00:00:30.0 -t 00:00:10.0 -acodec copy -vcodec copy -async 1 output.flv");
Can I get any help to know what is the error happening here?
exec("ffmpeg -i input.flv -ss 00:00:30.0 -t 00:00:10.0 -acodec copy -vcodec copy -async 1 output.flv",$output);
I tried it also. But I didn't get any error message in variable $output
As a general rule, you first need to check the return value: non-zero values indicate there has been an error (given that the author of the program you are running adheres to the standard). This value is captured in exec()'s third argument.
In second place, many programs do not send error messages to the standard output. Instead, they use the standard error. In this case, it seems safe to just redirect the latter to the former:
exec("ffmpeg -i input.flv -ss 00:00:30.0 -t 00:00:10.0 -acodec copy -vcodec copy -async 1 output.flv 2>&1", $output, $return_value);