string command = "ffmpeg -i D:\\vc\\images\\tanned_part_3600.mp4";
FILE* pPipe = _popen(command.c_str(), "rt");
if (!pPipe) {
return "popen failed!";
}
char* buffer = new char[1024];
char* info = new char[10000]{ 0 };
uint32_t bytesRead, readCount=0;
while (true) {
bytesRead = fread(buffer, 1, 1024, pPipe);
if (bytesRead == 0) {
break;
}
memcpy(info + readCount, buffer, bytesRead);
readCount += bytesRead;
}
//readCount 0,就是读取不到
单独执行上面command
$ ffmpeg -i D:\\vc\\images\\tanned_part_3600.mp4
ffmpeg version 4.3.1-full_build-www.gyan.dev Copyright (c) 2000-2020 the FFmpeg developers
。。。。。
handler_name : VideoHandler
At least one output file must be specified
报错了,难道是错误的原因?
那么换一个没有错误的命令:
ffmpeg -i D:\\vc\\images\\tanned_part_3600.mp4 -ss 00:00:00 -vframes 1 -y aaa.jpg
还是不行。。。
难道是打印日志级别的原因?
ffmpeg -loglevel info -i tanned_part_3600.mp4
还是不行
上述popen只是读取stdout的输出,,stderr是读取不到的,,猜测上面信息是打印到是stderr的了,搜了一下有种办法是建3个pipe可以间接取到stderr信息,不方便。
linux里有个stderr重定向的功能 2>&1 不妨一试,虽然是windows平台。
ffmpeg -i D:\\vc\\images\\tanned_part_3600.mp4 2>&1
竟然可以了。
然后通过正则获取比如,码率:
std::regex bitrate_reg(".*bitrate: (\\d+) kb.*");
std::smatch matchResult;
string inputstr, inputstr2;
inputstr = string(info);
inputstr2 = inputstr.substr(0, readCount);
if (std::regex_search(inputstr2, matchResult, bitrate_reg))
{
for (size_t i = 1; i < matchResult.size(); ++i)
{
cout << matchResult[i] << endl; //码率
}
}
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。
扫码关注腾讯云开发者
领取腾讯云代金券
Copyright © 2013 - 2025 Tencent Cloud. All Rights Reserved. 腾讯云 版权所有
深圳市腾讯计算机系统有限公司 ICP备案/许可证号:粤B2-20090059 深公网安备号 44030502008569
腾讯云计算(北京)有限责任公司 京ICP证150476号 | 京ICP备11018762号 | 京公网安备号11010802020287
Copyright © 2013 - 2025 Tencent Cloud.
All Rights Reserved. 腾讯云 版权所有