Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

FFmpeg avformat_open_input not working: Invalid data found when processing input

This is my first time using FFmpeg. Every type of media file that I try to open with avformat_open_input, returns "Invalid data found when processing input". I am using 32bit FFmpeg Build Version: 92de2c2. I setup my VS2015 project according to this answer: Use FFmpeg in Visual Studio. What could be going wrong with this code?

#include "stdafx.h"
#include <stdio.h>

extern "C"
{
    #include "libavcodec/avcodec.h"
    #include <libavformat/avformat.h>
    #include <libavutil/avutil.h>
}

int main(int argc, char *argv[])
{
    AVFormatContext *pFormatCtx = NULL;
    avcodec_register_all();

    const char* filename = "d:\\a.mp4";
    int ret = avformat_open_input(&pFormatCtx, filename, NULL, NULL);
    if (ret != 0) {
        char buff[256];
        av_strerror(ret, buff, 256);
        printf(buff);
        return -1;
    }
}
like image 597
John_Sheares Avatar asked Sep 29 '16 19:09

John_Sheares


1 Answers

You forgot to call av_register_all, ffmpeg has no demuxer/muxer registered.

#include "stdafx.h"
#include <stdio.h>

extern "C"
{
    #include "libavcodec/avcodec.h"
    #include <libavformat/avformat.h>
    #include <libavutil/avutil.h>
}

int main(int argc, char *argv[])
{
    AVFormatContext *pFormatCtx = NULL;
    av_register_all();
    avcodec_register_all();

    const char* filename = "d:\\a.mp4";
    int ret = avformat_open_input(&pFormatCtx, filename, NULL, NULL);
    if (ret != 0) {
        char buff[256];
        av_strerror(ret, buff, 256);
        printf(buff);
        return -1;
    }
}
like image 56
Been Woo Avatar answered Oct 18 '22 14:10

Been Woo