这是原来的代码,没有编码器参数
来源:10-7 H264码流结构

慕后端2131159
2025-03-18
int read_video()
{
int ret = 0;
char errors[1024];
AVFormatContext *fmt_ctx = NULL;
AVDictionary *options = NULL;
FILE *outfile_yuv = fopen("./out1.yuv", “wb+”);
if (outfile_yuv == nullptr)
{
printf(“filed open out file\n”);
}
AVPacket pkt;
av_init_packet(&pkt);
int frame_count = 0;
// 找到采集工具
const AVInputFormat *iformat = av_find_input_format("dshow");
if (iformat == NULL)
{
printf("AVInputFormat find failed \n");
return -1;
}
// 打开视频设备
av_dict_set(&options, "video_size", "1280x720", 0);
av_dict_set(&options, "framerate", "30", 0);
// av_dict_set(&options, "pixel_format", "yuyv422", 0);
ret = open_dev(&fmt_ctx, "video=Integrated Camera", iformat, &options);
if (ret < 0)
{
av_strerror(ret, errors, 1024);
fprintf(stderr, "Failed to open video device [%d]%s\n", ret, errors);
return -1;
}
int count_ = 0;
while (av_read_frame(fmt_ctx, &pkt) >= 0 && count_ < 100)
{
av_log(NULL, AV_LOG_INFO, "pkt-size:%d\n", pkt.size, pkt.data);
fwrite(pkt.data, 1, pkt.size, outfile_yuv);
fflush(outfile_yuv);
av_packet_unref(&pkt);
count_++;
}
avformat_close_input(&fmt_ctx);
fclose(outfile_yuv);
av_log(NULL, AV_LOG_DEBUG, "end");
return 0;
}
int open_dev(AVFormatContext **fmt_ctx, const char *devicename, const AVInputFormat *iformat, AVDictionary **options)
{
int ret = avformat_open_input(&(*fmt_ctx), devicename, iformat, &(*options));
return ret;
}
你好李老师,我read到的pkt-size在81024左右,100次接收下来也是在13MB左右,所以我疑惑是不是被压缩了呢?
写回答
1回答
-
李超
2025-03-19
你在命令行里加上rawvideo,然后把视频分辨率指定一下试试
022025-03-20
相似问题