[FFmpeg-user] Can I use ffmpeg to combine audio streams in .ts file?

skyscanner at gmx.ca skyscanner at gmx.ca
Tue Sep 30 01:42:17 CEST 2014


This is the sixth time I have attempted to send this to the list.  I think Lou may have identified the issue, so I am trying a different way of posting this and hope it will go through.  If it does, thanks Lou!
 
I have a strange situation in that I have a satellite receiver that receives one particular channel that has a rather different audio arrangement.  I can record programs, but at the moment I can't play them back and hear the full audio on my home theater PC.
 
The facts are:
 
The recordings are from a DVB-S2 satellite source and are saved as .ts files.  Each .ts file only contains the recording of a single channel; it's not one of those .ts files that contains a raw dump from a transponder with many channels.  The video is fine as is and does not need to be converted, it's only the audio that is a problem.
 
The recordings contain four different audio streams or tracks or channels (each software program calls them something different; I will refer to them as streams hereafter), each of which have a left and right channel.
 
Most software by default only plays the first stream, which contains only background music and sound effects in stereo, but no dialogue.   You can select a different stream but no matter which you select, you wind up missing some of the audio.
 
QuickTime on an OS X machine will play all the audio streams merged together and normally that sounds pretty good, except when there is a "described video" track (that narrates the action for sight-impaired users).  Since at this point in my life I don't have any vision problems that severe, I'd prefer not to hear that track, but QuickTimes give you no way to selectively turn it off, and anyway my HTPC box runs Ubuntu Linux, so running QuickTime there is not an option.  I really want to be able to play the recordings in XBMC.
 
As best I can tell, the way the broadcaster is sending the tracks appears to be as follows:

Stream 1: Background Music and sound effects in stereo
Stream 2: Left channel is vocal audio and a few additional sound effects.  Right channel appears to be low-level background noise only.
Stream 3: Appears to be rear channel audio (but no dialogue) in stereo
Stream 4: Left channel is either blank or contains described video narration (which I do NOT want).  Right channel contains dialogue but sometimes with slight reverb, probably for surround sound systems.

If my guess on that is accurate, and I am not 100% sure it is, then my suspicion is that the way the channels are supposed to be mapped are as follows:

Stream 1: Front left and right speakers
Stream 2: Left channel (dialogue) to center speaker.  Not sure about right channel, maybe mixed with front center?
Stream 3: Rear left and right speakers
Stream 4: Left channel for described video or alternate language. Right channel to rear center OR mixed with front center.

But, it would be acceptable to take the stream 2 Left channel and send it to the front left speaker, and the stream 4 right channel and send it to the front right center, mixed with the stream 1 audio of course.  What is not wanted is the stream 4 left channel audio.  This is what I believe QuickTime is doing, just mixing all the lefts together and all the rights together, and it sounds pretty good except when that unwanted described video track is present.

I have found that I can use this to get rid of the unwanted left channel in Stream 4:

ffmpeg -i "original_program.ts" -c:v copy -map 0:0 -map 0:1 -map_channel 0.1.0 -map_channel 0.1.1 -map 0:2 -map_channel 0.2.0 -map_channel 0.2.1 -map 0:3 -map_channel 0.3.0 -map_channel 0.3.1 -map 0:4 -map_channel -1 -map_channel 0.4.1 -c:a mp2  test.ts

That may not be the optimal way to do that (suggestions to streamline that would be appreciated) but it took me over six hours to get that much figured out. Unfortunately, it still saves the remaining audio as four separate streams:

Output #0, mpegts, to 'test.ts':
  Metadata:
    encoder         : Lavf55.33.100
    Stream #0:0: Video: h264 ([27][0][0][0] / 0x001B), yuvj420p, 1920x1080 [SAR 1:1 DAR 16:9], q=2-31, 29.97 fps, 90k tbn, 29.97 tbc
    Stream #0:1(aaa,aab): Audio: mp2, 48000 Hz, stereo, s16, 128 kb/s
    Stream #0:2(aac,aad): Audio: mp2, 48000 Hz, stereo, s16, 128 kb/s
    Stream #0:3(aae,aaf): Audio: mp2, 48000 Hz, stereo, s16, 128 kb/s
    Stream #0:4(aag,aah): Audio: mp2, 48000 Hz, stereo, s16, 128 kb/s
Stream mapping:
  Stream #0:0 -> #0:0 (copy)
  Stream #0:1 -> #0:1 (mp2 -> mp2)
  Stream #0:2 -> #0:2 (mp2 -> mp2)
  Stream #0:3 -> #0:3 (mp2 -> mp2)
  Stream #0:4 -> #0:4 (mp2 -> mp2)

This does not help me at all in XBMC. What I need to figure out is how to combine all the streams and merge them down to a single stereo stream (5.1 would be better, but at this point even plain stereo would be a huge improvement). Does ffmpeg have this capability?

TVHeadEnd will let you post-process a recording automatically as soon as the recording ends, so I was thinking that if it were possible to do this with ffmpeg, maybe I could run it that way.  Problem is, prior to looking at it for this use, I have have no experience at all with ffmpeg (other than being vaguely aware that it's a prerequisite for certain other software packages) so I have no idea what it's capable of, nor what options I would need to use to get the result I want.


More information about the ffmpeg-user mailing list