資源簡介
FFMPEG工程浩大,可以參考的書籍又不是很多,因此很多剛學習FFMPEG的人常常感覺到無從下手。因此做了一個FFmpeg中的libavdevice類庫的使用例子。
本工程包含兩個基于FFmpeg的libavdevice的例子:
simplest_ffmpeg_grabdesktop:屏幕錄制。
simplest_ffmpeg_readcamera:讀取攝像頭。
1.2版本增加了多平臺下編譯的支持:Windows,MacOS,以及Linux。
代碼片段和文件信息
/**
?*?最簡單的基于FFmpeg的AVDevice例子(屏幕錄制)
?*?Simplest?FFmpeg?Device?(Screen?Capture)
?*
?*?雷霄驊?Lei?Xiaohua
?*?leixiaohua1020@126.com
?*?中國傳媒大學/數字電視技術
?*?Communication?University?of?China?/?Digital?TV?Technology
?*?http://blog.csdn.net/leixiaohua1020
?*
?*?本程序實現了屏幕錄制功能。可以錄制并播放桌面數據。是基于FFmpeg
?*?的libavdevice類庫最簡單的例子。通過該例子,可以學習FFmpeg中
?*?libavdevice類庫的使用方法。
?*?本程序在Windows下可以使用2種方式錄制屏幕:
?*??1.gdigrab:?Win32下的基于GDI的屏幕錄制設備。
?*?????????????抓取桌面的時候,輸入URL為“desktop”。
?*??2.dshow:?使用Directshow。注意需要安裝額外的軟件screen-capture-recorder
?*?在Linux下則可以使用x11grab錄制屏幕。
?*
?*?This?software?capture?screen?of?computer.?It‘s?the?simplest?example
?*?about?usage?of?FFmpeg‘s?libavdevice?Library.?
?*?It‘s?suiltable?for?the?beginner?of?FFmpeg.
?*?This?software?support?2?methods?to?capture?screen?in?Microsoft?Windows:
?*??1.gdigrab:?Win32?GDI-based?screen?capture?device.
?*?????????????Input?URL?in?avformat_open_input()?is?“desktop“.
?*??2.dshow:?Use?Directshow.?Need?to?install?screen-capture-recorder.
?*?It?use?x11grab?to?capture?screen?in?Linux.
?*/
#include?
#define?__STDC_CONSTANT_MACROS
#ifdef?_WIN32
//Windows
extern?“C“
{
#include?“libavcodec/avcodec.h“
#include?“libavformat/avformat.h“
#include?“libswscale/swscale.h“
#include?“libavdevice/avdevice.h“
#include?“SDL/SDL.h“
};
#else
//Linux...
#ifdef?__cplusplus
extern?“C“
{
#endif
#include?
#include?
#include?
#include?
#include?
#ifdef?__cplusplus
};
#endif
#endif
//Output?YUV420P?
#define?OUTPUT_YUV420P?0
//‘1‘?Use?Dshow?
//‘0‘?Use?GDIgrab
#define?USE_DSHOW?0
//Refresh?Event
#define?SFM_REFRESH_EVENT??(SDL_USEREVENT?+?1)
int?thread_exit=0;
int?sfp_refresh_thread(void?*opaque)
{
while?(thread_exit==0)?{
SDL_Event?event;
event.type?=?SFM_REFRESH_EVENT;
SDL_PushEvent(&event);
SDL_Delay(40);
}
return?0;
}
//Show?Dshow?Device
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“);
????printf(“========Device?Info=============\n“);
????avformat_open_input(&pFormatCtx“video=dummy“iformat&options);
????printf(“================================\n“);
}
//Show?AVFoundation?Device
void?show_avfoundation_device(){
????AVFormatContext?*pFormatCtx?=?avformat_alloc_context();
????AVDictionary*?options?=?NULL;
????av_dict_set(&options“list_devices““true“0);
????AVInputFormat?*iformat?=?av_find_input_format(“avfoundation“);
????printf(“==AVFoundation?Device?Info===\n“);
????avformat_open_input(&pFormatCtx““iformat&options);
????printf(“=============================\n“);
}
int?main(int?argc?char*?argv[])
{
AVFormatContext *pFormatCtx;
int i?videoindex;
AVCodecContext *pCodecCtx;
AVCodec *pCodec;
av_register_al
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件??????????29??2015-02-12?17:39??.gitignore
?????文件?????????514??2015-02-12?17:39??ReadMe.txt
?????文件????????1439??2015-02-12?17:39??simplest_ffmpeg_device.sln
?????文件???????35328??2015-02-12?17:39??simplest_ffmpeg_device.suo
?????目錄???????????0??2015-02-12?17:39??simplest_ffmpeg_grabdesktop\
?????文件??????????67??2015-02-12?17:39??simplest_ffmpeg_grabdesktop\.gitignore
?????文件????????1259??2015-02-12?17:39??simplest_ffmpeg_grabdesktop\ReadMe.txt
?????文件??????303616??2015-02-12?17:39??simplest_ffmpeg_grabdesktop\SDL.dll
?????文件????18936320??2015-02-12?17:39??simplest_ffmpeg_grabdesktop\avcodec-55.dll
?????文件?????1340928??2015-02-12?17:39??simplest_ffmpeg_grabdesktop\avdevice-55.dll
?????文件?????2034688??2015-02-12?17:39??simplest_ffmpeg_grabdesktop\avfilter-4.dll
?????文件?????5342720??2015-02-12?17:39??simplest_ffmpeg_grabdesktop\avformat-55.dll
?????文件??????418304??2015-02-12?17:39??simplest_ffmpeg_grabdesktop\avutil-52.dll
?????文件?????????700??2015-02-12?17:39??simplest_ffmpeg_grabdesktop\compile_cl.bat
?????文件?????????496??2015-02-12?17:39??simplest_ffmpeg_grabdesktop\compile_gcc.sh
?????文件?????????513??2015-02-12?17:39??simplest_ffmpeg_grabdesktop\compile_gcc_mac.sh
?????文件?????????529??2015-02-12?17:39??simplest_ffmpeg_grabdesktop\compile_mingw.sh
?????目錄???????????0??2015-02-12?17:39??simplest_ffmpeg_grabdesktop\include\
?????目錄???????????0??2015-02-12?17:39??simplest_ffmpeg_grabdesktop\include\SDL\
?????文件????????3233??2015-02-12?17:39??simplest_ffmpeg_grabdesktop\include\SDL\SDL.h
?????文件????????1933??2015-02-12?17:39??simplest_ffmpeg_grabdesktop\include\SDL\SDL_active.h
?????文件???????11215??2015-02-12?17:39??simplest_ffmpeg_grabdesktop\include\SDL\SDL_audio.h
?????文件?????????986??2015-02-12?17:39??simplest_ffmpeg_grabdesktop\include\SDL\SDL_byteorder.h
?????文件????????6048??2015-02-12?17:39??simplest_ffmpeg_grabdesktop\include\SDL\SDL_cdrom.h
?????文件????????1474??2015-02-12?17:39??simplest_ffmpeg_grabdesktop\include\SDL\SDL_config.h
?????文件????????2803??2015-02-12?17:39??simplest_ffmpeg_grabdesktop\include\SDL\SDL_config_dreamcast.h
?????文件????????2801??2015-02-12?17:39??simplest_ffmpeg_grabdesktop\include\SDL\SDL_config_macos.h
?????文件????????4193??2015-02-12?17:39??simplest_ffmpeg_grabdesktop\include\SDL\SDL_config_macosx.h
?????文件????????1982??2015-02-12?17:39??simplest_ffmpeg_grabdesktop\include\SDL\SDL_config_minimal.h
?????文件????????2979??2015-02-12?17:39??simplest_ffmpeg_grabdesktop\include\SDL\SDL_config_nds.h
?????文件????????3635??2015-02-12?17:39??simplest_ffmpeg_grabdesktop\include\SDL\SDL_config_os2.h
............此處省略398個文件信息
- 上一篇:最簡單的基于FFMPEG的音頻編碼器 1.1
- 下一篇:ssh三大框架測試項目
評論
共有 條評論