我在laravel项目中使用php ffmpeg,做多项探测,提取帧和编码。从上传的视频文件创建框架时出现问题。 这就是框架的创建方式:
$video = $ffmpeg->open($destinationPath.'/'.$filename);
$video
->frame(FFMpeg\Coordinate\TimeCode::fromSeconds(10))
->save(public_path().$frame_path);
这有时会起作用并创建框架但其他时间则不然。我注意到当我尝试打开.mov文件时会出现此错误。
答案 0 :(得分:2)
您的ffmpeg版本可能不支持源视频文件中使用的编解码器,因此无法解压缩视频并提取图像。
您可以尝试从命令行处理文件,看看是否可以通过这种方式提取图像,ffmpeg可能会为您提供有关该问题的更多信息。
从视频文件中提取png帧的示例命令行
ffmpeg -y -ss 30 -i [source_file] -vframes 1 [target_file]
如果您的输出名称是变量,请添加-f image2
作为输出选项。
答案 1 :(得分: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 position(输入/输出)
当用作输入选项(在-i之前)时,在此输入文件中寻找位置。请注意,在大多数格式中它是 不可能完全寻求,所以ffmpeg将寻求最接近的寻求 在位置之前指出。启用转码和-accurate_seek时 (默认值),搜索点和位置之间的这个额外段 将被解码并丢弃。在进行流复制时或何时进行 -noaccurate_seek被使用,它将被保留。
当用作输出选项(在输出文件名之前)时,解码但是 丢弃输入,直到时间戳到达位置。
位置必须是持续时间规范,请参阅(ffmpeg-utils) ffmpeg-utils(1)手册中的持续时间部分。
答案 2 :(得分: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
// ...