[FFmpeg-devel] [PATCH] ffserver.c: Add ability to stream audio-only files.
Signed-off-by: Stephan Holljes --- Change from previous patch: More natural way to check if AUDIO_ONLY_SEGMENT_SECONDS has elapsed since last cut. ffserver.c | 16 +--- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/ffserver.c b/ffserver.c index 288f8a1..0278bc8 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; @@ -99,10 +101,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. @@ -141,8 +141,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 >= AUDIO_ONLY_SEGMENT_SECONDS * AV_TIME_BASE)) { if (seg) { segment_close(seg); publisher_push_segment(info->pub, seg); @@ -150,6 +151,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); if (!seg) { av_log(NULL, AV_LOG_ERROR, "Segment initialization failed, shutting down.\n"); -- 2.16.2 ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
Re: [FFmpeg-devel] [PATCH] ffserver.c: Add ability to stream audio-only files.
On Mon, May 28, 2018 at 08:28:36PM +0200, Stephan Holljes wrote: > Signed-off-by: Stephan Holljes > --- > 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)) { It feels more natural to me to convert the constant instead of the non constant. pts - last_cut >= AUDIO_ONLY_SEGMENT_SECONDS * AV_TIME_BASE [...] -- Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB If you fake or manipulate statistics in a paper in physics you will never get a job again. If you fake or manipulate statistics in a paper in medicin you will get a job for life at the pharma industry. signature.asc Description: PGP signature ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
[FFmpeg-devel] [PATCH] ffserver.c: Add ability to stream audio-only files.
Signed-off-by: Stephan Holljes --- 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