Wayne
Wayne

Reputation: 169

ffmpeg and docker result in averror_invaliddata

I am running ffmpeg within a docker container, and I am having a problem.

I have a wittled-down debug program (listing below) that simply opens (and reads) a test.mp4 I open the file with fopen(), read and print the first 32 bytes. The values agree and are correct whether running in docker or locally. (ie. the file is accessible and readable in the docker container) However, when it gets to avformat_open_input():

Running locally: Works just fine. (and the real program fully decodes it)

Running in docker container: The call to avformat_open_input() fails with AVERROR_INVALIDDATA. This is with test.mp4 in the docker directory.

I'm a bit lost at this point. I appreciate any ideas.

test program listing: =========================================

#include <stdio.h>
extern "C" {
#include <libavformat/avformat.h>
}

int main (int argc, char **argv)
{
    int erc=0;
    AVFormatContext* srcFmtCtx = NULL;
    const char* srcFile = "test.mp4";

    // Simple read/echo
    FILE *f = fopen(srcFile, "rb");
    printf("fopen() %s  0x%lx\n", srcFile, (unsigned long)f);
    for (int i=0; i<4; i++) {
        long val;
        erc = fread(&val, 1, sizeof(long), f); 
        printf("[%d]0x%lx ", i, val);
    }   
    printf("\n");
    fclose(f);

    // Open source with ffmpeg libavformat utils
    printf("avformat_open_input(): %s\n", srcFile);
    if ((erc = avformat_open_input(&srcFmtCtx, srcFile, NULL, NULL)) < 0) {
        printf("avformat_open_input(): Returned AvError: %d\n", erc);
        exit(1);
    }   
    printf("avformat_open_input(): Returned normally\n");
    avformat_close_input(&srcFmtCtx);
}

Upvotes: 1

Views: 1041

Answers (1)

Wayne
Wayne

Reputation: 169

It seems my problem is one of version mismatch.

My docker container is constructing a ubuntu:18.10 image (latest available)

That image provides an ffmpeg v3.3.5 (or so), libavformat v57.83.100

avformat_version(): 3756900 Ident: Lavf57.83.100

My local ffmpeg installation is v4.0, libavformat v58.12.100

avformat_version(): 3804260 Build: 3804260 Ident: Lavf58.12.100

One important difference between those versions is that avformat::av_register_all() is deprecated, and no longer used. I based my code on the new sources, and did not have that call. However, the older versions of libavformat requires it. Thus the failure in the docker container, and not in my local environment.

Upvotes: 1

Related Questions