您的位置:首页 > 其它

解读ffmpeg例程decoding_encoding.c

2014-08-21 16:34 323 查看
1.

static int chack_sample_fmt(AVCodec *codec, enum AVSampleFormat sample_fmt)

检查所给的实例格式是否是ffmpeg编码器所认识的格式

static int select_sample_rate(AVCodec * codec)

选择最佳的取样频率

static int select_channel_layout(AVCodec* codec)

为高速通道选择布局

---------------------------------------------------------------------------

2.音频编码:

static void audio_encode_example(const char *filename)

---------------------------------------------------------------------------

3.音频解码

static void audio_decode_example(const char* outfilename, const char *filename)

---------------------------------------------------------------------------

4.视频编码

static void video_encode_example(const char *filename, int codec_id)

a.AVCodec *codec;

codec = avcodec_find_encoder(codec_id);

根据codec_id获取特定的编码器,avcodec_find_encoder返回的值传入codec中,

codec获取编码器的信息和参数。

b.AVCodecContext *c = NULL;

c = avcodec_alloc_context3(codec);

获取编码器参数

c->bitrate
修改编码器的比特率

c->width 设置编码器宽度

c->height
设置编码器高度

c-time_base (AVRational){1,25}设置帧率为25/1=25
frames/s

c-gop_size
每隔多少帧插关键帧

c-max_b_frames设置B帧的帧数

c-pix_fmt 设置颜色空间的格式

c.av_opt_set(c-priv_data, "preset", "slow", 0);

d.avcodec_open2(c, codec, NULL);

打开/创建编码器

e.frame = avcodec_alloc_frame();

为编码帧开辟存储空间

设置帧的一些参数

frame->format = c->pix_fmt;

frame->width = c->width;

frame-height = c->height;

f.ret = av_image_alloc(frame->data, frame->linesize, c->width, c->height, c->pix_fmt, 32);

为编码后的帧开辟空间

g.ret = avcodec_encode_video2(c, &pkt, frame, &got_output);

编码器对帧进行编码

h.avcodec_close(c);//关闭编码器

av_free(c);

av_freep(&frame->data[0]);

av_codec_free_frame(&frame);

---------------------------------------------------------------------------

5.视频解码器

a.static void pgm_save(unsigned char *buf, int wrap, int xsize, int ysize, char *filename)

把解码后的数据帧存储为.pgm格式的图片

b.static int decode_write_frame(const char*outfilename, AVCodecContext *avctx, AVFrame *frame, int *frame_count,
AVPacket *pkt, int last)

avcodec_decode_video2(avctx, frame, &got_frame, pkt);

解码一帧

c.static
void video_decode_example(const char *outfilename, const char* filename)

-------------------------->未完待续<------------------------------------
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: