Log in

View Full Version : editing AC-3 metadata


jruggle
10th December 2008, 18:52
For a while, I've been thinking about writing a utility program to modify AC-3 and E-AC-3 metadata without changing the actual audio data. Is there already free software to do this? I'm not aware of any, but I could be wrong. If not, would this kind of thing be useful to anyone?

nautilus7
10th December 2008, 19:26
Could you give an example of what meta data is? Dialog Norm should be one type, but i'm not aware of other.

madshi
10th December 2008, 19:38
I guess you mean things like e.g. the "EX" and "headphone" flags etc? I've once read that there's a tool which can set the "EX" flag, but only if the bitstream is already in alternative bitstream syntax (bsid = 6).

I think a tool which can modify an AC3 bitstream so that the "EX" flag is set, even if the original AC3 bitstream is not "bsid = 6" would be useful, because there are some old AC3 tracks which are "EX" but which don't have the "EX" flag set. But I'm not sure if it is possible to manipulate a bitstream that much?

Right now I'm not sure what other useful metadata is there to be changed except the "EX" flag.

SeeMoreDigital
10th December 2008, 20:52
Could the "metadata" be manipulated to say, alter the length of an AC3 stream?

tebasuna51
10th December 2008, 21:07
Also the Dolby Surround mode flag can be set in 2.0 ac3

FlimsyFeet
10th December 2008, 21:15
And wasn't there a program that could chnage the dialog normalization level?

jruggle
11th December 2008, 00:01
Some of the things that could be modified for AC-3:
bitstream mode (main, dialogue, hearing impaired, etc...)
audio coding mode (channel layout - number of full bandwidth channels would have to match)
center and surround mix levels
dolby surround mode flag
dialnorm
dynamic range compression (this would be harder, but possible)
compression gain
language code
mixing level (dB SPL)
room type
copyright flag
original flag
preferred stereo downmix mode
downmix levels for Lt/Rt and Lo/Ro
EX mode
headphone mode
a/d converter type

For E-AC-3 the list is even longer.

Some of the options would require increasing the bitrate depending on what metadata is already contained in the source. A bitrate change would, of course, be communicated to the user.

As for changing the length of the file, sure. It could chop off frames from the beginning or end, or it could pad with silent frames.

tebasuna51
11th December 2008, 02:54
Some of the things that could be modified for AC-3:
...
dynamic range compression (this would be harder, but possible)
...
Justin, I say you than DRC in Aften is still pending. The differences with commercial encoders behaviour are very big. Do you want modify DRC?

Some of the options would require increasing the bitrate depending on what metadata is already contained in the source. A bitrate change would, of course, be communicated to the user.

As for changing the length of the file, sure. It could chop off frames from the beginning or end, or it could pad with silent frames.
Very dangerous. I'm sure you can make a better job than this (http://forum.doom9.org/showthread.php?p=770777#post770777) but maybe we can lose compatibility or sync.

jruggle
11th December 2008, 03:28
Justin, I say you than DRC in Aften is still pending. The differences with commercial encoders behaviour are very big. Do you want modify DRC?
You are correct that DRC from Aften is not very good right now, but I'm just talking about potentials here. :) I would likely start off with an option to remove the DRC and only add support for setting a new profile when the DRC processing is more mature. It would still be harder than the other metadata params because it would require digging deeper into each frame.


Very dangerous. I'm sure you can make a better job than this (http://forum.doom9.org/showthread.php?p=770777#post770777) but maybe we can lose compatibility or sync.
I don't understand why compatibility would be lost... All of this is very well-defined in the specification.

tebasuna51
11th December 2008, 04:00
'Increasing the bitrate' or 'change the file length' without reencode (same audio data) can't be compatible with containers than need AC3 CBR. Maybe for eac3.

jruggle
11th December 2008, 05:14
'Increasing the bitrate' or 'change the file length' without reencode (same audio data) can't be compatible with containers than need AC3 CBR. Maybe for eac3.
Why not? If the input is CBR and the bitrate (frame size) is increased for all frames, the output would also be CBR. I really don't see a problem here unless the output would be over 640kbps for normal AC3. In that case, the program would output an error.

madshi
11th December 2008, 08:05
Some of the things that could be modified for AC-3:
bitstream mode (main, dialogue, hearing impaired, etc...)
audio coding mode (channel layout - number of full bandwidth channels would have to match)
center and surround mix levels
dolby surround mode flag
dialnorm
dynamic range compression (this would be harder, but possible)
compression gain
language code
mixing level (dB SPL)
room type
copyright flag
original flag
preferred stereo downmix mode
downmix levels for Lt/Rt and Lo/Ro
EX mode
headphone mode
a/d converter type

For E-AC-3 the list is even longer.

Some of the options would require increasing the bitrate depending on what metadata is already contained in the source. A bitrate change would, of course, be communicated to the user.
Sounds good to me!

As for changing the length of the file, sure. It could chop off frames from the beginning or end, or it could pad with silent frames.
Not sure if that is necessary, since there are already other tools that can do this. But of course it wouldn't harm to implement that.

My guess is, though, that SeeMoreDigital wanted to have FPS changed on the fly without reencoding (e.g. removing PAL speedup). Of course that's not possible.

tebasuna51
11th December 2008, 13:05
I want to resume the metadata ac3 possible changes. Please correct me, or add other utilizations.

1) Easy and requested by users:
- Set Dialog Normalization (eac3to set to 0).
- Set Dolby Surround encoded flag (I have a little util).
- Add delays, cuts, validate, ... (DelayCut).

2) More difficult but requested:

- Set the EX flag
This implies add info to metadata (at least 14 bits) then you suggest increment the framelength (bitrate). Example:
You have a 5.1 448 Kbs 48 KHz with a framelength of 1792 bytes, to add 2 bytes you need incremet the framelength until 2048 bytes (512 Kb/s) padding 254 bytes.
Ok. Not possible if original is 640 Kb/s (max), 14% increment in size and a misleading precision.

- Audio coding mode
Plase say me if this is possible:
Now we have ac3 streams with TV capture than mix 2.0 and 5.1 content (and with some incompletes frames in changes).
We can obtain a valid ac3 stream (all the frames with the same Acmod, bitrate,...) and with same duration?
The 2.0 frames need be expanded to 5.1 channels without encoding (FC,SL,SR,LFE empty)

3) Requested but not possible without recoding:
- Change duration (removing PAL speedup, time stretch, ...)
- Remapping channels ( FR <-> FC, ...)

squid_80
11th December 2008, 13:23
Isn't it possible to reorder the channels without completely re-encoding? It's been a while since I worked with AC3 but can't think of anything off the top of my head to prevent it.

jruggle
11th December 2008, 17:51
Isn't it possible to reorder the channels without completely re-encoding? It's been a while since I worked with AC3 but can't think of anything off the top of my head to prevent it.
Well, you wouldn't have to COMPLETELY reencode, but you would have to do a whole lot more than you would with other metadata. (Sorry if this is too technical...) The frequency coefficient mantissas are coded in groups which overlap channels. So they would have to be decoded, regrouped, then reencoded. Luckily it could be done losslessly, so the audio data would remain the same.

edit: note that this would not be easy to do and would take some time to actually implement.

squid_80
11th December 2008, 19:36
Ah I remember now (case1=5bits,3mant case2=7bits,3mant case4=7bits,2mant). So you'd have to reorder the flags (blksw, dithflag, coupling etc.), exponents, bap info and repack the mantissas. Hardly trivial, plus I can't think of a decent reason for needing it; if the channel order is messed up either encode it again or remap on playback.

jruggle
12th December 2008, 17:06
I want to resume the metadata ac3 possible changes. Please correct me, or add other utilizations.
...

2) More difficult but requested:

- Set the EX flag
This implies add info to metadata (at least 14 bits) then you suggest increment the framelength (bitrate). Example:
You have a 5.1 448 Kbs 48 KHz with a framelength of 1792 bytes, to add 2 bytes you need incremet the framelength until 2048 bytes (512 Kb/s) padding 254 bytes.
Ok. Not possible if original is 640 Kb/s (max), 14% increment in size and a misleading precision.

I'm not too concerned about "misleading precision". The user would be sufficiently warned before either increasing the bitrate or using VBR.


- Audio coding mode
Plase say me if this is possible:
Now we have ac3 streams with TV capture than mix 2.0 and 5.1 content (and with some incompletes frames in changes).
We can obtain a valid ac3 stream (all the frames with the same Acmod, bitrate,...) and with same duration?
The 2.0 frames need be expanded to 5.1 channels without encoding (FC,SL,SR,LFE empty)

In theory, this could be possible to do without loss of data using original values for L/R. It would be trickier and more extensive if stereo rematrixing is used, which is likely most of the time. It could still be done by removing the rematrixing, and some time could saved by not doing the IMDCT/MDCT, but it would still essentially be reencoding.

tebasuna51
12th December 2008, 19:54
In theory, this could be possible to do without loss of data using original values for L/R. It would be trickier and more extensive if stereo rematrixing is used, which is likely most of the time. It could still be done by removing the rematrixing, and some time could saved by not doing the IMDCT/MDCT, but it would still essentially be reencoding.

Then, if the rematrix is used, maybe is best replace the frame with silence. The idea is preserve the sync for a next A/V cut.

madshi
29th December 2008, 18:42
@Justin, only losely related to this thread:

Is there a(n easy) way to manipulate an existing (E-)AC3 frame in such a way that it decodes as silence? That would be a neat trick I could really use...