寻找自己的采集图像设备

  • 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;
    

分类:

技术点:

相关文章: