diff mbox

[FFmpeg-devel,3/4] avformat/mpegenc - accept PCM_DVD streams

Message ID 6a07f25b-4b08-6a86-7a60-50055d2359e7@gmail.com
State Accepted
Commit f0809bc0fa634afe8b7c3f2682b8e51e87d0861e
Headers show

Commit Message

Gyan Feb. 15, 2018, 12:53 p.m. UTC
On 2/15/2018 8:57 AM, Michael Niedermayer wrote:
> On Tue, Feb 13, 2018 at 12:33:56AM +0530, Gyan Doshi wrote:

>> +    if (st->codecpar->codec_id == AV_CODEC_ID_PCM_DVD) {
>> +        if (size < 3) {
>> +            av_log(ctx, AV_LOG_ERROR, "Invalid packet size %d\n", size);
> 
>> +            return -1;
> 
> This should be a AVERROR code

Revised patch attached.

Gyan
From 12c5c7e5307aae14cbe401d376d2d8c0c096310c Mon Sep 17 00:00:00 2001
From: Gyan Doshi <gyandoshi@gmail.com>
Date: Wed, 7 Feb 2018 18:05:08 +0530
Subject: [PATCH v4] avformat/mpegenc - accept PCM_DVD streams

PCM_S16BE stream packets in MPEG-PS have a 3-byte header and
are recognized as PCM_DVD by the demuxer which prevents their
correct remuxing in MPEG-1/2 PS.
---
 libavformat/mpegenc.c | 23 +++++++++++++++++++++--
 1 file changed, 21 insertions(+), 2 deletions(-)

Comments

Michael Niedermayer Feb. 16, 2018, 9:50 p.m. UTC | #1
On Thu, Feb 15, 2018 at 06:23:06PM +0530, Gyan Doshi wrote:
> 
> On 2/15/2018 8:57 AM, Michael Niedermayer wrote:
> >On Tue, Feb 13, 2018 at 12:33:56AM +0530, Gyan Doshi wrote:
> 
> >>+    if (st->codecpar->codec_id == AV_CODEC_ID_PCM_DVD) {
> >>+        if (size < 3) {
> >>+            av_log(ctx, AV_LOG_ERROR, "Invalid packet size %d\n", size);
> >
> >>+            return -1;
> >
> >This should be a AVERROR code
> 
> Revised patch attached.
> 
> Gyan

>  mpegenc.c |   23 +++++++++++++++++++++--
>  1 file changed, 21 insertions(+), 2 deletions(-)
> 5cf30a6ffe273094e380f19299812d63987a0e2e  v4-0001-avformat-mpegenc-accept-PCM_DVD-streams.patch
> From 12c5c7e5307aae14cbe401d376d2d8c0c096310c Mon Sep 17 00:00:00 2001
> From: Gyan Doshi <gyandoshi@gmail.com>
> Date: Wed, 7 Feb 2018 18:05:08 +0530
> Subject: [PATCH v4] avformat/mpegenc - accept PCM_DVD streams
> 
> PCM_S16BE stream packets in MPEG-PS have a 3-byte header and
> are recognized as PCM_DVD by the demuxer which prevents their
> correct remuxing in MPEG-1/2 PS.
> ---
>  libavformat/mpegenc.c | 23 +++++++++++++++++++++--
>  1 file changed, 21 insertions(+), 2 deletions(-)

will apply

thx

[...]
diff mbox

Patch

diff --git a/libavformat/mpegenc.c b/libavformat/mpegenc.c
index 695de3f081..c84dc52eb9 100644
--- a/libavformat/mpegenc.c
+++ b/libavformat/mpegenc.c
@@ -353,7 +353,8 @@  static av_cold int mpeg_mux_init(AVFormatContext *ctx)
             if (!s->is_mpeg2 &&
                 (st->codecpar->codec_id == AV_CODEC_ID_AC3 ||
                  st->codecpar->codec_id == AV_CODEC_ID_DTS ||
-                 st->codecpar->codec_id == AV_CODEC_ID_PCM_S16BE))
+                 st->codecpar->codec_id == AV_CODEC_ID_PCM_S16BE ||
+                 st->codecpar->codec_id == AV_CODEC_ID_PCM_DVD))
                  av_log(ctx, AV_LOG_WARNING,
                         "%s in MPEG-1 system streams is not widely supported, "
                         "consider using the vob or the dvd muxer "
@@ -363,7 +364,12 @@  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) {
+            } 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;
+                }
                 stream->id = lpcm_id++;
                 for (j = 0; j < 4; j++) {
                     if (lpcm_freq_tab[j] == st->codecpar->sample_rate)
@@ -1150,6 +1156,19 @@  static int mpeg_mux_write_packet(AVFormatContext *ctx, AVPacket *pkt)
         return AVERROR(ENOMEM);
     pkt_desc->pts            = pts;
     pkt_desc->dts            = dts;
+
+    if (st->codecpar->codec_id == AV_CODEC_ID_PCM_DVD) {
+        if (size < 3) {
+            av_log(ctx, AV_LOG_ERROR, "Invalid packet size %d\n", size);
+            return AVERROR(EINVAL);
+        }
+
+        /* Skip first 3 bytes of packet data, which comprise PCM header
+           and will be written fresh by this muxer. */
+        buf += 3;
+        size -= 3;
+    }
+
     pkt_desc->unwritten_size =
     pkt_desc->size           = size;
     if (!stream->predecode_packet)