最简单的基于FFmpeg的AVDevice例子(读取摄像头)【转】

简介: 转自:http://blog.csdn.net/leixiaohua1020/article/details/39702113 版权声明:本文为博主原创文章,未经博主允许不得转载。   目录(?)[-] libavdevice使用 注意事项 代码 结果 下载 ...

转自:http://blog.csdn.net/leixiaohua1020/article/details/39702113

 
 

=====================================================
最简单的基于FFmpeg的AVDevice例子文章列表:

最简单的基于FFmpeg的AVDevice例子(读取摄像头)

最简单的基于FFmpeg的AVDevice例子(屏幕录制)
=====================================================

 

FFmpeg中有一个和多媒体设备交互的类库:Libavdevice。使用这个库可以读取电脑(或者其他设备上)的多媒体设备的数据,或者输出数据到指定的多媒体设备上。

Libavdevice支持以下设备作为输入端:
alsa
avfoundation
bktr
dshow
dv1394
fbdev
gdigrab
iec61883
jack
lavfi
libcdio
libdc1394
openal
oss
pulse
qtkit
sndio
video4linux2, v4l2
vfwcap
x11grab
decklink
Libavdevice支持以下设备作为输出端:
alsa
caca
decklink
fbdev
opengl
oss
pulse
sdl
sndio
xv


libavdevice使用

计划记录两个基于FFmpeg的libavdevice类库的例子,分成两篇文章写。本文记录一个基于FFmpeg的Libavdevice类库读取摄像头数据的例子。下一篇文章记录一个基于FFmpeg的Libavdevice类库录制屏幕的例子。本文程序读取计算机上的摄像头的数据并且解码显示出来。有关解码显示方面的代码本文不再详述,可以参考文章:
100行代码实现最简单的基于FFMPEG+SDL的视频播放器(SDL1.x)

 

本文主要记录使用libavdevice需要注意的步骤。

首先,使用libavdevice的时候需要包含其头文件:
[cpp]  view plain  copy
 
  1. #include "libavdevice/avdevice.h"  
然后,在程序中需要注册libavdevice:
[cpp]  view plain  copy
 
  1. avdevice_register_all();  

接下来就可以使用libavdevice的功能了。
使用libavdevice读取数据和直接打开视频文件比较类似。因为系统的设备也被FFmpeg认为是一种输入的格式(即AVInputFormat)。使用FFmpeg打开一个普通的视频文件使用如下函数:
[cpp]  view plain  copy
 
  1. AVFormatContext *pFormatCtx = avformat_alloc_context();  
  2. avformat_open_input(&pFormatCtx, "test.h265",NULL,NULL);  

使用libavdevice的时候,唯一的不同在于需要首先查找用于输入的设备。在这里使用av_find_input_format()完成:
[cpp]  view plain  copy
 
  1. AVFormatContext *pFormatCtx = avformat_alloc_context();  
  2. AVInputFormat *ifmt=av_find_input_format("vfwcap");  
  3. avformat_open_input(&pFormatCtx, 0, ifmt,NULL);  

上述代码首先指定了vfw设备作为输入设备,然后在URL中指定打开第0个设备(在我自己计算机上即是摄像头设备)。
在Windows平台上除了使用vfw设备作为输入设备之外,还可以使用DirectShow作为输入设备:
[cpp]  view plain  copy
 
  1. AVFormatContext *pFormatCtx = avformat_alloc_context();  
  2. AVInputFormat *ifmt=av_find_input_format("dshow");  
  3. avformat_open_input(&pFormatCtx,"video=Integrated Camera",ifmt,NULL) ;  

使用ffmpeg.exe打开vfw设备和Directshow设备的方法可以参考文章:
FFmpeg获取DirectShow设备数据(摄像头,录屏)

注意事项

1. URL的格式是"video={设备名称}",但是设备名称外面不能加引号。例如在上述例子中URL是"video=Integrated Camera",而不能写成"video=\"Integrated Camera\"",否则就无法打开设备。这与直接使用ffmpeg.exe打开dshow设备(命令为:ffmpeg -list_options true -f dshow -i video="Integrated Camera")有很大的不同。
2. Dshow的设备名称必须要提前获取,在这里有两种方法:

(1) 通过FFmpeg编程实现。使用如下代码:

 

[cpp]  view plain  copy
 
  1. //Show Device  
  2. void show_dshow_device(){  
  3.     AVFormatContext *pFormatCtx = avformat_alloc_context();  
  4.     AVDictionary* options = NULL;  
  5.     av_dict_set(&options,"list_devices","true",0);  
  6.     AVInputFormat *iformat = av_find_input_format("dshow");  
  7.     printf("Device Info=============\n");  
  8.     avformat_open_input(&pFormatCtx,"video=dummy",iformat,&options);  
  9.     printf("========================\n");  
  10. }  

 

上述代码实际上相当于输入了下面一条命令:
[plain]  view plain  copy
 
  1. ffmpeg -list_devices true -f dshow -i dummy    

执行的结果如下图所示:

 

该方法好处是可以使用程序自动获取名称。但是当设备名称中包含中文字符的时候,会出现设备名称为乱码的情况。如果直接把乱码的设备名作为输入的话,是无法打开该设备的。这时候需要把乱码ANSI转换为UTF-8。例如上图中的第一个音频设备显示为“鍐呰楹﹀厠椋?(Conexant 20672 SmartAudi”,转码之后即为“内装麦克风 (Conexant 20672 SmartAudi”。使用转码之后的名称即可打开该设备。


(2) 自己去系统中看。
这个方法更简单一些,但是缺点是需要手工操作。该方法使用DirectShow的调试工具GraphEdit(或者网上下一个GraphStudioNext)即可查看输入名称。
打开GraphEdit选择“图像->插入滤镜”
 
然后就可以通过查看Audio Capture Sources来查看音频输入设备的简体中文名称了。从图中可以看出是“内装麦克风 (Conexant 20672 SmartAudi”。
 


在Linux平台上可以使用video4linux2打开视频设备;在MacOS上,可以使用avfoundation打开视频设备,这里不再详述。


代码

下面直接贴上程序代码:

 

[cpp]  view plain  copy
 
  1. /** 
  2.  * 最简单的基于FFmpeg的AVDevice例子(读取摄像头) 
  3.  * Simplest FFmpeg Device (Read Camera) 
  4.  * 
  5.  * 雷霄骅 Lei Xiaohua 
  6.  * leixiaohua1020@126.com 
  7.  * 中国传媒大学/数字电视技术 
  8.  * Communication University of China / Digital TV Technology 
  9.  * http://blog.csdn.net/leixiaohua1020 
  10.  * 
  11.  * 本程序实现了本地摄像头数据的获取解码和显示。是基于FFmpeg 
  12.  * 的libavdevice类库最简单的例子。通过该例子,可以学习FFmpeg中 
  13.  * libavdevice类库的使用方法。 
  14.  * 本程序在Windows下可以使用2种方式读取摄像头数据: 
  15.  *  1.VFW: Video for Windows 屏幕捕捉设备。注意输入URL是设备的序号, 
  16.  *          从0至9。 
  17.  *  2.dshow: 使用Directshow。注意作者机器上的摄像头设备名称是 
  18.  *         “Integrated Camera”,使用的时候需要改成自己电脑上摄像头设 
  19.  *          备的名称。 
  20.  * 在Linux下可以使用video4linux2读取摄像头设备。 
  21.  * 在MacOS下可以使用avfoundation读取摄像头设备。 
  22.  * 
  23.  * This software read data from Computer's Camera and play it. 
  24.  * It's the simplest example about usage of FFmpeg's libavdevice Library.  
  25.  * It's suiltable for the beginner of FFmpeg. 
  26.  * This software support 2 methods to read camera in Microsoft Windows: 
  27.  *  1.gdigrab: VfW (Video for Windows) capture input device. 
  28.  *             The filename passed as input is the capture driver number, 
  29.  *             ranging from 0 to 9. 
  30.  *  2.dshow: Use Directshow. Camera's name in author's computer is  
  31.  *             "Integrated Camera". 
  32.  * It use video4linux2 to read Camera in Linux. 
  33.  * It use avfoundation to read Camera in MacOS. 
  34.  *  
  35.  */  
  36.   
  37.   
  38. #include <stdio.h>  
  39.   
  40. #define __STDC_CONSTANT_MACROS  
  41.   
  42. #ifdef _WIN32  
  43. //Windows  
  44. extern "C"  
  45. {  
  46. #include "libavcodec/avcodec.h"  
  47. #include "libavformat/avformat.h"  
  48. #include "libswscale/swscale.h"  
  49. #include "libavdevice/avdevice.h"  
  50. #include "SDL/SDL.h"  
  51. };  
  52. #else  
  53. //Linux...  
  54. #ifdef __cplusplus  
  55. extern "C"  
  56. {  
  57. #endif  
  58. #include <libavcodec/avcodec.h>  
  59. #include <libavformat/avformat.h>  
  60. #include <libswscale/swscale.h>  
  61. #include <libavdevice/avdevice.h>  
  62. #include <SDL/SDL.h>  
  63. #ifdef __cplusplus  
  64. };  
  65. #endif  
  66. #endif  
  67.   
  68. //Output YUV420P   
  69. #define OUTPUT_YUV420P 0  
  70. //'1' Use Dshow   
  71. //'0' Use VFW  
  72. #define USE_DSHOW 0  
  73.   
  74.   
  75. //Refresh Event  
  76. #define SFM_REFRESH_EVENT  (SDL_USEREVENT + 1)  
  77.   
  78. #define SFM_BREAK_EVENT  (SDL_USEREVENT + 2)  
  79.   
  80. int thread_exit=0;  
  81.   
  82. int sfp_refresh_thread(void *opaque)  
  83. {  
  84.     thread_exit=0;  
  85.     while (!thread_exit) {  
  86.         SDL_Event event;  
  87.         event.type = SFM_REFRESH_EVENT;  
  88.         SDL_PushEvent(&event);  
  89.         SDL_Delay(40);  
  90.     }  
  91.     thread_exit=0;  
  92.     //Break  
  93.     SDL_Event event;  
  94.     event.type = SFM_BREAK_EVENT;  
  95.     SDL_PushEvent(&event);  
  96.   
  97.     return 0;  
  98. }  
  99.   
  100.   
  101. //Show Dshow Device  
  102. void show_dshow_device(){  
  103.     AVFormatContext *pFormatCtx = avformat_alloc_context();  
  104.     AVDictionary* options = NULL;  
  105.     av_dict_set(&options,"list_devices","true",0);  
  106.     AVInputFormat *iformat = av_find_input_format("dshow");  
  107.     printf("========Device Info=============\n");  
  108.     avformat_open_input(&pFormatCtx,"video=dummy",iformat,&options);  
  109.     printf("================================\n");  
  110. }  
  111.   
  112. //Show Dshow Device Option  
  113. void show_dshow_device_option(){  
  114.     AVFormatContext *pFormatCtx = avformat_alloc_context();  
  115.     AVDictionary* options = NULL;  
  116.     av_dict_set(&options,"list_options","true",0);  
  117.     AVInputFormat *iformat = av_find_input_format("dshow");  
  118.     printf("========Device Option Info======\n");  
  119.     avformat_open_input(&pFormatCtx,"video=Integrated Camera",iformat,&options);  
  120.     printf("================================\n");  
  121. }  
  122.   
  123. //Show VFW Device  
  124. void show_vfw_device(){  
  125.     AVFormatContext *pFormatCtx = avformat_alloc_context();  
  126.     AVInputFormat *iformat = av_find_input_format("vfwcap");  
  127.     printf("========VFW Device Info======\n");  
  128.     avformat_open_input(&pFormatCtx,"list",iformat,NULL);  
  129.     printf("=============================\n");  
  130. }  
  131.   
  132. //Show AVFoundation Device  
  133. void show_avfoundation_device(){  
  134.     AVFormatContext *pFormatCtx = avformat_alloc_context();  
  135.     AVDictionary* options = NULL;  
  136.     av_dict_set(&options,"list_devices","true",0);  
  137.     AVInputFormat *iformat = av_find_input_format("avfoundation");  
  138.     printf("==AVFoundation Device Info===\n");  
  139.     avformat_open_input(&pFormatCtx,"",iformat,&options);  
  140.     printf("=============================\n");  
  141. }  
  142.   
  143.   
  144. int main(int argc, char* argv[])  
  145. {  
  146.   
  147.     AVFormatContext *pFormatCtx;  
  148.     int             i, videoindex;  
  149.     AVCodecContext  *pCodecCtx;  
  150.     AVCodec         *pCodec;  
  151.       
  152.     av_register_all();  
  153.     avformat_network_init();  
  154.     pFormatCtx = avformat_alloc_context();  
  155.       
  156.     //Open File  
  157.     //char filepath[]="src01_480x272_22.h265";  
  158.     //avformat_open_input(&pFormatCtx,filepath,NULL,NULL)  
  159.   
  160.     //Register Device  
  161.     avdevice_register_all();  
  162.   
  163. //Windows  
  164. #ifdef _WIN32  
  165.   
  166.     //Show Dshow Device  
  167.     show_dshow_device();  
  168.     //Show Device Options  
  169.     show_dshow_device_option();  
  170.     //Show VFW Options  
  171.     show_vfw_device();  
  172.   
  173. #if USE_DSHOW  
  174.     AVInputFormat *ifmt=av_find_input_format("dshow");  
  175.     //Set own video device's name  
  176.     if(avformat_open_input(&pFormatCtx,"video=Integrated Camera",ifmt,NULL)!=0){  
  177.         printf("Couldn't open input stream.\n");  
  178.         return -1;  
  179.     }  
  180. #else  
  181.     AVInputFormat *ifmt=av_find_input_format("vfwcap");  
  182.     if(avformat_open_input(&pFormatCtx,"0",ifmt,NULL)!=0){  
  183.         printf("Couldn't open input stream.\n");  
  184.         return -1;  
  185.     }  
  186. #endif  
  187. #elif defined linux  
  188.     //Linux  
  189.     AVInputFormat *ifmt=av_find_input_format("video4linux2");  
  190.     if(avformat_open_input(&pFormatCtx,"/dev/video0",ifmt,NULL)!=0){  
  191.         printf("Couldn't open input stream.\n");  
  192.         return -1;  
  193.     }  
  194. #else  
  195.     show_avfoundation_device();  
  196.     //Mac  
  197.     AVInputFormat *ifmt=av_find_input_format("avfoundation");  
  198.     //Avfoundation  
  199.     //[video]:[audio]  
  200.     if(avformat_open_input(&pFormatCtx,"0",ifmt,NULL)!=0){  
  201.         printf("Couldn't open input stream.\n");  
  202.         return -1;  
  203.     }  
  204. #endif  
  205.   
  206.   
  207.     if(avformat_find_stream_info(pFormatCtx,NULL)<0)  
  208.     {  
  209.         printf("Couldn't find stream information.\n");  
  210.         return -1;  
  211.     }  
  212.     videoindex=-1;  
  213.     for(i=0; i<pFormatCtx->nb_streams; i++)   
  214.         if(pFormatCtx->streams[i]->codec->codec_type==AVMEDIA_TYPE_VIDEO)  
  215.         {  
  216.             videoindex=i;  
  217.             break;  
  218.         }  
  219.     if(videoindex==-1)  
  220.     {  
  221.         printf("Couldn't find a video stream.\n");  
  222.         return -1;  
  223.     }  
  224.     pCodecCtx=pFormatCtx->streams[videoindex]->codec;  
  225.     pCodec=avcodec_find_decoder(pCodecCtx->codec_id);  
  226.     if(pCodec==NULL)  
  227.     {  
  228.         printf("Codec not found.\n");  
  229.         return -1;  
  230.     }  
  231.     if(avcodec_open2(pCodecCtx, pCodec,NULL)<0)  
  232.     {  
  233.         printf("Could not open codec.\n");  
  234.         return -1;  
  235.     }  
  236.     AVFrame *pFrame,*pFrameYUV;  
  237.     pFrame=av_frame_alloc();  
  238.     pFrameYUV=av_frame_alloc();  
  239.     //unsigned char *out_buffer=(unsigned char *)av_malloc(avpicture_get_size(AV_PIX_FMT_YUV420P, pCodecCtx->width, pCodecCtx->height));  
  240.     //avpicture_fill((AVPicture *)pFrameYUV, out_buffer, AV_PIX_FMT_YUV420P, pCodecCtx->width, pCodecCtx->height);  
  241.     //SDL----------------------------  
  242.     if(SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_TIMER)) {    
  243.         printf( "Could not initialize SDL - %s\n", SDL_GetError());   
  244.         return -1;  
  245.     }   
  246.     int screen_w=0,screen_h=0;  
  247.     SDL_Surface *screen;   
  248.     screen_w = pCodecCtx->width;  
  249.     screen_h = pCodecCtx->height;  
  250.     screen = SDL_SetVideoMode(screen_w, screen_h, 0,0);  
  251.   
  252.     if(!screen) {    
  253.         printf("SDL: could not set video mode - exiting:%s\n",SDL_GetError());    
  254.         return -1;  
  255.     }  
  256.     SDL_Overlay *bmp;   
  257.     bmp = SDL_CreateYUVOverlay(pCodecCtx->width, pCodecCtx->height,SDL_YV12_OVERLAY, screen);   
  258.     SDL_Rect rect;  
  259.     rect.x = 0;      
  260.     rect.y = 0;      
  261.     rect.w = screen_w;      
  262.     rect.h = screen_h;    
  263.     //SDL End------------------------  
  264.     int ret, got_picture;  
  265.   
  266.     AVPacket *packet=(AVPacket *)av_malloc(sizeof(AVPacket));  
  267.   
  268. #if OUTPUT_YUV420P   
  269.     FILE *fp_yuv=fopen("output.yuv","wb+");    
  270. #endif    
  271.   
  272.     struct SwsContext *img_convert_ctx;  
  273.     img_convert_ctx = sws_getContext(pCodecCtx->width, pCodecCtx->height, pCodecCtx->pix_fmt, pCodecCtx->width, pCodecCtx->height, AV_PIX_FMT_YUV420P, SWS_BICUBIC, NULL, NULL, NULL);   
  274.     //------------------------------  
  275.     SDL_Thread *video_tid = SDL_CreateThread(sfp_refresh_thread,NULL);  
  276.     //  
  277.     SDL_WM_SetCaption("Simplest FFmpeg Read Camera",NULL);  
  278.     //Event Loop  
  279.     SDL_Event event;  
  280.   
  281.     for (;;) {  
  282.         //Wait  
  283.         SDL_WaitEvent(&event);  
  284.         if(event.type==SFM_REFRESH_EVENT){  
  285.             //------------------------------  
  286.             if(av_read_frame(pFormatCtx, packet)>=0){  
  287.                 if(packet->stream_index==videoindex){  
  288.                     ret = avcodec_decode_video2(pCodecCtx, pFrame, &got_picture, packet);  
  289.                     if(ret < 0){  
  290.                         printf("Decode Error.\n");  
  291.                         return -1;  
  292.                     }  
  293.                     if(got_picture){  
  294.                         SDL_LockYUVOverlay(bmp);  
  295.                         pFrameYUV->data[0]=bmp->pixels[0];  
  296.                         pFrameYUV->data[1]=bmp->pixels[2];  
  297.                         pFrameYUV->data[2]=bmp->pixels[1];       
  298.                         pFrameYUV->linesize[0]=bmp->pitches[0];  
  299.                         pFrameYUV->linesize[1]=bmp->pitches[2];     
  300.                         pFrameYUV->linesize[2]=bmp->pitches[1];  
  301.                         sws_scale(img_convert_ctx, (const unsigned char* const*)pFrame->data, pFrame->linesize, 0, pCodecCtx->height, pFrameYUV->data, pFrameYUV->linesize);  
  302.   
  303. #if OUTPUT_YUV420P    
  304.                         int y_size=pCodecCtx->width*pCodecCtx->height;      
  305.                         fwrite(pFrameYUV->data[0],1,y_size,fp_yuv);    //Y     
  306.                         fwrite(pFrameYUV->data[1],1,y_size/4,fp_yuv);  //U    
  307.                         fwrite(pFrameYUV->data[2],1,y_size/4,fp_yuv);  //V    
  308. #endif    
  309.   
  310.                         SDL_UnlockYUVOverlay(bmp);   
  311.                           
  312.                         SDL_DisplayYUVOverlay(bmp, &rect);   
  313.   
  314.                     }  
  315.                 }  
  316.                 av_free_packet(packet);  
  317.             }else{  
  318.                 //Exit Thread  
  319.                 thread_exit=1;  
  320.             }  
  321.         }else if(event.type==SDL_QUIT){  
  322.             thread_exit=1;  
  323.         }else if(event.type==SFM_BREAK_EVENT){  
  324.             break;  
  325.         }  
  326.   
  327.     }  
  328.       
  329.   
  330.     sws_freeContext(img_convert_ctx);  
  331.   
  332. #if OUTPUT_YUV420P   
  333.     fclose(fp_yuv);  
  334. #endif   
  335.   
  336.     SDL_Quit();  
  337.   
  338.     //av_free(out_buffer);  
  339.     av_free(pFrameYUV);  
  340.     avcodec_close(pCodecCtx);  
  341.     avformat_close_input(&pFormatCtx);  
  342.   
  343.     return 0;  
  344. }  

 

 


结果

程序的运行效果如下。输出了摄像头的数据。

可以通过下面的宏定义来确定是否将解码后的YUV420P数据输出成文件:
[cpp]  view plain  copy
 
  1. #define OUTPUT_YUV420P 0  

可以通过下面的宏定义来确定使用VFW或者是Dshow打开摄像头:

 

[cpp]  view plain  copy
 
  1. //'1' Use Dshow   
  2. //'0' Use VFW  
  3. #define USE_DSHOW 0  

 

 

下载

 

 

Simplest FFmpeg Device 

 

项目主页

SourceForge:https://sourceforge.net/projects/simplestffmpegdevice/

Github:https://github.com/leixiaohua1020/simplest_ffmpeg_device

开源中国:http://git.oschina.net/leixiaohua1020/simplest_ffmpeg_device

 

CSDN下载地址:

http://download.csdn.net/detail/leixiaohua1020/7994049

 

注:

 本工程包含两个基于FFmpeg的libavdevice的例子:
 simplest_ffmpeg_grabdesktop:屏幕录制。
 simplest_ffmpeg_readcamera:读取摄像头。


更新-1.1(2015.1.9)=========================================

该版本中,修改了SDL的显示方式,弹出的窗口可以移动了。

CSDN下载地址:http://download.csdn.net/detail/leixiaohua1020/8344695

 

更新-1.2 (2015.2.13)=========================================

这次考虑到了跨平台的要求,调整了源代码。经过这次调整之后,源代码可以在以下平台编译通过:

VC++:打开sln文件即可编译,无需配置。

cl.exe:打开compile_cl.bat即可命令行下使用cl.exe进行编译,注意可能需要按照VC的安装路径调整脚本里面的参数。编译命令如下。

[plain]  view plain  copy
 
  1. ::VS2010 Environment  
  2. call "D:\Program Files\Microsoft Visual Studio 10.0\VC\vcvarsall.bat"  
  3. ::include  
  4. @set INCLUDE=include;%INCLUDE%  
  5. ::lib  
  6. @set LIB=lib;%LIB%  
  7. ::compile and link  
  8. cl simplest_ffmpeg_readcamera.cpp /MD /link SDL.lib SDLmain.lib avcodec.lib ^  
  9. avformat.lib avutil.lib avdevice.lib avfilter.lib postproc.lib swresample.lib swscale.lib ^  
  10. /SUBSYSTEM:WINDOWS /OPT:NOREF  

MinGW:MinGW命令行下运行compile_mingw.sh即可使用MinGW的g++进行编译。编译命令如下。

 

[plain]  view plain  copy
 
  1. g++ simplest_ffmpeg_readcamera.cpp -g -o simplest_ffmpeg_readcamera.exe \  
  2. -I /usr/local/include -L /usr/local/lib \  
  3. -lmingw32 -lSDLmain -lSDL -lavformat -lavcodec -lavutil -lavdevice -lswscale  

 

GCC(Linux):Linux命令行下运行compile_gcc.sh即可使用GCC进行编译。编译命令如下。

 

[plain]  view plain  copy
 
  1. gcc simplest_ffmpeg_readcamera.cpp -g -o simplest_ffmpeg_readcamera.out \  
  2. -I /usr/local/include -L /usr/local/lib -lSDLmain -lSDL -lavformat -lavcodec -lavutil -lavdevice -lswscale  

 

 

GCC(MacOS):MacOS命令行下运行compile_gcc_mac.sh即可使用GCC进行编译。Mac的GCC和Linux的GCC差别不大,但是使用SDL1.2的时候,必须加上“-framework Cocoa”参数,否则编译无法通过。编译命令如下。

 

[plain]  view plain  copy
 
  1. gcc simplest_ffmpeg_readcamera.cpp -g -o simplest_ffmpeg_readcamera.out \  
  2. -framework Cocoa -I /usr/local/include -L /usr/local/lib -lSDLmain -lSDL -lavformat -lavcodec -lavutil -lavdevice -lswscale  

PS:相关的编译命令已经保存到了工程文件夹中

此外,增加了MacOS下使用avfoundation读取摄像头的代码。

CSDN下载地址:http://download.csdn.net/detail/leixiaohua1020/8445747

SourceForge上已经更新。

【作者】 张昺华
【新浪微博】 张昺华--sky
【twitter】 @sky2030_
【facebook】 张昺华 zhangbinghua
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利.
目录
相关文章
|
1月前
|
C++ 计算机视觉
Opencv(C++)系列学习---读取视频文件和打开摄像头
Opencv(C++)系列学习---读取视频文件和打开摄像头
|
4月前
|
计算机视觉 索引
opencv读取MP4文件和摄像头数据
opencv读取MP4文件和摄像头数据
53 0
|
4月前
|
计算机视觉 索引 Python
OpenCV中读取、显示、保存摄像头视频讲解与实战(附Python源码)
OpenCV中读取、显示、保存摄像头视频讲解与实战(附Python源码)
45 0
|
4月前
|
编解码 计算机视觉 Python
OpenCV保存摄像头视频和视频文件操作实战(附Python源码)
OpenCV保存摄像头视频和视频文件操作实战(附Python源码)
222 0
|
4月前
|
Python
Python 视频流读取
Python 视频流读取
|
4月前
|
Linux C语言
ffmpeg编程查看视频文件信息
ffmpeg编程查看视频文件信息
55 0
|
API 计算机视觉
V4L2抓取USB摄像头YUV视频数据代码
V4L2抓取USB摄像头YUV视频数据代码
219 0
|
数据采集 编解码 计算机视觉
Python+Opencv读取高帧率USB摄像头问题
Python+Opencv读取高帧率USB摄像头问题
298 0
|
数据采集 开发工具 计算机视觉
使用Python+Opencv从摄像头逐帧读取图片保存在本地
使用Python+Opencv,从摄像头的实时视频流中逐帧读取图片,保存到本地
535 0
使用Python+Opencv从摄像头逐帧读取图片保存在本地
|
计算机视觉
【Opencv工程开发所用类】VideoTracker 视频摄像头
【Opencv工程开发所用类】VideoTracker 视频摄像头
【Opencv工程开发所用类】VideoTracker 视频摄像头