连接的Android codeR复用器:原料H264的MP4容器 [英] Android encoder muxer: raw h264 to mp4 container
问题描述
我创建了一个H264原始视频文件,我能够与Android MediaMuxer混流它在Android 4.3及以上。现在我需要支持的Android版本4.1和4.2。我发现ĴcodeC。还有就是做一个这样的例子:
I created a h264 raw video file, and I was able to mux it with Android MediaMuxer on Android 4.3 and up. Now I need to support Android versions 4.1 and 4.2. I found Jcodec. And there is an example for doing this:
<一个href="https://github.com/j$c$cc/j$c$cc/blob/master/samples/main/java/org/j$c$cc/samples/mux/AVCMP4Mux.java" rel="nofollow">https://github.com/j$c$cc/j$c$cc/blob/master/samples/main/java/org/j$c$cc/samples/mux/AVCMP4Mux.java
但我在70线获得java.nio.ReadOnlyBufferException异常:
But I'm getting java.nio.ReadOnlyBufferException exception at line 70:
H264Utils.en codeMOVPacket(数据);
H264Utils.encodeMOVPacket(data);
我想这code不是为Android?我该如何解决这个问题。可有人熟悉这个ĴcodeC的帮助?
I guess this code is not for Android? How do I fix this. Can someone familiar with Jcodec help on this?
推荐答案
我放弃了J上codeC。它暴露了太多的codeC内部的东西,并没有对使用没有任何文件都没有。 Mp4Parser 做的工作对我来说,这很简单。这里是code我混流原料H264视频转换成MP4容器:
I gave up on Jcodec. It exposes too many codec internal stuff, and there is no documentation on usage at all. Mp4Parser did the job for me, and it's simple. Here is the code I mux raw h264 video into mp4 container:
String h264Path = "path to my h264 file, generated by Android MediaCodec";
DataSource videoFile = new FileDataSourceImpl(h264Path);
H264TrackImpl h264Track = new H264TrackImpl(videoFile, "eng", 5, 1); // 5fps. you can play with timescale and timetick to get non integer fps, 23.967 is 24000/1001
Movie movie = new Movie();
movie.addTrack(h264Track);
Container out = new DefaultMp4Builder().build(movie);
FileOutputStream fos = new FileOutputStream(new File("path to my generated file.mp4"));
out.writeContainer(fos.getChannel());
fos.close();
被发现code例子<一href="https://github.com/sannies/mp4parser/tree/master/examples/src/main/java/com/google$c$c/mp4parser/muxformats"相对=nofollow>此处。环闭合!现在我的视频连接codeR实施从安卓4.1及以上的作品,没有FFmpeg的需要
Code examples were found here. Loop is closed! Now my video encoder implementation works from Android 4.1 and up, without the need of FFMpeg
BTW:Android的股票画廊应用程序使用Mp4Parser,在它的开放源代码许可上市。
BTW: Android stock "Gallery" app uses Mp4Parser, listed in its open source licenses.
这篇关于连接的Android codeR复用器:原料H264的MP4容器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!