ffmpeg6.1版本更改

https://www.cnblogs.com/jiayayao/p/18092197

根据提供的引用内容,以下是使用ffmpeg SDK进行录屏的示例代码: ```c++ #include <iostream> #include <string> extern "C" { #include <libavformat/avformat.h> #include <libavutil/avutil.h> #include <libavutil/opt.h> #include <libavutil/imgutils.h> #include <libswscale/swscale.h> } int main() { // 初始化ffmpeg av_register_all(); // 创建AVFormatContext AVFormatContext* formatContext = nullptr; avformat_alloc_output_context2(&formatContext, nullptr, nullptr, "output.mp4"); // 打开视频设备 AVInputFormat* inputFormat = av_find_input_format("dshow"); AVDictionary* options = nullptr; av_dict_set(&options, "video_size", "640x480", 0); av_dict_set(&options, "framerate", "30", 0); av_dict_set(&options, "pixel_format", "yuyv422", 0); AVFormatContext* inputContext = nullptr; avformat_open_input(&inputContext, "video=Integrated Camera", inputFormat, &options); // 添加视频流 AVStream* videoStream = avformat_new_stream(formatContext, nullptr); avcodec_parameters_copy(videoStream->codecpar, inputContext->streams[0]->codecpar); videoStream->codecpar->codec_tag = 0; // 打开输出文件 avio_open(&formatContext->pb, "output.mp4", AVIO_FLAG_WRITE); // 写入文件头 avformat_write_header(formatContext, nullptr); // 读取视频帧并写入输出文件 AVPacket packet; while (av_read_frame(inputContext, &packet) >= 0) { if (packet.stream_index == 0) { av_interleaved_write_frame(formatContext, &packet); } av_packet_unref(&packet); } // 写入文件尾 av_write_trailer(formatContext); // 清理资源 avformat_close_input(&inputContext); avio_close(formatContext->pb); avformat_free_context(formatContext); return 0; } ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值