Opened 3 years ago

Closed 3 years ago

#5388 closed defect (fixed)

Audio Stream Specifier Need to Change for MP2 & MP3

Reported by: smallishzulu Owned by:
Priority: normal Component: avformat
Version: git-master Keywords: mpegts
Cc: Blocked By:
Blocking: Reproduced by developer: no
Analyzed by developer: no

Description

Hello,

libavformat/mpegtsenc.c
Line 311:

It should be
stream_type = STREAM_TYPE_AUDIO_MPEG2;

based on broadcasting standarts.

Regards,

Attachments (1)

a6067a6e-aa13-4867-bae9-116b003597b9.png (379.9 KB) - added by smallishzulu 3 years ago.
MPEG1 Audio

Download all attachments as: .zip

Change History (11)

comment:1 Changed 3 years ago by cehoyos

  • Component changed from undetermined to avformat
  • Keywords mpegts added
  • Type changed from enhancement to defect
  • Version changed from unspecified to git-master

Please either:

  • send a patch made with 'git format-patch' to the FFmpeg development mailing list

or

  • explain your issue: What did you do, what did you expect and why and what happened? Or to rephrase: What do you mean with broadcasting standards?

comment:2 follow-up: Changed 3 years ago by smallishzulu

Hello,

I am more DVB engineer than doing coding. So, I am not familiar with git format patches.
However, for sure I can explain in details. Here is the issue:

The Problem:
There are Elementary Stream Types defined by ISO Standart 13818.
https://en.wikipedia.org/wiki/Program-specific_information#Elementary_stream_types

In the standart, MPEG2 Audio need to have specifier of 0x04.
However, in FFmpeg libavformat/mpegtsenc.c file in Line 310, the definition is:

case AV_CODEC_ID_MP2:
case AV_CODEC_ID_MP3:

stream_type = STREAM_TYPE_AUDIO_MPEG1;

Where in libavformat/mpegts.h STREAM_TYPE_AUDIO_MPEG1 defined as;

At Line 47:
#define STREAM_TYPE_AUDIO_MPEG1 0x03
#define STREAM_TYPE_AUDIO_MPEG2 0x04

So MPEG2 Audio gets identifier as 0x03. But in ISO Standart it needs to be 0x04.

The Fix:
Line 312 in libavformat/mpegtsenc.c needs to be as below:

case AV_CODEC_ID_MP2:
case AV_CODEC_ID_MP3:

stream_type = STREAM_TYPE_AUDIO_MPEG2;

So it gets 0x04 identifier.

I hope I did a clear explanation. This fix makes FFmpeg mpegts streams compatible with STBs which just check identifier to set a decoder.

comment:3 in reply to: ↑ 2 Changed 3 years ago by cehoyos

Replying to smallishzulu:

In the standart, MPEG2 Audio need to have specifier of 0x04.

But AV_CODEC_ID_MP2 is not MPEG2 Audio but MPEG1 (Layer II) audio.

So did you create a file with FFmpeg that does not confirm to some specification or are you just looking at the code to find possible issues?

Last edited 3 years ago by cehoyos (previous) (diff)

Changed 3 years ago by smallishzulu

MPEG1 Audio

comment:4 follow-up: Changed 3 years ago by smallishzulu

I created a file with FFmpeg. My command was like below:

ffmpeg -i input.ts -vcodec mpeg2video -vb 2500k -acodec mp2 -ab 128k -muxrate 3000k -f mpegts output.ts

When you analyze the output with Dectek StreamXpert? tool, it seems MPEG 1 Audio. However, codec is MP2. And other PC based analyze tools which makes packet analyze, shows it is MPEG 2 Audio.
So, the issues is only the stream specifier is wrong for MP2 codec.

comment:5 in reply to: ↑ 4 Changed 3 years ago by cehoyos

Replying to smallishzulu:

ffmpeg -i input.ts -vcodec mpeg2video -vb 2500k -acodec mp2 -ab 128k -muxrate 3000k -f mpegts output.ts

What is the audio input (and output) sample rate? If it is not below 32kHz, the audio in this stream is MPEG-1 audio.

When you analyze the output with Dectek StreamXpert? tool, it seems MPEG 1 Audio.

Which is correct: AV_CODEC_ID_MP2 is MPEG-1 Layer II Audio, see for example https://en.wikipedia.org/wiki/MPEG-1_Audio_Layer_II

However, codec is MP2.

The audio codec known as MP2 was defined in MPEG-1.

comment:6 follow-up: Changed 3 years ago by smallishzulu

Hi,

Audio sample rate 48kHz.

I understood what you mean and it is correct. Actually, DVB spec is more complicated than code.
https://www.dvb.org/resources/public/standards/a38_dvb-si_specification.pdf

What I experienced in field with STBs over FFmpeg mpegts encoded Mpeg2 Video and Audio streams, setting specifier to 0x03 MPEG1 Audio brings Audio sync or no audio problems in decode.

Defining specifier as 0x04 MPEG2 Audio fixes the problems and MPEG2 Audio decode is backward compatiable.
https://en.wikipedia.org/wiki/MPEG-1#MPEG-2_audio_extensions

So; setting value to 0x04 instead of 0x03, in my view, is a better decision.

comment:7 in reply to: ↑ 6 Changed 3 years ago by cehoyos

Replying to smallishzulu:

What I experienced in field with STBs

Please be more specific.

comment:8 Changed 3 years ago by smallishzulu

Simple; when I encode with below command line;

ffmpeg -i input.ts -vcodec mpeg2video -vb 2500k -acodec mp2 -ab 128k -muxrate 3000k -f mpegts output.ts

Audio Specifier is 0x03 and when I playout the TS file in SD STBs most of them is OK. But 2 STBs;

a) Pace SD STBs has no audio.
b) Vestel 9200 STBs has audio decode delay.

If I change stream specifier to 0x04, these STBs also play audio correctly.

I discussed this issue with manufacturer engineers and learned that they define decoding codec based on specifier, so it cause problem with MPEG 1 audio decoder via 0x03. When 0x04 is set, MPEG 2 Audio decoder is set and no problems occured.

Thats the all story.

comment:9 Changed 3 years ago by smallishzulu

Please close this ticket. It is fixed by:

https://github.com/FFmpeg/FFmpeg/commit/fd0f1442eb78e2520fcfc7b13250ddf1ead2bc9d

Additonal Note:
If some SD STBs cause problem with MP2 Audio decoding of FFmpeg MPEGTS output, please set muxdelay to 0.5. This sets PCR Jitter to 0.5 and these problematic SD STBs will work OK for MP2 audio decoding.

comment:10 Changed 3 years ago by cehoyos

  • Resolution set to fixed
  • Status changed from new to closed

Thank you for the analysis!

Note: See TracTickets for help on using tickets.