I am using ffmpeg to convert a video file to mp4. here is my code
echo "converting ".basename($src)." --- to --- ".basename($dest).".mp4...<br />";
$command = FFMPEG.' -i ' . $src . ' -sameq -strict -2 -vcodec libx264 -ar 22050 -y ' . $dest.'.mp4 2>&1'; //
echo $command.'<br>';
exec($command,$output,$status);
echo '<pre>',join('<br>',$output),'</pre><br>';
if($status == 0) { // Success
echo 'Successfully converted to MP4!<br />';
} else {
echo $status."<br>failed<br>";
}
The code works fine on my localhost (Windows 7 + wamp).. But on live server , only $command is echoed.. and script is terminated. The output file is generated but it is only 4.5MB (it should be around 17 MB) and not complete... and sometime I get the following output..
ffmpeg version 0.11.1 Copyright (c) 2000-2012 the FFmpeg developers built on Sep 10 2012 00:38:24 with gcc 4.1.2 20080704 (Red Hat 4.1.2-52) configuration: --prefix=/home/one01qsc/local --extra-cflags='-L/home/one01qsc/local/lib/ -I /home/one01qsc/local/include/' --extra-ldflags='-L/home/one01qsc/local/lib/ -Wl,-rpath,/home/one01qsc/local/lib/' --enable-libmp3lame --enable-libvorbis --enable-shared --disable-yasm --enable-libtheora --enable-libx264 --enable-gpl
libavutil 51. 54.100 / 51. 54.100
libavcodec 54. 23.100 / 54. 23.100
libavformat 54. 6.100 / 54. 6.100
libavdevice 54. 0.100 / 54. 0.100
libavfilter 2. 77.100 / 2. 77.100
libswscale 2. 1.100 / 2. 1.100
libswresample 0. 15.100 / 0. 15.100
libpostproc 52. 0.100 / 52. 0.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '/home/one01qsc/public_html/temp/pending/1455-testing-mobidick.mov':
Metadata:
major_brand : qt
minor_version : 537199360
compatible_brands: qt
creation_time : 2012-09-08 16:00:41
Duration: 00:00:23.13, start: 0.490000, bitrate: 6028 kb/s
Stream #0:0: Video: h264 (High) (avc1 / 0x31637661), yuv420p, 1920x1080, 5331 kb/s, 29.97 fps, 29.97 tbr, 60k tbn, 59.94 tbc
Metadata:
creation_time : 2012-09-08 16:00:41
handler_name : Apple Alias Data Handler
Stream #0:1: Audio: aac (mp4a / 0x6134706D), 44100 Hz, stereo, s16, 192 kb/s
Metadata:
creation_time : 2012-09-08 16:00:41
handler_name : Apple Alias Data Handler
[buffer # 0x2405ce0] w:1920 h:1080 pixfmt:yuv420p tb:1/60000 sar:0/1 sws_param:flags=2
[buffersink # 0x2429ec0] No opaque field provided
[aformat # 0x23fa560] auto-inserting filter 'auto-inserted resampler 0' between the filter 'src' and the filter 'aformat'
[aresample # 0x2402e60] chl:stereo fmt:s16 r:44100Hz -> chl:stereo fmt:flt r:22050Hz
[libx264 # 0x24288e0] using cpu capabilities: none!
[libx264 # 0x24288e0] profile High, level 4.0
[libx264 # 0x24288e0] 264 - core 128 - H.264/MPEG-4 AVC codec - Copyleft 2003-2012 - http://www.videolan.org/x264.html - options: cabac=1 ref=3 deblock=1:0:0 analyse=0x3:0x113 me=hex subme=7 psy=1 psy_rd=1.00:0.00 mixed_ref=1 me_range=16 chroma_me=1 trellis=1 8x8dct=1 cqm=0 deadzone=21,11 fast_pskip=1 chroma_qp_offset=-2 threads=24 lookahead_threads=4 sliced_threads=0 nr=0 decimate=1 interlaced=0 bluray_compat=0 constrained_intra=0 bframes=3 b_pyramid=2 b_adapt=1 b_bias=0 direct=1 weightb=1 open_gop=0 weightp=2 keyint=250 keyint_min=25 scenecut=40 intra_refresh=0 rc_lookahead=40 rc=crf mbtree=1 crf=23.0 qcomp=0.60 qpmin=0 qpmax=69 qpstep=4 ip_ratio=1.40 aq=1:1.00
Output #0, mp4, to '/home/one01qsc/public_html/temp/1455-testing-mobidick.mp4':
Metadata:
major_brand : qt
minor_version : 537199360
compatible_brands: qt
creation_time : 2012-09-08 16:00:41
encoder : Lavf54.6.100
Stream #0:0: Video: h264 (![0][0][0] / 0x0021), yuv420p, 1920x1080, q=-1--1, 30k tbn, 29.97 tbc
Metadata:
creation_time : 2012-09-08 16:00:41
handler_name : Apple Alias Data Handler
Stream #0:1: Audio: aac (#[0][0][0] / 0x0040), 22050 Hz, stereo, flt, 128 kb/s
Metadata:
creation_time : 2012-09-08 16:00:41
handler_name : Apple Alias Data Handler
Stream mapping:
Stream #0:0 -> #0:0 (h264 -> libx264)
Stream #0:1 -> #0:1 (aac -> aac)
Press [q] to stop, [?] for help
frame= 18 fps=0.0 q=0.0 size= 0kB time=00:00:00.00 bitrate= 0.0kbits/s
the value printed for $status is 137 in this case.
Any help is really appreciated.
137 means it got a signal 9. So you must have a program checking on your live server for how much memory / CPU a single process can consume. If it exceeds that limit, it will be terminated, which is what is happening to your process.
Related
I use this code to convert GIFs to MP4:
$videoname = str_replace('.gif', '.mp4', $picname);
$ffmpeg = FFMpeg\FFMpeg::create(array(
'ffmpeg.binaries' => 'ffmpeg/bin/ffmpeg.exe',
'ffprobe.binaries' => 'ffmpeg/bin/ffprobe.exe',
'timeout' => 6600, // The timeout for the underlying process
'ffmpeg.threads' => 12, // The number of threads that FFMpeg should use
), $logger);
$video = $ffmpeg->open('memes/' . $folder . '/' . $picname);
$format = new \FFMpeg\Format\Video\X264('libvo_aacenc', 'libx264');
$format->setAdditionalParameters(array('-profile:v', 'baseline', '-pix_fmt', 'yuv420p'));
$video
->save($format, 'memes/' . $folder . '/' . $videoname);
Some GIFs are getting converted but some not, this is the error message:
[16-Aug-2020 14:47:21 Europe/Berlin] PHP Fatal error: Uncaught Alchemy\BinaryDriver\Exception\ExecutionFailureException: ffmpeg failed to execute command "ffmpeg/bin/ffmpeg.exe" -y -i "memes/38/Dr5W6yzR_gif_38.gif" -threads 12 -vcodec libx264 -acodec libvo_aacenc -b:v 1000k -refs 6 -coder 1 -sc_threshold 40 -flags +loop -me_range 16 -subq 7 -i_qfactor 0.71 -qcomp 0.6 -qdiff 4 -trellis 1 -b:a 128k -profile:v baseline -pix_fmt yuv420p -pass 1 -passlogfile "C:\Windows\TEMP\ffmpeg-passes5f392ad8ba750qewzr/pass-5f392ad8bb9b7" "memes/38/Dr5W6yzR_gif_38.mp4":
Error Output:
ffmpeg version 4.2.2 Copyright (c) 2000-2019 the FFmpeg developers
built with gcc 9.2.1 (GCC) 20200122
configuration: --enable-gpl --enable-version3 --enable-sdl2 --enable-fontconfig --enable-gnutls --enable-iconv --enable-libass --enable-libdav1d --enable-libbluray --enable-libfreetype --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libopus --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libtheora --enable-libtwolame --e in C:\Inetpub\vhosts\yolol.de\vendor\php-ffmpeg\php-ffmpeg\src\FFMpeg\Media\AbstractVideo.php on line 106
What is all this crap?
Please help!
EDIT:
This is what I'm getting when running this code in cmd:
ffmpeg version 4.2.2 Copyright (c) 2000-2019 the FFmpeg developers
built with gcc 9.2.1 (GCC) 20200122
configuration: --enable-gpl --enable-version3 --enable-sdl2 --enable-fontconfig --enable-gnutls --enable-iconv --enable-libass --enable-libdav1d --enable-libbluray --enable-libfreetype --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libopus --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libtheora --enable-libtwolame --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 --enable-libzimg --enable-lzma --enable-zlib --enable-gmp --enable-libvidstab --enable-libvorbis --enable-libvo-amrwbenc --enable-libmysofa --enable-libspeex --enable-libxvid --enable-libaom --enable-libmfx --enable-amf --enable-ffnvcodec --enable-cuvid --enable-d3d11va --enable-nvenc --enable-nvdec --enable-dxva2 --enable-avisynth --enable-libopenmpt
libavutil 56. 31.100 / 56. 31.100
libavcodec 58. 54.100 / 58. 54.100
libavformat 58. 29.100 / 58. 29.100
libavdevice 58. 8.100 / 58. 8.100
libavfilter 7. 57.100 / 7. 57.100
libswscale 5. 5.100 / 5. 5.100
libswresample 3. 5.100 / 3. 5.100
libpostproc 55. 5.100 / 55. 5.100
Input #0, gif, from 'C://ttt.gif':
Duration: 00:00:03.08, start: 0.000000, bitrate: 10411 kb/s
Stream #0:0: Video: gif, bgra, 636x357, 14.25 fps, 14.29 tbr, 100 tbn, 100 tbc
Stream mapping:
Stream #0:0 -> #0:0 (gif (native) -> h264 (libx264))
Press [q] to stop, [?] for help
[libx264 # 0000021dca771a40] height not divisible by 2 (636x357)
Error initializing output stream 0:0 -- Error while opening encoder for output stream #0:0 - maybe incorrect parameters such as bit_rate, rate, width or height
Conversion failed!
So the error is height not divisible by 2 (636x357) I guess, but what would be the solution?
The solution:
$format->setAdditionalParameters(array('-profile:v', 'baseline', '-pix_fmt', 'yuv420p', '-vf', 'scale=trunc(iw/2)*2:trunc(ih/2)*2'));
I am using a shared hosting server with ffmpeg installed. i have been told they cant upgrade the version I have. I am trying to convert video files to html5 formats. When I try to convert to webm, I get below error. Can anyone help with this problem?
exec("/usr/bin/ffmpeg -i eliza.mp4 -acodec copy -vcodec copy 2>&1 video.webm");
array(29) { [0]=> string(67) "FFmpeg version 0.6.5, Copyright (c) 2000-2010 the FFmpeg developers"
[1]=> string(74) " built on Jan 29 2012 23:55:02 with gcc 4.1.2 20080704 (Red Hat 4.1.2-51)" [2]=>
string(649) " configuration: --prefix=/usr --libdir=/usr/lib64 --shlibdir=/usr/lib64
--mandir=/usr/share/man --incdir=/usr/include --disable-avisynth --extra-cflags='-O2 -g -pipe
-Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64
-mtune=generic -fPIC' --enable-avfilter --enable-avfilter-lavf --enable-libdirac --enable-libfaac
--enable-libfaad --enable-libfaadbin --enable-libgsm --enable-libmp3lame --enable-libopencore-amrnb
--enable-libopencore-amrwb --enable-libx264 --enable-gpl --enable-nonfree --enable-postproc
--enable-pthreads --enable-shared --enable-swscale --enable-vdpau --enable-version3
--enable-x11grab" [3]=> string(35) " libavutil 50.15. 1 / 50.15. 1" [4]=> string(35) "
libavcodec 52.72. 2 / 52.72. 2" [5]=> string(35) " libavformat 52.64. 2 / 52.64. 2"
[6]=> string(35) " libavdevice 52. 2. 0 / 52. 2. 0" [7]=> string(35) " libavfilter 1.19. 0 / 1.19. 0" [8]=>
string(35) " libswscale 0.11. 0 / 0.11. 0" [9]=> string(35) " libpostproc 51. 2. 0 / 51. 2. 0" [10]=>
string(52) "Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'eliza.mp4':" [11]=> string(11) " Metadata:" [12]=>
string(26) " major_brand : mp42" [13]=> string(23) " minor_version : 0" [14]=> string(35) " compatible_brands:
mp42isomavc1" [15]=> string(48) " encoder : HandBrake 0.9.4 2009112300" [16]=> string(59) " Duration:
00:00:05.56, start: 0.000000, bitrate: 551 kb/s" [17]=> string(94) " Stream #0.0(und): Video: h264,
yuv420p, 560x320, 465 kb/s, 30 fps, 30 tbr, 90k tbn, 60 tbc" [18]=> string(62) " Stream #0.1(eng):
Audio: aac, 48000 Hz, mono, s16, 83 kb/s" [19]=> string(72) "[webm # 0x7200a0]Only VP8 video and
Vorbis audio are supported for WebM." [20]=> string(33) "Output #0, webm, to 'video.webm':"
[21]=> string(11) " Metadata:" [22]=> string(33) " encoder : Lavf52.64.2" [23]=> string(89) "
Stream #0.0(und): Video: libx264, yuv420p, 560x320, q=2-31, 465 kb/s, 90k tbn, 30 tbc" [24]=>
string(61) " Stream #0.1(eng): Audio: libfaac, 48000 Hz, mono, 83 kb/s" [25]=> string(15)
"Stream mapping:" [26]=> string(21) " Stream #0.0 -> #0.0" [27]=> string(21) " Stream #0.1 ->
#0.1" [28]=> string(72) "Could not write header for output file #0 (incorrect codec parameters ?)" }
According to your own error log:
[webm # 0x7200a0] Only VP8 video and Vorbis audio are supported for WebM
Your input file is H.264/AAC and you're trying to copy the source codecs using -acodec copy -vcodec copy instead of converting them to VP8/Vorbis.
You can try to re-encode the file. Unfortunately the FFmpeg version is really outdated. The latest release is 2.6.2 (vs. 0.6.5).
Alright, I've been fighting this problem for a few days. Works fine on my local windows machine but, can't seem to get it to work on my CentOS server. My script grabs the duration of the video being converted and also grabs the current seconds it has processed inside of ffmpeg. However, it is only grabbing the "input file" of the ffmpeg output and stopping there. I have tried using both pipes (STDOUT [1] & STDERR [2]) for some reason ffmpeg likes to output on the STDERR pipe. Weird.
$filename = "somefilename.tmp";
$descriptor = array(
0 => array("pipe", "r"),
1 => array("pipe", "w"),
2 => array("pipe", "w")
);
$ffmpeg = "ffmpeg -i /var/www/spotloader/videos/flipped/tmp/".$file."_comb.ts -vcodec mpeg2video -acodec pcm_s16le -pix_fmt yuv422p -vtag xdvb -b:v 13000k -r 30000/1001 /var/www/spotloader/videos/flipped/tmp/".$file.".mov";
//open the process
$process = proc_open($ffmpeg, $descriptor, $pipes, NULL, $_ENV);
//if the process opened
if ( is_resource( $process ) == true )
{
//get process status
$procStatus = proc_get_status( $process );
//if its running, let node know
if ( $procStatus['running'] )
{
//nodejs socket, nothing wrong here
$this->_sendSocket('converting', array('filename' => str_replace('.tmp', '', $file)));
}
//while the process is running
while( $procStatus['running'] === true )
{
//there is output in the pipe
if ( !feof( $pipes[1] ) )
{
//get the output
$data = fgets($pipes[1], 128);
//match the outputs duration and save it.
if(preg_match('/Duration:\s([0-9]{2}:[0-9]{2}:[0-9]{2})/', $data, $matches))
{
static $duration;
$duration = $this->_convertToSeconds($matches[1]);
}
//match the outputs current encoding time
if(preg_match('/time=([0-9]{2}:[0-9]{2}:[0-9]{2})/', $data, $matches))
{
//convert to seconds works fine, so it is not included.
$curTime = $this->_convertToSeconds($matches[1]);
//nodejs socket, nothing wrong here
$this->_sendSocket('update', array('percent' => round( ($curTime / $duration) * 100), 'filename' => str_replace('.tmp', '', $file)));
}
}
//update process status
$procStatus = proc_get_status( $process );
}
//nodejs socket, nothing wrong here
$this->_sendSocket('converted', array('percent' => 100, 'filename' => str_replace('.tmp', '', $file)));
}
FFMPEG output I receive using the PHP code above
ffmpeg version 1.2.1 Copyright (c) 2000-2013 the FFmpeg developers
built on May 10 2013 15:14:14 with gcc 4.4.6 (GCC) 20120305 (Red Hat 4.4.6-4)
configuration: --prefix=/usr --libdir=/usr/lib64 --shlibdir=/usr/lib64
--mandir=/usr/share/man --enable-shared --enable-runtime-cpudetect --enable-gpl
--enable-version3 --enable-postproc --enable-avfilter --enable-pthreads
--enable-x11grab --enable-vdpau --disable-avisynth --enable-frei0r --enable-libopencv
--enable-libdc1394 --enable-libgsm --enable-libmp3lame --enable-libnut
--enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg
--enable-librtmp --enable-libspeex --enable-libtheora --enable-libvorbis
--enable-libvpx --enable-libx264 --enable-libxavs --enable-libxvid
--extra-cflags='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions
-fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic -fPIC'
--disable-stripping
libavutil 52. 18.100 / 52. 18.100
libavcodec 54. 92.100 / 54. 92.100
libavformat 54. 63.104 / 54. 63.104
libavdevice 54. 3.103 / 54. 3.103
libavfilter 3. 42.103 / 3. 42.103
libswscale 2. 2.100 / 2. 2.100
libswresample 0. 17.102 / 0. 17.102
libpostproc 52. 2.100 / 52. 2.100
[mpegts # 0x243c620] max_analyze_duration 5000000 reached at 5016000 microseconds
Input #0, mpegts, from '/var/www/spotloader/videos/flipped/tmp/Wildlife10.tmp_comb.ts':
Duration: 00:00:02.02, start: 1.389978, bitrate: 227018 kb/s
Program 1
Metadata:
service_name : Service01
service_provider: FFmpeg
Stream #0:0[0x100]: Video: mpeg2video (4:2:2) ([2][0][0][0] / 0x0002), yuv422p, 1920x1080 [SAR 1:1 DAR 16:9], 29.97 fps, 29.97 tbr, 90k tbn, 59.94 tbc
Stream #0:1[0x101](eng): Audio: mp2 ([3][0][0][0] / 0x0003), 48000 Hz, 1 channels (FL+FR), s16p, 128 kb/s
FFMPEG output I'm expecting the "time=00:00:00" towards the end is what I need to capture in realtime. This is taken by running the FFMPEG command directly in the shell.
ffmpeg version 1.2.1 Copyright (c) 2000-2013 the FFmpeg developers
built on May 10 2013 15:14:14 with gcc 4.4.6 (GCC) 20120305 (Red Hat 4.4.6-4)
configuration: --prefix=/usr --libdir=/usr/lib64 --shlibdir=/usr/lib64
--mandir=/usr/share/man --enable-shared --enable-runtime-cpudetect --enable-gpl
--enable-version3 --enable-postproc --enable-avfilter --enable-pthreads
--enable-x11grab --enable-vdpau --disable-avisynth --enable-frei0r --enable-libopencv
--enable-libdc1394 --enable-libgsm --enable-libmp3lame --enable-libnut
--enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg
--enable-librtmp --enable-libspeex --enable-libtheora --enable-libvorbis
--enable-libvpx --enable-libx264 --enable-libxavs --enable-libxvid
--extra-cflags='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions
-fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic -fPIC'
--disable-stripping
libavutil 52. 18.100 / 52. 18.100
libavcodec 54. 92.100 / 54. 92.100
libavformat 54. 63.104 / 54. 63.104
libavdevice 54. 3.103 / 54. 3.103
libavfilter 3. 42.103 / 3. 42.103
libswscale 2. 2.100 / 2. 2.100
libswresample 0. 17.102 / 0. 17.102
libpostproc 52. 2.100 / 52. 2.100
[mpegts # 0x10c9620] max_analyze_duration 5000000 reached at 5016000 microseconds
Input #0, mpegts, from '/var/www/spotloader/videos/flipped/tmp/Wildlife10.tmp_comb.ts':
Duration: 00:00:02.02, start: 1.389978, bitrate: 227018 kb/s
Program 1
Metadata:
service_name : Service01
service_provider: FFmpeg
Stream #0:0[0x100]: Video: mpeg2video (4:2:2) ([2][0][0][0] / 0x0002), yuv422p, 1920x1080 [SAR 1:1 DAR 16:9], 29.97 fps, 29.97 tbr, 90k tbn, 59.94 tbc
Stream #0:1[0x101](eng): Audio: mp2 ([3][0][0][0] / 0x0003), 48000 Hz, 1 channels (FL+FR), s16p, 128 kb/s
Channel layout 'stereo' with 2 channels does not match specified number of channels 1: ignoring specified channel layout
Output #0, mov, to '/var/www/spotloader/videos/flipped/tmp/Wildlife10.tmp.mov':
Metadata:
encoder : Lavf54.63.104
Stream #0:0: Video: mpeg2video (xdvb / 0x62766478), yuv422p, 1920x1080 [SAR 1:1 DAR 16:9], q=2-31, 13000 kb/s, 30k tbn, 29.97 tbc
Stream #0:1(eng): Audio: pcm_s16le (sowt / 0x74776F73), 48000 Hz, stereo, s16, 1536 kb/s
Stream mapping:
Stream #0:0 -> #0:0 (mpeg2video -> mpeg2video)
Stream #0:1 -> #0:1 (mp2 -> pcm_s16le)
Press [q] to stop, [?] for help
Input stream #0:1 frame changed from rate:48000 fmt:s16p ch:1 chl:1 channels (FL+FR) to rate:48000 fmt:s16p ch:2 chl:stereo
Input stream #0:1 frame changed from rate:48000 fmt:s16p ch:2 chl:stereo to rate:48000 fmt:s16p ch:1 chl:mono
Input stream #0:1 frame changed from rate:48000 fmt:s16p ch:1 chl:mono to rate:48000 fmt:s16p ch:2 chl:stereo
Input stream #0:0 frame changed from size:1920x1080 fmt:yuv422p to size:1280x720 fmt:yuv422p0
Input stream #0:1 frame changed from rate:48000 fmt:s16p ch:2 chl:stereo to rate:44100 fmt:s16p ch:2 chl:stereo
frame= 741 fps= 52 q=2.6 size= 43866kB time=00:00:24.65 bitrate=14573.5kbits/s dup=5 drop=0
Any ideas? What needs changing from the switch from Windows to CentOS?
EDIT:
I got this to work using popen instead. It also reduced my code. If anyone else does have a solution go ahead and post it. Thanks!
heres something
This was from a project i was working on a while ago. I think it's pretty close to what you want. Be warned it's a bit buggy and not very secure
ffmpeTest.php
<html>
<body>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"></script>
<h2>Video Uploader</h2>
<form method="post" enctype="multipart/form-data">
<input type="file" required id="upload" name="file"/>
<input type="submit" value="Upload video" id="upload" name="upload"/>
</form>
<?
ini_set('memory_limit', '1000M');
ini_set('post_max_size', '1000M');
ini_set('upload_max_filesize', '1000M');
if(isset($_POST['upload'])){
$ffmpeg = '/usr/local/Cellar/ffmpeg/1.2.1/bin/ffmpeg';//path to ffmpeg
$origVideo = $_FILES['file']['tmp_name'];
$newVideo = "videos/".$_FILES['file']['name'];
move_uploaded_file($origVideo, $newVideo);
$time = time();
$command1 = $ffmpeg.' -i "'.$newVideo.'" videos/'.$time.'.flv ';
shell_exec(sprintf('%s > videos/block.txt 2>&1 &', $command1));
}
?>
<div id="load"></div>
<script>
$('#thumb').load(function(){
setInterval(function() {
$('#load').load('http://localhost/Playground/ffmpeLoader.php ffmpeLoader.php');
}, 600);
});
</script>
</body>
</html>
ffmpeloader.php
<?
$content = #file_get_contents('videos/block.txt');
if($content){
//get duration of source
preg_match("/Duration: (.*?), start:/", $content, $matches);
$rawDuration = $matches[1];
//rawDuration is in 00:00:00.00 format. This converts it to seconds.
$ar = array_reverse(explode(":", $rawDuration));
$duration = floatval($ar[0]);
if (!empty($ar[1])) $duration += intval($ar[1]) * 60;
if (!empty($ar[2])) $duration += intval($ar[2]) * 60 * 60;
//get the time in the file that is already encoded
preg_match_all("/time=(.*?) bitrate/", $content, $matches);
$rawTime = array_pop($matches);
//this is needed if there is more than one match
if (is_array($rawTime)){$rawTime = array_pop($rawTime);}
//rawTime is in 00:00:00.00 format. This converts it to seconds.
$ar = array_reverse(explode(":", $rawTime));
$time = floatval($ar[0]);
if (!empty($ar[1])) $time += intval($ar[1]) * 60;
if (!empty($ar[2])) $time += intval($ar[2]) * 60 * 60;
//calculate the progress
$progress = round(($time/$duration) * 100);
echo "<progress id='p' max='100' value='" . $progress . "'></progress><span> ".$progress."%</span>";
}
if($progress == 100){
echo '<p> Done!</p>';
}
?>
i am converting a videofile with the latest version of ffmpeg in php:
exec("ffmpeg -y -i capture.wmv capture.mp4 2>&1", $output);
var_dump($output);
This is the result:
array(21) {
[0]=>
string(99) "FFmpeg version SVN-r0.5.9-4:0.5.9-0ubuntu0.10.04.3, Copyright (c) 2000-2009 Fabrice Bellard, et al."
[1]=>
string(451) " configuration: --extra-version=4:0.5.9-0ubuntu0.10.04.3 --prefix=/usr --enable-avfilter --enable-avfilter-lavf --enable-vdpau --enable-bzlib --enable-libgsm --enable-libschroedinger --enable-libspeex --enable-libtheora --enable-libvorbis --enable-pthreads --enable-zlib --disable-stripping --disable-vhook --enable-runtime-cpudetect --enable-gpl --enable-postproc --enable-swscale --enable-x11grab --enable-libdc1394 --enable-shared --disable-static"
[2]=>
string(35) " libavutil 49.15. 0 / 49.15. 0"
[3]=>
string(35) " libavcodec 52.20. 1 / 52.20. 1"
[4]=>
string(35) " libavformat 52.31. 0 / 52.31. 0"
[5]=>
string(35) " libavdevice 52. 1. 0 / 52. 1. 0"
[6]=>
string(35) " libavfilter 0. 4. 0 / 0. 4. 0"
[7]=>
string(35) " libswscale 0. 7. 1 / 0. 7. 1"
[8]=>
string(35) " libpostproc 51. 2. 0 / 51. 2. 0"
[9]=>
string(43) " built on Jan 24 2013 19:42:59, gcc: 4.4.3"
[10]=>
string(34) "Input #0, asf, from 'capture.wmv':"
[11]=>
string(60) " Duration: 00:04:11.45, start: 3.000000, bitrate: 1755 kb/s"
[12]=>
string(62) " Stream #0.0: Audio: wmav2, 44100 Hz, stereo, s16, 128 kb/s"
[13]=>
string(82) " Stream #0.1: Video: wmv2, yuv420p, 1280x720, 1600 kb/s, 1k tbr, 1k tbn, 1k tbc"
[14]=>
string(33) "Output #0, mp4, to 'capture.mp4':"
[15]=>
string(83) " Stream #0.0: Video: mpeg4, yuv420p, 1280x720, q=2-31, 200 kb/s, 90k tbn, 1k tbc"
[16]=>
string(62) " Stream #0.1: Audio: 0x0000, 44100 Hz, stereo, s16, 64 kb/s"
[17]=>
string(15) "Stream mapping:"
[18]=>
string(21) " Stream #0.1 -> #0.0"
[19]=>
string(21) " Stream #0.0 -> #0.1"
[20]=>
string(40) "Unsupported codec for output stream #0.1"
}
I need a standard mp4-file for playing in web with html5. Where could be the problem? Is the codex not installed? Or is something wrong with the console command?
EDIT:
After using a static build i try to convert a wmv to mp4 with
exec("/www/htdocs/xxxx/video/ffmpeg -y -i capture.wmv capture.mp4 2>&1", $output);
The result file has a size of only some bytes - this is the output:
array(40) {
[0]=>
string(77) "ffmpeg version N-49805-gfd6a021 Copyright (c) 2000-2013 the FFmpeg developers"
[1]=>
string(61) " built on Feb 11 2013 05:23:18 with gcc 4.6 (Debian 4.6.3-1)"
[2]=>
string(609) " configuration: --prefix=/root/ffmpeg-static/64bit --extra-cflags='-I/root/ffmpeg-static/64bit/include -static' --extra-ldflags='-L/root/ffmpeg-static/64bit/lib -static' --extra-libs='-lxml2 -lexpat -lfreetype' --enable-static --disable-shared --disable-ffserver --disable-doc --enable-bzlib --enable-zlib --enable-postproc --enable-runtime-cpudetect --enable-libx264 --enable-gpl --enable-libtheora --enable-libvorbis --enable-libmp3lame --enable-gray --enable-libass --enable-libfreetype --enable-libopenjpeg --enable-libspeex --enable-libvo-aacenc --enable-libvo-amrwbenc --enable-version3 --enable-libvpx"
[3]=>
string(40) " libavutil 52. 17.101 / 52. 17.101"
[4]=>
string(40) " libavcodec 54. 91.102 / 54. 91.102"
[5]=>
string(40) " libavformat 54. 62.100 / 54. 62.100"
[6]=>
string(40) " libavdevice 54. 3.103 / 54. 3.103"
[7]=>
string(40) " libavfilter 3. 37.101 / 3. 37.101"
[8]=>
string(40) " libswscale 2. 2.100 / 2. 2.100"
[9]=>
string(40) " libswresample 0. 17.102 / 0. 17.102"
[10]=>
string(40) " libpostproc 52. 2.100 / 52. 2.100"
[11]=>
string(54) "Guessed Channel Layout for Input Stream #0.0 : stereo"
[12]=>
string(34) "Input #0, asf, from 'capture.wmv':"
[13]=>
string(11) " Metadata:"
[14]=>
string(32) " WMFSDKNeeded : 0.0.0.0000"
[15]=>
string(32) " DeviceConformanceTemplate: #"
[16]=>
string(37) " WMFSDKVersion : 12.0.7601.17514"
[17]=>
string(23) " IsVBR : 0"
[18]=>
string(60) " Duration: 00:04:13.40, start: 0.000000, bitrate: 1742 kb/s"
[19]=>
string(90) " Stream #0:0(ger): Audio: wmav2 (a[1][0][0] / 0x0161), 44100 Hz, stereo, fltp, 128 kb/s"
[20]=>
string(125) " Stream #0:1(ger): Video: wmv2 (WMV2 / 0x32564D57), yuv420p, 1280x720, 1600 kb/s, SAR 1:1 DAR 16:9, 1k tbr, 1k tbn, 1k tbc"
[21]=>
string(35) "[libx264 # 0x2f082e0] using SAR=1/1"
[22]=>
string(63) "[libx264 # 0x2f082e0] MB rate (3600000) > level limit (2073600)"
[23]=>
string(88) "[libx264 # 0x2f082e0] using cpu capabilities: MMX2 SSE2Fast SSSE3 FastShuffle SSE4.2 AVX"
[24]=>
string(45) "[libx264 # 0x2f082e0] profile High, level 5.2"
[25]=>
string(684) "[libx264 # 0x2f082e0] 264 - core 129 r2230 1cffe9f - H.264/MPEG-4 AVC codec - Copyleft 2003-2012 - http://www.videolan.org/x264.html - options: cabac=1 ref=3 deblock=1:0:0 analyse=0x3:0x113 me=hex subme=7 psy=1 psy_rd=1.00:0.00 mixed_ref=1 me_range=16 chroma_me=1 trellis=1 8x8dct=1 cqm=0 deadzone=21,11 fast_pskip=1 chroma_qp_offset=-2 threads=6 lookahead_threads=1 sliced_threads=0 nr=0 decimate=1 interlaced=0 bluray_compat=0 constrained_intra=0 bframes=3 b_pyramid=2 b_adapt=1 b_bias=0 direct=1 weightb=1 open_gop=0 weightp=2 keyint=250 keyint_min=25 scenecut=40 intra_refresh=0 rc_lookahead=40 rc=crf mbtree=1 crf=23.0 qcomp=0.60 qpmin=0 qpmax=69 qpstep=4 ip_ratio=1.40 aq=1:1.00"
[26]=>
string(33) "Output #0, mp4, to 'capture.mp4':"
[27]=>
string(11) " Metadata:"
[28]=>
string(32) " WMFSDKNeeded : 0.0.0.0000"
[29]=>
string(32) " DeviceConformanceTemplate: #"
[30]=>
string(37) " WMFSDKVersion : 12.0.7601.17514"
[31]=>
string(23) " IsVBR : 0"
[32]=>
string(35) " encoder : Lavf54.62.100"
[33]=>
string(122) " Stream #0:0(ger): Video: h264 ([33][0][0][0] / 0x0021), yuv420p, 1280x720 [SAR 1:1 DAR 16:9], q=-1--1, 16k tbn, 1k tbc"
[34]=>
string(90) " Stream #0:1(ger): Audio: aac ([64][0][0][0] / 0x0040), 44100 Hz, stereo, s16, 128 kb/s"
[35]=>
string(15) "Stream mapping:"
[36]=>
string(39) " Stream #0:1 -> #0:0 (wmv2 -> libx264)"
[37]=>
string(45) " Stream #0:0 -> #0:1 (wmav2 -> libvo_aacenc)"
[38]=>
string(31) "Press [q] to stop, [?] for help"
[39]=>
string(96) "frame= 158 fps=0.0 q=33.0 size= 0kB time=00:00:00.10 bitrate= 3.6kbits/s dup=155 drop=0"
}
slhck - thanks for your tipps - do you see the problem?
Your FFmpeg version is 0.5.9, which is from a branch that was cut in 2009 (!). Chances are the problem is due to the ancient release and there's no point trying to troubleshoot something which is entirely unsupported. As far as I can tell FFmpeg can't find a proper audio codec to encode the video with. You don't have any external AAC or MP3 encoder as well.
In any case: Install a newer version. Do this by either compiling it yourself, or downloading a static build.
To produce a HTML5-ready MP4 video, you'd probably explicitly choose an H.264-encoded video with the Baseline profile (to suit mobile devices) and AAC audio:
ffmpeg -i capture.wmv -c:v libx264 -profile:v baseline -c:a aac -strict experimental -b:a 192k out.mp4
To change the video quality, add the -crf option, with a value between 18–28 (23 is default). Lower means better quality. See the x264 Encoding Guide on the FFmpeg Wiki for more info.
Your video should contain the MOOV atom at the beginning of the file, which would allow your users to start streaming the contents immediately (otherwise they'd have to download the entire file). You can set this while encoding:
ffmpeg -i [stuff from above…] -movflags faststart out.mp4
If you have FFmpeg with FAAC support (check with ffmpeg -codecs | grep libfaac), you can also use the following, similar to above:
ffmpeg -i -c:v libx264 -profile:v baseline -c:a libfaac -q:a 100 out.mp4
Here, you'd get VBR AAC audio of better quality instead of the fixed bitrate stream above. The quality is in percent, and 100 is the default.
i am doing the following
$output = shell_exec('/usr/local/bin/ffmpeg -i intro.mp3 2>&1');
echo "<pre>$output</pre>";
This outputs
ffmpeg version 0.8.5, Copyright (c) 2000-2011 the FFmpeg developers
built on Aug 20 2012 09:28:43 with clang 3.1 (tags/Apple/clang-318.0.61)
configuration: --enable-nonfree --enable-gpl --enable-version3 --enable-postproc --enable-swscale --enable-avfilter --enable-libmp3lame --enable-libvorbis --enable-libtheora --enable-libfaac --enable-libxvid --enable-libx264 --enable-libvpx --enable-hardcoded-tables --enable-shared --enable-pthreads --disable-indevs --cc=clang
libavutil 51. 9. 1 / 51. 9. 1
libavcodec 53. 7. 0 / 53. 7. 0
libavformat 53. 4. 0 / 53. 4. 0
libavdevice 53. 1. 1 / 53. 1. 1
libavfilter 2. 23. 0 / 2. 23. 0
libswscale 2. 0. 0 / 2. 0. 0
libpostproc 51. 2. 0 / 51. 2. 0
[mp3 # 0x7f9481807c00] max_analyze_duration 5000000 reached at 5015510
Input #0, mp3, from 'intro.mp3':
Metadata:
album : Frank
artist : Amy Winehouse
genre : R&B
title : [Intro] Stronger Than Me
track : 01
date : 2008
Duration: 00:03:54.71, start: 0.000000, bitrate: 230 kb/s
Stream #0.0: Audio: mp3, 44100 Hz, stereo, s16, 160 kb/s
At least one output file must be specified
i want to get the information to insert into a database album,artist,genre,title etc
But all seperately
i can get them by doing the following
$output = shell_exec('/usr/local/bin/ffmpeg -i intro.mp3 2>&1');
$edit = explode(' ', $output);
$edit = implode("#", $edit);
$edit = explode(':', $output);
echo "<pre>";
print_r($edit);
echo "</pre>";
then running
<?php echo $edit[9]; ?>
etc
but this seems like a really bad way and annoying way to get values and sometimes the output is slightly different which messes with the outputs.
Whats the best way to do this or am i stuck doing this?
There is a better way to retrieve metadata using ffmpeg.
1. Create a new ffmpeg_movie object e.g
$movie = new ffmpeg_movie(String path_to_media, boolean persistent);
2. Start getting metada like so:
$movie->getAuthor();
$movie->getGenre();
$movie->getAlbum();
List of what's available at ffmpeg-php API documentation.
3. Celebrate good times.