Skip to content

Commit

Permalink
Adding easy channel layout extractors
Browse files Browse the repository at this point in the history
  • Loading branch information
Yahweasel committed Dec 12, 2024
1 parent a1850c9 commit 3b4662a
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
25 changes: 25 additions & 0 deletions libav.in.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
20 changes: 20 additions & 0 deletions libav.types.in.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 3b4662a

Please sign in to comment.