如何在Android中将MPEG4数据写入(包装)成MP4文件?Android上的视频处理,如何将MPEG4数据写入MP4文件?
我做Android平台的某种视频处理,但我不知道怎么写处理的数据(在某种标准编码,如MPEG4)回的MP4的视频文件。我认为最好使用API来做到这一点,但我找不到所需的API。
有没有人有任何想法?
如何在Android中将MPEG4数据写入(包装)成MP4文件?Android上的视频处理,如何将MPEG4数据写入MP4文件?
我做Android平台的某种视频处理,但我不知道怎么写处理的数据(在某种标准编码,如MPEG4)回的MP4的视频文件。我认为最好使用API来做到这一点,但我找不到所需的API。
有没有人有任何想法?
OpenCV可能是有点吃不消了工作,但我想不出什么更容易。 OpenCV是一个为C,C++和Python提供API的计算机视觉库。
由于您使用的是Android,你必须下载OpenCV的Java包装命名为JavaCV,这是一个第三方的API。我写了一个instructions to install OpenCV/JavaCV on Windows的小贴子,并将它与Netbeans一起使用,但最终你必须搜索一个教程来展示如何为Android平台安装OpenCV/JavaCV。
This is a C++ example展示了如何打开一个输入视频和帧复制到输出文件。但是,由于您使用的是Android的使用JavaCV是更好的一个例子,所以从输入视频帧下面的代码拷贝,并将其写入名为out.mp4
的输出文件:在帧OpenCV的商店像素:
package opencv_videowriter;
import static com.googlecode.javacv.cpp.opencv_core.*;
import static com.googlecode.javacv.cpp.opencv_imgproc.*;
import static com.googlecode.javacv.cpp.opencv_highgui.*;
public class OpenCV_videowriter
{
public static void main(String[] args)
{
CvCapture capture = cvCreateFileCapture("cleanfish47.mp4");
if (capture == null)
{
System.out.println("!!! Failed cvCreateFileCapture");
return;
}
int fourcc_code = (int)cvGetCaptureProperty(capture, CV_CAP_PROP_FOURCC);
double fps = cvGetCaptureProperty(capture, CV_CAP_PROP_FPS);
int w = (int)cvGetCaptureProperty(capture, CV_CAP_PROP_FRAME_WIDTH);
int h = (int)cvGetCaptureProperty(capture, CV_CAP_PROP_FRAME_HEIGHT);
CvVideoWriter writer = cvCreateVideoWriter("out.mp4", // filename
fourcc_code, // video codec
fps, // fps
cvSize(w, h), // video dimensions
1); // is colored
if (writer == null)
{
System.out.println("!!! Failed cvCreateVideoWriter");
return;
}
IplImage captured_frame = null;
while (true)
{
// Retrieve frame from the input file
captured_frame = cvQueryFrame(capture);
if (captured_frame == null)
{
System.out.println("!!! Failed cvQueryFrame");
break;
}
// TODO: write code to process the captured frame (if needed)
// Store frame in output file
if (cvWriteFrame(writer, captured_frame) == 0)
{
System.out.println("!!! Failed cvWriteFrame");
break;
}
}
cvReleaseCapture(capture);
cvReleaseVideoWriter(writer);
}
}
注意订单号为BGR。
mp4parser可以完全创建码流,只有工作,ü不能用它写帧帧。纠正我,如果我错了
H264TrackImpl h264Track = new H264TrackImpl(new BufferedInputStream(some input stream here));
Movie m = new Movie();
IsoFile out = new DefaultMp4Builder().build(m);
File file = new File("/sdcard/encoded.mp4");
FileOutputStream fos = new FileOutputStream(file);
out.getBox(fos.getChannel());
fos.close();
现在我们需要知道如何写帧逐帧。
感谢您提供帮助。 – guanlin
根据这个SO问题(http://stackoverflow.com/questions/21546906/how-to-open-cvvideowriter-in-android)“OpenCV4adnroid不支持视频阅读和写作”。它从android实现的OpenCV中缺失。 – Mick