mirror of
https://github.com/arcodange-org/mediabunny.git
synced 2026-09-27 02:43:48 +02:00
Add InputTrack.number
This commit is contained in:
@@ -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 };
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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';
|
||||
|
||||
|
||||
Reference in New Issue
Block a user