gpac icon indicating copy to clipboard operation
gpac copied to clipboard

Help - MP4Box Batch processing with differing track numbers

Open petenun opened this issue 7 years ago • 1 comments

I'm not sure where else to post my question so please forgive me if this is in the wrong forum.

I get a number of MP4 files, each with a single video track and multiple audio tracks (different languages). The track numbers for each file can differ. For example, on one source MP4 file, the video track may be Track #3 with the ENG audio track being Track #5. On another source file, the video track could be Track #4, with the ENG audio track being Track #3.

I am looking for a way to batch process hundreds of these files to retain only the video file and ENG language track, stripping-out all other information.

All examples I've seen require specifying track numbers. Instead of using track numbers, is there any way to add tracks by specifying some other consistent parameter such as "Media Info: Language "English" - Type "soun:mp4a"" for audio tracks, or "Type "vide:avc1"" for video tracks?

Thanks, Petenun

petenun avatar Sep 06 '19 22:09 petenun

You can do this with 0.9.0 (filters branch) with both MP4Box and gpac.

Using gpac:

gpac -i src.mp4 reframer @#CodecID=avc,#Language=eng -o dest.mp4

which is a "shortcut" for:

gpac -i src.mp4 reframer:FID=1 -o dest.mp4:SID=1#CodecID=avc,1#Language=eng

This tells the destination filter (-o dest.mp4) to only accept media streams with property CodecID=avc1 or media streams with property Language=fra. If none of the required properties are found in the media stream, the stream will be accepted.

Note: the reframer filter is mandatory to force demuxing of source, otherwise you would have a direct file copy.

You can specify multiple properties to check for: SID=1#CodecID=mp3#Language=fra,1#CodecID=avc,1#CodecID=mp4v2

Using MP4Box, this is just a matter of passing the sourceID option to the destination:

MP4Box -add src.mp4:dopt:SID=#CodecID=avc,#Language=eng -new dest.mp4

Note that you don't need an identifier in SID in this case since there is only one possible source (src.mp4).

HTH, Jean

jeanlf avatar Apr 30 '20 12:04 jeanlf