PHP FFMPEG - 将.mov转换为.mp4(H264)

问题描述 投票:0回答:1

我最近在服务器上安装了PHP-FFMpeg lib并使用了以下教程:https://github.com/PHP-FFMpeg/PHP-FFMpeg

我设法将.mov视频(通过移动设备上传)转换为webm和ogg,但是当编码为mp4时,我总是从错误对象中获取“编码失败”消息(在try catch中)。

这是我在实例化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');

谢谢你的帮助!

php ffmpeg backend php-ffmpeg
1个回答
1
投票

如果有人遇到此问题并需要使用FFMpeg将MOV转换为MP4,则正确的方法是:

  $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');

答案发现here

© www.soinside.com 2019 - 2024. All rights reserved.