[FFmpeg-user] Fixed GOP encoding for HLS

Steven Liu lingjiujianke at gmail.com
Fri Dec 21 06:21:44 CET 2012


2012/12/19 Stefano Sabatini <stefasab at gmail.com>:
> On date Tuesday 2012-12-18 16:42:53 +1100, Andrew Sinclair wrote:
>> Looking at the proposed code change the +1 isn't necessary as according the
>> HLS spec the #EXT-X-TARGETDURATION only needs to be >= the segment
>> timeframe so as long as it is equal to it is OK.
>>
>> I am also getting closer to the issue that I am seeing and it could be for
>> support for some older players as using a decimal/float as the duration is
>> only a reasonably recent addition to the spec as previously the #EXTINF
>> needed to be an int. I am going to play with some patches to the code I
>> have done for this and will report back.
>>
>
>> However there is definitely some significant variaion in what segment.c is
>> generating as the #EXTINF durations and what ffprobe reports as the
>> duration. Can anyone point me in the direction of how segment.c calculates
>> the duration?
>
> max_pkt_end_time - start_time
>
> where max_pkt_end_time is the maximum of the values pts+duration for
> all packets in the segment.
>
> This can be improved, for example defining a reference stream and only
> considering the packets coming from that stream when computing the
> max_pkt_end_time.
>
> On the other hand ffprobe relies on header information and on the
> assumed bitrate for computing the duration, but the only reliable way
> to get a stream duration is to demux the stream and read the various
> timestamps.

And the code have told us,

 /* if the segment has video, start a new segment *only* with a key
video frame */
    if ((st->codec->codec_type == AVMEDIA_TYPE_VIDEO || !seg->has_video) &&
        pkt->pts != AV_NOPTS_VALUE &&
        av_compare_ts(pkt->pts, st->time_base,
                      end_pts-seg->time_delta, AV_TIME_BASE_Q) >= 0 &&
        pkt->flags & AV_PKT_FLAG_KEY)

the codetype equ AVMEDIA_TYPE_VIDEO or !seg->has_video  and the
packets pts is not NOPTS, and the message waht Stefano Sabatini said,
and the packets flag is AV_PKT_FLAG_KEY . the segment is end, if there
have more stream, the packets will start a new segment.


More information about the ffmpeg-user mailing list