PHP-FFMpeg / PHP-FFMpeg

An object oriented PHP driver for FFMpeg binary
MIT License
4.86k stars 888 forks source link

x264 ERROR #467

Open Sub-7 opened 6 years ago

Sub-7 commented 6 years ago
Q A
Bug? YES
New Feature? no
Version Used Specific tag or commit sha
FFmpeg Version Compilation ffmpeg.org: N-89811-g27b9f82, built with gcc 5.4.0
OS Ubuntu 16.04 PHP7

Coding in x264:

require 'vendor/autoload.php';
$ffmpeg = FFMpeg\FFMpeg::create();
$video = $ffmpeg->open('INPUT/video.mp4');
$video
    ->filters()
    ->resize(new FFMpeg\Coordinate\Dimension(320, 240))
    ->synchronize();
$video
    ->frame(FFMpeg\Coordinate\TimeCode::fromSeconds(10))
    ->save('OUTPUT/frame.jpg');
$video
    ->save(new FFMpeg\Format\Video\X264(), 'OUTPUT/output-x264.mp4');

Fatal error: Object(SplObje in /var/www/html/vendor/php-ffmpeg/php-ffmpeg/src/FFMpeg/Media/Video.php on line 96

if I change last line, everything is fine: ->save(new FFMpeg\Format\Video\WMV(), 'export-wmv.wmv') or ->save(new FFMpeg\Format\Video\WebM(), 'export-webm.webm');

no problem with it: shell_exec("ffmpeg -y -i INPUT/video.mp4 -vcodec libx264 OUTPUT/output.avi </dev/null >/dev/null 2>/var/www/html/log/CODER.log &");

jens1o commented 6 years ago

Could you post the full exception message please?

Sub-7 commented 6 years ago

Sicher doch,

Fatal error: Uncaught Alchemy\BinaryDriver\Exception\ExecutionFailureException: ffmpeg failed to execute command '/usr/bin/ffmpeg' '-y' '-i' 'INPUT/video.mp4' '-async' '1' '-metadata:s:v:0' 'start_time=0' '-vcodec' 'libx264' '-acodec' 'libfaac' '-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' '-vf' '[in]scale=320:240 [out]' '-pass' '1' '-passlogfile' '/tmp/ffmpeg-passes5a5fa9e2b5e3bsx8v8/pass-5a5fa9e2b5eb9' 'OUTPUT/output-x264.mp4' in /var/www/html/vendor/alchemy/binary-driver/src/Alchemy/BinaryDriver/ProcessRunner.php:100 Stack trace: #0 /var/www/html/vendor/alchemy/binary-driver/src/Alchemy/BinaryDriver/ProcessRunner.php(72): Alchemy\BinaryDriver\ProcessRunner->doExecutionFailure(''/usr/bin/ffmpe...') #1 /var/www/html/vendor/alchemy/binary-driver/src/Alchemy/BinaryDriver/AbstractBinary.php(209): Alchemy\BinaryDriver\ProcessRunner->run(Object(Symfony\Component\Process\Process), Object(Spl in /var/www/html/vendor/php-ffmpeg/php-ffmpeg/src/FFMpeg/Media/Video.php on line 96

jens1o commented 6 years ago

The exception message does not match to what your code is saying.

Can you verify that the user hosting the php process has access to the tmp directory and any files you're touching?

Sub-7 commented 6 years ago

Error message is correct, I only copied the last line

even rights changed, nothing happens, but it works fine with webm and wmv. According to error message he looks for ffmpeg in / usr / bin / ffmpeg what was not with wmv and webm (new files have also copied there and reboot)

idea?

jens1o commented 6 years ago

According to error message he looks for ffmpeg in / usr / bin / ffmpeg what was not with wmv and webm (new files have also copied there and reboot)

The Format does not change how the executables are being looked up in any way.

Could you try changing the method save to getFinalCommand? Do not change the parameters. It will give you the command that will be executed under the hood. Next, try to execute the given command in the CLI and report to us what you can see.

Sub-7 commented 6 years ago

like so? but i see no output require 'vendor/autoload.php'; $ffmpeg = FFMpeg\FFMpeg::create(); $video = $ffmpeg->open('INPUT/video.mp4'); $video ->filters() ->resize(new FFMpeg\Coordinate\Dimension(320, 240)) ->synchronize(); $video ->frame(FFMpeg\Coordinate\TimeCode::fromSeconds(10)) ->save('OUTPUT/frame.jpg'); $video ->getFinalCommand(new FFMpeg\Format\Video\X264(), 'OUTPUT/export.mp4');

jens1o commented 6 years ago

The code will be returned that you need to execute.

nikolamakin commented 6 years ago

I have the same problem.

  | Fatal error: Uncaught exception 'Alchemy\BinaryDriver\Exception\ExecutionFailureException' with message 'ffmpeg failed to execute command '/server/ffmpeg/bin/ffmpeg' '-y' '-i' '/www/xinqi/1.mp4' '-vcodec' 'libx264' '-acodec' 'libfaac' '-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' '-pass' '1' '-passlogfile' '/tmp/ffmpeg-passes5a70624d609803hedm/pass-5a70624d60a65' '2.mp4'' in /www/xinqi/plug/vendor/alchemy/binary-driver/src/Alchemy/BinaryDriver/ProcessRunner.php:100   | Stack trace:   | #0 /www/xinqi/plug/vendor/alchemy/binary-driver/src/Alchemy/BinaryDriver/ProcessRunner.php(72): Alchemy\BinaryDriver\ProcessRunner->doExecutionFailure(''/server/ffmpeg...')   | #1 /www/xinqi/plug/vendor/alchemy/binary-driver/src/Alchemy/BinaryDriver/AbstractBinary.php(209): Alchemy\BinaryDriver\ProcessRunner->run(Object(Symfony\Component\Process\Process), Object(SplObjectStorage), false)   | #2 /www/xinqi/plug/vendor/alc in /www/xinqi/plug/vendor/php-ffmpeg/php-ffmpeg/src/FFMpeg/Media/Video.php on line 96

nikolamakin commented 6 years ago

but,its can ssh :ffmpeg -i /www/xinqi/1.wmv -vcodec libx264 /www/xinqi/s.mp4

jens1o commented 6 years ago

Please check the permissions of the user executing the php script.

nikolamakin commented 6 years ago

php script is default use 'daemon' use : ->save(new FFMpeg\Format\Video\WMV(), 'export-wmv.wmv') is no problem

But it's a problem with this: ->save(new FFMpeg\Format\Video\X264(), 'export-x264.mp4')

nikolamakin commented 6 years ago

问题解决了,是因为最新版本的ffmpeg不支持--enable-libfaac ,所以PHP-FFMpeg默认用的libfaac会导致错误。 可以这样new FFMpeg\Format\Video\X264('libmp3lame') 或者使用libfdk_aac 也可以直接改写类 public function __construct($audioCodec = 'libfdk_aac', $videoCodec = 'libx264')

感谢PHP-FFMpeg

jens1o commented 6 years ago

Please write in proper English sentences.

nise commented 6 years ago

I have a similar problem with the following code. All files, paths, and permissions are well defined. The php-File is owned by www-data and has been set on 777 for testing.

`require_once 'vendor/autoload.php'; $ffmpeg = FFMpeg\FFMpeg::create(array( 'ffmpeg.binaries' => $this->config['ffmpeg'], // /usr/bin 'ffprobe.binaries' => $this->config['ffprobe'], 'timeout' => 360000, // The timeout for the underlying process 'ffmpeg.threads' => 16, // The number of threads that FFMpeg should use ));

    $ffmpeg = FFMpeg\FFMpeg::create();
    $video = $ffmpeg->open( $filename );
    $formatx264 = new FFMpeg\Format\Video\X264();
    $formatx264->setAudioCodec("libmp3lame");
   //...

    $video->save($formatx264, $this->TMP_DIR . '/' . $name . '.mp4');`

Apache error log says:

PHP Fatal error: Uncaught Alchemy\BinaryDriver\Exception\ExecutionFailureException: ffmpeg failed to execute command '/usr/bin/ffmpeg' '-y' '-i' '/home/abb/Documents/www/videos/tmp/1527848448-pn3260p.mp4' '-vcodec' 'libx264' '-acodec' 'libmp3lame' '-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' '-pass' '2' '-passlogfile' '/tmp/ffmpeg-passes5b111e09a5e49snw9r/pass-5b111e09a5f02' '/home/abb/Documents/www/videos/tmp/1527848448-pn3260p.mp4' in /home/abb/Documents/www/videos/php-video-upload-chain/vendor/alchemy/binary-driver/src/Alchemy/BinaryDriver/ProcessRunner.php:100\nStack trace:\n#0 /home/abb/Documents/www/videos/php-video-upload-chain/vendor/alchemy/binary-driver/src/Alchemy/BinaryDriver/ProcessRunner.php(72): Alchemy\BinaryDriver\ProcessRunner->doExecutionFailure(''/usr/bin/ffmpe...')\n#1 /home/abb/Documents/www/videos/php-video-upload-chain/vendor/alchemy/binary-driver/src/Alchemy/BinaryDri in /home/abb/Documents/www/videos/php-video-upload-chain/vendor/php-ffmpeg/php-ffmpeg/src/FFMpeg/Media/Video.php on line 109, referer: http://localhost/moodle/mod/videodatabase/view.php?id=1

If I run the ffmpeg command in terminal: /usr/bin/ffmpeg -y -i /home/abb/Downloads/pn3260p.mp4 -vcodec libx264 -acodec libmp3lame -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 -pass 2 -passlogfile /tmp/ffmpeg-passes5b111e09a5e49snw9r/pass-5b111e09a5f02 /home/abb/Documents/www/videos/tmp/1527848448-pn3260p.mp4

I am getting an error:

sudo /usr/bin/ffmpeg -y -i /home/abb/Downloads/pn3260p.mp4 -vcodec libx264 -acodec libmp3lame -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 -pass 2 -passlogfile /tmp/ffmpeg-passes5b111e09a5e49snw9r/pass-5b111e09a5f02 /home/abb/Documents/www/videos/tmp/1527848448-pn3260p.mp4 ffmpeg version 2.8.14-0ubuntu0.16.04.1 Copyright (c) 2000-2018 the FFmpeg developers built with gcc 5.4.0 (Ubuntu 5.4.0-6ubuntu1~16.04.9) 20160609 configuration: --prefix=/usr --extra-version=0ubuntu0.16.04.1 --build-suffix=-ffmpeg --toolchain=hardened --libdir=/usr/lib/x86_64-linux-gnu --incdir=/usr/include/x86_64-linux-gnu --cc=cc --cxx=g++ --enable-gpl --enable-shared --disable-stripping --disable-decoder=libopenjpeg --disable-decoder=libschroedinger --enable-avresample --enable-avisynth --enable-gnutls --enable-ladspa --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libflite --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libgme --enable-libgsm --enable-libmodplug --enable-libmp3lame --enable-libopenjpeg --enable-libopus --enable-libpulse --enable-librtmp --enable-libschroedinger --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libssh --enable-libtheora --enable-libtwolame --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx265 --enable-libxvid --enable-libzvbi --enable-openal --enable-opengl --enable-x11grab --enable-libdc1394 --enable-libiec61883 --enable-libzmq --enable-frei0r --enable-libx264 --enable-libopencv libavutil 54. 31.100 / 54. 31.100 libavcodec 56. 60.100 / 56. 60.100 libavformat 56. 40.101 / 56. 40.101 libavdevice 56. 4.100 / 56. 4.100 libavfilter 5. 40.101 / 5. 40.101 libavresample 2. 1. 0 / 2. 1. 0 libswscale 3. 1.101 / 3. 1.101 libswresample 1. 2.101 / 1. 2.101 libpostproc 53. 3.100 / 53. 3.100 Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '/home/abb/Downloads/pn3260p.mp4': Metadata: major_brand : isom minor_version : 512 compatible_brands: isomiso2avc1mp41 encoder : Lavf57.25.100 replaygain_track_gain: 0.55 replaygain_track_peak: 0.50 replaygain_track_minmax: 106,167 Duration: 00:00:30.29, start: 0.021333, bitrate: 1538 kb/s Stream #0:0(eng): Video: h264 (Constrained Baseline) (avc1 / 0x31637661), yuv420p, 854x480, 1408 kb/s, 59.94 fps, 59.94 tbr, 60k tbn, 119.88 tbc (default) Metadata: handler_name : VideoHandler Stream #0:1(eng): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 123 kb/s (default) Metadata: handler_name : SoundHandler Side data: replaygain: track gain - 0.550000, track peak - 0.000012, album gain - unknown, album peak - unknown, [libx264 @ 0xf2e1a0] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX [libx264 @ 0xf2e1a0] ratecontrol_init: can't open stats file Output #0, mp4, to '/home/abb/Documents/www/videos/tmp/1527848448-pn3260p.mp4': Metadata: major_brand : isom minor_version : 512 compatible_brands: isomiso2avc1mp41 encoder : Lavf57.25.100 replaygain_track_gain: 0.55 replaygain_track_peak: 0.50 replaygain_track_minmax: 106,167 Stream #0:0(eng): Video: h264, none, q=2-31, 128 kb/s, 59.94 fps (default) Metadata: handler_name : VideoHandler encoder : Lavc56.60.100 libx264 Stream #0:1(eng): Audio: mp3, 0 channels, 128 kb/s (default) Metadata: handler_name : SoundHandler encoder : Lavc56.60.100 libmp3lame Stream mapping: Stream #0:0 -> #0:0 (h264 (native) -> h264 (libx264)) Stream #0:1 -> #0:1 (aac (native) -> mp3 (libmp3lame)) Error while opening encoder for output stream #0:0 - maybe incorrect parameters such as bit_rate, rate, width or height

Mediainfo:

General Complete name : /home/abb/Downloads/pn3260p.mp4 Format : MPEG-4 Format profile : Base Media Codec ID : isom (isom/iso2/avc1/mp41) File size : 5.56 MiB Duration : 30s 294ms Overall bit rate mode : Variable Overall bit rate : 1 539 Kbps Encoded date : UTC 1904-01-01 00:00:00 Tagged date : UTC 2017-03-11 16:04:01 Writing application : Lavf57.25.100 replaygain_track_gain : 0.55 replaygain_track_peak : 0.50 replaygain_track_minmax : 106,167

Video ID : 1 Format : AVC Format/Info : Advanced Video Codec Format profile : Baseline@L3.1 Format settings, CABAC : No Format settings, ReFrames : 3 frames Codec ID : avc1 Codec ID/Info : Advanced Video Coding Duration : 30s 231ms Bit rate : 1 409 Kbps Width : 854 pixels Height : 480 pixels Display aspect ratio : 16:9 Frame rate mode : Constant Frame rate : 59.940 (60000/1001) fps Color space : YUV Chroma subsampling : 4:2:0 Bit depth : 8 bits Scan type : Progressive Bits/(Pixel*Frame) : 0.057 Stream size : 5.08 MiB (91%) Writing library : x264 core 148 r2601 a0cd7d3 Encoding settings : cabac=0 / ref=3 / deblock=1:0:0 / analyse=0x1:0x111 / me=hex / subme=7 / psy=1 / psy_rd=1.00:0.00 / mixed_ref=1 / me_range=16 / chroma_me=1 / trellis=1 / 8x8dct=0 / 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=0 / weightp=0 / 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 Language : English Encoded date : UTC 1904-01-01 00:00:00 Tagged date : UTC 1904-01-01 00:00:00

Audio ID : 2 Format : AAC Format/Info : Advanced Audio Codec Format profile : LC Codec ID : 40 Duration : 30s 294ms Bit rate mode : Variable Bit rate : 124 Kbps Maximum bit rate : 128 Kbps Channel(s) : 2 channels Channel positions : Front: L R Sampling rate : 48.0 KHz Frame rate : 46.875 fps (1024 spf) Compression mode : Lossy Stream size : 457 KiB (8%) Language : English Default : Yes Alternate group : 1 Encoded date : UTC 1904-01-01 00:00:00 Tagged date : UTC 1904-01-01 00:00:00

jens1o commented 6 years ago

@nise Could you please ping me in a few days? At the moment, I do not have time to troubleshot.

nise commented 6 years ago

@jens1o You want to be pinged back. Have you any ideas on how to solve the error?

jens1o commented 6 years ago

@nise Not yet.. I think we might set parameters that confuse ffpeg.

estherDow commented 4 years ago

Please write in proper English sentences.

I think the users input was valuable. If you dont speak chinese, there are many translating apps to help you