FFmpeg Principle分析Out put File 数据结构

作者:Loken1 时间:2023-02-17 08:26:49 

struct OutputFile

struct OutputFile 是单个输出文件的管理器。之前在 parse_optgroup() 处理好的 OptionsContext o 变量,有一部分字段会赋值给 OutputFile 管理器

如下:

FFmpeg Principle分析Out put File 数据结构

OptionsContext o 变量的另一部分字段,会在 open_output_file() 里面传递给 API 函数,例如:avformat_write_header(),或者赋值给 OutputStream 的一些字段。

ret = avformat_write_header(of->ctx, &of->opts);

output_files 全局变量是一个数组,里面的成员正是 OutputFile,所以你在二次开发 ffmpeg.exe 的时候,可以通过 output_files 全局变量获取到所有的输出文件的信息。

OutputFile   **output_files   = NULL;
int         nb_output_files   = 0;

我们接下来仔细学习一下 struct OutputFile 的结构,如下:

typedef struct OutputFile {
   AVFormatContext *ctx;
   AVDictionary *opts;
   int ost_index;       /* index of the first stream in output_streams */
   int64_t recording_time;  ///< desired length of the resulting file in microseconds == AV_TIME_BASE units
   int64_t start_time;      ///< start time in microseconds == AV_TIME_BASE units
   uint64_t limit_filesize; /* filesize limit expressed in bytes */
   int shortest;
   int header_written;
} OutputFile;

相比 InputFileOutputFile 数据结构的字段简直太少了,读起来太爽了。

struct OutputFile 字段解析

1, AVFormatContext *ctx,容器上下文,也叫容器实例。

2, AVDictionary *opts,容器格式的参数,是从 OptionsContext 里面 的 OptionGroup 的 format_opts 复制过来的,如下:

av_dict_copy(&of->opts, o->g->format_opts, 0);

opts 会传递给 avformat_write_header() 函数,如下:

ret = avformat_write_header(of->ctx, &of->opts);

3, int ost_index,输出文件的第一个流在 output_streams 数组里面的索引,output_streams 数组是一个全局变量,里面包含所有输出文件的所有输出流。你二次开发 ffmpeg.exe 的时候,可以使用 output_streams 数组,获取到所有的输出流。

4, int64_t recording_time,命令行选项 -t 的值,设置输出文件的时长,单位是微秒,具体的功能是通过 trim 滤镜来实现的。

5, int64_t start_time,标记输出文件的开始时间,例如一个输入文件本来是 6 分钟的,你可以用 -ss 120 指定 start_time,这样,输出文件就会裁剪成 第 2 ~ 6分钟 的视频,前面 2 分钟丢弃。

6, uint64_t limit_filesize,限制输出文件的大小,一旦达到这个大小,输出文件立即结束。

7, int shortest,命令行选项 -shortest 的值,当最短的输出流结束的时候,整个文件就结束了,例如一个输出文件里面有 音频流 跟 视频流,视频流 3 分钟,音频流 5 分钟。如果启用了这个选项,音频流就会被裁剪成 3 分钟。

8, int header_written,是否已经调用了 avformat_write_header() 函数,往输出文件写入了头部信息。

来源:https://juejin.cn/post/7159422966650896415

标签:FFmpeg,Principle,OutputFile,数据结构
0
投稿

猜你喜欢

  • Android编程将Activity背景设置为墙纸的简单实现方法

    2022-01-13 14:27:42
  • 一篇文章带你入门Java接口

    2023-11-06 02:07:55
  • Java编程调用微信分享功能示例

    2022-10-16 06:39:49
  • Android实现登录界面记住密码的存储

    2022-11-29 04:55:44
  • C# 根据字符串生成二维码的实例代码

    2023-09-16 09:06:50
  • Java API文档的使用方法详解

    2022-06-15 20:12:03
  • Android编程实现实时监听EditText文本输入的方法

    2023-04-23 02:58:16
  • 浅谈Mybatis之参数传递的几种姿势

    2021-06-20 01:26:54
  • Javaweb获取表单数据的多种方式

    2022-12-25 18:13:41
  • java1.8安装及环境变量配置教程

    2023-04-29 10:36:49
  • C#删除只读文件或文件夹(解决File.Delete无法删除文件)

    2022-06-30 15:01:59
  • Java Validation Api使用方法实例解析

    2023-05-16 05:44:58
  • SpringMVC的执行过程浅析

    2021-05-31 20:51:11
  • Java高级架构之FastDFS分布式文件集群详解

    2023-07-23 14:57:50
  • java 排序算法之快速排序

    2022-07-23 17:39:03
  • IDEA连接Mysql数据库的详细图文教程

    2023-10-09 09:51:24
  • java中文传值乱码问题的解决方法

    2023-11-25 16:26:47
  • Java字符串编码知识点详解介绍

    2023-10-16 09:41:04
  • Android Studio 报错failed to create jvm error code -4的解决方法

    2023-01-22 03:13:49
  • C#实现自定义光标并动态切换

    2021-09-25 09:06:28
  • asp之家 软件编程 m.aspxhome.com