gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-04 13:29:24 24 4
gpt4 key购买 nike

我有一个使用 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com