avformat_open_input(); 返回-5

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

ps = avformat_alloc_context();

fmt = av_find_input_format("dshow");

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

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

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

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

ps = avformat_alloc_context();

fmt = av_find_input_format("dshow");

char *filename = dup_wchar_to_utf8(L"audio=麦克风阵列 (Conexant SmartAudio HD)");// 添加一句转换

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

 

// 用于将中文字符串,转化为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上写的。其他平台可能不适用哦。

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 3
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值