本文介紹了Java mp4parser輸出為空的處理方法,對(duì)大家解決問(wèn)題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)吧!
問(wèn)題描述
此使用案例是一項(xiàng)服務(wù),它手動(dòng)將一系列未壓縮的.wav媒體段編碼為.m4s片段以通過(guò)mpeg-dash進(jìn)行廣播,并使用ffmpeg將.wav壓縮為.aac,并使用sannies/mp4parser將AAC音頻組裝為.m4s媒體片段。
我創(chuàng)建了this public GitHub project以完整復(fù)制該問(wèn)題。
例如,下面是自定義ChunkFragmentM4sBuilder.java類(lèi)。
使用MP4盒的第一個(gè)示例可以工作,因?yàn)槲夷軌蛏梢粋€(gè)初始化的MP4+系列片段M4
然后可以串聯(lián)這些文件以形成可播放的MPEG4流。
注意:此用例要求從單獨(dú)生成的源段對(duì)每個(gè)媒體段進(jìn)行編碼,而不是使用MP4Box等工具從連續(xù)的音頻源進(jìn)行流媒體。
通過(guò)mp4parser手動(dòng)構(gòu)建媒體段的嘗試總體上仍然失敗,因?yàn)橛?br />
下面使用的ChunkFragmentM4sBuilder.java格式不正確。
但我很難理解它們到底是如何畸形的。
將兩個(gè)測(cè)試日志并排比較對(duì)我很有幫助
側(cè)面,ChunkFragmentM4sBuilderTest.log.txt
和MP4BoxTest.log.txt。
通過(guò)Java mp4parser(格式錯(cuò)誤)
前者log是
來(lái)自ChunkFragmentM4sBuilderTest.java,其結(jié)果是
中的串聯(lián)測(cè)試輸出test-java-mp4parser.mp4
事實(shí)為空:
Files.deleteIfExists(Path.of(m4sFilePath));
AACTrackImpl aacTrack=new AACTrackImpl(new FileDataSourceImpl(aacFilePath));
Movie movie=new Movie();
movie.addTrack(aacTrack);
Container mp4file=new ChunkFragmentM4sBuilder(hz,seconds,seqNum,bufferSize).build(movie);
FileChannel fc=new FileOutputStream(m4sFilePath).getChannel();
mp4file.writeContainer(fc);
fc.close();
test5.mpd
test5-128k-163493804.m4s
test5-128k-163493805.m4s
test5-128k-163493806.m4s
test5-128k-IS.mp4
串聯(lián)框:
FileTypeBox[majorBrand=iso5;minorVersion=512;compatibleBrand=iso6;compatibleBrand=mp41]
MovieBox[MovieHeaderBox[creationTime=Thu Dec 31 16:00:00 PST 1903;modificationTime=Thu Dec 31 16:00:00 PST 1903;timescale=1000;duration=0;rate=1.0;volume=1.0;matrix=Rotate 0°;nextTrackId=2];TrackBox[TrackHeaderBox[creationTime=Thu Dec 31 16:00:00 PST 1903;modificationTime=Thu Dec 31 16:00:00 PST 1903;trackId=1;duration=0;layer=0;alternateGroup=1;volume=1.0;matrix=Rotate 0°;width=0.0;height=0.0];EditBox[EditListBox{entries=[Entry{segmentDuration=0, mediaTime=1024, mediaRate=1.0}]}];MediaBox[MediaHeaderBox[creationTime=Thu Dec 31 16:00:00 PST 1903;modificationTime=Thu Dec 31 16:00:00 PST 1903;timescale=48000;duration=0;language=und];HandlerBox[handlerType=soun;name=SoundHandler];MediaInformationBox[SoundMediaHeaderBox[balance=0.0];DataInformationBox[DataReferenceBox[DataEntryUrlBox[]]];SampleTableBox[SampleDescriptionBox[AudioSampleEntry{bytesPerSample=0, bytesPerFrame=0, bytesPerPacket=0, samplesPerPacket=0, packetSize=0, compressionId=0, soundVersion=0, sampleRate=48000, sampleSize=16, channelCount=2, boxes=[org.mp4parser.boxes.iso14496.part14.ESDescriptorBox@bed094d2]}];TimeToSampleBox[entryCount=0];SampleToChunkBox[entryCount=0];SampleSizeBox[sampleSize=0;sampleCount=0];StaticChunkOffsetBox[entryCount=0]]]]];MovieExtendsBox[org.mp4parser.boxes.iso14496.part12.TrackExtendsBox@11e7301d];UserDataBox[MetaBox[HandlerBox[handlerType=mdir;name=];AppleItemListBox[org.mp4parser.boxes.apple.AppleEncoderBox@691fba4]]]]
SegmentTypeBox[majorBrand=msdh;minorVersion=0;compatibleBrand=msdh;compatibleBrand=msix]
SegmentIndexBox{entries=[Entry{referenceType=0, referencedSize=160944, subsegmentDuration=480000, startsWithSap=1, sapType=0, sapDeltaTime=0}], referenceId=1, timeScale=48000, earliestPresentationTime=0, firstOffset=0, reserved=0}
MovieFragmentBox[MovieFragmentHeaderBox{sequenceNumber=151304042};TrackFragmentBox[TrackFragmentHeaderBox{trackId=1, baseDataOffset=-1, sampleDescriptionIndex=0, defaultSampleDuration=-1, defaultSampleSize=-1, defaultSampleFlags=null, durationIsEmpty=true, defaultBaseIsMoof=true};TrackFragmentBaseMediaDecodeTimeBox{baseMediaDecodeTime=0};TrackRunBox{sampleCount=470, dataOffset=-1, dataOffsetPresent=false, sampleSizePresent=true, sampleDurationPresent=true, sampleFlagsPresentPresent=false, sampleCompositionTimeOffsetPresent=false, firstSampleFlags=null}]]
org.mp4parser.boxes.iso14496.part12.MediaDataBox@3969adb0
通過(guò)MP4Box(Ok)
后者log是
從MP4BoxTest.java產(chǎn)生串聯(lián)的測(cè)試輸出
test-mp4box.mp4可以。
注意,此方法對(duì)于最終用例是不可接受的,因?yàn)榇薶ack方法輸出的塊中存在缺陷。
MP4Box
-profile live
-add aacFilePath
-dash 10000
-frag 10000
-idx ${NUM}
-moof-sn ${NUM}
-out test5.mpd
-segment-name test5-128k-
-segment-ext m4s
-single-traf
-subsegs-per-sidx 0
-daisy-chain
-single-segment
/tmp
test5.mpd
test5-128k-163494320.m4s
test5-128k-163494321.m4s
test5-128k-163494322.m4s
test5-128k-IS.mp4
串聯(lián)框:
FileTypeBox[majorBrand=iso5;minorVersion=512;compatibleBrand=iso6;compatibleBrand=mp41]
MovieBox[MovieHeaderBox[creationTime=Thu Dec 31 16:00:00 PST 1903;modificationTime=Thu Dec 31 16:00:00 PST 1903;timescale=1000;duration=0;rate=1.0;volume=1.0;matrix=Rotate 0°;nextTrackId=2];TrackBox[TrackHeaderBox[creationTime=Thu Dec 31 16:00:00 PST 1903;modificationTime=Thu Dec 31 16:00:00 PST 1903;trackId=1;duration=0;layer=0;alternateGroup=1;volume=1.0;matrix=Rotate 0°;width=0.0;height=0.0];EditBox[EditListBox{entries=[Entry{segmentDuration=0, mediaTime=1024, mediaRate=1.0}]}];MediaBox[MediaHeaderBox[creationTime=Thu Dec 31 16:00:00 PST 1903;modificationTime=Thu Dec 31 16:00:00 PST 1903;timescale=48000;duration=0;language=und];HandlerBox[handlerType=soun;name=SoundHandler];MediaInformationBox[SoundMediaHeaderBox[balance=0.0];DataInformationBox[DataReferenceBox[DataEntryUrlBox[]]];SampleTableBox[SampleDescriptionBox[AudioSampleEntry{bytesPerSample=0, bytesPerFrame=0, bytesPerPacket=0, samplesPerPacket=0, packetSize=0, compressionId=0, soundVersion=0, sampleRate=48000, sampleSize=16, channelCount=2, boxes=[org.mp4parser.boxes.iso14496.part14.ESDescriptorBox@bed094d2]}];TimeToSampleBox[entryCount=0];SampleToChunkBox[entryCount=0];SampleSizeBox[sampleSize=0;sampleCount=0];StaticChunkOffsetBox[entryCount=0]]]]];MovieExtendsBox[org.mp4parser.boxes.iso14496.part12.TrackExtendsBox@7ce1e496];UserDataBox[MetaBox[HandlerBox[handlerType=mdir;name=];AppleItemListBox[org.mp4parser.boxes.apple.AppleEncoderBox@51da5351]]]]
SegmentTypeBox[majorBrand=msdh;minorVersion=0;compatibleBrand=msdh;compatibleBrand=msix]
SegmentIndexBox{entries=[Entry{referenceType=0, referencedSize=162267, subsegmentDuration=479232, startsWithSap=1, sapType=1, sapDeltaTime=0}], referenceId=1, timeScale=48000, earliestPresentationTime=0, firstOffset=0, reserved=0}
MovieFragmentBox[MovieFragmentHeaderBox{sequenceNumber=151304042};TrackFragmentBox[TrackFragmentHeaderBox{trackId=1, baseDataOffset=-1, sampleDescriptionIndex=0, defaultSampleDuration=-1, defaultSampleSize=-1, defaultSampleFlags=null, durationIsEmpty=false, defaultBaseIsMoof=true};TrackFragmentBaseMediaDecodeTimeBox{baseMediaDecodeTime=0};TrackRunBox{sampleCount=468, dataOffset=1964, dataOffsetPresent=true, sampleSizePresent=true, sampleDurationPresent=false, sampleFlagsPresentPresent=false, sampleCompositionTimeOffsetPresent=false, firstSampleFlags=null}]]
org.mp4parser.boxes.iso14496.part12.MediaDataBox@640d3ba5
推薦答案
test-java-mp4parser.mp4
不為空,但無(wú)效,原因是:
sidx
條目引用大小錯(cuò)誤
tfhd
正在使用0
覆蓋默認(rèn)的樣本說(shuō)明索引(1
)
trun
未指定數(shù)據(jù)偏移量
mdat
AAC數(shù)據(jù)以8個(gè)零字節(jié)開(kāi)始,導(dǎo)致解碼失敗
如果FFmpeg已修復(fù),則使用FFmpeg播放文件。
列出的m4s
段的格式也不正確,似乎與串聯(lián)結(jié)果不一致。例如,序列號(hào)用作樣本描述索引。
這篇關(guān)于Java mp4parser輸出為空的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,