From patchwork Fri Jan 26 14:00:10 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gyan X-Patchwork-Id: 7422 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.2.156.27 with SMTP id q27csp746433jak; Fri, 26 Jan 2018 06:24:12 -0800 (PST) X-Google-Smtp-Source: AH8x2276sPVKQhWWYH+j5SGvwMnTeHQIre08VIjS3qkpXrVCcXiMjTwGhzJkgDLNhj9lt9YMr9xh X-Received: by 10.28.190.3 with SMTP id o3mr11872834wmf.17.1516976652463; Fri, 26 Jan 2018 06:24:12 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1516976652; cv=none; d=google.com; s=arc-20160816; b=OB12NhcPMP3M/jTpbL9JrEQRc91bFCyDEbnv2S8fhUf+tmw9MB9vYi/1LcpHSSrXiU wBBPsihepfOp05XRvsoguWbzMF9I91ZaT6CsulyihQDPzIo+v1d5luJGOfUUn8iw9pug XxlPf4ZMsznNZoORwBs8W8lhJjtLb6cXXwKeKOZJIrYoj0lAEU7T6Mo/DyId2JKOMtoe 56xmL2caeLMe1SAXW8xdHT1sypO2RYyYtnsNX02Tp9vDKoBgSawuCv/hU3875zVq79b9 iEz6jcXA4OojSNKbmoYBSlPsQbvk7VvyzeVNe3DvqpETqLrdAVVYIUVkNTTlLNLSQ2Ke SBZQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:reply-to:list-subscribe :list-help:list-post:list-archive:list-unsubscribe:list-id :precedence:subject:content-disposition:content-language :mime-version:user-agent:date:message-id:from:to:dkim-signature :delivered-to:arc-authentication-results; bh=DIaz5pXSISDOQDEVGW8leA1caSBEwJ7Fc9jda6Ox8jE=; b=xFYHbEkK55wWokK4Qc7HOPnNd7yAqBOSm2xMR0zBFtuHkQlVYeXWFnEgbaSNlhOxE4 acOdNu/ukmGeltjjQepqsO9UuOZIKKYEyVskseo9ERX0wZXom+4TUypkniPABMaLLxsh vL0l8GVejlhCKExl4MRt0X/UJE0h1fl1kQYExksC45I36ZAVkuUo/lMStBVGKyoBv6lo mEO8Xr4y/6A+l1a063NibJQaqvSNGdjJup1A9703r8Mhg5SO7Zzxo3uFUdwUHLxk7icq Z03tVINwa1Qi8/PbH0FO5l8+4pQAWXw7BysjWd8kMgSK3ANWLerawOo22SsgZXsKIYzE oTcQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20161025 header.b=GKigL3V3; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=gmail.com Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id j13si2643279wmh.30.2018.01.26.06.24.10; Fri, 26 Jan 2018 06:24:12 -0800 (PST) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20161025 header.b=GKigL3V3; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=gmail.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 1680E689A66; Fri, 26 Jan 2018 16:24:06 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pf0-f196.google.com (mail-pf0-f196.google.com [209.85.192.196]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id A676C689818 for ; Fri, 26 Jan 2018 16:23:59 +0200 (EET) Received: by mail-pf0-f196.google.com with SMTP id a88so336803pfe.12 for ; Fri, 26 Jan 2018 06:24:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=to:from:subject:message-id:date:user-agent:mime-version :content-language; bh=Zi0InifsFUXRNBGv0v33ZjG/WwYwPRCISpDbh40cQ/w=; b=GKigL3V3LMBfcGwmRVB/HOFVQkSDZI0tyGp0drGS2BYZLApBNJFNYdUzd19641HTRs vT6uuXaPTaSLguu2ncVhx3Z1semfWtLw8PRliJrparJ5FjGkV9FmKEQ+rlahDZn6Xrs5 w9h0bvrB21QItFMIVyoHtsOmGKgGn3w/2bR5u4Z8e+AYcuBw+Utue9BZP9CwQB51h6FP U6q+F52gOGwKudVjrL2dXcYv/f2o1TL6jl8Poh/1fU2sm6QR0aq+71Lg4UwW0CvbNpvl cUX1yhTBKcAtBeXykZBDu9wmj8uqfIPKeIWl51xqnLpV5dwlsHuUohYqiGakebh9AdEE 7DuA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:to:from:subject:message-id:date:user-agent :mime-version:content-language; bh=Zi0InifsFUXRNBGv0v33ZjG/WwYwPRCISpDbh40cQ/w=; b=i0zsybfI/PGP2sa+Z0Haq6yB4L7clwsPTB7KbSUwO8PgbC2tiz7lYO5jOXVOiRYqGA tXfOQ4cwCz/bzJtACnFzMYMIMURB7I8J3npUpb4tnvvWo2ec+XJrqTu4S6p/PTqdO1nR W0ENJW4TT3LobDi6zilX7fcihC9hwqlPmi83CDFBeXa37ZEFOUZQnBpuqx6Z5wO0i2BU U/4BdyrRMJyQjauB9aY1ozJzAvsj9z2GCazaAhOzEWlK/nxXjt79ApkZNlwyrZx/1fiE cw+NfznK0NV/E7fWt3U0XujipgeeI509JE2+0DxeeWeP7VZuhcC+TFL0Z9b6Cs1O8X3d fwww== X-Gm-Message-State: AKwxytd+Q2WQ/Sig8WqOgRD9LbluUAM/mI6ogNevXH/JZqBYgBq9QP3H TV5o+dMhAJMCkrgQp0O557GTo6cU X-Received: by 10.98.75.146 with SMTP id d18mr19452028pfj.11.1516975222524; Fri, 26 Jan 2018 06:00:22 -0800 (PST) Received: from [192.168.1.15] ([103.206.133.162]) by smtp.gmail.com with ESMTPSA id b66sm19054546pfd.182.2018.01.26.06.00.20 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 26 Jan 2018 06:00:21 -0800 (PST) To: ffmpeg-devel@ffmpeg.org From: Gyan Doshi Message-ID: Date: Fri, 26 Jan 2018 19:30:10 +0530 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.5.2 MIME-Version: 1.0 Content-Language: en-US Content-Disposition: attachment; filename*0="0001-avformat-mpegenc-fix-PCM-16BE-muxing-and-disallow-un.pa"; filename*1="tch" X-Content-Filtered-By: Mailman/MimeDel 2.1.20 Subject: [FFmpeg-devel] [PATCH] avformat/mpegenc - fix PCM 16BE muxing and disallow, unsupported audio codecs X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" From 7c31072230e392ca8be218df4affff1f5a2c1b5d Mon Sep 17 00:00:00 2001 From: Gyan Doshi Date: Fri, 26 Jan 2018 19:15:28 +0530 Subject: [PATCH] avformat/mpegenc - fix PCM 16BE muxing and disallow unsupported audio codecs PCM_S16BE streams in MPEG-PS are recognized as PCM_DVD by the demuxer which prevents their proper remuxing in MPEG-1/2 PS. In addition, the muxer only supports five audio codecs but will silently go ahead and process any codec. Demuxing of these other streams fails. Couple of error messages added and one error typo (VBV size) corrected. --- libavformat/mpegenc.c | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/libavformat/mpegenc.c b/libavformat/mpegenc.c index c77c3dfe41..1b20cb7282 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,20 +364,34 @@ 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) { stream->id = lpcm_id++; for (j = 0; j < 4; j++) { if (lpcm_freq_tab[j] == st->codecpar->sample_rate) break; } - if (j == 4) + if (j == 4) { + int sr; + av_log(ctx, AV_LOG_ERROR, "Invalid sampling rate for PCM stream.\n"); + av_log(ctx, AV_LOG_INFO, "Allowed sampling rates:"); + for (sr = 0; sr < 4; sr++) + av_log(ctx, AV_LOG_INFO, " %d", lpcm_freq_tab[sr]); + av_log(ctx, AV_LOG_INFO, "\n"); goto fail; - if (st->codecpar->channels > 8) - return -1; + } + if (st->codecpar->channels > 8) { + av_log(ctx, AV_LOG_ERROR, "At most 8 channels allowed for LPCM stream.\n"); + return AVERROR(EINVAL); + } stream->lpcm_header[0] = 0x0c; 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_MP2 && + st->codecpar->codec_id != AV_CODEC_ID_MP3) { + av_log(ctx, AV_LOG_ERROR, "Unsupported audio codec. Must be one of mp2, mp3, pcm_s16be, ac3 or dts.\n"); + return AVERROR(EINVAL); } else { stream->id = mpa_id++; } @@ -397,7 +412,7 @@ static av_cold int mpeg_mux_init(AVFormatContext *ctx) stream->max_buffer_size = 6 * 1024 + props->buffer_size / 8; else { av_log(ctx, AV_LOG_WARNING, - "VBV buffer size not set, using default size of 130KB\n" + "VBV buffer size not set, using default size of 230KB\n" "If you want the mpeg file to be compliant to some specification\n" "Like DVD, VCD or others, make sure you set the correct buffer size\n"); // FIXME: this is probably too small as default