java - 复用 MP4 和 AAC(jcodec、MP4Parser)

标签 java android encoding mp4parser jcodec

我有一个使用 jcodec 生成的 MP4 文件。

然后我就有了一个使用 Android 的 MediaCodec 生成的 AAC 文件。

我想将它们混合到一个文件中,并且由于我不想将我的 Android API 限制得太高,所以我选择 MP4Parser .

<小时/>

这是我当前的代码:

H264TrackImpl h264Track = new H264TrackImpl(new FileDataSourceImpl("input.mp4"));
AACTrackImpl aacTrack = new AACTrackImpl(new FileDataSourceImpl("input.aac"));

Movie movie = new Movie();
movie.addTrack(h264Track);
movie.addTrack(aacTrack);

Container mp4file = new DefaultMp4Builder().build(movie);

FileOutputStream fileOutputStream = new FileOutputStream(new File("output.mp4"));
FileChannel fc = fileOutputStream.getChannel();
mp4file.writeContainer(fc);
fileOutputStream.close();
<小时/>

代码在以下行崩溃:

H264TrackImpl h264Track = new H264TrackImpl(new FileDataSourceImpl("input.mp4"));

以此作为堆栈跟踪:

09-01 18:46:40.611: E/AndroidRuntime(14115): FATAL EXCEPTION: GLThread 1260
09-01 18:46:40.611: E/AndroidRuntime(14115): Process: package.app, PID: 14115
09-01 18:46:40.611: E/AndroidRuntime(14115): java.lang.RuntimeException: Sequence parameter set extension is not yet handled. Needs TLC.
09-01 18:46:40.611: E/AndroidRuntime(14115):    at com.googlecode.mp4parser.authoring.tracks.H264TrackImpl.readSamples(H264TrackImpl.java:362)
09-01 18:46:40.611: E/AndroidRuntime(14115):    at com.googlecode.mp4parser.authoring.tracks.H264TrackImpl.parse(H264TrackImpl.java:108)
09-01 18:46:40.611: E/AndroidRuntime(14115):    at com.googlecode.mp4parser.authoring.tracks.H264TrackImpl.<init>(H264TrackImpl.java:90)
09-01 18:46:40.611: E/AndroidRuntime(14115):    at com.googlecode.mp4parser.authoring.tracks.H264TrackImpl.<init>(H264TrackImpl.java:96)
09-01 18:46:40.611: E/AndroidRuntime(14115):    at com.googlecode.mp4parser.authoring.tracks.H264TrackImpl.<init>(H264TrackImpl.java:100)
09-01 18:46:40.611: E/AndroidRuntime(14115):    at ...

(崩溃发生在 this function at this line 中。)

<小时/>

所以我不太确定这意味着什么? jcodec 输出的 MP4 文件(顺便说一句,它适用于所有视频播放器)是否与 MP4Parser 不兼容?

我应该考虑什么来解决这个问题?

感谢任何建议。

<小时/>

编辑

以前的方法是错误的,但这个方法有效

Movie movie = MovieCreator.build(_videoFile.getAbsolutePath());

AACTrackImpl aacTrack = new AACTrackImpl(new FileDataSourceImpl(_aacFile));
CroppedTrack aacCroppedTrack = new CroppedTrack(aacTrack, 1, aacTrack.getSamples().size());
movie.addTrack(aacCroppedTrack);

Container mp4file = new DefaultMp4Builder().build(movie);

FileOutputStream fileOutputStream = new FileOutputStream(_outputFile);
FileChannel fc = fileOutputStream.getChannel();
mp4file.writeContainer(fc);
fileOutputStream.close();

最佳答案

这对我有用......

        DataSource videoFile = new FileDataSourceImpl(filePath);

        Movie sor = MovieCreator.build(videoFile);

        List<Track> videoTracks = sor.getTracks();
        Track h264Track = null;

        for (Track t : videoTracks
             ) {
            if(t.getHandler().contains("vid"))
            {
                h264Track = t;

关于java - 复用 MP4 和 AAC(jcodec、MP4Parser),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32342156/

相关文章:

java - 尝试在 JAVA Spring,@AutoWired 过滤器服务,但抛出 NPE

java - 为什么有些资源文件放在META-INF目录下

objective-c - Objective-C 中的转义引号

assembly - 该跳转指令在 Intel64 中如何编码?

objective-c - NSMutableString 和(字符)编码问题 : getting\U00fc in case of ü

java double 计算

java - 合并不同的持久单元

java - 用于关闭对话框的按钮引发 nullpointerException

java - 使用数组适配器将对象的多个值分配给 ListView 中的单个项目

android - 单击其子项时禁用 View 寻呼机的滑动