用JavaCV和FFmpeg播放视频 [英] Playing a video with JavaCV and FFmpeg

查看:3223
本文介绍了用JavaCV和FFmpeg播放视频的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以,我正在为Android开发自定义的视频播放器,但是我需要播放比android支持的视频文件(mp4,3gp ...),比如wmv,avi,flv。

So, I'm developing a custom video player for Android but I need to play more than the android supported video files (mp4, 3gp...), like wmv, avi, flv.

此时,我已经将任何视频类型转换为.mp4,我可以在重新编码后播放,但是我不知道如何在没有重新编码的情况下播放这些wmv,avi文件mp4。

At this time I do already convert any video type to .mp4 and I'm able to play them after recoding, but I have no idea how can I play those wmv, avi files without recoding them to mp4.

有没有办法我可以在Android上播放任何视频而不重新编码?
JavaCV + FFmpeg库已经工作,只是不知道该怎么做。

Is there any way I can play any video on Android without recoding them? JavaCV + FFmpeg library already working, just don't know how to do that.

顺便说一句,我要用代码重新编码视频:

By the way, heres the code that I'm using to recode videos:

public static void convert(File file) {

    FFmpegFrameGrabber frameGrabber =
            new FFmpegFrameGrabber(file.getAbsolutePath());

    IplImage captured_frame = null;

    FrameRecorder recorder = null;
    recorder = new FFmpegFrameRecorder("/mnt/sdcard/external_sd/videosteste/primeiroteste.mp4", 300, 300);
    recorder.setVideoCodec(13);
    recorder.setFrameRate(30);
    recorder.setFormat("mp4");
    try {
        recorder.start();
        frameGrabber.start();
        while (true) {
            try {
                captured_frame = frameGrabber.grab();

                if (captured_frame == null) {
                    System.out.println("!!! Failed cvQueryFrame");
                    break;
                }
                recorder.record(captured_frame);
            } catch (Exception e) {
            }
        }
        recorder.stop();
        recorder.release();
    } catch (Exception e) {
        e.printStackTrace();
    }
}


推荐答案


有没有办法可以在Android上播放任何视频,而无需重新编码?

Is there any way I can play any video on Android without recoding them?

为什么录制视频??没有必要录制视频。 JavaCv。

Why are you recording the Video?? There is no need to record the video. JavaCv.

这是为您提供创意的示例代码,如何实现。

This is sample code for giving you the idea, how you can achieve it.

FrameGrabber grabber = new FrameGrabber(videoFile);
grabber.start();
BufferedImage image= null;
while((image=grabber.grab())!=null){
   // TODO set the image on the canvas or panel where ever you want. 
}
grabber.stop();

这篇关于用JavaCV和FFmpeg播放视频的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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