1

我在 laravel 项目中使用 php ffmpeg 来做多项探测、提取帧和编码。从上传的视频文件创建帧时出现问题。这是创建框架的方式:

    $video = $ffmpeg->open($destinationPath.'/'.$filename);

    $video
        ->frame(FFMpeg\Coordinate\TimeCode::fromSeconds(10))
        ->save(public_path().$frame_path);

这有时会起作用并创建框架,但有时则不会。我注意到当我试图打开一个 .mov 文件时会出现这个错误。

4

3 回答 3

3

您的 ffmpeg 版本可能不支持源视频文件中使用的编解码器,因此它无法解压缩视频并提取图像。

您可以尝试从命令行处理文件以查看是否可以通过这种方式提取图像,ffmpeg 可能会为您提供有关该问题的更多信息。

从视频文件中提取 png 帧的示例命令行

ffmpeg -y -ss 30 -i [source_file] -vframes 1 [target_file]

如果您的输出名称是变量,则添加-f image2为输出选项。

于 2014-03-24T12:02:32.050 回答
0

PHP-FFMpeg 库默认在输入文件之前附加 -ss 参数,这需要时间戳准确才能获取帧。我在 mkv 文件的情况下遇到了这个问题。mkv 和 mov 等文件无法准确查找。

https://github.com/PHP-FFMpeg/PHP-FFMpeg/blob/master/src/FFMpeg/Media/Frame.php#L79

您需要将true第二个参数作为第二个参数传递给 save 函数,以便提供最接近给定点的 Frame。它改变了 ffmpeg 命令中 -ss 参数的位置。

-ss 位置(输入/输出)

当用作输入选项时(在 -i 之前),在此输入文件中查找位置。请注意,在大多数格式中,不可能精确查找,因此 ffmpeg 将查找位置之前最近的查找点。当转码和 -accurate_seek 启用(默认)时,搜索点和位置之间的这个额外段将被解码并丢弃。在进行流复制或使用 -noaccurate_seek 时,它将被保留。

当用作输出选项时(在输出文件名之前),解码但丢弃输入,直到时间戳到达位置。

position 必须是持续时间规范,请参阅 (ffmpeg-utils) ffmpeg-utils(1) 手册中的持续时间部分。

于 2016-02-26T08:44:45.137 回答
0

这是我一直在使用 PHP 的代码:

https://totaldev.com/extract-image-frame-video-php-ffmpeg/

<?php

// Full path to ffmpeg (make sure this binary has execute permission for PHP)
$ffmpeg = "/full/path/to/ffmpeg";

// Full path to the video file
$videoFile = "/full/path/to/video.mp4";

// Full path to output image file (make sure the containing folder has write permissions!)
$imgOut = "/full/path/to/frame.jpg";

// Number of seconds into the video to extract the frame
$second = 0;

// Setup the command to get the frame image
$cmd = $ffmpeg." -i \"".$videoFile."\" -an -ss ".$second.".001 -y -f mjpeg \"".$imgOut."\" 2>&1";

// Get any feedback from the command
$feedback = `$cmd`;

// Use $imgOut (the extracted frame) however you need to 
// ... 
于 2018-09-29T02:17:52.757 回答