2

I've recently installed the PHP-FFMpeg lib on a server and used the following tutorial: https://github.com/PHP-FFMpeg/PHP-FFMpeg

I managed to convert a .mov video (uploaded through a mobile device) to webm and ogg but when encoding to mp4 I always get an "Encoding Failed" message from the error object (in a try catch).

This is the code I'm using after instantiating FFMPEG

    $video->filters()->resize(new FFMpeg\Coordinate\Dimension(756, 461), $mode = RESIZEMODE_SCALE_WIDTH)->synchronize();

$video->frame(FFMpeg\Coordinate\TimeCode::fromSeconds(10))->save('sites/default/files/videos/thumbnails/'.$filename.'.jpg');

$video->save(new FFMpeg\Format\Video\Ogg(), 'sites/default/files/videos/'.$filename.'.ogg')
      ->save(new FFMpeg\Format\Video\X264(), 'sites/default/files/videos/'.$filename.'.mp4')
      ->save(new FFMpeg\Format\Video\WebM(), 'sites/default/files/videos/'.$filename.'.webm');

Thanks for your help!

Emii Khaos
  • 9,983
  • 3
  • 34
  • 57
Alex
  • 565
  • 2
  • 6
  • 17
  • The github page says you need FFMpeg and FFProbe installed and in your system path (otherwise explicitly define the path). Have you made sure you've done this? – crunch Apr 05 '14 at 02:10
  • Yes! Everything is up and running from this side. By the way I managed to convert the video to MP4 through this method: exec("ffmpeg -i sites/default/files/videos/originals/video.mov -vcodec copy -acodec copy sites/default/files/videos/video.mp4"); Although it would be great to make it work with the library. Thanks for your reply! – Alex Apr 05 '14 at 02:15
  • 1
    I'm afraid I don't know enough about the library to help you, but if you do it with exec() then make sure you absolutely sanitize anything that comes from user input. – crunch Apr 05 '14 at 02:18

1 Answers1

1

In case anyone comes upon this and needs to convert MOV to MP4 using FFMpeg, the correct method is:

  $ffmpeg = FFMpeg\FFMpeg::create();

  $video = $ffmpeg->open('path/to/movie.mov');
  $format = new FFMpeg\Format\Video\X264();
  $format->setAudioCodec("libmp3lame");

 $video
     ->save($format, 'path/to/movie.mp4');

Answer found here

BugLogic
  • 117
  • 5
  • 2
    Gathering from the linked answer, the point is that you have to set a compatible audio codec in addition to the video codec. (I'm not sure though why it breaks if one tries to set the codec like this `$format = new FFMpeg\Format\Video\X264('libmp3lame', 'libx264');`) – Arne L. Apr 11 '19 at 17:31