11

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;
    }
}
Community
  • 1
  • 1
John_Sheares
  • 1,404
  • 2
  • 21
  • 34
  • Have you tried another video file? Sometimes this error means the format of input file is invalid. – halfelf Sep 30 '16 at 02:53
  • Yes, I and tried several different video files and formats including mp4, mkv, avi, mp3. I know these file work because they are handled no problem when I process them through ffmpeg.exe – John_Sheares Sep 30 '16 at 03:10

1 Answers1

20

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;
    }
}
Emily L.
  • 5,673
  • 2
  • 40
  • 60
Been Woo
  • 336
  • 2
  • 5