FFmpeg处理过程(代码说明)
来源:互联网 发布:mac怎么退出qq 编辑:程序博客网 时间:2024/06/02 03:06
编码环境:ubuntu 麒麟 14.10
FFmpeg默认编译。
在编译自己写的代码时,由于默认路径原因,直接修改源代码中doc/example下面的Makefile文件
头文件如下:
#include <libavcodec/avcodec.h>#include <libavformat/avformat.h>#include <libavformat/avio.h>#include <libavutil/file.h>struct buffer_data { uint8_t *ptr; size_t size; ///< size left in the buffer};static int read_packet(void *opaque, uint8_t *buf, int buf_size){ struct buffer_data *bd = (struct buffer_data *)opaque; buf_size = FFMIN(buf_size, bd->size); printf("ptr:%p size:%zu\n", bd->ptr, bd->size); /* copy internal buffer data to buf */ memcpy(buf, bd->ptr, buf_size); bd->ptr += buf_size; bd->size -= buf_size; return buf_size;}int main(int argc, char *argv[]){ AVFormatContext *fmt_ctx = NULL; AVIOContext *avio_ctx = NULL; uint8_t *buffer = NULL, *avio_ctx_buffer = NULL; size_t buffer_size, avio_ctx_buffer_size = 4096; char *input_filename = NULL; int ret = 0; struct buffer_data bd = { 0 }; if (argc != 2) { fprintf(stderr, "usage: %s input_file\n" "API example program to show how to read from a custom buffer " "accessed through AVIOContext.\n", argv[0]); return 1; } input_filename = argv[1]; /* register codecs and formats and other lavf/lavc components*/ av_register_all(); /* slurp file content into buffer */ ret = av_file_map(input_filename, &buffer, &buffer_size, 0, NULL); if (ret < 0) goto end; /* fill opaque structure used by the AVIOContext read callback */ bd.ptr = buffer; bd.size = buffer_size; if (!(fmt_ctx = avformat_alloc_context())) { ret = AVERROR(ENOMEM); goto end; } avio_ctx_buffer = av_malloc(avio_ctx_buffer_size); if (!avio_ctx_buffer) { ret = AVERROR(ENOMEM); goto end; } avio_ctx = avio_alloc_context(avio_ctx_buffer, avio_ctx_buffer_size, 0, &bd, &read_packet, NULL, NULL); if (!avio_ctx) { ret = AVERROR(ENOMEM); goto end; } fmt_ctx->pb = avio_ctx; ret = avformat_open_input(&fmt_ctx, NULL, NULL, NULL); if (ret < 0) { fprintf(stderr, "Could not open input\n"); goto end; } ret = avformat_find_stream_info(fmt_ctx, NULL); if (ret < 0) { fprintf(stderr, "Could not find stream information\n"); goto end; } av_dump_format(fmt_ctx, 0, input_filename, 0);end: avformat_close_input(&fmt_ctx); /* note: the internal buffer could have changed, and be != avio_ctx_buffer */ if (avio_ctx) { av_freep(&avio_ctx->buffer); av_freep(&avio_ctx); } av_file_unmap(buffer, buffer_size); if (ret < 0) { fprintf(stderr, "Error occurred: %s\n", av_err2str(ret)); return 1; } return 0;}
上面的代码为源代码中的一个例子,可以大致看出运行的顺序。
首先注册容器、编码器:
av_register_all();
0 0
- FFmpeg处理过程(代码说明)
- ffmpeg参数说明(转载)
- ffmpeg参数说明(转载)
- 使用ffmpeg转换文件格式,及ffmpeg参数说明(转)
- 伪代码说明Linux进程创建过程
- 伪代码说明Linux进程创建过程
- cgywin编译ffmpeg过程分享(错误处理)版本1.1.1
- Windows消息处理机制--详细代码说明
- jQuery选择器代码详解(五)——实例说明tokenize的解析过程
- ffmpeg编解码详细过程(转)
- ffmpeg编译过程(三)-->编译
- FFmpeg 参数说明
- ffmpeg configure参数说明
- ffmpeg ./configure参数说明
- ffmpeg configure参数说明
- ffmpeg ./configure参数说明
- ffmpeg ./configure参数说明
- ffmpeg ./configure参数说明
- HzhJava框架搭建三:一个基于配置的spring程序
- HQL 查询
- 程序性能优化-深入理解计算机系统
- 黑马程序员----------------------------------------------C语言易忘基础知识点一
- POJ 3723 Conscription (最大生成树)
- FFmpeg处理过程(代码说明)
- 面向对象(成员变量和局部变量)
- Spark MLlib[学习计划]
- Dominating Patterns(Aho_corasick入门)
- java数据引擎(六):高级主题
- TCP握手挥手以及分包发送
- hihoCoder 1136 Professor Q's Software 微软2016校园招聘在线笔试
- 在win7上安装qt/qt creator
- 数据结构之二叉堆(构建堆,堆排序)-(七)