Opened 9 years ago
Closed 8 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)
Change History (11)
comment:1 by , 9 years ago
Component: | undetermined → avformat |
---|---|
Keywords: | mpegts added |
Type: | enhancement → defect |
Version: | unspecified → git-master |
follow-up: 3 comment:2 by , 9 years ago
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 by , 9 years ago
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?
follow-up: 5 comment:4 by , 9 years ago
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 by , 9 years ago
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.
follow-up: 7 comment:6 by , 9 years ago
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 by , 9 years ago
comment:8 by , 9 years ago
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 by , 8 years ago
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.
Please either:
or