Signed-off-by: Stephan Holljes <klaxa1...@googlemail.com> --- ffserver.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-)
diff --git a/ffserver.c b/ffserver.c index cdcc064..b0db64b 100644 --- a/ffserver.c +++ b/ffserver.c @@ -42,6 +42,7 @@ #define BUFFER_SECS 30 #define LISTEN_TIMEOUT_MSEC 1000 +#define AUDIO_ONLY_SEGMENT_SECONDS 2 struct ReadInfo { struct PublisherContext *pub; @@ -76,8 +77,9 @@ void *read_thread(void *arg) AVFormatContext *ifmt_ctx = info->ifmt_ctx; int ret, i; int video_idx = -1; + int audio_only = 0; int id = 0; - int64_t pts, now, start; + int64_t pts, now, start, last_cut = 0; int64_t *ts; struct Segment *seg = NULL; AVPacket pkt; @@ -101,10 +103,8 @@ void *read_thread(void *arg) break; } } - if (video_idx == -1) { - av_log(ifmt_ctx, AV_LOG_ERROR, "No video stream found.\n"); - goto end; - } + if (video_idx == -1) + audio_only = 1; // All information needed to start segmenting the file is gathered now. @@ -143,8 +143,9 @@ void *read_thread(void *arg) now = av_gettime_relative() - start; } - // keyframe or first Segment - if ((pkt.flags & AV_PKT_FLAG_KEY && pkt.stream_index == video_idx) || !seg) { + // keyframe or first Segment or audio_only and more than AUDIO_ONLY_SEGMENT_SECONDS passed since last cut + if ((pkt.flags & AV_PKT_FLAG_KEY && pkt.stream_index == video_idx) || !seg || + (audio_only && ((pts - last_cut) / AV_TIME_BASE) >= AUDIO_ONLY_SEGMENT_SECONDS)) { if (seg) { segment_close(seg); publisher_push_segment(info->pub, seg); @@ -152,6 +153,7 @@ void *read_thread(void *arg) publish(info->pub); av_log(NULL, AV_LOG_DEBUG, "Published new segment.\n"); } + last_cut = pts; segment_init(&seg, ifmt_ctx); seg->id = id++; av_log(NULL, AV_LOG_DEBUG, "Starting new segment, id: %d\n", seg->id); -- 2.16.2 _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel