avformat_open_input(); 返回-5

先初始化 输入封装格式上下文ps 和 输入格式 fmt,然后打开文件。返回值为 -5。

ps = avformat_alloc_context();

fmt = av_find_input_format("dshow");

int avformat_open_input(AVFormatContext **ps, const char *filename, AVInputFormat *fmt, AVDictionary **options);
 

====================解决办法=========================================================

查找了一番原因,是因为我的 filename输入有一点错误。这个文件路径,一定要仔细核对,不能有一丁点的错误。

尤其是打开麦克风,出现中文的时候,一定要进行宽字符转换。

char *psDevName = dup_wchar_to_utf8(L"audio=麦克风阵列 (Conexant SmartAudio HD)");

 

// 用于将中文字符串,转化为UTF8
static char *dup_wchar_to_utf8(wchar_t *w)
{
    char *s = NULL;
    int l = WideCharToMultiByte(CP_UTF8, 0, w, -1, 0, 0, 0, 0);
    s = (char *)av_malloc(l);
    if (s)
        WideCharToMultiByte(CP_UTF8, 0, w, -1, s, l, 0, 0);
    return s;
}

 

以上程序是在VS2010 MFC上写的。其他平台可能不适用哦。

你可能感兴趣的:(ffmpeg音视频开发,VS2010)