vs版本:2017
ffmpeg版本号:
ffmpeg version N-102642-g864d1ef2fc Copyright © 2000-2021 the FFmpeg developers
built with gcc 8.1.0 (x86_64-win32-seh-rev0, Built by MinGW-W64 project)
configuration: --arch=x86_64 --prefix=/home/ffmpeg_static_x64 --disable-debug
libavutil 57. 0.100 / 57. 0.100
libavcodec 59. 1.100 / 59. 1.100
libavformat 59. 2.101 / 59. 2.101
libavdevice 59. 0.100 / 59. 0.100
libavfilter 8. 0.101 / 8. 0.101
libswscale 6. 0.100 / 6. 0.100
libswresample 4. 0.100 / 4. 0.100
关于ffmpeg的lib和dll,本人在csdn上上传了相关资源,并且免费下载。
桌面录制时,发现有一些暂不了解的地方,比如avformat_write_header后,time_base发生了改变,这个使得av_packet_rescale_ts(&packet, pCodecCtx_Video->time_base, pFormatCtx_Out->streams[0]->time_base);这句特别重要,若没这句,视频播放速度可能会很快。
今天先在此记录,后面若有其他发现,会继续更新此博客。
代码如下:
// FfmpegTest.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <Windows.h>
#include <conio.h>
#ifdef __cplusplus
extern "C"
{
#endif
#include "libavcodec/avcodec.h"
#include "libavformat/avformat.h"
#include "libswscale/swscale.h"
#include "libavdevice/avdevice.h"
#include "libavutil/audio_fifo.h"
#include "libavutil/imgutils.h"
#pragma comment(lib, "avcodec.lib")
#pragma comment(lib, "avformat.lib")
#pragma comment(lib, "avutil.lib")
#pragma comment(lib, "avdevice.lib")
#pragma comment(lib, "avfilter.lib")
//#pragma comment(lib, "avfilter.lib")
//#pragma comment(lib, "postproc.lib")
//#pragma comment(lib, "swresample.lib")
#pragma comment(lib, "swscale.lib")
#ifdef __cplusplus
};
#endif
AVFormatContext *pFormatCtx_Video = NULL, *pFormatCtx_Out = NULL;
AVCodecContext *pCodecCtx_Video = NULL;
AVCodec *pCodec_Video = NULL;
AVFifoBuffer *fifo_video = NULL;
int VideoIndex;
AVCodecContext *pCodecEncodeCtx_Video = NULL;
AVCodec *pCodecEncode_Video = NULL;
SwsContext *img_convert_ctx;
int frame_size = 0;
uint8_t *picture_buf = NULL, *frame_buf = NULL;
bool bCap = true;
DWORD WINAPI ScreenCapThreadProc(LPVOID lpParam);
int OpenVideoCapture()
{
const AVInputFormat *ifmt = av_find_input_format("gdigrab");
//这里可以加参数打开,例如可以指定采集帧率
AVDictionary *options = NULL;
av_dict_set(&options, "framerate", "25", NULL);
av_dict_set(&options, "probesize", "50000000", NULL);
//av_dict_set(&options,"offset_x","20",0);
//The distance from the top edge of the screen or desktop
//av_dict_set(&options,"offset_y","40",0);
//Video frame size. The default is to capture the full screen
//av_dict_set(&options,"video_size","320x240",0);
if (avformat_open_input(&pFormatCtx_Video, "desktop", ifmt, &options) != 0)
{
printf<

最低0.47元/天 解锁文章
1046

被折叠的 条评论
为什么被折叠?



