From patchwork Sun Feb 12 18:31:43 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Miroslav_Sluge=C5=88?= X-Patchwork-Id: 2522 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.103.89.21 with SMTP id n21csp575591vsb; Sun, 12 Feb 2017 10:31:55 -0800 (PST) X-Received: by 10.223.174.183 with SMTP id y52mr17791877wrc.112.1486924315611; Sun, 12 Feb 2017 10:31:55 -0800 (PST) Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id 18si10678194wrt.177.2017.02.12.10.31.54; Sun, 12 Feb 2017 10:31:55 -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=@email.cz; dkim=neutral (body hash did not verify) header.i=@email.cz; 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=email.cz Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 6B540689DA0; Sun, 12 Feb 2017 20:31:47 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mxf1.seznam.cz (mxf1.seznam.cz [77.75.78.123]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id DB3EE687ECA for ; Sun, 12 Feb 2017 20:31:40 +0200 (EET) Received: from email.seznam.cz by email-smtpc12b.ko.seznam.cz (email-smtpc12b.ko.seznam.cz [10.53.14.105]) id 019fb7f13548afed010d9efc; Sun, 12 Feb 2017 19:31:45 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=email.cz; s=beta; t=1486924305; bh=cC3SroTcg25mziq7MXDPN6HPnJrkf8igx7mkitwr2vI=; h=DKIM-Signature:Received:From:Subject:To:Message-ID:Date: User-Agent:MIME-Version:Content-Type; b=FtoBcuNcWBhxee//oQOPf0buIMjCPTXljA0EC+zaV/5k70N26Ngh6aiW22gfUsZUB q5AdPq5D6lr4jd0OGy3Hz1m9zof/09Q780o/eAfeHLcPCXnRmcwqSsKh8QqHkPujfd +4LmzFLNdpHcrpIUEmurOl0CTqMIZmXJ0qSExVpo= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=email.cz; s=beta; t=1486924304; bh=cC3SroTcg25mziq7MXDPN6HPnJrkf8igx7mkitwr2vI=; h=Received:From:Subject:To:Message-ID:Date:User-Agent:MIME-Version: Content-Type; b=M0wJClw9FDYeBo4Fx3Dn74VNuC3tIbOOg0x8okcaJ+CLCQJSxK6YCa6rVIwu1WMLJ unJ8ycd75AreXRtsagublSqF7lOdwvaBcCaByC6KwpGHR6XPeKF7eoZWe5dYqW8XD1 tbmAQr5YBybaZuq2SNAPyesN2ktl+1XqGhz3tOJ8= Received: from [192.168.0.6] (ip-94-113-140-7.net.upcbroadband.cz [94.113.140.7]) by email-relay11.ko.seznam.cz (Seznam SMTPD 1.3.56) with ESMTP; Sun, 12 Feb 2017 19:31:44 +0100 (CET) From: =?UTF-8?Q?Miroslav_Sluge=c5=88?= To: ffmpeg-devel@ffmpeg.org Message-ID: <58A0AA0F.8040906@email.cz> Date: Sun, 12 Feb 2017 19:31:43 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.0.1 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH] hlsenc: intialize only on ref_pkt and drop all packets 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" This patch will fix cutting hls segments into exactly same length. Because it will intialize only on first ref_packet, which is video frame, not audio frame (old behavior) It will also drop all packets without PTS, drop all packets before initialization and drop all packets before first intialization packet PTS. Now it should be possible to create segments at exactly same length if we use new -force_key_frames hls:time_in_seconds parameter. This is required to support adaptive HLS. From a59a7dbe6fdcab64c1402adb8f11cc31400f4516 Mon Sep 17 00:00:00 2001 From: Miroslav Slugen Date: Sun, 12 Feb 2017 19:25:54 +0100 Subject: [PATCH 1/1] hlsenc: intialize only on ref_pkt and drop all packets before initialized --- libavformat/hlsenc.c | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c index ad5205a..226dd89 100644 --- a/libavformat/hlsenc.c +++ b/libavformat/hlsenc.c @@ -1278,10 +1278,6 @@ static int hls_write_packet(AVFormatContext *s, AVPacket *pkt) oc = hls->avf; stream_index = pkt->stream_index; } - if (hls->start_pts == AV_NOPTS_VALUE) { - hls->start_pts = pkt->pts; - hls->end_pts = pkt->pts; - } if (hls->has_video) { can_split = st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO && @@ -1292,6 +1288,11 @@ static int hls_write_packet(AVFormatContext *s, AVPacket *pkt) is_ref_pkt = can_split = 0; if (is_ref_pkt) { + if (hls->start_pts == AV_NOPTS_VALUE) { + hls->start_pts = pkt->pts; + hls->end_pts = pkt->pts; + } + if (hls->new_start) { hls->new_start = 0; hls->duration = (double)(pkt->pts - hls->end_pts) @@ -1371,6 +1372,21 @@ static int hls_write_packet(AVFormatContext *s, AVPacket *pkt) } } + if (pkt->pts == AV_NOPTS_VALUE) { + av_log(s, AV_LOG_WARNING, "packet has no PTS, dropping packet from stream: %d\n", pkt->stream_index); + return 0; + } + + if (hls->start_pts == AV_NOPTS_VALUE) { + av_log(s, AV_LOG_WARNING, "stream not initialized yet, dropping packet from stream: %d\n", pkt->stream_index); + return 0; + } + + if (pkt->pts + pkt->duration <= hls->start_pts) { + av_log(s, AV_LOG_WARNING, "packet has PTS < START PTS (%"PRId64" < %"PRId64"), dropping packet from stream: %d\n", pkt->pts, hls->start_pts, pkt->stream_index); + return 0; + } + ret = ff_write_chained(oc, stream_index, pkt, s, 0); return ret; -- 2.1.4