image - 从 MJPG 文件中提取图像帧

标签 image ffmpeg mjpeg

我正在尝试从 IP cam 的短片中提取图像帧。特别是这个剪辑。

http://db.tt/GQwu0nZ8

所以,我试图用 ffmpeg 提取那些帧。
ffmpeg -i M00001.jpg -vcodec mjpeg -f image2 image%03d.jpg

我只是得到剪辑的第一帧。我怎样才能得到其余的帧?我可以使用其他工具来获取这些图像吗?

谢谢

最佳答案

这可能太多了,但这里有一个用于 Node.js 的简短 javascript 程序 https://nodejs.org/这将剥离所有可读的帧并将它们保存为当前目录中单独的顺序编号的 jpg 文件。请注意,即使是一个简短的视频剪辑也可以生成数千帧,并且 Node 使用的 V8 javascript 引擎非常快,因此我建议关闭您的文件浏览器,因为它会占用资源来跟上。

如果视频文件太大而无法为其创建缓冲区,Node 将发出错误并退出。
在这种情况下,最简单的做法是使用您的 shell 实用程序或 HexEdit 之类的程序将文件拆分为多个 block 。 http://www.hexedit.com/

重写此代码以异步处理文件将解决该问题,但编写异步代码仍然让我感到焦虑。

var orgFile=process.cwd()+"/"+process.argv[2]; //Grab the video filename from the command line
var fs = require("fs"); //Load the filesystem module
var stats = fs.statSync(orgFile);//Get stats of video file
var fileSizeInBytes = stats["size"];//Get video file size from stats
var fdata=new Buffer(fileSizeInBytes);//Create a new buffer to hold the video data
var i=0;
var fStart=0;
var fStop=0;
var fCount=0;
fdata=fs.readFileSync(orgFile);//Read the video file into the buffer
//This section looks for the markers at the begining and end of each jpg image
//records their positions and then writes them as separate files.
while (i<fileSizeInBytes){

if (fdata[i]==0xFF){
    //console.log("Found FF at "+i.toString);
    if (fdata[i+1]==0xD8){
        //console.log("Found D8 at "+(i+1).toString);

        if (fdata[i+2]==0xFF){
            //console.log("Found FF at "+(i+2).toString);
            fStart=i;
            }
        }
    }
if (fStart>0){
    if (fdata[i]==0xFF){
        if(fdata[i+1]==0xD9){
            fStop=i+1;

        }
    }
if (fStart>0){
    if (fStop>0){
    fCount++;
    fs.writeFileSync(orgFile+"."+fCount.toString()+".jpg",fdata.slice(fStart,fStop));   
    console.log (orgFile+"."+fCount.toString()+".jpg");
    fStart=0;
    fStop=0;
    }
}
}

i++;
}

console.log ("Wrote "+fCount.toString()+" frames.");

如果您将上述代码保存为 mjpeg_parse.js,则调用示例将是:

节点 mjepeg_parse.js videofile.avi

关于image - 从 MJPG 文件中提取图像帧,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13860525/

相关文章:

javascript - 获取图像作为 Angular 文件

c++ - FFmpeg 卡在缓冲区填充 C++

javascript - Mjpg paparazzo.js 不工作

html - 由于 CSS,网站上的图像模糊?

ios - 上传图片作为个人资料图片

java - Java 中的离散小波变换在图像中创建白点

python - mjpeg @ 0x27ee9e0 缓冲区小于最小大小 : How to create a video file with size less than the minimum buffer size?

ffmpeg - Phpvideotoolkit - "maxlen ' = >' 3072 ' 在 buggedcom\phpvideotoolkit\src\PHPVideoToolkit\Mime.php 行 202"

ffmpeg - 在 UWP 中转码视频

c# - 使用 C# 从静止图像创建 MJPEG 视频