FFmepg 如何在 window 上使用?

  1. 下载FFmepg官网库直接使用即可。
avdevice.lib
avcodec.lib
avfilter.lib
avformat.lib
avutil.lib
postproc.lib
swresample.lib
swscale.lib
// ConsoleFFmpeg.cpp : 定义控制台应用程序的入口点。
//

#include "stdafx.h"
#include <iostream>
#include <string>
#include <stdlib.h>

//#define __STDC_CONSTANT_MACROS
#ifdef __cplusplus
extern "C" {
#endif

#include "libavcodec/avcodec.h"		//编码/解码库
#include "libavdevice/avdevice.h"	//特殊设备复合/复制库
#include "libavfilter/avfilter.h"	//基于图形的框架编辑库
#include "libavformat/avformat.h"		// I/O 格式库
#include "libavutil/avutil.h"			//所有FFmpeg库共享的通用代码
#include "libpostproc/postprocess.h"	//视频后处理库
#include "libswresample/swresample.h"	//音频处理重采样,样本格式转换和混合的库
#include "libswscale/swscale.h"			//颜色转换和缩放库
#ifdef __cplusplus
}
#endif

void show_dshow_device() 
{
	AVFormatContext *pFormatCtx = avformat_alloc_context();
	AVDictionary* options = NULL;
	//设置键值对数组
	av_dict_set(&options, "list_devices", "true", 0);
	AVInputFormat *iformat = av_find_input_format("dshow");
	//ffmpeg -list_devices true -f dshow -i dummy  
	avformat_open_input(&pFormatCtx, "video=dummy", iformat, &options);
        avformat_free_context(pFormatCtx);
}

int main()
{
	avdevice_register_all();
	AVFormatContext *s = avformat_alloc_context();//分配一个结构体 free 释放
	AVInputFormat *input = NULL;
	AVOutputFormat *out = NULL;
	input = av_input_video_device_next(input);
	out = av_output_video_device_next(out);
	while (out)
	{
		std::cout << "输出视频设备:" << out->name << " " << out->long_name << std::endl;
		out = av_output_video_device_next(out);
	}
	while (input)
	{
		std::cout << "输入视频设备:" << input->name << " " << input->long_name << std::endl;
		input = av_input_video_device_next(input);
	}
	show_dshow_device();
	AVDeviceInfoList **device_list = NULL;
	AVInputFormat * dshow = av_find_input_format("dshow");
	AVInputFormat *avInput = NULL;
	AVOutputFormat *avOut = NULL;
	while (avInput)
	{
		std::cout << "xxx设备:" << avInput->name << " " << avInput->long_name << std::endl;
		avInput = av_iformat_next(avInput);
	}
	while (avOut)
	{
		std::cout << "xxx设备:" << avOut->name << " " << avOut->long_name << std::endl;
		avOut = av_oformat_next(avOut);
	}
	AVDeviceCapabilitiesQuery ** query = NULL;
	AVDictionary ** device_options;
	avformat_free_context(s);
	system("pause");
    return 0;
}

/*
int avformat_open_input	(	AVFormatContext ** 	ps,const char * url,AVInputFormat * fmt,AVDictionary ** options)
*/
/*!
    枚举设备
    ffmpeg -list_devices true -f dshow -i dummy
    等价于如下代码
*/
void listDShowDevice()
{
    AVFormatContext *fmtCtx = avformat_alloc_context();
    AVDictionary *options = NULL;
    av_dict_set(&options,"list_devices","true",0);
    AVInputFormat *inputFmt = av_find_input_format("dshow");
    if(avformat_open_input(&fmtCtx,"video=dummy",inputFmt,&options) == 0){
        avformat_close_input(&fmtCtx);
        return;
    }
    avformat_free_context(fmtCtx);
}

/*!
    枚举指定图像设备分辨率大小
    ffmpeg -list_options true -f dshow -i video=device_name
    等价于如下代码
*/
void listDShowDeviceOption(const char *deviceName)
{
    AVFormatContext *fmtCtx = avformat_alloc_context();
    AVDictionary *options = NULL;
    av_dict_set(&options,"list_options","true",0);
    AVInputFormat *inputFmt = av_find_input_format("dshow");
    char buff[256] = {0};
    sprintf(buff,"video=%s",deviceName);
    if(avformat_open_input(&fmtCtx,buff,inputFmt,&options) == 0){
        avformat_close_input(&fmtCtx);
        return;
    }
    avformat_free_context(fmtCtx);
}
posted @ 2017-11-02 17:20  學海無涯  阅读(615)  评论(0编辑  收藏  举报