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.

Comments

idflood’s picture

Issue summary: View changes

.

idflood’s picture

Digging 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.

    reading_from_cache (Boolean) TRUE
    ffmpeg-found (Boolean) TRUE
    compiler (Array, 0 elements)
    binary (Array, 3 elements)
    ffmpeg-php-support (Boolean) FALSE
    raw (String, 4 characters )
    formats (Array, 0 elements)
    codecs (Array, 3 elements)
        video (Array, 0 elements)
        audio (Array, 0 elements)
        subtitle (Array, 0 elements)
    filters (Array, 0 elements)
    protocols (Array, 0 elements)
    abbreviations (Array, 0 elements)
    _cache_date (Integer) 1318322323
idflood’s picture

Issue summary: View changes

tested with latest dev version

idflood’s picture

The 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"

idflood’s picture

Status: Active » Needs review
StatusFileSize
new969 bytes

Here 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.

valencianok’s picture

Version: 7.x-2.x-dev » 7.x-2.4
Component: Code » Video Transcoding
StatusFileSize
new1.22 KB
new5.3 KB

Hi

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)

reubenavery’s picture

Also 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'.

reubenavery’s picture

Status: Needs review » Needs work
Tsubo’s picture

#2 worked for me.

Thanks.

Jorrit’s picture

Status: Needs work » Postponed (maintainer needs more info)

Please retest using the latest 7.x-2.x-dev version. I think I have fixed all your problems. If not, please recreate your patch.

leewillis77’s picture

I'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.

Jorrit’s picture

Have you cleared the Drupal cache? Does the file /tmp/_ffmpeg_info.php exist on your computer?

leewillis77’s picture

I'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.

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.

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 format

Setting to OGG, rather than MP4 also fails with the error:

Error set options PHPVideoToolkit Error: Value "theora" 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.

In both cases if I monitor /tmp/ I can see .mp4/.ogg files being created during the transcode process.

leewillis77’s picture

Also - 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

Jorrit’s picture

leewillis77 : can you post the output of ffmpeg -version and ffmpeg -codecs?

leewillis77’s picture

StatusFileSize
new14.22 KB
new283 bytes

Info attached - let me know if there's anything else I can do to debug.

Jorrit’s picture

Just 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?

leewillis77’s picture

Hi,

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:

Something went wrong with your video transcoding. Please check your recent log entries for further debugging.
Notice: Undefined variable: items in conditional_fields_entity_view_alter() (line 760 of /home/webserver/videodebug/sites/all/modules/conditional_fields/conditional_fields.module).
Notice: Undefined variable: items in conditional_fields_entity_view_alter() (line 760 of /home/webserver/videodebug/sites/all/modules/conditional_fields/conditional_fields.module).

and the node content shows:

The video conversion process has failed. You might want to submit a simpler video format like mpeg or divx avi.
If the problem persists contact your website administrator. Please check logs for further debugging.

The error messages in my log are:

PHPVideoToolkit Error: Execute error. It was not possible to encode "/home/webserver/videodebug/sites/default/files/videos/original/scen4.flv" as FFmpeg returned an error. The error is with the video codec of the input file. FFmpeg reports the error to be "Error while opening encoder for output stream #0.0 - maybe incorrect parameters such as bit_rate, rate, width or height".

Note that in this test, no converted videos were produced at all.

ram4nd’s picture

I 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.

Jorrit’s picture

Is this still a problem with version 7.x-2.5? I have changed a lot of code regarding reading supported codec information.

Jorrit’s picture

Status: Postponed (maintainer needs more info) » Closed (cannot reproduce)

Closed because of lack of response.

anniegreens’s picture

Version: 7.x-2.4 » 7.x-2.6
Status: Closed (cannot reproduce) » Active

I 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:

2012-06-27 17:54:20 install ffmpeg <none> 4:0.7.6-0ubuntu0.11.10.1
2012-06-27 23:46:19 install libx264-116 <none> 2:0.116.2042+git178455c-1ubuntu1
2012-06-27 23:46:20 install libx264-dev <none> 2:0.116.2042+git178455c-1ubuntu1
2012-06-27 23:46:20 install x264 <none> 2:0.116.2042+git178455c-1ubuntu1

I also have confirmed ffmpeg does have the 'h264' codec installed:

user@host:~$ ffmpeg -formats
ffmpeg version 0.7.6-4:0.7.6-0ubuntu0.11.10.1, Copyright (c) 2000-2011 the Libav developers
  built on Jun 12 2012 16:44:09 with gcc 4.6.1
  configuration: --extra-version='4:0.7.6-0ubuntu0.11.10.1' --arch=amd64 --prefix=/usr --enable-vdpau --enable-bzlib --enable-libgsm --enable-libschroedinger --enable-libspeex --enable-libtheora --enable-libvorbis --enable-pthreads --enable-zlib --enable-libvpx --enable-runtime-cpudetect --enable-vaapi --enable-gpl --enable-postproc --enable-swscale --enable-x11grab --enable-libdc1394 --enable-shared --disable-static
  libavutil    51.  7. 0 / 51.  7. 0
  libavcodec   53.  6. 0 / 53.  6. 0
  libavformat  53.  3. 0 / 53.  3. 0
  libavdevice  53.  0. 0 / 53.  0. 0
  libavfilter   2.  4. 0 /  2.  4. 0
  libswscale    2.  0. 0 /  2.  0. 0
  libpostproc  52.  0. 0 / 52.  0. 0
File formats:
 D. = Demuxing supported
 .E = Muxing supported
 --
 <SNIP>
 DE h261            raw H.261
 DE h263            raw H.263
 DE h264            raw H.264 video format
 <SNIP>

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.

Jorrit’s picture

The 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-libx264 there, 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.

Jorrit’s picture

Category: bug » support
anniegreens’s picture

Thanks 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.

Jorrit’s picture

Could you send a screenshot or export of the preset settings and a link to the resulting file?

rurri’s picture

StatusFileSize
new18.13 KB
new9.74 KB
new32.23 KB

Having the same issue here. Used the following kludge in The TranscoderFactory.

          if ($value =='h264') {
            $value = 'libx264';
          }
          $result = $this->transcoder->setVideoCodec($value, FALSE);

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:

 DE h264            raw H.264 video format
  E ipod            iPod H.264 MP4 format

Codecs:

 D V D B  h264            H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10
  EV      libx264         libx264 H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10
  EV      libx264rgb      libx264 H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10 RGB
Jorrit’s picture

When you go to the H.264 preset settings, which x264 related codecs are available in the Video Codec dropdown.

rurri’s picture

Just those two in the screenshot above:

  • zmbv Zip Motion Blocks Video
  • prores_kostya Apple ProRes(Codec Pro).

I am able to encode video currently but is obviously just a short term fix based on what I have done above.

Jorrit’s picture

rurri: Sorry that I asked something that you already told. What version of the video module are you using?

rurri’s picture

Getting this with: 7.x-2.6

Jorrit’s picture

Status: Active » Fixed

It 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.

rurri’s picture

Excellent.

I'll wait and test on the release version since I have a work around going now.

Jorrit’s picture

The fix is quite easy to apply. You can edit libraries/phpvideotoolkit/phpvideotoolkit.php5.php and 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)) {

rurri’s picture

Jorrit,

I can confirm that the change now causes my video codec drop down to populate. Looks like it fixed it!

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

Anonymous’s picture

Issue summary: View changes

little summary