Electronic Frontier Foundation: The patent on Dolby Digital (AC-3) has just expired

To quote from an Electronic Frontier Foundation (EFF) page,

What is Dolby Digital (AC-3)?

AC-3 is a compressed digital audio format like MP3. It made its public debut in 1992. AC-3 has become the most common format for audio in film and television.

  • For digital television, AC-3 is a mandatory part of the ATSC standard (North America), DVB standards (Europe), and others.
  • For home video, AC-3 is a mandatory part of the DVD and Blu-ray standards.
  • For Internet streaming, AC-3 is supported in HTTP Live Streaming on many devices.

AC-3 supports up to 5.1 surround sound.

This is the format used to deliver 5.1 surround sound on many North American free-to-air TV channels. What this means is that satellite receiver manufacturers have one less patent to worry about.

This ought to put an end to some of the whining that occasionally appears in the satellite TV forums about cheap imported receivers that (in the opinion of the authors of the messages) violate patent laws, because the manufacturers allegedly did not purchase legitimate Dolby Digital licenses, yet included an AC-3 decoder in their receivers. Usually it is satellite equipment dealers that overbought on more expensive digital satellite receivers, and are sitting on old stock they’d like to sell, that complain about such things because they hate the competition (some dealers that have their own forums even censor discussion about such receivers, which strikes me as incredibly petty and self-serving, but it’s their forums). They fume that (in their opinion) such receivers enter the country illegally, and are sold more inexpensively than they should be, because the (usually Asian) manufacturer never cared about such things as paying patent license fees for their Dolby Digital decorder. Well as of today (March 20, 2017), payment is no longer required, according to this EFF article.

Manufacturers probably should avoid using trademarks such as “Dolby Digital” on their equipment, packaging, description of their product, in on-screen menus, etc. and instead stick to the non-trademarked “AC-3” designation, in order to stay on the right side of trademark law. And, as the article explains, this patent expiration only applies to AC-3 format. It does not apply to EAC-3 (“Dolby Digital Plus”), MLP, or TrueHD, which are still covered by several patents.

I am not a lawyer, and am only reporting what the EFF has to say about this, so if this matters to you, please consult your own lawyer for legal advice. Again, the article is here: At midnight on March 20, 2017, Dolby’s last relevant patent on Dolby Digital expired.

By the way, for anyone that’s ever had an argument with a friend or family member about whether a channel is carrying 5.1 audio (especially when Kodi claims it’s 2 channel, yet your ears tell you otherwise), note this article states that “AC-3 supports up to 5.1 surround sound”, and then further down, it also mentions AAC, DTS, and Opus as examples of other multichannel formats. So if Kodi shows the audio source as AAC or AC3, yes, it still might actually contain some form of 5.1 audio.

Advertisements

How to add NOAA weather radio (or another streaming radio station) as a radio channel in TVHeadEnd

I confess, this has nothing to do with Satellite TV, but there are times when you may be watching recorded TV or even a saved video on your HTPC and the weather outside starts to have ominous rumblings.  Wouldn’t you like to be able to quickly tune to your local NOAA weather radio station to hear the current forecast and any weather alerts?  I realize most of you will tune to a local TV station or grab your phone to check the weather, but there are satellite TV viewers in parts of the country that lose all local TV reception in severe weather.  So as long as your Internet connection stays up, and assuming there is a stream covering your area, you can do a quick check just by tuning to the NOAA weather radio station.

Of course you should not rely on this as your sole way of getting weather information, since it could unexpectedly go down for a number of reasons.  But another reason for publishing this was to show the basic method of setting up a radio station in TVHeadEnd that originates from a streaming source.  Once set up in this manner, you can listen to it live or even record it using TVHeadEnd’s Digital Video Recorder (Time Schedules).

First, if you have not already created an IPTV Network, see my previous article, Fixing the audio on live TV from a certain network (which shall remain nameless) in TVHeadend and generally follow the process shown there, up to the point where it shows the pipe URL usage. In this case, the pipe command you will want to use should look something like this:

pipe://ffmpeg -loglevel fatal -i http://ADDRESS_OF_STREAM -vn -acodec aac -flags +global_header -strict -2 -metadata service_provider=RADIOPROVIDER -metadata service_name=RADIONAME -f mpegts -mpegts_service_type digital_radio pipe:1

Replace http://ADDRESS_OF_STREAM with the URL to your NOAA weather radio stream. You can go to this Weather Underground page and if a city in your area is on the list of available stations, right click on the mp3 URL link for that city and copy the link. So for example, if you are in Los Angeles, the address would be http://audioplayer.wunderground.com/wb6ypf/Altadena.mp3 (as of the date when this article was written – note these links could change over time!).

Optionally, replace RADIOPROVIDER with something meaningful, like NOAA or Weather_Underground. Do not use spaces or punctuation (underscores in place of spaces are okay).

Replace RADIONAME with a meaningful name, like NOAA_Weather_Radio. Again, do not use spaces or punctuation.

Also in the Add Mux screen, make sure the Scan Status is set to PEND and that EPG Scan is disabled. Also it is important that you fill in the Mux Name field with something meaningful, since this will be the default channel name.  Click the Create button and it should find the stream and add it to the Services tab, and from there you can map it to a channel. It seems that with these streams mapping the channel in the normal manner does work.

Here is how the MUX configuration screen should appear after it’s been created and scanned (the Scan Status here shows IDLE, but when first created you’d use PEND):

NOAA Weather Stream Configuration

I won’t guarantee this will work with all audio streams you encounter on the Internet, but it’s always worth a try. In particular, I don’t know how it would work with stream URLs that do not start with http://. But at least this will get you started. If you have a “recipe” for another specific type of stream, please feel free to leave it in the comments.

EDIT: If you are using Tvheadend 4.3 or newer and you get an error such as “iptv: libav: Could not open input ‘pipe:///usr/bin/ffmpeg … (blah, blah) … ‘: Protocol not found”, you probably need to uncheck the box “Use A/V Library” in the IPTV network settings, and/or select “Do not use” in the dropdown for the “Use A/V Library” setting in your Mux settings – see this thread in the Tvheadend forum for details.

You may also be wondering if it’s possible to build a TV channel from an online streaming video source. Well of course it is possible, I just don’t know the “formula” for the pipe command at this time. Credit goes to this thread on the Kodi forum and user kaiseruk for providing the basic format of the pipe URL shown above.

Fixing the audio on live TV from a certain network (which shall remain nameless) in TVHeadend

266px-Pavo_cristatus_(male)_-feathers-8aThis is a followup to a previous article, Fixing the audio on recorded programs from a certain network (which shall remain nameless). In that article, which you may want to read first for some additional background information, I showed you how to fix the audio on previously-recorded programs. In this article, I’ll show you how to do it in real time, assuming you are using TVHeadend (version 3.9.2100 or later) as your PVR backend software. This is useful for both watching live TV, and for when you are recording a program but want to begin watching the recording before the program has ended.

My note about ffmpeg from the previous article also applies here:

Note: For this to work, you must have a version of ffmpeg from ffmpeg.org (link is to download page) or, if you are a Linux user but do not feel comfortable attempting to build software from source, then you may be better off using a static build such as is offered at this site (technically this is an unofficial build, so use at your own risk, but as I write this the packages offered in the deb repositories are older versions that don’t work as well for this purpose, and produce files that don’t play well on underpowered systems). Please note that some Linux distributions, notably some versions of Debian and Ubuntu and their derivatives, provide a package called ffmpeg in their repositories that is not true ffmpeg, but instead is a transitional package for libav. The syntax shown above will not work with the transitional package version; you need true ffmpeg for this to work! For the reason this sad situation exists, see The FFmpeg/Libav situation or for a slightly more technical view, FFmpeg versus Libav.

Another possible way to get the real ffmpeg installed on Ubuntu and some derivative systems is explained in the article, How To Install FFmpeg 2.6.1 On Ubuntu 15.04, Ubuntu 14.10, Ubuntu 14.04 And Derivative Systems from the LinuxG.net site.

This assumes that you have already scanned in the relevant channels from either the Ku-band side of AMC-1 or the C-band side of AMC-18 and that you have assigned them channel numbers in TVHeadend’s web interface. If you are in the habit of occasionally renumbering your channels as you add new ones or remove ones that are no longer functional, then I suggest you give those channels high numbers that will not be changed (starting with 1000 or even 10000, for example). The reason is that if you change the numbering of those original channels, this will stop working until you make the necessary adjustments. In any case, you need to note the channel numbers assigned to those channels, as they will be needed in one of the steps here.

The first thing you have to do, if you have not done it already, is to create an IPTV network. In TVHeadend’s web interface, go to Configuration > DVB Inputs > Networks and create a new IPTV Network:

Select IPTV network from the dropdownConfigure the new network as shown here:

Give the network a name, and uncheck The Network Name can be anything you like; I just called it IPTV to make it easy to recognize.  I also unchecked “Network Discovery” because it seems that you can’t automatically scan the channels anyway, so I didn’t want TVHeadend trying to do something in the background that would fail.

The above only has to be done once, no matter how many channels you add.  The next thing you need to do is add a Mux.  In TVHeadend’s web interface, go to Configuration > DVB Inputs > Muxes and create a new Mux, selecting the IPTV network from the dropdown:

Choose the IPTV network from the dropdown.Configure the new Mux as shown here:

Add Mux 2The full URL should be in this form (this is all one line):

In FFMPEG Version 2.x:
pipe:///usr/local/bin/ffmpeg -loglevel fatal -i http://127.0.0.1:9981/stream/channelnumber/CHANNEL_NUMBER -c copy -filter_complex [0:1][0:2][0:3]amerge=inputs=3,pan=5.1|FL=c0|FR=c1|FC=c2|LFE=c3|BL=c4|BR=c5 -c:a eac3 -f mpegts pipe:1

In FFMPEG Version 3.0 and later (only when using eac3 as the output codec):
pipe:///usr/local/bin/ffmpeg -loglevel fatal -i http://127.0.0.1:9981/stream/channelnumber/CHANNEL_NUMBER -c copy -filter_complex [0:1][0:2][0:3]amerge=inputs=3,pan=5.1|FL=c0|FR=c1|FC=c2|LFE=c3|BL=c4|BR=c5 -c:a eac3 -mpegts_flags system_b -f mpegts pipe:1

      • The above line assumes that ffmpeg is located in the /usr/local/bin directory on your system – if that’s not the case, and there’s a good chance it isn’t depending on which instructions you followed when you installed ffmpeg, you must change the path to point to the actual location of ffmpeg (you can enter “which ffmpeg” from the Linux command line to find the correct path).
      • Replace CHANNEL_NUMBER with the channel number of the original channel – this is why I suggested that you assign those channels high channel numbers, so you would not want or need to renumber them later.
      • Note that this converts the audio to eac3, which Kodi will generally play as true 5.1 audio, depending on its audio settings and the ability of your AV receiver to handle encoded audio (in some Kodi skins it’s erroneously reported as 7.1, but it’s really 5.1). If that doesn’t work for some reason, you can try changing the -c:a option from eac3 to ac3 or if it still doesn’t work, you can try mp2 as a last resort (but you may only get 2-channel stereo if you use mp2). When using ffmpeg 3.0 or later and specifying the eac3 codec, the -mpegts_flags system_b option must be included, or you may get no audio at all!
      • The above line converts the audio stream only.  All other streams are copied verbatim, which means that video, closed captions (if available) and anything else in the original stream should also be available in the converted stream (although closed captions seem to be iffy; in my experience that stream often has missing characters or is not present at all).

Be sure to give the Mux a name of your choosing – it makes it a lot easier to work with in the subsequent steps.  Short and simple is better here, for example just the network name and time zone.  It only needs to be unique and recognizable.

After adding your Mux, you can look in the Services tab to make sure it got added, but don’t try to map the service from there because it won’t work (at least I could never get it to work).  Instead, go to Configuration > Channels / EPG > Channels and click the Add button or link (in the bar just above the channel list).  You can then add the channel from this dialog box:

Add ChannelMake sure the “Enabled” box is checked.  For the Name, enter the channel name as you want it to appear in your channel list and guide in Kodi.  For the Number, give it the channel number you want it to use.  In the Services dropdown, select the correct service from the list; it will be in the format Network Name/Mux Name/Service01.  Note you may also see a listing of the form Network Name/Mux Name/{PMT:####} or something similar in the dropdown, but don’t use that one because it won’t work.  Use the one that ends in Service01.

If you have figured out how to add channels to the Electronic Program Guide, then you should also select the correct EPG Source from the dropdown.  Do not check the “Auto EPG Channel” box.  Then click the “Create” button.

If you want to add more channels (for different time zones, etc.) then just repeat the above process, starting with adding a new Mux.

You should be able to play your added channel(s) just like any other satellite channels in Kodi (or whatever you use to play video from the backend).  Note that because this is piping a stream through ffmpeg in real time, there may be a short delay (a few seconds at most) before the stream starts playing if you are trying to watch Live TV.  Unfortunately, this short delay apparently sometimes causes Kodi to ignore the video stream, but only when trying to play Live TV.   My guess is that because the video doesn’t arrive quickly enough, Kodi thinks you’re playing a radio or other audio-only channel and ignores  the video stream.  If this happens, you can stop the playback and try again, or you can start recording the channel, wait several seconds, and then start playing the recording.  I have never seen this problem occur when playing a recording, probably because recordings tend to start playing almost immediately. You only see it when you attempt to play the live stream directly, and even then it will only happen a certain (hopefully small) percentage of the time.

Speaking of recording,  if you want to record from the channel, you do that in the normal manner, just as you would for any other channel.  There’s no need to do any type of post-processing, unless you do that for reasons other than to fix the audio.

EDIT: If you are using Tvheadend 4.3 or newer and you get an error such as “iptv: libav: Could not open input ‘pipe:///usr/bin/ffmpeg … (blah, blah) … ‘: Protocol not found”, you probably need to uncheck the box “Use A/V Library” in the IPTV network settings, and/or select “Do not use” in the dropdown for the “Use A/V Library” setting in your Mux settings – see this thread in the Tvheadend forum for details.

EDIT: If it doesn’t work or suddenly stops working, check that you haven’t inadvertently blocked TVHeadEnd from accessing itself in the Access Entries tab in TVHeadend’s web interface.  At one point we tried changing the Network prefix values away from the default 0.0.0.0/0 to something more specific to the local network.  Everything else on the network could still access the backend, but it caused these channels to fail with an error message “No input source available for subscription” because TVHeadEnd could no longer access itself.  Strange…

On my TVHeadend backend, I’ve found that ffmpeg does not add significantly to the CPU usage as long as you are only converting audio.  I think converting video would be an entirely different story, and I doubt you could do that in real time unless you have a very high-powered backend system (and maybe not even then), but feel free to try if you have that need.

Reference:
Custom MPEG-TS Input (TVHeadend Wiki)

Why you’re not hearing full surround sound on some satellite channels – or maybe just think you aren’t

This is a followup to a previous article, I hear there’s a problem with playing satellite audio…, but I will try to go into a bit more detail here.

When you watch TV from a terrestrial TV station using a regular TV antenna, and you are using an audio receiver that supports 5.1 audio, you will often hear full surround sound, particularly from the major network stations. But when you run a backend system such as TVHeadEnd, and use Kodi to watch live or recorded programs from free-to-air satellite channels, you may see both Kodi and your receiver indicate that you are only receiving stereo (2.0) audio. This might be expected on a station or network that carries primarily old shows from the days of black and white TV, but if you happen to come across a network feed channel, you might be surprised to see that you’re still only getting stereo audio. This can be especially confusing if your ears are telling you that you’re hearing 5.1 audio, but Kodi and your receiver’s display indicate otherwise (no, you’re not going crazy).

Without getting too much into technical details, the issue is that most TV stations that transmit full surround sound encode the audio using a consumer friendly format, typically Dolby Digital. In North America, the ATSC standards specify Dolby Digital as the audio codec. Some satellite channels also transmit their audio in Dolby Digital format. If they do, and if the audio is 5.1 surround sound, chances are that both Kodi and your audio receiver will recognize that it’s receiving 5.1 surround sound.

But network feeds are not intended for consumers; they are intended for television stations. And therefore, each network can (and often does) use its own format for sending audio signals. A typical DVB-S or DVB-S2 satellite transport stream will contain several packetized elementary streams that can contain video, data, and most important for this discussion, audio.

A common situation is to see several audio streams that contain pairs of channels. The important thing to note is that the network can define these channels any way it wants to. As long as their stations can retrieve the audio and get it on the air in a format that consumer television receivers understand, that’s all that matters to the company that’s uplinking the signals.

In many cases the uplinkers will put a pair of mp2 audio channels on the first audio stream. If those channels are encoded using Dolby Digital or Dolby Digital Plus format, then both Kodi and the receiver will generally indicate the true number of channels. However, there are other audio formats that are not intended for direct reception by end users, such as Dolby E, which is described as:

An audio encoding technology, Dolby E enables broadcasting and postproduction facilities to carry up to eight channels of sound over their existing stereo (two-channel) infrastructures.

Dolby E is not intended for reception by home viewers:

Unlike some other Dolby technologies, the Dolby E signal never reaches your home viewer. Rather, it’s decoded back to baseband audio just prior to the final transmission and then reencoded into the final audio format—Dolby Digital, for example, or Dolby Digital Plus™.

Now if a satellite feed uses Dolby E, or some other format not intended for reception by home viewers, in theory that audio (or at least the extra channels beyond basic stereo) can’t be heard by the home viewer. And Kodi, and perhaps your receiver, will tell you that you are receiving MP2, 2.0 audio. Kodi doesn’t know what the format really is, so it doesn’t display any indicator for it.

And, whoever programmed the display for your receiver probably thought that as a consumer, you’d never encounter a Dolby E signal, so there’s no display indication for it. BUT, and this is just speculation on my part, it’s quite possible that your receiver contains a decoder chip that can decode more formats that those that are listed in the receiver’s user manual. So if it has a Dolby decoder chip and sees a Dolby E signal, it just might decode it, without changing the receiver’s display to indicate that it is doing so. Thus, if you are lucky, you might hear the surround sound, even though there’s no indication on your receiver’s display about what format it’s actually receiving. You might have to play with the audio settings on your receiver to make this happen (see the end of the previous article, I hear there’s a problem with playing satellite audio…).

I understand there’s another multichannel format called SMPTE 302M (s302m) that might appear on the first audio stream. I don’t believe that any consumer grade equipment can decode that, and Kodi seems to be smart enough to realize that there’s nothing usable where, so it skips to the first non-s302m stream. I may be wrong about that, but available information on that format is rather sparse unless you want to pay $50 to get SMPTE’s technical documentation, which I don’t.

The bottom line is that if the uplinker is encoding their multichannel audio using a format that intended for reception by broadcasters and not by consumers, Kodi probably doesn’t know how to deal with it. But if you have enabled passthrough audio in Kodi, your receiver might be able to decode it. Otherwise, you’ll probably only hear stereo audio (if you’re lucky), unless you’re trying to watch the network that sends all the channels as discrete audio.

And if you use a standalone satellite receiver rather than a backend system, you’re kind of at the mercy of the manufacturer.  If the manufacturer spent the money to license the Dolby technology and has included an actual Dolby decoder chip, then you stand a far better chance of getting the surround sound than if the manufacturer was trying to build the receiver as cheaply as possible, and used no licensed decoder.  But if the satellite receiver can pass the received audio stream to an AV receiver via HDMI or S/PDIF, then it’s possible the receiver might still be able to decode it, assuming it can decode Dolby audio.

I hear there’s a problem with playing satellite audio…

You may not realize it but when you run a backend such as TVHeadEnd with a satellite tuner card or device for the purpose of recording or viewing Free-To-Air signals in North America, and then use Kodi as your frontend, there’s a good chance you are not hearing the audio correctly on some channels, particularly if you have a multi-channel audio system (5.1 or better). The reason is that many of the uplinkers encode their audio in a specific manner that Kodi doesn’t understand.

This is not the same issue I wrote about in Fixing the audio on recorded programs from a certain network (which shall remain nameless), although that does show that different uplinkers encode their audio in a different ways. In fact, on “feeds” channels the audio can vary from program to program.

When you play a stream or recording in Kodi, if you display the on-screen controls or press INFO on your remote (depending on the skin you are using), you will often see an indicator of what type of audio Kodi thinks it is receiving. If you see indicators for both “Dolby Digital” and “5.1” then it is probably decoding the audio correctly. If you see anything else, such as “MP3” or “2.0”, then it may or may not be decoding the audio correctly, depending on how the source was encoded.

The strange thing is that if you have a suspect recording and you happen to have a machine that has the MythTV frontend software installed and you play the recording there, you may in fact hear the full 5.1 audio! Play the same recording using Kodi and you’ll hear audio on all channels, but your ears might tell you there’s something wrong.

Here’s the issue: 5.1 audio has 6 channels – Left Front, Right Front, Center Front, LFE (low frequency audio generally played through a subwoofer), Left Surround, and Right Surround. Kodi will play the first four of those through the proper channel in almost all cases, but it’s the Left and Right Surround channels that are mishandled. If you play the recording in the MythTV frontend, you will hear the Left Surround audio come from both the left front and left rear speakers, but with equal energy from both OR more audio from the rear. Same with the Right Surround, except that it will only come from the right front and rear speakers. However, when that same audio is played in Kodi, what sometimes happens is that any audio that should come from the Left or Right surrounds will be played at equal volume from all four Left and Right speakers, or if there is a difference in audio energy it will be biased more toward the front speakers! In other words, the Left and Right channel separation is totally lost for surround sounds.

So as you are sitting watching a recording or a live TV screen, you may notice that you are getting more than just 2-channel stereo, but it doesn’t sound quite right. Kodi will tell you it’s only 2.0 audio, and if you have a display on your receiver it may tell you the same thing. In fact it actually is 2-channel audio, viewed one way, but with the 5.1 channel information encoded within those two channels.

I’ve been reading various threads on this subject over the last few days, and it appears that in at least some cases what is happening is that the uplinkers are using Dolby Pro Logic II audio or some variation. To confuse matters further, in the audio communities this is sometimes referred to as just PLII audio.

It appears that the MythTV frontend has code that will decode this audio correctly, while Kodi does not. And you can’t even use ffmpeg to post-process a recording and convert the audio to a format that Kodi understands, because although ffmpeg has a PLII encoder, it does not have a PLII decoder.

This was a topic of recent discussion in a thread on the Kodi forum, although it appears that the developers didn’t show much interest in fixing the problem. There is a reference to a Dolby Pro Logic II test video on YouTube, which if you can figure out how to download and save, it will show you the problem in Kodi.

The thread above references a “ffmpeg user thread” – in my searching I found this archive of ffmpeg mailing list messages, and if you look at the ones with “5.1” in the subject, I suspect that is the thread being referenced, though I’m not entirely sure since the person who mentioned that thread in the Kodi forum did not include a link. In any case, reading those messages proved rather informative, even if ultimately nothing was ever resolved.

Normally when I present a problem, I like to also present a solution, but it this case it appears that for the time being there isn’t one. Programs that have this type of audio encoding will not play correctly in Kodi – it’s not that any audio will be missing, it just won’t be coming from the correct speakers, and some people may not even care about that (and if you only have two stereo speakers you definitely won’t care). If you happen to also have the MythTV frontend installed, you could play recordings in that, but in my experience some satellite recordings do not play all that well in the MythTV frontend – you may get all the audio channels coming from the correct speakers, but the audio itself may have microgaps and breakups. I suppose this in part depends on how good your HTPC hardware is; if you have a better HTPC than I do, then recordings may play fine in the MythTV frontend for you.

Most people will not want to install MythTV just to hear better audio, so that’s not really a viable solution for most readers. And MythTV has problems of its own, as I mentioned in What is the best backend software to use for a Free-To-Air satellite TV system?. So I guess the point of this article is to simply bring awareness of the problem. Maybe if enough people are aware that there is an issue, someone more knowledgeable than I will contribute code to the Kodi or ffmpeg projects that can play or convert this audio format correctly, or perhaps someone will develop a (hopefully free) standalone converter that can reformat the audio in the .ts files to something that Kodi understands.

I will note that some AV receivers may play this audio correctly IF you tell the receiver to use the correct decoder, and IF you have all the capabilities of your receiver enabled in Kodi’s System – Settings – Audio section (particularly “Dolby Digital (AC3) Capable Receiver” and “Dolby Digital Plus (E-AC3) Capable Receiver”, also be sure to “Enable Passthrough” so those settings will be used). For example, with Yamaha 5.1 receivers, you may find that using one of the Dolby or Neo:6 settings plays the audio of certain channels or recordings through the correct speakers, but selecting a “normal” mode does not. I imagine this is true of some other brand receivers as well, and may require that the receiver has HDMI connectors (this may not work if you are sending the audio to the receiver over a S/PDIF conection). I have found that the “Neo:6 Cinema” setting will play many types of encoding correctly, but feel free to try others. On such receivers, the “SUR. DECODE” button on the remote is your friend!

There is a followup article:
Why you’re not hearing full surround sound on some satellite channels – or maybe just think you aren’t

Kodi (Linux version) users, here’s a possible way to restore full 5.1 audio to certain recordings since upgrading to Gotham/Helix/Isengard/Jarvis/Krypton

If you are running Kodi under Linux and you find that certain types of recordings, including many programs recorded from satellite feeds, will play in stereo only even though you know they were transmitted with multichannel audio, here’s a possible quick fix. Bring up a terminal window and start Kodi this way:

AE_SINK=ALSA kodi

You might also need to tweak an audio setting or two in Kodi itself. This forces Kodi to use ALSA rather than PulseAudio, as it did in the (XBMC) Frodo version and probably some earlier versions. If this fixes the problem, you can create a shortcut or a shell script that starts Kodi up this way. Apparently some distributions such as Kodibuntu already use ALSA by default, but if you are a normal Linux desktop user, chances are that Kodi is using PulseAudio on your system.

On the following AskUbuntu page…

Enabling 7.1 audio passthru in 14.04 for Kodi

… it suggests that if forcing Kodi to use ALSA works, you may want to start it using this startup script:

#! /bin/bash

pasuspender
AE_SINK=ALSA kodi

It seems that this is particularly effective when the audio link between the system running Kodi and the receiver is via S/PDIF, but I’ve also observed it to help even when the link is via a HDMI connection.

There’s a discussion about this on the Reddit XBMC forum.

(Article edited August, 2015 and January, 2017 to change most mentions of XBMC to Kodi, and to add information from the AskUbuntu site).

Fixing the audio on recorded programs from a certain network (which shall remain nameless)

This bird has no relevance to anything in this article, I just thought it was a nice picture (Source: Public Domain Pictures.net)

This bird has no relevance to anything in this article, I just thought it was a nice picture 😉 (Source: Public Domain Pictures.net)

I have said that I won’t mention any specific channels or networks you can receive in North America by name (with specific exceptions), but if you receive channels from either the Ku-band side of AMC-1 or the C-band side of AMC-18 you have probably encountered some channels with split up audio, where various channels are sent on different streams. The most common format on those channels seems to be:

Stream 1: Left and right front
Stream 2: Center (on left channel) and low frequency (on right channel)
Stream 3: Left and right rear
Stream 4: Described video (when used, on left) and mono (on right channel)

If you have recorded a program from one of those channels as a .ts file, then ffmpeg can convert it to real 5.1 audio, keeping all other streams including video as is, and usually in under five minutes unless you have a underpowered computer:

In FFMPEG Version 2.x:
ffmpeg -i "original program filename.ts" -c copy -filter_complex '[0:1][0:2][0:3]amerge=inputs=3,pan=5.1|FL=c0|FR=c1|FC=c2|LFE=c3|BL=c4|BR=c5' -c:a eac3 "converted program filename.ts"

In FFMPEG Version 3.0 and later (only when using eac3 as the output codec):
ffmpeg -i "original program filename.ts" -c copy -filter_complex '[0:1][0:2][0:3]amerge=inputs=3,pan=5.1|FL=c0|FR=c1|FC=c2|LFE=c3|BL=c4|BR=c5' -c:a eac3 -mpegts_flags system_b "converted program filename.ts"

The above is all one line, even if it appears otherwise in this blog. This discards stream 4, and maps the other three to 5.1 audio. Note that this converts the audio to eac3, which Kodi will generally play as true 5.1 audio, depending on its audio settings and the ability of your AV receiver to handle encoded audio. If that doesn’t work for some reason, you can try changing the -c:a option from eac3 to ac3 or mp2 (and omit the -mpegts_flags system_b option if using ffmpeg version 3.0 or later, since that option is only needed when using the eac3 codec), but in my experience Kodi treats mp2 audio as stereo only.

Note that although the above example lines attempt to copy all non-audio streams verbatim, including ATSC closed captions, I have noticed that closed captions don’t fare well after passing through ffmpeg. In some cases they are missing altogether, and in other cases they are just garbled or missing characters. I don’t know why this happens and I don’t have any solution for the problem at this time.

Some backend programs, such as TVHeadEnd, give you the option to run a Post-Processor Command when a recording is finished, so with such a backend it may be possible to do this conversion automatically. Note, however, that ffmpeg by default sends a lot of output to stderr, which can cause issues in some systems (or just send a lot of unnecessary email to the system administrator), particularly if you are trying to run ffmpeg from a script. Once you know you have it working, you can suppress this output by using the -loglevel quiet switch, like this:

In FFMPEG Version 2.x:
ffmpeg -loglevel quiet -i "original program filename.ts" -c copy -filter_complex '[0:1][0:2][0:3]amerge=inputs=3,pan=5.1|FL=c0|FR=c1|FC=c2|LFE=c3|BL=c4|BR=c5' -c:a eac3 "converted program filename.ts"

In FFMPEG Version 3.0 and later (only when using eac3 as the output codec):
ffmpeg -loglevel quiet -i "original program filename.ts" -c copy -filter_complex '[0:1][0:2][0:3]amerge=inputs=3,pan=5.1|FL=c0|FR=c1|FC=c2|LFE=c3|BL=c4|BR=c5' -c:a eac3 -mpegts_flags system_b "converted program filename.ts"

If you would like to have logging, but only when something goes terribly wrong, use -loglevel fatal instead of -loglevel quiet.

Note: For this to work, you must have a version of ffmpeg from ffmpeg.org (link is to download page) or, if you are a Linux user but do not feel comfortable attempting to build software from source, then you may be better off using a static build such as is offered at this site (technically this is an unofficial build, so use at your own risk, but as I write this the packages offered in the deb repositories are older versions that don’t work as well for this purpose, and produce files that don’t play well on underpowered systems). Please note that some Linux distributions, notably some versions of Debian and Ubuntu and their derivatives, provide a package called ffmpeg in their repositories that is not true ffmpeg, but instead is a transitional package for libav. The syntax shown above will not work with the transitional package version; you need true ffmpeg for this to work! For the reason this sad situation exists, see The FFmpeg/Libav situation or for a slightly more technical view, FFmpeg versus Libav.

Another possible way to get the real ffmpeg installed on Ubuntu and some derivative systems is explained in the article, How To Install FFmpeg 2.6.1 On Ubuntu 15.04, Ubuntu 14.10, Ubuntu 14.04 And Derivative Systems from the LinuxG.net site.

I am not adverse to libav or a companion package called avconv for this process, I just don’t know if either of those can be used for this purpose, or if so, what the correct syntax would be. If anyone knows, please feel free to leave a comment.

There is a followup to this article: Fixing the audio on live TV from a certain network (which shall remain nameless) in TVHeadend. This discusses how to do the audio conversion in real time, so that you can view live TV with proper audio, or begin watching a recorded program before it has completely finished recording.

You may also be interested in this article:
How to play video recorded from high-bitrate 4:2:2 sources on low-power systems