尋找自己的采集圖像設備
-
av_find_input_format()
根據名稱查找鏈表當中的輸入的格式
如果要查找設備在使用之前去調用: avdevice_register_all();
AVInputFormat *av_find_input_format(const char *short_name); /* @param short_name : 指定輸入的名稱,可以是設備名稱avfoundation,或者編碼格式:H264, h265... @return: AVInputFormat 結構體看下面 */ typedef struct AVInputFormat { const char *name; // 封裝格式名稱簡寫(short_name)[h264] const char *long_name; // 碼流輸入格式的長名稱[raw H.264 video] int flags; const char *extensions; const struct AVCodecTag * const *codec_tag; const AVClass *priv_class; const char *mime_type; struct AVInputFormat *next; int raw_codec_id int priv_data_size; int (*read_probe)(AVProbeData *); int (*read_header)(struct AVFormatContext *); int64_t (*read_timestamp)(struct AVFormatContext *s, int stream_index,int64_t *pos, int64_t pos_limit); int (*read_play)(struct AVFormatContext *); int (*read_pause)(struct AVFormatContext *); int (*get_device_list)(struct AVFormatContext *s, struct AVDeviceInfoList *device_list); int (*create_device_capabilities)(struct AVFormatContext *s, struct AVDeviceCapabilitiesQuery *caps); int (*free_device_capabilities)(struct AVFormatContext *s, struct AVDeviceCapabilitiesQuery *caps); } AVInputFormat;
-
avformat_open_input()
主要用來打開輸入流並存儲到格式化上下文AVFormatContext中。這個api是不會打開編解碼器的
打開的格式化上下文必須要使用:avformat_close_input()來關閉!
int avformat_open_input(AVFormatContext **ps, const char *url, AVInputFormat *fmt, AVDictionary **options); /* @param ps : 打開之后的數據傳入的格式化上線文的指針,失敗會自動釋放打開的內容 @param url : 要打開的流的URL,可以是設備ID、rtmp、http @param fmt : 輸入的格式,如果為空則會自動查找輸入的格式 @param options :AVFormatContext和demuxer私有選項的字典。 @return 0: 成功 <0: 失敗 */
-
struct AVFormatContext;
typedef struct AVFormatContext { const AVClass *av_class; struct AVInputFormat *iformat; // 輸入容器格式 struct AVOutputFormat *oformat; // 輸入容器格式 void *priv_data; // 連接私有數據 AVIOContext *pb; // IO 上下文 int ctx_flags; unsigned int nb_streams; // 流的數量,只能被avformat_new_stream來設置 AVStream **streams; // 文件中所有的流 #if FF_API_FORMAT_FILENAME attribute_deprecated char filename[1024]; // 輸入或者輸出的文件名 #endif char *url; // 輸入或者輸出的URL int64_t start_time; //容器的第一幀的時間 int64_t duration; // 流的持續時間 int64_t bit_rate; // 總流的比特率,比特/秒為單位 unsigned int packet_size; int max_delay; int flags; // 修改行為標志 #define AVFMT_FLAG_GENPTS 0x0001 #define AVFMT_FLAG_IGNIDX 0x0002 #define AVFMT_FLAG_NONBLOCK 0x0004 #define AVFMT_FLAG_IGNDTS 0x0008 #define AVFMT_FLAG_NOFILLIN 0x0010 #define AVFMT_FLAG_NOPARSE 0x0020 #define AVFMT_FLAG_NOBUFFER 0x0040 #define AVFMT_FLAG_CUSTOM_IO 0x0080 #define AVFMT_FLAG_DISCARD_CORRUPT 0x0100 #define AVFMT_FLAG_FLUSH_PACKETS 0x0200 #define AVFMT_FLAG_BITEXACT 0x0400 #if FF_API_LAVF_MP4A_LATM #define AVFMT_FLAG_MP4A_LATM 0x8000 #endif #define AVFMT_FLAG_SORT_DTS 0x10000 #define AVFMT_FLAG_PRIV_OPT 0x20000 #if FF_API_LAVF_KEEPSIDE_FLAG #define AVFMT_FLAG_KEEP_SIDE_DATA 0x40000 #endif #define AVFMT_FLAG_FAST_SEEK 0x80000 #define AVFMT_FLAG_SHORTEST 0x100000 #define AVFMT_FLAG_AUTO_BSF 0x200000 int64_t probesize; int64_t max_analyze_duration; // 讀取數據最大的持續時間 const uint8_t *key; int keylen; unsigned int nb_programs; AVProgram **programs; enum AVCodecID video_codec_id; // 強制在解復用的設置視頻解碼器的id enum AVCodecID audio_codec_id; // 強制在解復用的設置音頻解碼器的id enum AVCodecID subtitle_codec_id; // 強制在解復用的時候設置字幕的解碼器id unsigned int max_index_size; // 解復用的時候流索引的最大內存 unsigned int max_picture_buffer; // 緩沖幀的最大內存,在實時步驟設備的時候會用到 unsigned int nb_chapters; AVChapter **chapters; AVDictionary *metadata; int64_t start_time_realtime; // 啟動的流在現實的時間 int fps_probe_size; // 確定幀率的幀數 int error_recognition; // 錯誤識別 AVIOInterruptCB interrupt_callback; // IO中斷回調 int debug; #define FF_FDEBUG_TS 0x0001 int64_t max_interleave_delta; // 交錯的最大緩沖時間 int strict_std_compliance; int event_flags; #define AVFMT_EVENT_FLAG_METADATA_UPDATED 0x0001 int max_ts_probe; int avoid_negative_ts; #define AVFMT_AVOID_NEG_TS_AUTO -1 #define AVFMT_AVOID_NEG_TS_MAKE_NON_NEGATIVE 1 #define AVFMT_AVOID_NEG_TS_MAKE_ZERO 2 int ts_id; int audio_preload; int max_chunk_duration; int max_chunk_size; int use_wallclock_as_timestamps; int avio_flags; enum AVDurationEstimationMethod duration_estimation_method; int64_t skip_initial_bytes; unsigned int correct_ts_overflow; int seek2any; int flush_packets; int probe_score; int format_probesize; char *codec_whitelist; char *format_whitelist; AVFormatInternal *internal; int io_repositioned; AVCodec *video_codec; AVCodec *audio_codec; AVCodec *subtitle_codec; AVCodec *data_codec; int metadata_header_padding; void *opaque; av_format_control_message control_message_cb; int64_t output_ts_offset; uint8_t *dump_separator; enum AVCodecID data_codec_id; #if FF_API_OLD_OPEN_CALLBACKS attribute_deprecated int (*open_cb)(struct AVFormatContext *s, AVIOContext **p, const char *url, int flags, const AVIOInterruptCB *int_cb, AVDictionary **options); #endif char *protocol_whitelist; int (*io_open)(struct AVFormatContext *s, AVIOContext **pb, const char *url,int flags, AVDictionary **options); // 打開新的IO流進行回調 void (*io_close)(struct AVFormatContext *s, AVIOContext *pb); char *protocol_blacklist; int max_streams; // 最大流的數量 int skip_estimate_duration_from_pts; } AVFormatContext;