[FFmpeg-devel,2/2] avformat/mpegenc: extend muxing PCM-DVD to other depths

Submitted by Paul B Mahol on Nov. 29, 2018, 11:39 a.m.

Details

Message ID 20181129113910.4570-2-onemda@gmail.com
State New
Headers show

Commit Message

Paul B Mahol Nov. 29, 2018, 11:39 a.m.
Fixes #6783.

Signed-off-by: Paul B Mahol <onemda@gmail.com>
---
 libavformat/mpegenc.c | 27 +++++++++++++++++++++------
 1 file changed, 21 insertions(+), 6 deletions(-)

Comments

Gyan Nov. 29, 2018, 1:06 p.m.
On 29-11-2018 05:09 PM, Paul B Mahol wrote:
> Fixes #6783.
> 
> Signed-off-by: Paul B Mahol <onemda@gmail.com>
> ---
>   libavformat/mpegenc.c | 27 +++++++++++++++++++++------
>   1 file changed, 21 insertions(+), 6 deletions(-)
> 
> diff --git a/libavformat/mpegenc.c b/libavformat/mpegenc.c
> index 4c6fa67fb8..1389288b7f 100644
> --- a/libavformat/mpegenc.c
> +++ b/libavformat/mpegenc.c

> +
> +                switch (st->codecpar->sample_rate) {
> +                case 48000: freq = 0; break;
> +                case 96000: freq = 1; break;
> +                case 44100: freq = 2; break;
> +                case 32000: freq = 3; break;
> +                default:
> +                    av_log(ctx, AV_LOG_ERROR, "Unsupported sample rate.\n");
> +                    return AVERROR(EINVAL);
> +                }
It will be helpful to the users to mention the supported rates.

Gyan
Paul B Mahol Nov. 29, 2018, 2:13 p.m.
On 11/29/18, Gyan Doshi <gyandoshi@gmail.com> wrote:
> On 29-11-2018 05:09 PM, Paul B Mahol wrote:
>> Fixes #6783.
>>
>> Signed-off-by: Paul B Mahol <onemda@gmail.com>
>> ---
>>   libavformat/mpegenc.c | 27 +++++++++++++++++++++------
>>   1 file changed, 21 insertions(+), 6 deletions(-)
>>
>> diff --git a/libavformat/mpegenc.c b/libavformat/mpegenc.c
>> index 4c6fa67fb8..1389288b7f 100644
>> --- a/libavformat/mpegenc.c
>> +++ b/libavformat/mpegenc.c
>
>> +
>> +                switch (st->codecpar->sample_rate) {
>> +                case 48000: freq = 0; break;
>> +                case 96000: freq = 1; break;
>> +                case 44100: freq = 2; break;
>> +                case 32000: freq = 3; break;
>> +                default:
>> +                    av_log(ctx, AV_LOG_ERROR, "Unsupported sample
>> rate.\n");
>> +                    return AVERROR(EINVAL);
>> +                }
> It will be helpful to the users to mention the supported rates.

Already mentioned in encoder.
Paul B Mahol Nov. 30, 2018, 10:17 a.m.
On 11/29/18, Paul B Mahol <onemda@gmail.com> wrote:
> On 11/29/18, Gyan Doshi <gyandoshi@gmail.com> wrote:
>> On 29-11-2018 05:09 PM, Paul B Mahol wrote:
>>> Fixes #6783.
>>>
>>> Signed-off-by: Paul B Mahol <onemda@gmail.com>
>>> ---
>>>   libavformat/mpegenc.c | 27 +++++++++++++++++++++------
>>>   1 file changed, 21 insertions(+), 6 deletions(-)
>>>
>>> diff --git a/libavformat/mpegenc.c b/libavformat/mpegenc.c
>>> index 4c6fa67fb8..1389288b7f 100644
>>> --- a/libavformat/mpegenc.c
>>> +++ b/libavformat/mpegenc.c
>>
>>> +
>>> +                switch (st->codecpar->sample_rate) {
>>> +                case 48000: freq = 0; break;
>>> +                case 96000: freq = 1; break;
>>> +                case 44100: freq = 2; break;
>>> +                case 32000: freq = 3; break;
>>> +                default:
>>> +                    av_log(ctx, AV_LOG_ERROR, "Unsupported sample
>>> rate.\n");
>>> +                    return AVERROR(EINVAL);
>>> +                }
>> It will be helpful to the users to mention the supported rates.
>
> Already mentioned in encoder.
>

Will apply soon.

Patch hide | download patch | download mbox

diff --git a/libavformat/mpegenc.c b/libavformat/mpegenc.c
index 4c6fa67fb8..1389288b7f 100644
--- a/libavformat/mpegenc.c
+++ b/libavformat/mpegenc.c
@@ -364,12 +364,7 @@  static av_cold int mpeg_mux_init(AVFormatContext *ctx)
                 stream->id = ac3_id++;
             } else if (st->codecpar->codec_id == AV_CODEC_ID_DTS) {
                 stream->id = dts_id++;
-            } else if (st->codecpar->codec_id == AV_CODEC_ID_PCM_S16BE ||
-                       st->codecpar->codec_id == AV_CODEC_ID_PCM_DVD) {
-                if (st->codecpar->bits_per_coded_sample != 16) {
-                    av_log(ctx, AV_LOG_ERROR, "Only 16 bit LPCM streams can be muxed.\n");
-                    goto fail;
-                }
+            } else if (st->codecpar->codec_id == AV_CODEC_ID_PCM_S16BE) {
                 stream->id = lpcm_id++;
                 for (j = 0; j < 4; j++) {
                     if (lpcm_freq_tab[j] == st->codecpar->sample_rate)
@@ -392,6 +387,26 @@  static av_cold int mpeg_mux_init(AVFormatContext *ctx)
                 stream->lpcm_header[1] = (st->codecpar->channels - 1) | (j << 4);
                 stream->lpcm_header[2] = 0x80;
                 stream->lpcm_align     = st->codecpar->channels * 2;
+            } else if (st->codecpar->codec_id == AV_CODEC_ID_PCM_DVD) {
+                int freq;
+
+                switch (st->codecpar->sample_rate) {
+                case 48000: freq = 0; break;
+                case 96000: freq = 1; break;
+                case 44100: freq = 2; break;
+                case 32000: freq = 3; break;
+                default:
+                    av_log(ctx, AV_LOG_ERROR, "Unsupported sample rate.\n");
+                    return AVERROR(EINVAL);
+                }
+
+                stream->lpcm_header[0] = 0x0c;
+                stream->lpcm_header[1] = (freq << 4) |
+                                         (((st->codecpar->bits_per_coded_sample - 16) / 4) << 6) |
+                                         st->codecpar->channels - 1;
+                stream->lpcm_header[2] = 0x80;
+                stream->id = lpcm_id++;
+                stream->lpcm_align = st->codecpar->channels * st->codecpar->bits_per_coded_sample / 8;
             } else {
                 stream->id = mpa_id++;
             }