你可以试试 OpenCV。我有读取和修改视频文件的功能,它可以打开多种格式。它适用于 C++,但不确定它是否适用于 JAVA。它也不会解析音频。
这是我在计算机视觉项目中使用的示例实现
.h 文件
#ifndef _VPLAYER_H_
#define _VPLAYER_H_
#include #include #include #include "cv.h" #include "highgui.h"
类VPlayer {
公共:VPlayer();~VPlayer();
私人的:
CvCapture* pAvi;
IplImage* pFrame;
公共:int高度;整数宽度;帧速率;整数帧数;双编解码器代码;
上市:
bool LoadVideo(char * fname);
void GetFrame(int FrameNo);
void GetImage (IplImage* &pOutBuffer);
void GetProperties();
};
#万一
.cpp 文件
#include "stdafx.h" #include "VideoPlayer_PB_1.h"
bool VPlayer::LoadVideo(char * fname){
if(pAvi)cvReleaseCapture(&pAvi);
if(!(pAvi = cvCaptureFromAVI(fname)))return false;
GetProperties();
return true;
}
VPlayer::VPlayer(){ pAvi = 0; pFrame = 0; }
VPlayer::~VPlayer(){
cvReleaseCapture(&pAvi);
}
无效 VPlayer::GetFrame(int FrameNo){
cvSetCaptureProperty(pAvi,CV_CAP_PROP_POS_FRAMES,FrameNo);
if(!cvGrabFrame(pAvi)){ // capture a frame
printf("Could not grab a frame\n\7");
exit(0);
}
pFrame = cvRetrieveFrame(pAvi);
}
无效 VPlayer::GetImage (IplImage* &pOutBuffer){
pOutBuffer = cvCloneImage(pFrame);
}
无效 VPlayer::GetProperties(){ if(pAvi){ cvQueryFrame(pAvi); // 此调用对于获取正确的捕获属性是必需的
Height = (int) cvGetCaptureProperty(pAvi, CV_CAP_PROP_FRAME_HEIGHT);
Width = (int) cvGetCaptureProperty(pAvi, CV_CAP_PROP_FRAME_WIDTH);
fps = (int) cvGetCaptureProperty(pAvi, CV_CAP_PROP_FPS);
numFrames = (int) cvGetCaptureProperty(pAvi, CV_CAP_PROP_FRAME_COUNT);
CodecCode = cvGetCaptureProperty(pAvi, CV_CAP_PROP_FOURCC);
}
}