您的位置:首页 > 大数据 > 人工智能

register all media file container muxers in ffmpeg

2017-02-02 19:44 337 查看
register all media file container muxers in ffmpeg

1. muxers such mov and 3gp
libavformat/movenc.c:
#if CONFIG_MOV_MUXER
MOV_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_MUXER
MOV_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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: