[FFmpeg-devel] [PATCH] ffserver.c: Add ability to stream audio-only files.

Michael Niedermayer michael at niedermayer.cc
Tue May 29 00:49:27 EEST 2018


On Mon, May 28, 2018 at 08:28:36PM +0200, Stephan Holljes wrote:
> Signed-off-by: Stephan Holljes <klaxa1337 at 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)) {

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.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 181 bytes
Desc: not available
URL: <http://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20180528/6fdb43dc/attachment.sig>


More information about the ffmpeg-devel mailing list