[Libav-user] avformat_find_stream_info times out on rtp stream

Philippe Gorley philippe.gorley at savoirfairelinux.com
Fri Sep 16 19:16:00 EEST 2016


Hi,

I'm looking to upgrade my application (I'm currently using FFmpeg from the Ubuntu 16.04 repo) to a more recent release of FFmpeg, such as 3.1.3. Everything went well, except that avformat_find_stream_info now times out on my RTP stream, although it does eventually return the info. I've tried linking against master with the same result. Doing some investigation, I found that release 2.8.6 does not exhibit this behaviour, while 2.8.7 does.

I can reproduce the behaviour with the following snippet, with vlc taking care of the RTP stream (I use a mp4 file with h264 and aac codecs):

#include <stdio.h>
#include <sys/time.h>

#include <libavcodec/avcodec.h>
#include <libavformat/avformat.h>
#include <libavutil/avutil.h>

int main(int argc, char **argv) {
    AVFormatContext *fmt_ctx = NULL;
    char *file_to_stream = NULL;
    char *stream_addr = NULL;
    int ret;

    if (argc != 2) {
        fprintf(stderr, "usage: %s rtp://hostname:port\n",
                argv[0]);
        return 1;
    }

    stream_addr = argv[1];

    av_register_all();
    avformat_network_init();

    fmt_ctx = avformat_alloc_context();
    if (!fmt_ctx) {
        ret = AVERROR(ENOMEM);
        goto end;
    }

    ret = avformat_open_input(&fmt_ctx, stream_addr, NULL, NULL);
    if (ret < 0) {
        fprintf(stderr, "Could not open input\n");
        goto end;
    }

    fmt_ctx->max_analyze_duration = 30 * AV_TIME_BASE;
    printf("Finding stream info\n");

    struct timeval start, end;
    double elapsed_time;
    gettimeofday(&start, NULL);

    ret = avformat_find_stream_info(fmt_ctx, NULL);
    if (ret < 0) {
        fprintf(stderr, "Could not find stream information\n");
        goto end;
    }

    gettimeofday(&end, NULL);
    elapsed_time = (end.tv_sec - start.tv_sec) * 1000.0;
    elapsed_time += (end.tv_usec - start.tv_usec) / 1000.0;

    av_dump_format(fmt_ctx, 0, stream_addr, 0);

    printf("Found stream info in %f ms\n", elapsed_time);

end:
    avformat_close_input(&fmt_ctx);
    avformat_network_deinit();
    if (ret < 0) {
        fprintf(stderr, "Error occurred: %s\n", av_err2str(ret));
        return 1;
    }

    return 0;
}

I've compiled FFmpeg with the following configuration: ./configure --prefix=/usr/local --disable-everything --disable-programs --enable-protocols --enable-demuxers --enable-parser=h264 --enable-decoder=h264 --enable-indev=v4l2 --enable-shared

Is this timeout a known bug?

Any help is appreciated,

Philippe


More information about the Libav-user mailing list