diff --git a/libav.in.js b/libav.in.js index 346cd94..99c5752 100644 --- a/libav.in.js +++ b/libav.in.js @@ -121,6 +121,31 @@ return [dv.getInt32(0, true), dv.getInt32(4, true)]; }; + libavStatics.ff_channel_layout(frame) { + if (frame.channel_layout) + return frame.channel_layout; + else if (frame.channels && frame.channels !== 1) + return (1 << frame.channels) - 1; + else + return 4; // Mono + }; + + libavStatics.ff_channels(frame) { + if (frame.channels) { + return frame.channels; + } else if (frame.channel_layout) { + var channels = 0; + var cl = frame.channel_layout; + while (cl) { + channels += (cl & 1); + cl >>= 1; + } + return channels; + } else { + return 1; + } + }; + // Some enumerations lifted directly from FFmpeg function enume(vals, first) { if (typeof first === undefined) diff --git a/libav.types.in.d.ts b/libav.types.in.d.ts index 29f197f..1854177 100644 --- a/libav.types.in.d.ts +++ b/libav.types.in.d.ts @@ -407,6 +407,26 @@ declare namespace LibAV { */ bigIntToi64(val: BigInt): [number, number]; + /** + * Extract the channel layout from a frame (or any other source of + * channel layout). Unifies the various ways that channel layouts may + * be stored. + */ + ff_channel_layout(frame: { + channel_layout?: number, + channels?: number + }): number; + + /** + * Extract the channel count from a frame (or any other source of + * channel layout). Unifies the various ways that channel layouts may be + * stored. + */ + ff_channels(frame: { + channel_layout?: number, + channels?: number + }): number; + // Enumerations: AV_OPT_SEARCH_CHILDREN: number; AVMEDIA_TYPE_UNKNOWN: number;