[Libav-user] HLS demuxing delays
Debendra Modi
dmodi at mcl.in
Mon Sep 12 17:53:44 EEST 2016
I am trying to demux live HLS audio and find delays in the loop for reading
frames whenever it starts reading the next segment file.
The HLS audio segment files are MP3, 1 second target duration. Each 1
second file has 13 frames.
The live HLS source and our code is started at the same time.
avformat_open_input takes about 5 seconds to return, as it waits for 3
segment files as required by HLS standards.
The av_read_frame loop reads 13 frames from each segment file and then it
takes about 1.5 to 2 seconds before it starts reading the next 13 frames
from the next segment file. Our interrupt callback is called several times
within this duration and we return a 0 to continue reading.
The playlist has several segment files available for it to read so it is
not waiting for the segment file to be available in the playlist.
Given below is the code snippet and attached is the m3u8.
static int interrupt_cb(void *start_ticks)
{
long starttime = (long)start_ticks; //the start time ticks is in opaque
//timeout after 5 seconds of no activity
if (GetTickCount() - starttime >7000))
return 1;
log("Returning 0");
return 0;
}
static bool hls_demuxer( char* fileName )
{
AVDictionary *options = NULL;
av_dict_set(&options, "analyzeduration", "100000", 0);
AVFormatContext* formatContext = avformat_alloc_context( );
formatContext->interrupt_callback.callback = interrupt_cb;
long startticks = GetTickCount();
formatContext->interrupt_callback.opaque = (void*) startticks;
formatContext->flags|=AVFMT_FLAG_NONBLOCK;
//added the following additional parameters to see if they would help to
speed up reading frames - but in vain
formatContext->probesize = 2048;
formatContext->max_delay = 100000; //0.1 secs, default 5 secs
formatContext->probe_score = 100;
formatContext->max_analyze_duration = 100000; //0.1 secs
if ( avformat_open_input( &formatContext, fileName, NULL, NULL ) !=0 )
{
return false;
}
av_dict_free(&options);
av_dump_format(formatContext,0,filename,0); ----------------------------
reaches here after 4 secs of start. Interrupt callback called several
times. This is OK.
if (avformat_find_stream_info(formatContext,NULL) != 0)
return false;
AVPacket pkt;
while(!threadstop)
{
startticks = GetTickCount();
if (av_read_frame(formatContext,&pkt) != 0) -----------------------------reads
13 frames from first segment file. No interrupt callback. Then before
using the next segment file, calls interrupt
return false; -----------------------------callback several times (about 1
to 2 secs) before reading next segment file, then reads the next 13
frames. Playlist
-----------------------------has several files available.
log("Packet read");
//Do something with packet
av_packet_unref(&pkt);
}
return true; ----------------------------When the playlist ends, it has 38
files. The demuxer takes over 30 seconds longer.
}
Any suggestions ? Thanks in advance.
Debendra Modi
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://ffmpeg.org/pipermail/libav-user/attachments/20160912/58772c91/attachment.html>
-------------- next part --------------
#EXTM3U
#EXT-X-VERSION:3
#EXT-X-TARGETDURATION:1
#EXT-X-ALLOW-CACHE:NO
#EXT-X-MEDIA-SEQUENCE:0
#EXT-X-PROGRAM-DATE-TIME:2016-09-12T15:07:16.023Z
#EXTINF:0.936,
audio_0.mp3
#EXTINF:0.936,
audio_1.mp3
#EXTINF:0.936,
audio_2.mp3
#EXTINF:0.936,
audio_3.mp3
#EXTINF:0.936,
audio_4.mp3
#EXTINF:0.936,
audio_5.mp3
#EXTINF:0.936,
audio_6.mp3
#EXTINF:0.936,
audio_7.mp3
#EXTINF:0.936,
audio_8.mp3
#EXTINF:0.936,
audio_9.mp3
#EXTINF:0.936,
audio_10.mp3
#EXTINF:0.936,
audio_11.mp3
#EXTINF:0.936,
audio_12.mp3
#EXTINF:0.936,
audio_13.mp3
#EXTINF:0.936,
audio_14.mp3
#EXTINF:0.936,
audio_15.mp3
#EXTINF:0.936,
audio_16.mp3
#EXTINF:0.936,
audio_17.mp3
#EXTINF:0.936,
audio_18.mp3
#EXTINF:0.936,
audio_19.mp3
#EXTINF:0.936,
audio_20.mp3
#EXTINF:0.936,
audio_21.mp3
#EXTINF:0.936,
audio_22.mp3
#EXTINF:0.936,
audio_23.mp3
#EXTINF:0.936,
audio_24.mp3
#EXTINF:0.936,
audio_25.mp3
#EXTINF:0.936,
audio_26.mp3
#EXTINF:0.936,
audio_27.mp3
#EXTINF:0.936,
audio_28.mp3
#EXTINF:0.936,
audio_29.mp3
#EXTINF:0.936,
audio_30.mp3
#EXTINF:0.936,
audio_31.mp3
#EXTINF:0.936,
audio_32.mp3
#EXTINF:0.936,
audio_33.mp3
#EXTINF:0.936,
audio_34.mp3
#EXTINF:0.936,
audio_35.mp3
#EXTINF:0.936,
audio_36.mp3
#EXTINF:0.936,
audio_37.mp3
#EXTINF:0.72,
audio_38.mp3
#EXT-X-DISCONTINUITY
More information about the Libav-user
mailing list