mirror of
https://github.com/arcodange-org/mediabunny.git
synced 2026-10-02 21:33:52 +02:00
Rename
This commit is contained in:
+12
-12
@@ -864,38 +864,38 @@ export type Vp9CodecInfo = {
|
|||||||
matrixCoefficients: number;
|
matrixCoefficients: number;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const extractVp9CodecInfoFromFrame = (
|
export const extractVp9CodecInfoFromPacket = (
|
||||||
frame: Uint8Array,
|
packet: Uint8Array,
|
||||||
): Vp9CodecInfo | null => {
|
): Vp9CodecInfo | null => {
|
||||||
// eslint-disable-next-line @stylistic/max-len
|
// eslint-disable-next-line @stylistic/max-len
|
||||||
// https://storage.googleapis.com/downloads.webmproject.org/docs/vp9/vp9-bitstream-specification-v0.7-20170222-draft.pdf
|
// https://storage.googleapis.com/downloads.webmproject.org/docs/vp9/vp9-bitstream-specification-v0.7-20170222-draft.pdf
|
||||||
// http://downloads.webmproject.org/docs/vp9/vp9-bitstream_superframe-and-uncompressed-header_v1.0.pdf
|
// http://downloads.webmproject.org/docs/vp9/vp9-bitstream_superframe-and-uncompressed-header_v1.0.pdf
|
||||||
|
|
||||||
// Handle superframe
|
// Handle superframe
|
||||||
const lastByte = frame[frame.length - 1];
|
const lastByte = packet[packet.length - 1];
|
||||||
if (lastByte && (lastByte & 0xe0) === 0xc0) { // Is superframe
|
if (lastByte && (lastByte & 0xe0) === 0xc0) { // Is superframe
|
||||||
const bytesPerFrameSize = ((lastByte & 0x18) >> 3) + 1;
|
const bytesPerFrameSize = ((lastByte & 0x18) >> 3) + 1;
|
||||||
const numFrames = (lastByte & 0x07) + 1;
|
const numFrames = (lastByte & 0x07) + 1;
|
||||||
const indexSize = 2 + numFrames * bytesPerFrameSize;
|
const indexSize = 2 + numFrames * bytesPerFrameSize;
|
||||||
|
|
||||||
// Verify matching marker bytes
|
// Verify matching marker bytes
|
||||||
if (frame[frame.length - indexSize] !== lastByte) {
|
if (packet[packet.length - indexSize] !== lastByte) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get first frame size
|
// Get first frame size
|
||||||
let frameSize = 0;
|
let frameSize = 0;
|
||||||
const offset = frame.length - indexSize + 1;
|
const offset = packet.length - indexSize + 1;
|
||||||
|
|
||||||
for (let i = 0; i < bytesPerFrameSize; i++) {
|
for (let i = 0; i < bytesPerFrameSize; i++) {
|
||||||
if (!frame[offset + i]) return null;
|
if (!packet[offset + i]) return null;
|
||||||
frameSize |= frame[offset + i]! << (8 * i);
|
frameSize |= packet[offset + i]! << (8 * i);
|
||||||
}
|
}
|
||||||
|
|
||||||
frame = frame.subarray(0, frameSize);
|
packet = packet.subarray(0, frameSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
const bitstream = new Bitstream(frame);
|
const bitstream = new Bitstream(packet);
|
||||||
|
|
||||||
// Frame marker (0b10)
|
// Frame marker (0b10)
|
||||||
const frameMarker = bitstream.readBits(2);
|
const frameMarker = bitstream.readBits(2);
|
||||||
@@ -1044,12 +1044,12 @@ export type Av1CodecInfo = {
|
|||||||
* When AV1 codec information is not provided by the container, we can still try to extract the information by digging
|
* When AV1 codec information is not provided by the container, we can still try to extract the information by digging
|
||||||
* into the AV1 bitstream.
|
* into the AV1 bitstream.
|
||||||
*/
|
*/
|
||||||
export const extractAv1CodecInfoFromFrame = (
|
export const extractAv1CodecInfoFromPacket = (
|
||||||
data: Uint8Array,
|
packet: Uint8Array,
|
||||||
): Av1CodecInfo | null => {
|
): Av1CodecInfo | null => {
|
||||||
// https://aomediacodec.github.io/av1-spec/av1-spec.pdf
|
// https://aomediacodec.github.io/av1-spec/av1-spec.pdf
|
||||||
|
|
||||||
const bitstream = new Bitstream(data);
|
const bitstream = new Bitstream(packet);
|
||||||
|
|
||||||
const readLeb128 = (): number | null => {
|
const readLeb128 = (): number | null => {
|
||||||
let value = 0;
|
let value = 0;
|
||||||
|
|||||||
@@ -13,8 +13,8 @@ import {
|
|||||||
HevcDecoderConfigurationRecord,
|
HevcDecoderConfigurationRecord,
|
||||||
Vp9CodecInfo,
|
Vp9CodecInfo,
|
||||||
Av1CodecInfo,
|
Av1CodecInfo,
|
||||||
extractVp9CodecInfoFromFrame,
|
extractVp9CodecInfoFromPacket,
|
||||||
extractAv1CodecInfoFromFrame,
|
extractAv1CodecInfoFromPacket,
|
||||||
} from '../codec-data';
|
} from '../codec-data';
|
||||||
import { Demuxer } from '../demuxer';
|
import { Demuxer } from '../demuxer';
|
||||||
import { Input } from '../input';
|
import { Input } from '../input';
|
||||||
@@ -2360,10 +2360,10 @@ class IsobmffVideoTrackBacking extends IsobmffTrackBacking implements InputVideo
|
|||||||
return this.decoderConfigPromise ??= (async (): Promise<VideoDecoderConfig> => {
|
return this.decoderConfigPromise ??= (async (): Promise<VideoDecoderConfig> => {
|
||||||
if (this.internalTrack.info.codec === 'vp9' && !this.internalTrack.info.vp9CodecInfo) {
|
if (this.internalTrack.info.codec === 'vp9' && !this.internalTrack.info.vp9CodecInfo) {
|
||||||
const firstPacket = await this.getFirstPacket({});
|
const firstPacket = await this.getFirstPacket({});
|
||||||
this.internalTrack.info.vp9CodecInfo = firstPacket && extractVp9CodecInfoFromFrame(firstPacket.data);
|
this.internalTrack.info.vp9CodecInfo = firstPacket && extractVp9CodecInfoFromPacket(firstPacket.data);
|
||||||
} else if (this.internalTrack.info.codec === 'av1' && !this.internalTrack.info.av1CodecInfo) {
|
} else if (this.internalTrack.info.codec === 'av1' && !this.internalTrack.info.av1CodecInfo) {
|
||||||
const firstPacket = await this.getFirstPacket({});
|
const firstPacket = await this.getFirstPacket({});
|
||||||
this.internalTrack.info.av1CodecInfo = firstPacket && extractAv1CodecInfoFromFrame(firstPacket.data);
|
this.internalTrack.info.av1CodecInfo = firstPacket && extractAv1CodecInfoFromPacket(firstPacket.data);
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
import {
|
import {
|
||||||
extractAv1CodecInfoFromFrame,
|
extractAv1CodecInfoFromPacket,
|
||||||
extractAvcDecoderConfigurationRecord,
|
extractAvcDecoderConfigurationRecord,
|
||||||
extractHevcDecoderConfigurationRecord,
|
extractHevcDecoderConfigurationRecord,
|
||||||
extractVp9CodecInfoFromFrame,
|
extractVp9CodecInfoFromPacket,
|
||||||
} from '../codec-data';
|
} from '../codec-data';
|
||||||
import {
|
import {
|
||||||
AacCodecInfo,
|
AacCodecInfo,
|
||||||
@@ -1577,10 +1577,10 @@ class MatroskaVideoTrackBacking extends MatroskaTrackBacking implements InputVid
|
|||||||
? extractHevcDecoderConfigurationRecord(firstPacket.data)
|
? extractHevcDecoderConfigurationRecord(firstPacket.data)
|
||||||
: null,
|
: null,
|
||||||
vp9CodecInfo: this.internalTrack.info.codec === 'vp9' && firstPacket
|
vp9CodecInfo: this.internalTrack.info.codec === 'vp9' && firstPacket
|
||||||
? extractVp9CodecInfoFromFrame(firstPacket.data)
|
? extractVp9CodecInfoFromPacket(firstPacket.data)
|
||||||
: null,
|
: null,
|
||||||
av1CodecInfo: this.internalTrack.info.codec === 'av1' && firstPacket
|
av1CodecInfo: this.internalTrack.info.codec === 'av1' && firstPacket
|
||||||
? extractAv1CodecInfoFromFrame(firstPacket.data)
|
? extractAv1CodecInfoFromPacket(firstPacket.data)
|
||||||
: null,
|
: null,
|
||||||
}),
|
}),
|
||||||
codedWidth: this.internalTrack.info.width,
|
codedWidth: this.internalTrack.info.width,
|
||||||
|
|||||||
Reference in New Issue
Block a user