如何在Java中获取mp4-Movie的单个图像 [英] How to get the single images of an mp4-Movie in Java

查看:106
本文介绍了如何在Java中获取mp4-Movie的单个图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想对以.mp4格式存储的视频进行一些图像分析.因此,我需要一种方法来仅用Java获取该电影的图像. 我走了很多路,发现了一些库,例如jcodec和jaad.但是我无法让这些库运行这些东西.而且我发现,有一些例子(至少我没有发现)显示了我的用例.

I want to do some image analysis on a video that's stored in .mp4 format. Therefore I need a way to just get the images of this movie in Java. I goolged a lot and found some libraries like jcodec and jaad. BUT I wasn't able to get the things running with these libraries. And as I found out, there were examples (at least I found none) that showed my usecase.

你能帮我吗?您是否知道可以满足我的需要并且至少在Win7 64位上运行的任何库. 还是您知道如何使用jcodec做到这一点?

Can you help me? Do you know any library that can do what I need and is running at least on Win7 64 bit. Or do you know how to accomplish this with jcodec?

如我所写,我在jcodec上尝试过.我发现了如何获取帧的数据,但没有找到如何将其获取到诸如BufferedImage之类的东西中.我希望这些数据不是简单的RGB格式,而是任何压缩格式. (我对吗?)我不知道要解码这些数据.

As I wrote, I tried it with jcodec. I found out how to get the data of a frame, but not how I can get it into something like a BufferedImage or so. I expect that these data isn't in a simple RGB format but in any compressed format or so. (Am I right with that?) I don't know to to decode this data.

您可以使用jcodec如下获取帧的数据(至少据我了解):

You can get the data of a frame with jcodec as follows (at least as far as I understand this):

public static void main(String[] args) throws IOException, MP4DemuxerException {
    String path = "videos/video-2011-09-21-20-07-21.mp4";

    MP4Demuxer demuxer1 = new MP4Demuxer(new FileInput(new File(path)));
    DemuxerTrack videoTrack = demuxer1.getVideoTrack();

    Packet firstFrame = videoTrack.getFrames(1);
    byte[] data = firstFrame.getData();
}

我还发现了以下内容:

I also found the following: http://code.google.com/p/jcodec/source/browse/trunk/src/test/java/org/jcodec/containers/mp4/DitherTest.java?r=70 But this isn't working (has compile errors) with the downloadable jar-package.

推荐答案

您可以使用jcodec( http://jcodec.org/)中,我正在从视频中提取帧.

you could use jcodec(http://jcodec.org/) in the followinf program i am extracting frames from a video.

/*
 * To extract frames from a mp4(avc) video
 * 
 */
package avc_frame;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
import org.jcodec.api.FrameGrab;
import org.jcodec.api.JCodecException;

public class Avc_frame {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) throws IOException, JCodecException {

        long time = System.currentTimeMillis();
        for (int i = 50; i < 57; i++) { 
            BufferedImage frame = FrameGrab.getFrame(new File("/Users/jovi/Movies/test.mp4"), i);
            ImageIO.write(frame, "bmp", new File("/Users/jovi/Desktop/frames/frame_"+i+".bmp"));
        }
        System.out.println("Time Used:" + (System.currentTimeMillis() - time)+" Milliseconds");
    }
}

这篇关于如何在Java中获取mp4-Movie的单个图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆