Ticket #1258 (open enhancement)

Opened 13 months ago

Last modified 13 months ago

Codec support request : MPEG Multichannel Audio

Reported by: aquarat Owned by:
Priority: wish Component: avcodec
Version: git-master Keywords: mp2
Cc: Blocked By:
Blocking: Reproduced by developer: no
Analyzed by developer: no

Description

Hi

Support for MPEG Multichannel audio seems to be missing. This is different to ac3. More information can be found here :  http://en.wikipedia.org/wiki/MPEG_Multichannel

It's a method of encoding surround audio into stereo mpeg2 files. If the files are played back using software that doesn't support the extra channels, the data is dropped and only the first two channels are decoded.

This codec forms part of the HDV specification (specifically the 4 channel audio option on some HDV camcorders). The Canon XLH1, in particular, made use of this system.

I have found a very old project called mctoolamed :  http://mctoolame.sourceforge.net which can decode this codec.

mctoolamed has several issues; it doesn't make provision for sample rates other than 44.1kHz and it also only supports 2,6 and 8 channel files (HDV cameras shoot 4 channels).

Attachments

test.aiff-mpeg1-192.mp2 Download (234.5 KB) - added by aquarat 13 months ago.
Sample of a 6 channel mix encoded in a stereo mp2 file.
mctoolamed-01a.tgz Download (42.5 KB) - added by aquarat 13 months ago.
The original mctoolamed source.
lamedecoder.zip Download (157.2 KB) - added by aquarat 13 months ago.
Modified version of mctoolamed to set bitrate to 48kHz and add support for 4 channel files.
4CHsample.mp2 Download (500.0 KB) - added by aquarat 13 months ago.
4 channel sample from an HDV stream

Change History

Changed 13 months ago by aquarat

Sample of a 6 channel mix encoded in a stereo mp2 file.

Changed 13 months ago by aquarat

The original mctoolamed source.

comment:1 Changed 13 months ago by aquarat

I've included mctoolamed-01a.tgz, which is also available on Sourceforge. I've also included my modified version of the code "lamedecoder"... my C++ skills are really bad, so I've highlighted the changes I've made below. I also tried modifying the code to change the output file names depending on the input file name... but yeah, C skills are lacking.

To compile mctoolamed on Debian you need to change the architecture in the Makefile. I changed it to "core2" to get it to run on my Core-based machine (Intel Xeon).

I had to modify part of the code to get it to handle 4 channel files :
in audio_write.c : I modified the soundfile array

Original :

char soundfile[MTYPES][MAXCHANNELS][256] = {
  {"left.wav", "right.wav", "centre.wav", "left_surround.wav", "right_surround.wav"},
  {"left.wav", "right.wav", "centre.wav", "lfe_this_may_not_play.wav", "left_surround.wav", "right_surround.wav"}
};

Revised :

char soundfile[MTYPES][MAXCHANNELS][256] = {
  {"left.wav", "right.wav", "centre.wav", "left_surround.wav", "right_surround.wav"},
  {"left.wav", "right.wav", "centre.wav", "lfe_this_may_not_play.wav", "left_surround.wav", "right_surround.wav"},
  {"left.wav", "right.wav", "rearleft.wav", "rearright.wav"}
};

The "waveheader" array has the sample rate flag set for 44.1kHz. If left unchanged the resulting files will play back slower than they should.

Modification to handle 4 channels :

Original :

void init_audio_outputs(int numchan) {
  int i,j;
  int type=-1;

  numchannels = numchan; // Set the global var for later on.
  if (numchan == 5)
    type = 0;
  if (numchan == 6)
    type = 1;
  if (soundfile>=0) {
    fprintf(stderr,"initialising %i output files\n",numchannels);
    for (i=0;i<numchannels;i++) {
      if ( (audioout[i] = fopen(soundfile[type][i], "w")) == NULL ) {
	fprintf(stderr,"Error opening %s for output\n",soundfile[type][i]);
	exit(99);
      }
      /* Write a really dodgy wave header */
      /* Fix this to write the proper sampling frequency */
      for (j=0;j<WAVEHEADERSIZE;j++)
	fputc(wave_header[j], audioout[i]);
    }
  }
}

Revised :

void init_audio_outputs(int numchan) {
  int i,j;
  int type=-1;

  numchannels = numchan; // Set the global var for later on.
  if (numchan == 5)
    type = 0;
  if (numchan == 6)
    type = 1;
  if (numchan == 4)
    type = 2;
  if (soundfile>=0) {
    fprintf(stderr,"initialising %i output files\n",numchannels);
    for (i=0;i<numchannels;i++) {
      if ( (audioout[i] = fopen(soundfile[type][i], "w")) == NULL ) {
	fprintf(stderr,"Error opening %s for output\n",soundfile[type][i]);
	exit(99);
      }
      /* Write a really dodgy wave header */
      /* Fix this to write the proper sampling frequency */
      for (j=0;j<WAVEHEADERSIZE;j++)
	fputc(wave_header[j], audioout[i]);
    }
  }
}

Changed 13 months ago by aquarat

Modified version of mctoolamed to set bitrate to 48kHz and add support for 4 channel files.

comment:2 Changed 13 months ago by cehoyos

  • Keywords mp2 added; mpeg mctoolame multichannel removed
  • Priority changed from normal to wish
  • Status changed from new to open
  • Component changed from FFmpeg to avcodec
  • Version changed from unspecified to git-master

comment:3 follow-up: ↓ 4 Changed 13 months ago by cehoyos

Do you have a 4-channel sample?

comment:4 in reply to: ↑ 3 Changed 13 months ago by aquarat

Replying to cehoyos:

Do you have a 4-channel sample?

Yes I do, I'll attach it now. This is the process used to get the file :

ffmpeg -i hdvinput.hdv -vn -acodec copy out.mp2
(where hdvinput.hdv is a raw hdv file captured off HDV tape)

dd if=out.mp2 of=4CHsample.mp2 bs=1024 count=500

Hope that helps.

Changed 13 months ago by aquarat

4 channel sample from an HDV stream

Note: See TracTickets for help on using tickets.