]> git.sesse.net Git - ffmpeg/commitdiff
avformat/hlsenc: Fix initial setting for start_pts
authorHongcheng Zhong <sj.hc_Zhong@sjtu.edu.cn>
Fri, 6 Mar 2020 03:58:22 +0000 (11:58 +0800)
committerSteven Liu <lq@chinaffmpeg.org>
Thu, 12 Mar 2020 05:00:29 +0000 (13:00 +0800)
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 <sj.hc_Zhong@sjtu.edu.cn>
Reviewed-by: Steven Liu <liuqi05@kuaishou.com>
libavformat/hlsenc.c

index f6dd894343c113f48a99dcafdc12140b6a0fad01..19aa2b120833c6ae5c020d38dbfbdcbd3eefaa9d 100644 (file)
@@ -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,6 +2275,12 @@ 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) {