From patchwork Thu Mar 5 13:41:52 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hongcheng Zhong X-Patchwork-Id: 18055 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 91A5644BBEF for ; Thu, 5 Mar 2020 15:42:30 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 6648468A7CB; Thu, 5 Mar 2020 15:42:30 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from smtp181.sjtu.edu.cn (smtp181.sjtu.edu.cn [202.120.2.181]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 5BDBF6882E5 for ; Thu, 5 Mar 2020 15:42:24 +0200 (EET) Received: from proxy01.sjtu.edu.cn (unknown [202.112.26.54]) by smtp181.sjtu.edu.cn (Postfix) with ESMTPS id CFCDD1008CBF9 for ; Thu, 5 Mar 2020 21:42:18 +0800 (CST) Received: from localhost (localhost [127.0.0.1]) by proxy01.sjtu.edu.cn (Postfix) with ESMTP id C1696201844AC; Thu, 5 Mar 2020 21:42:18 +0800 (CST) X-Virus-Scanned: amavisd-new at proxy01.sjtu.edu.cn Received: from proxy01.sjtu.edu.cn ([127.0.0.1]) by localhost (proxy01.sjtu.edu.cn [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id yeu17CZedgPn; Thu, 5 Mar 2020 21:42:18 +0800 (CST) Received: from localhost (unknown [111.186.55.152]) (Authenticated sender: sj.hc_Zhong) by proxy01.sjtu.edu.cn (Postfix) with ESMTPSA id D18772018035F; Thu, 5 Mar 2020 21:42:17 +0800 (CST) From: Hongcheng Zhong To: ffmpeg-devel@ffmpeg.org Date: Thu, 5 Mar 2020 21:41:52 +0800 Message-Id: <1583415712-6396-1-git-send-email-sj.hc_Zhong@sjtu.edu.cn> X-Mailer: git-send-email 2.7.4 Subject: [FFmpeg-devel] [PATCH] avformat/hlsenc: Fix initial setting for start_pts 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 Cc: Hongcheng Zhong MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" This patch fixes Bug #8469 If x264 baseline profile is used with other profiles, start_pts will be initialized to audio stream's first pts, while the duration is calculated based on video stream's pts. In this patch the start_pts is initialized with the correct stream's first pts. Signed-off-by: Hongcheng Zhong --- libavformat/hlsenc.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c index f6dd894..3b2434f 100644 --- a/libavformat/hlsenc.c +++ b/libavformat/hlsenc.c @@ -126,6 +126,7 @@ typedef struct VariantStream { int has_video; int has_subtitle; int new_start; + int start_pts_from_audio; double dpp; // duration per packet int64_t start_pts; int64_t end_pts; @@ -2274,9 +2275,15 @@ static int hls_write_packet(AVFormatContext *s, AVPacket *pkt) if (vs->start_pts == AV_NOPTS_VALUE) { vs->start_pts = pkt->pts; + if (st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO) + vs->start_pts_from_audio = 1; + } + if (vs->start_pts_from_audio && st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO && vs->start_pts > pkt->pts) { + vs->start_pts = pkt->pts; + vs->start_pts_from_audio = 0; } - if (vs->has_video) { + if (vs->has_video) { can_split = st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO && ((pkt->flags & AV_PKT_FLAG_KEY) || (hls->flags & HLS_SPLIT_BY_TIME)); is_ref_pkt = (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) && (pkt->stream_index == vs->reference_stream_index); @@ -2751,6 +2758,7 @@ static int hls_init(AVFormatContext *s) vs->sequence = hls->start_sequence; vs->start_pts = AV_NOPTS_VALUE; vs->end_pts = AV_NOPTS_VALUE; + vs->start_pts_from_audio = 0; vs->current_segment_final_filename_fmt[0] = '\0'; if (hls->flags & HLS_SPLIT_BY_TIME && hls->flags & HLS_INDEPENDENT_SEGMENTS) {