我有一个用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是否输出与MP4Parser不兼容的MP4文件(可在所有视频播放器中使用)?
我应该寻找什么来解决这个问题?
感谢任何建议。
编辑
用错误的方式去做,这可行
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;