register all media file container muxers in ffmpeg

来源:互联网 发布:剑网3刘亦菲捏脸数据 编辑:程序博客网 时间:2024/06/06 01:25
register all media file container muxers in ffmpeg

1. muxers such mov and 3gp
libavformat/movenc.c:
#if CONFIG_MOV_MUXERMOV_CLASS(mov)AVOutputFormat ff_mov_muxer = {    .name              = "mov",    .long_name         = NULL_IF_CONFIG_SMALL("QuickTime / MOV"),    .extensions        = "mov",    .priv_data_size    = sizeof(MOVMuxContext),    .audio_codec       = AV_CODEC_ID_AAC,    .video_codec       = CONFIG_LIBX264_ENCODER ?                         AV_CODEC_ID_H264 : AV_CODEC_ID_MPEG4,    .write_header      = mov_write_header,    .write_packet      = mov_write_packet,    .write_trailer     = mov_write_trailer,    .flags             = AVFMT_GLOBALHEADER | AVFMT_ALLOW_FLUSH | AVFMT_TS_NEGATIVE,    .codec_tag         = (const AVCodecTag* const []){        ff_codec_movvideo_tags, ff_codec_movaudio_tags, 0    },    .priv_class        = &mov_muxer_class,};#endif#if CONFIG_TGP_MUXERMOV_CLASS(tgp)AVOutputFormat ff_tgp_muxer = {    .name              = "3gp",    .long_name         = NULL_IF_CONFIG_SMALL("3GP (3GPP file format)"),    .extensions        = "3gp",    .priv_data_size    = sizeof(MOVMuxContext),    .audio_codec       = AV_CODEC_ID_AMR_NB,    .video_codec       = AV_CODEC_ID_H263,    .write_header      = mov_write_header,    .write_packet      = mov_write_packet,    .write_trailer     = mov_write_trailer,    .flags             = AVFMT_GLOBALHEADER | AVFMT_ALLOW_FLUSH | AVFMT_TS_NEGATIVE,    .codec_tag         = (const AVCodecTag* const []){ codec_3gp_tags, 0 },    .priv_class        = &tgp_muxer_class,};#endif


2. so how to register these muxers such as mov and 3gp?
in libavformat/allformats.c:
#define REGISTER_MUXER(X, x)                                            \    {                                                                   \        extern AVOutputFormat ff_##x##_muxer;                           \        if (CONFIG_##X##_MUXER)                                         \            av_register_output_format(&ff_##x##_muxer);                 \    }#define REGISTER_DEMUXER(X, x)                                          \    {                                                                   \        extern AVInputFormat ff_##x##_demuxer;                          \        if (CONFIG_##X##_DEMUXER)                                       \            av_register_input_format(&ff_##x##_demuxer);                \    }#define REGISTER_MUXDEMUX(X, x) REGISTER_MUXER(X, x); REGISTER_DEMUXER(X, x)

also in libavformat/allformats.c
void av_register_all(void){    static int initialized;    if (initialized)        return;    initialized = 1;    avcodec_register_all();    /* (de)muxers */    REGISTER_MUXER   (A64,              a64);    REGISTER_DEMUXER (AAC,              aac);    REGISTER_MUXDEMUX(AC3,              ac3);......    REGISTER_MUXDEMUX(MOV,              mov);    REGISTER_MUXER   (MP2,              mp2);    REGISTER_MUXDEMUX(MP3,              mp3);    REGISTER_MUXER   (MP4,              mp4);

all the registered muxers are save in the below single linked list:
static AVOutputFormat *first_oformat = NULL;
linked by the below field of AVOutputFormat:
    struct AVOutputFormat *next;


get the target AVOutputFormat(a muxer) according to muxer name, for example mov:
m_pFormatCtx->oformat = av_guess_format("mov", NULL, NULL);

AVOutputFormat *av_guess_format(const char *short_name, const char *filename,                                const char *mime_type)    /* Find the proper file type. */    fmt_found = NULL;    score_max = 0;    while ((fmt = av_oformat_next(fmt))) {        score = 0;        if (fmt->name && short_name && match_format(short_name, fmt->name))            score += 100;        if (fmt->mime_type && mime_type && !strcmp(fmt->mime_type, mime_type))            score += 10;        if (filename && fmt->extensions &&            av_match_ext(filename, fmt->extensions)) {            score += 5;        }        if (score > score_max) {            score_max = score;            fmt_found = fmt;        }    }    return fmt_found;

in the above example, only short_name is not null. both filename and mime_type are null












0 0
原创粉丝点击