Summary
The codec validation is made against the static version of the phpvideotoolkit.php5.php.
If the ffmpeg binary is located at the default location and the /tmp directory is correct it will work:
function __construct($ffmpeg_binary = '/usr/bin/ffmpeg', $tmp_dir='/tmp/') {
The problem is that the settings defined in drupal aren't applied for the codec validation only.
public function setVideoCodec($video_codec, $validate_codec=true) {
if (!in_array($video_codec, array(self::FORMAT_3GP2, self::FORMAT_3GP, self::FORMAT_AVI, self::FORMAT_FLV, self::FORMAT_GIF, self::FORMAT_MJ2, self::FORMAT_MP4, self::FORMAT_MPEG4, self::FORMAT_M4A, self::FORMAT_MPEG, self::FORMAT_MPEG1, self::FORMAT_MPEG2, self::FORMAT_MPEGVIDEO))) {
//return $this->_raiseError('setVideoFormat_valid_format', array('format'=>$video_codec));
//<- exits
}
if ($validate_codec === true) {
if ($this->canCodecBeEncoded('video', $video_codec) === false) {
return $this->_raiseError('setVideoFormat_cannnot_encode', array('codec' => $video_codec));
}
}
return $this->addCommand('-vcodec', $video_codec);
}
...
public static function canCodecBeEncoded($type, $codec) {
return self::validateCodec($codec, $type, 'encode'); // this static call may be the root of the issue
}
So is it possible to directly modify the source of phpvideotoolkit.php5.php?
Original report:
I had some difficulties installing ffmpeg on osx but now everything is fine. The only issue remaining is codec validation. I had this kind of error:
Error set options PHPVideoToolkit Error: Value "libx264" set from $toolkit->setVideoCodec, can not be used to encode the output as the version of FFmpeg that you are using does not have the capability to encode video with this codec.
Since I was sure these codecs are installed I disabled the validation by changing two lines in transcoders/TranscoderAbstractionFactoryFfmpeg.inc:
$result = $this->transcoder->setVideoCodec($value, FALSE);
$result = $this->transcoder->setAudioCodec($value, FALSE);
The second parameters tells phpvideotoolkit.php5.php to ommit the validation. By doing that my test video got converted, so obviously something is wrong with that validation.
Here is the a extract from "$this->transcoder->getFFmpegInfo(FALSE)":
reading_from_cache (Boolean) FALSE
ffmpeg-found (Boolean) TRUE
compiler (Array, 0 elements)
binary (Array, 3 elements)
ffmpeg-php-support (Boolean) FALSE
raw (String, 22310 characters ) FFmpeg version 0.6, Copyright (c) 2000-2010 the...
formats (Array, 157 elements)
codecs (Array, 3 elements)
video (Array, 141 elements)
...
h264 (Array, 6 elements)
encode (Boolean) FALSE
decode (Boolean) TRUE
draw_horizontal_band (Boolean) FALSE
direct_rendering_method_1 (Boolean) TRUE
weird_frame_truncation (Boolean) FALSE
fullname (String, 41 characters ) H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10
...
libx264 (Array, 6 elements)
encode (Boolean) TRUE
decode (Boolean) FALSE
draw_horizontal_band (Boolean) FALSE
direct_rendering_method_1 (Boolean) FALSE
weird_frame_truncation (Boolean) FALSE
fullname (String, 49 characters ) libx264 H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10
...
audio (Array, 111 elements)
subtitle (Array, 4 elements)
filters (Array, 95 elements)
protocols (Array, 1 element)
abbreviations (Array, 0 elements)
edit: updated to latest dev version, didn't helped.
| Comment | File | Size | Author |
|---|---|---|---|
| #25 | Screen Shot 2012-07-16 at 9.57.18 PM.png | 32.23 KB | rurri |
| #25 | formats.txt | 9.74 KB | rurri |
| #25 | codecs.txt | 18.13 KB | rurri |
| #14 | ffmpeg_version.txt | 283 bytes | leewillis77 |
| #14 | ffmpeg_codecs.txt | 14.22 KB | leewillis77 |
Comments
Comment #0.0
idflood commented.
Comment #1
idflood commentedDigging a little deeper I've found that the validateCodec function in phpvideotoolkit.php5.php use the cached version of the ffmpegInfos. In this case the result is nothing like the uncached version shown in #1.
Comment #1.0
idflood commentedtested with latest dev version
Comment #2
idflood commentedThe codec validation seems to work only if the ffmpeg library is located at the default location defined in phpvideotoolkit.php5.php at line 481. ($ffmpeg_binary = '/usr/bin/ffmpeg')
As a workaround this made the issue disappear in my case: "sudo ln -s /opt/local/bin/ffmpeg /usr/bin/ffmpeg"
Comment #3
idflood commentedHere is a first patch. I'm not sure about the possibility to modify this file but looks like the cleanest solution I can think of.
Comment #4
valencianok commentedHi
I had this problem to, and resolved it with a few fixes on the phpvideotoolkit
Here is the patch.
BTW, I think TranscoderAbstractionFactoryFfmpeg has an error because sometimes it cant create the last thumbnail, so on line 127 I substracted 2 instead of 1 seconds. (also here is the patch)
Comment #5
reubenavery commentedAlso running into this.. Have tried patches in #3 and #4 and neither seem to resolve the issue. I'm 90% sure that my ffmpeg install is working, because I can take the exec string out of $exec_string in line 2913 of phpvideotoolkit.php5.php, output it, and then manually run it in a terminal and 'it works'.
Comment #6
reubenavery commentedComment #7
Tsubo commented#2 worked for me.
Thanks.
Comment #8
Jorrit commentedPlease retest using the latest 7.x-2.x-dev version. I think I have fixed all your problems. If not, please recreate your patch.
Comment #9
leewillis77 commentedI'm using 7.x-2.4+54-dev and still see the errors reported in the original bug, as per comment #5 - if I dump the exec string out and run it manually then ffmpeg successfully converts the video.
Anything I can do to help diagnose the issue?
Actually - I'm also experiencing other issues as well, e.g. #1325664: Undefined offset: in PHPVideoToolkit->getFFmpegInfo() in case that's related.
Comment #10
Jorrit commentedHave you cleared the Drupal cache? Does the file /tmp/_ffmpeg_info.php exist on your computer?
Comment #11
leewillis77 commentedI've just tried this again, on a fresh pressflow install, ffmpeg 0.7.3-4:0.7.3-0ubuntu0.11.10.1, video_presets 7.x-2.x, and video from git (7.x-2.x branch).
I've applied the patch on #1325664-33: Undefined offset: in PHPVideoToolkit->getFFmpegInfo() but otherwise no modifications. I do not have a /tmp/_ffmpeg_info.php file on my machine at all.
If I edit the mp4 preset, sure enough h264 doesn't appear in the list of available codecs, despite ffmpeg -formats reporting:
DE h264 raw H.264 video formatSetting to OGG, rather than MP4 also fails with the error:
In both cases if I monitor /tmp/ I can see .mp4/.ogg files being created during the transcode process.
Comment #12
leewillis77 commentedAlso - it appears that the converted videos are being stored in default/files/videos/converted//
E.g.
total 34852
-rw-r--r-- 1 www-data www-data 7145288 2012-03-07 14:22 scen4_mp4_1331130146.mp4
-rw-r--r-- 1 www-data www-data 14245588 2012-03-07 14:26 scen4_ogg_1331130306.ogg
-rw-r--r-- 1 www-data www-data 7145288 2012-03-07 14:28 scen4_mp4_1331130474.mp4
-rw-r--r-- 1 www-data www-data 7145288 2012-03-07 14:46 scen4_mp4_1331131554.mp4
Comment #13
Jorrit commentedleewillis77 : can you post the output of
ffmpeg -versionandffmpeg -codecs?Comment #14
leewillis77 commentedInfo attached - let me know if there's anything else I can do to debug.
Comment #15
Jorrit commentedJust to make sure, can you clear the Drupal cache? I do not see why encoding shouldn't work. After you've cleared the caches and edit your presets, are h264 and theora still available in the Video codec drop downs?
Comment #16
leewillis77 commentedHi,
I'll try and rule out any oddness by going back to a fresh install.
without the patch from http://drupal.org/files/video-1325664-33.patch I can't edit the presets as the dropdowns for video extension/codec are empty. If I apply the patch, clear the cache, and re-visit the presets screen, then the dropdowns are populated.
I go in and edit the mp4 preset, and the video codec defaults to "Multicolour charset for Commodore 64" - presumably because it doesn't think that the codec shipped with the preset in the standard feature is available?
So - I change this to "libx264 H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10" and save the preset.
I then add a node that has a video field. The thumbnails are created, but the following warnings are reported on node save:
and the node content shows:
The error messages in my log are:
Note that in this test, no converted videos were produced at all.
Comment #17
ram4nd commentedI went to sites/all/modules/video/libraries/phpvideotoolkitl/phpvideotoolkit.php5.php and changed wrong definitons paths. Then i went to admin/config/media/video/presets/preset/FLV and changed the video codec from asus to flv video.
Comment #18
Jorrit commentedIs this still a problem with version 7.x-2.5? I have changed a lot of code regarding reading supported codec information.
Comment #19
Jorrit commentedClosed because of lack of response.
Comment #20
anniegreens commentedI am still having this issue in 7.x-2.6, though not exactly the same. I have FFMPEG installed on Ubuntu 11.10 with the base codecs included with the ffmpeg package and additionally installed the following packages: libx264-116, libx264-dev, and x264. Version info below:
I also have confirmed ffmpeg does have the 'h264' codec installed:
I am unable to select H.264 as the video codec in my MP4 preset, as it does not show up, which results in the error stated in this issue and below. Caches have been flushed after package installs.
Error set options PHPVideoToolkit Error: Value "h264" set from $toolkit->setVideoCodec, can not be used to encode the output as the version of FFmpeg that you are using does not have the capability to encode video with this codec.Comment #21
Jorrit commentedThe snippet you're giving is a list of the (container) formats, such as MP4, AVI, etc. You should give the output of
ffmpeg -codecs, which gives the list of codecs. Could you execute that command and provide the output?Also, when I look at the line starting with
configuration:, there is no mention of--enable-libx264there, so something between FFmpeg and x264 is not setup right.The guides that I can find about FFmpeg + x264 on Ubuntu recommend compiling it yourself. I still use Ubuntu 11.04 and I had to install libav-extra instead of libav to get it to work. See http://ubuntuforums.org/showthread.php?t=1117283.
Comment #22
Jorrit commentedComment #23
anniegreens commentedThanks for the follow-up. I was able to get the codec drop-down to populate after installing libavcodec-extra-53. The codec I'm using is libx264 H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10. Now I'm just dealing with working out the quality/preset settings. Even when setting video quality to 5 and video speed to 1 (and any combination in between) I'm getting terrible results.
Comment #24
Jorrit commentedCould you send a screenshot or export of the preset settings and a link to the resulting file?
Comment #25
rurri commentedHaving the same issue here. Used the following kludge in The TranscoderFactory.
I am getting only two codecs listed under video codecs when I view the mp4 preset (See screenshot). I also have to manually adjust the h264 to libx264. Definitely a hack so would love for a more permanent solution. Any ideas?
Full values of formats and codecs output attached, but I think the relevant parts are.
Formats:
Codecs:
Comment #26
Jorrit commentedWhen you go to the H.264 preset settings, which x264 related codecs are available in the Video Codec dropdown.
Comment #27
rurri commentedJust those two in the screenshot above:
I am able to encode video currently but is obviously just a short term fix based on what I have done above.
Comment #28
Jorrit commentedrurri: Sorry that I asked something that you already told. What version of the video module are you using?
Comment #29
rurri commentedGetting this with: 7.x-2.6
Comment #30
Jorrit commentedIt appears that for very recent FFmpeg versions such as yours the codec information format has changed. I have updated the module to take this into account. You can try the next -dev release (built within 12 hours) or wait for 2.7, which I will release very soon.
Comment #31
rurri commentedExcellent.
I'll wait and test on the release version since I have a work around going now.
Comment #32
Jorrit commentedThe fix is quite easy to apply. You can edit
libraries/phpvideotoolkit/phpvideotoolkit.php5.phpand find the following line:if (preg_match_all('/ ([DEVAST ]{0,6}) ([A-Za-z0-9\_]*) (.*)/', $codecs, $codecsmatches)) {Replace it with:
if (preg_match_all('/ ((?:[DEVAST ]{6})|(?:[DEVASTFB ]{8})) ([A-Za-z0-9\_]+) (.+)/', $codecs, $codecsmatches)) {Comment #33
rurri commentedJorrit,
I can confirm that the change now causes my video codec drop down to populate. Looks like it fixed it!
Comment #34.0
(not verified) commentedlittle summary