java ffmpeg视频采集,玩JavaCV和FFmpeg的视频

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.

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.

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();

}

}

解决方案

first you create the CanvasFrame then use "canvas.showImage(captured_frame);" instead of "recorder.record(captured_frame);"

Here is the code:

public class GrabberShow implements Runnable

{

final static int INTERVAL=40;///you may use interval

IplImage image;

static CanvasFrame canvas = new CanvasFrame("JavaCV player");

public GrabberShow()

{

canvas.setDefaultCloseOperation(javax.swing.JFrame.EXIT_ON_CLOSE);

}

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 = new FFmpegFrameRecorder("D://temp.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);

canvas.showImage(captured_frame);

Thread.sleep(INTERVAL);

} catch (Exception e) {

}

}

recorder.stop();

recorder.release();

} catch (Exception e) {

e.printStackTrace();

}

}

@Override

public void run()

{

convert(new File("D://aes.mp4"));

}

public static void main(String[] args) {

GrabberShow gs = new GrabberShow();

Thread th = new Thread(gs);

th.start();

}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值