Add InputTrack.number

This commit is contained in:
Vanilagy
2026-01-22 09:18:43 +01:00
parent e1e32c9505
commit e20f779ede
14 changed files with 118 additions and 13 deletions
+3 -3
View File
@@ -306,8 +306,8 @@ const conversion = await Conversion.init({
output,
// Function gets invoked for each video track:
video: (videoTrack, n) => {
if (n > 1) {
video: (videoTrack) => {
if (videoTrack.number > 1) {
// Keep only the first video track
return { discard: true };
}
@@ -319,7 +319,7 @@ const conversion = await Conversion.init({
},
// Async functions work too:
audio: async (audioTrack, n) => {
audio: async (audioTrack) => {
if (audioTrack.languageCode !== 'rus') {
// Keep only Russian audio tracks
return { discard: true };
+6 -4
View File
@@ -556,14 +556,16 @@ const output = new Output(...);
const conversion = await Conversion.init({
input,
output,
video: {
video: track => ({
width: 480,
bitrate: QUALITY_LOW,
},
audio: {
discard: track.number > 1, // Keep only the first video track
}),
audio: track => ({
numberOfChannels: 1,
bitrate: QUALITY_LOW,
},
discard: track.number > 1, // Keep only the first audio track
}),
trim: {
// Let's keep only the first 60 seconds
start: 0,
+4
View File
@@ -98,6 +98,10 @@ Once you have an `InputTrack`, you can start extracting metadata from it.
// Get a unique ID for this track in the input file:
track.id; // => number
// Get the 1-based index of this track among all tracks of the same type
// (e.g., first video track is 1, second video track is 2, etc.):
track.number; // => number
// Check the track's type:
track.type; // => 'video' | 'audio' | 'subtitle';