From patchwork Thu May 21 11:03:49 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Martin_Storsj=C3=B6?= X-Patchwork-Id: 19792 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 D3B8C44AE84 for ; Thu, 21 May 2020 14:03:58 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id A8B6A68A285; Thu, 21 May 2020 14:03:58 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-lf1-f53.google.com (mail-lf1-f53.google.com [209.85.167.53]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id CC4A2687ECE for ; Thu, 21 May 2020 14:03:51 +0300 (EEST) Received: by mail-lf1-f53.google.com with SMTP id c12so4196820lfc.10 for ; Thu, 21 May 2020 04:03:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=martin-st.20150623.gappssmtp.com; s=20150623; h=from:to:subject:date:message-id; bh=OGuBbTOTvnFLtpPDiC23nc4WBV/yrT3FQvRQ/VzYl20=; b=0NykIOMqjFcGuBgFh9w1wciqAQEdUlCVpKeO9UUKBl1ASzU/5Xw7TQB9ZyNF2gO1EA 7/DkXZT3EDaE8LO9djl6Vitvga3pLYX+yUwDfXuq+lVNw5n7NO7T8tHMN3oLe4vM0+sd 7fIUoHzjZ6rFea87htdGhBelTJzxIFLVg1ck1jffq23suCYBfjteL5mlK6qWRg9Uqn1k vNwXcXFsxoxzum4596I91btqrCssn8ClIyz6RgRzMmvST7QYjhTwKdzqNtP9+CnkWzvd UOuLG3jMetRqcEE7dCG4eVQVUZUcROekhBOLnoKFJ405Wkv1zCeNgFje8BWHvC5uLJmP kCUQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id; bh=OGuBbTOTvnFLtpPDiC23nc4WBV/yrT3FQvRQ/VzYl20=; b=gcYaARXMEQdwtPrQiWAzh/bjqBGbXdlLzI5yGxT+sr0/Rw9e4pb0/KnE66+Zh+e3Hl XluWKO/uPgTDo6J9+S3BdqNrJuNUfLfFMHomneBn5wxSd5aT/DI9GhWoJGfuRV9QOG+L 5y0c/UIKsK05HN0wz8moqwW22puCVDMMRm8uKhkJXr/u7OeIPHlzAxPPpdGG/zoNUm89 F+5Hf6dKRus/1hQubqArVxLBTRoqhAdxyKaZ0U0Ej3Gw7azhIhjMZWyHXcaHCim8O9it wOjDSC2E2Hdih5UmL7mKhczdTrjQkQjPr1WR6DL9a3J6FStg7h55uL4Sn+1FZcubwau3 frvw== X-Gm-Message-State: AOAM530fxSdZR080EyUNc/wO2poB8Un2EFmulUm3HzbGTkfIblEkyH82 EaInsRETYFE56q7NEZdLBg3J6BwtKtk= X-Google-Smtp-Source: ABdhPJxr+j3Ho+K1NAXwW/jR+cHBJ23yesfMPDwJJQ5feC2Fc6nOEZRHkxhXj5FEXHm1daTXeY3vGg== X-Received: by 2002:a19:3804:: with SMTP id f4mr4759509lfa.121.1590059030850; Thu, 21 May 2020 04:03:50 -0700 (PDT) Received: from localhost.localdomain (dsl-tkubng21-58c01c-243.dhcp.inet.fi. [88.192.28.243]) by smtp.gmail.com with ESMTPSA id j10sm1656934ljc.21.2020.05.21.04.03.50 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 May 2020 04:03:50 -0700 (PDT) From: =?utf-8?q?Martin_Storsj=C3=B6?= To: ffmpeg-devel@ffmpeg.org Date: Thu, 21 May 2020 14:03:49 +0300 Message-Id: <20200521110349.28062-1-martin@martin.st> X-Mailer: git-send-email 2.17.1 Subject: [FFmpeg-devel] [PATCH] movenc: Fix conversion of the first frame for extradata-less H264/HEVC 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 MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Move the copying of the frame to vos_data further up in the function, so that when writing the actual frame data for the first frame, it's clear that the stream really is in annex b format, for the cases where we create extradata from the first frame. Alternatively - we could invert the checks for bitstream format. If extradata is missing, we can't pretend that the bitstream is in mp4 form, because we can't even know the NAL unit length prefix size in that case. --- libavformat/movenc.c | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/libavformat/movenc.c b/libavformat/movenc.c index 4560064add..b61ae7aad9 100644 --- a/libavformat/movenc.c +++ b/libavformat/movenc.c @@ -5504,6 +5504,24 @@ int ff_mov_write_packet(AVFormatContext *s, AVPacket *pkt) memset(trk->vos_data + trk->vos_len, 0, AV_INPUT_BUFFER_PADDING_SIZE); } + if ((par->codec_id == AV_CODEC_ID_DNXHD || + par->codec_id == AV_CODEC_ID_H264 || + par->codec_id == AV_CODEC_ID_HEVC || + par->codec_id == AV_CODEC_ID_TRUEHD || + par->codec_id == AV_CODEC_ID_AC3 || + par->codec_id == AV_CODEC_ID_H264 || + par->codec_id == AV_CODEC_ID_HEVC) && !trk->vos_len) { + /* copy frame to create needed atoms */ + trk->vos_len = size; + trk->vos_data = av_malloc(size + AV_INPUT_BUFFER_PADDING_SIZE); + if (!trk->vos_data) { + ret = AVERROR(ENOMEM); + goto err; + } + memcpy(trk->vos_data, pkt->data, size); + memset(trk->vos_data + size, 0, AV_INPUT_BUFFER_PADDING_SIZE); + } + if (par->codec_id == AV_CODEC_ID_AAC && pkt->size > 2 && (AV_RB16(pkt->data) & 0xfff0) == 0xfff0) { if (!s->streams[pkt->stream_index]->nb_frames) { @@ -5582,24 +5600,6 @@ int ff_mov_write_packet(AVFormatContext *s, AVPacket *pkt) } } - if ((par->codec_id == AV_CODEC_ID_DNXHD || - par->codec_id == AV_CODEC_ID_H264 || - par->codec_id == AV_CODEC_ID_HEVC || - par->codec_id == AV_CODEC_ID_TRUEHD || - par->codec_id == AV_CODEC_ID_AC3 || - par->codec_id == AV_CODEC_ID_H264 || - par->codec_id == AV_CODEC_ID_HEVC) && !trk->vos_len) { - /* copy frame to create needed atoms */ - trk->vos_len = size; - trk->vos_data = av_malloc(size + AV_INPUT_BUFFER_PADDING_SIZE); - if (!trk->vos_data) { - ret = AVERROR(ENOMEM); - goto err; - } - memcpy(trk->vos_data, pkt->data, size); - memset(trk->vos_data + size, 0, AV_INPUT_BUFFER_PADDING_SIZE); - } - if (trk->entry >= trk->cluster_capacity) { unsigned new_capacity = trk->entry + MOV_INDEX_CLUSTER_SIZE; if (av_reallocp_array(&trk->cluster, new_capacity,