From patchwork Tue Oct 1 17:56:04 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Calvin Walton X-Patchwork-Id: 15441 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id A081C4484EF for ; Tue, 1 Oct 2019 21:02:56 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 78AF7687FB6; Tue, 1 Oct 2019 21:02:56 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-io1-f67.google.com (mail-io1-f67.google.com [209.85.166.67]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id D6952687F29 for ; Tue, 1 Oct 2019 21:02:49 +0300 (EEST) Received: by mail-io1-f67.google.com with SMTP id u8so50321246iom.5 for ; Tue, 01 Oct 2019 11:02:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kepstin.ca; s=google; h=message-id:subject:from:to:date:user-agent:mime-version :content-transfer-encoding; bh=ICFdEr90SzFMCDrLFnHv3yGi/4bKKjpA6VM1IDo+Kvg=; b=jcY78TOuLAHXto4mGwJQhu3xQeh1GmQuwGdQbL9vMA2ztUZQre1SWSEyg0doz74oMV thkB62fVU0FK0o+CAM0uBQF3FZneVvMU4zYjqo2WYpt0KblR0tGVrI1gjMKHY8NZmST6 5wni6wQAeQDWSW0yRflcP4BpnT65A/J2qtylw= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:subject:from:to:date:user-agent :mime-version:content-transfer-encoding; bh=ICFdEr90SzFMCDrLFnHv3yGi/4bKKjpA6VM1IDo+Kvg=; b=a+71OGkonM11Jke+X4bcLUceN0uct/NKIMMNivd8DVjvfqeLeByZyUhIDWEpSjYxld 2kmJCYkJfPhuEyszq/LrsC1deAEQJyaqDwxPehdl37a5PAcCz/S7TFT7T+j2O0V1iu8h JBImvRBpjgyacMsiI5teL4rOcppvqo5EIvId4w/hZrF7cMZ2bW79RmFIrvvtISD5TqaA O/4DJQIH3e5iXOP+2vvboEcG9D1ShtwJ9oK1+IqHp+UUHWyIYEBt5A8zGjvz+ZgDbyZv toY2lLn0Cx+b21AJ3BhwMXZP2pUjFLzqoGfWcK3km101kkxokD7PBpjypjazPNwaz8Ax x/Uw== X-Gm-Message-State: APjAAAXvfqnXJPW7GpZP0aNaTReVqeR5gGRy0nS6v4XJGTkxAsKZPQNe Q+DNtUOrFICEwlpAmcX8zNgLCJ6Tv1E0sg== X-Google-Smtp-Source: APXvYqy+VokpwYEAGoA6nvav/XkAMbH7QLSGon8MAPJ5Zyu0D2FyqK/NGrNSTN+291Oro7kc98GxYg== X-Received: by 2002:a6b:630d:: with SMTP id p13mr4899353iog.29.1569952567163; Tue, 01 Oct 2019 10:56:07 -0700 (PDT) Received: from rocky.ottawa.blindsidenetworks.com ([2607:fea8:bea0:e11::e561]) by smtp.gmail.com with ESMTPSA id x18sm6827453ilc.48.2019.10.01.10.56.05 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 01 Oct 2019 10:56:06 -0700 (PDT) Message-ID: <4efe528fe8a1c2221bd4f1e81ce5de80b866589e.camel@kepstin.ca> From: Calvin Walton To: FFmpeg development discussions and patches Date: Tue, 01 Oct 2019 13:56:04 -0400 User-Agent: Evolution 3.32.4 (3.32.4-1.fc30) MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH] ivfdec/ivfenc: Match behaviour of libvpx and chromium 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" The ffmpeg code read and wrote a 64bit duration field (in timebase units) in the ivf header, where the libvpx and chromium code instead use a 32bit frame count field, and then 32bits of unused (reserved?) space. Switch ffmpeg to match the behaviour of libvpx & chromium. Note that libvpx writes 0 to the frame count field when initially writing the header then seeks back and overwrites it with the real frame count. ffmpeg used to write 0xFFFFFFFF - I've changed the behaviour to match libvpx. References: https://github.com/webmproject/libvpx/blob/v1.8.1/ivfenc.c#L16 Which is called from: https://github.com/webmproject/libvpx/blob/v1.8.1/vpxenc.c#L1191 (initial header) https://github.com/webmproject/libvpx/blob/v1.8.1/vpxenc.c#L1209 (rewrite with frame count) And the chromium parser: https://chromium.googlesource.com/chromium/src/media/+/1681b9abff73fe0e3d0932aefdab4f039a284d1a/filters/ivf_parser.h --- libavformat/ivfdec.c | 3 ++- libavformat/ivfenc.c | 11 ++++------- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/libavformat/ivfdec.c b/libavformat/ivfdec.c index 40ae464b76..2eaa5164ff 100644 --- a/libavformat/ivfdec.c +++ b/libavformat/ivfdec.c @@ -53,7 +53,8 @@ static int read_header(AVFormatContext *s) st->codecpar->height = avio_rl16(s->pb); time_base.den = avio_rl32(s->pb); time_base.num = avio_rl32(s->pb); - st->duration = avio_rl64(s->pb); + st->nb_frames = avio_rl32(s->pb); + avio_skip(s->pb, 4); // 32 bits unused st->need_parsing = AVSTREAM_PARSE_HEADERS; diff --git a/libavformat/ivfenc.c b/libavformat/ivfenc.c index adf72117e9..85ca6045ba 100644 --- a/libavformat/ivfenc.c +++ b/libavformat/ivfenc.c @@ -22,8 +22,7 @@ #include "libavutil/intreadwrite.h" typedef struct IVFEncContext { - unsigned frame_cnt; - uint64_t last_pts, sum_delta_pts; + uint32_t frame_cnt; } IVFEncContext; static int ivf_write_header(AVFormatContext *s) @@ -53,7 +52,8 @@ static int ivf_write_header(AVFormatContext *s) avio_wl16(pb, par->height); avio_wl32(pb, s->streams[0]->time_base.den); avio_wl32(pb, s->streams[0]->time_base.num); - avio_wl64(pb, 0xFFFFFFFFFFFFFFFFULL); + avio_wl32(pb, 0); // frame count + avio_wl32(pb, 0); // unused return 0; } @@ -66,10 +66,7 @@ static int ivf_write_packet(AVFormatContext *s, AVPacket *pkt) avio_wl32(pb, pkt->size); avio_wl64(pb, pkt->pts); avio_write(pb, pkt->data, pkt->size); - if (ctx->frame_cnt) - ctx->sum_delta_pts += pkt->pts - ctx->last_pts; ctx->frame_cnt++; - ctx->last_pts = pkt->pts; return 0; } @@ -83,7 +80,7 @@ static int ivf_write_trailer(AVFormatContext *s) size_t end = avio_tell(pb); avio_seek(pb, 24, SEEK_SET); - avio_wl64(pb, ctx->frame_cnt * ctx->sum_delta_pts / (ctx->frame_cnt - 1)); + avio_wl32(pb, ctx->frame_cnt); avio_seek(pb, end, SEEK_SET); }