解读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)
-------------------------->未完待续<------------------------------------
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)
-------------------------->未完待续<------------------------------------
相关文章推荐
- 解读ffmpeg例程decoding_encoding.c
- 解析ffmpeg-2.8自带例子decoding_encoding.c了解如何解析音视频流程
- Realtime h264 encoding and decoding with x264 and ffmpeg-1
- 调通了ffmpeg tutorial例程
- 字符串编码(charset,encoding/decoding)问题原理
- ffmpeg的mpeg2编码I帧代码解读(三)
- Top 5 Best H.265 (HEVC) Codec Decoding and Encoding Tools
- Ffmpeg框架结构解读 .
- URL Encoding/Decoding
- URL Encoding/Decoding in C
- Alamofire源码解读系列(四)之参数编码(ParameterEncoding)
- 字符串编码(charset, encoding/decoding)问题原理
- Ffmpeg框架结构解读
- ffmpeg框架结构解读
- FFmpeg框架结构解读
- Ffmpeg框架结构解读 (转)
- Ffmpeg框架结构解读
- (未完成)ffmpeg tutorial 4 (播放视频) 解读
- HTML5 Base64_encoding_and_decoding
- ffmpeg的mpeg2编码I帧代码解读