1. 程式人生 > >使用ffmpeg 3.3+sdl 2.0 不能直接獲取攝像頭的原因

使用ffmpeg 3.3+sdl 2.0 不能直接獲取攝像頭的原因

本文主要是下面這個連結的補充https://blog.csdn.net/leixiaohua1020/article/details/39702113

avdevice_register_all ();
avformat_network_init ();
av_register_all ();
AVFormatContext	* pFormatCtx = avformat_alloc_context ();
AVInputFormat *ifmt = av_find_input_format ( "dshow" );
av_register_input_format ( ifmt ); // 唯一區別,在我使用的3.3版本中,不加此句會獲取失敗
if (avformat_open_input ( &pFormatCtx, "video=Integrated Camera", ifmt, NULL ) != 0)
{
		printf ( "Couldn't open input stream.\n" );
		return -1;
}

2. main函式進不去的解決辦法: 在此過程中,碰到了include "SDL.h" 就會進不去main函式的問題,解決辦法是在main函式之前加上#undef main 。發生這種情況的原因是因為sdl這個lib中定義了main,而我們一般都是先宣告標頭檔案,這樣編譯器在尋找main的過程中,就會先在sdl中發現main這個關鍵字,最終就導致了每次我們啟動程式,入口點就變成sdl定義的main函式。

歡迎在下方留言探討