diff --git a/README.md b/README.md index 66a35a4..8c846a3 100644 --- a/README.md +++ b/README.md @@ -42,7 +42,7 @@ Mediabunny is a JavaScript library for reading, writing, and converting media fi Core features include: -- **Wide format support**: Read and write MP4, WebM, WAVE, MP3, Ogg, and more +- **Wide format support**: Read and write MP4, MOV, WebM, MKV, WAVE, MP3, Ogg, ADTS - **Built-in encoding & decoding**: Supports 25+ video, audio, and subtitle codecs, hardware-accelerated using the WebCodecs API - **High precision**: Fine-grained, microsecond-accurate reading and writing operations - **Conversion API**: Easy-to-use API with features such as transmuxing, transcoding, resizing, rotation, resampling, trimming, and more diff --git a/dev/demux.html b/dev/demux.html index 3bfb4db..6a6cb94 100644 --- a/dev/demux.html +++ b/dev/demux.html @@ -17,6 +17,9 @@ }); const videoTrack = await input.getPrimaryVideoTrack(); + console.log(await videoTrack.getFirstTimestamp(), await videoTrack.computeDuration()); + + /* const sink = new Mediabunny.EncodedPacketSink(videoTrack); for await (const packet of sink.packets()) { @@ -24,6 +27,7 @@ //if (packet.timestamp > 135) break; } + */ /* const audioTrack = await input.getPrimaryAudioTrack(); diff --git a/src/isobmff/isobmff-demuxer.ts b/src/isobmff/isobmff-demuxer.ts index 9a88c43..cfafef7 100644 --- a/src/isobmff/isobmff-demuxer.ts +++ b/src/isobmff/isobmff-demuxer.ts @@ -2460,15 +2460,10 @@ abstract class IsobmffTrackBacking implements InputTrackBacking { metadataReader.pos = startPos + boxInfo.totalSize; } - let result: EncodedPacket | null = null; const bestFragment = bestFragmentIndex !== -1 ? this.internalTrack.fragments[bestFragmentIndex]! : null; - if (bestFragment) { - // If we finished looping but didn't find a perfect match, still return the best match we found - result = await this.fetchPacketInFragment(bestFragment, bestSampleIndex, options); - } // Catch faulty lookup table entries - if (!result && lookupEntry && (!bestFragment || bestFragment.moofOffset < lookupEntry.moofOffset)) { + if (lookupEntry && (!bestFragment || bestFragment.moofOffset < lookupEntry.moofOffset)) { // The lookup table entry lied to us! We found a lookup entry but no fragment there that satisfied // the match. In this case, let's search again but using the lookup entry before that. const previousLookupEntry = this.internalTrack.fragmentLookupTable![lookupEntryIndex - 1]; @@ -2476,7 +2471,12 @@ abstract class IsobmffTrackBacking implements InputTrackBacking { return this.performFragmentedLookup(getBestMatch, newSearchTimestamp, latestTimestamp, options); } - return result; + if (bestFragment) { + // If we finished looping but didn't find a perfect match, still return the best match we found + return this.fetchPacketInFragment(bestFragment, bestSampleIndex, options); + } + + return null; } finally { release(); } diff --git a/src/matroska/matroska-demuxer.ts b/src/matroska/matroska-demuxer.ts index 46632cd..c72c92b 100644 --- a/src/matroska/matroska-demuxer.ts +++ b/src/matroska/matroska-demuxer.ts @@ -1731,15 +1731,10 @@ abstract class MatroskaTrackBacking implements InputTrackBacking { metadataReader.pos = dataStartPos + size; } - let result: EncodedPacket | null = null; const bestCluster = bestClusterIndex !== -1 ? this.internalTrack.clusters[bestClusterIndex]! : null; - if (bestCluster) { - // If we finished looping but didn't find a perfect match, still return the best match we found - result = await this.fetchPacketInCluster(bestCluster, bestBlockIndex, options); - } // Catch faulty cue points - if (!result && cuePoint && (!bestCluster || bestCluster.elementStartPos < cuePoint.clusterPosition)) { + if (cuePoint && (!bestCluster || bestCluster.elementStartPos < cuePoint.clusterPosition)) { // The cue point lied to us! We found a cue point but no cluster there that satisfied the match. In this // case, let's search again but using the cue point before that. const previousCuePoint = this.internalTrack.cuePoints[cuePointIndex - 1]; @@ -1747,7 +1742,12 @@ abstract class MatroskaTrackBacking implements InputTrackBacking { return this.performClusterLookup(getBestMatch, newSearchTimestamp, latestTimestamp, options); } - return result; + if (bestCluster) { + // If we finished looping but didn't find a perfect match, still return the best match we found + return this.fetchPacketInCluster(bestCluster, bestBlockIndex, options); + } + + return null; } finally { release(); }