日本免费高清视频-国产福利视频导航-黄色在线播放国产-天天操天天操天天操天天操|www.shdianci.com

學無先后,達者為師

網站首頁 編程語言 正文

FFmpeg?Principle分析Out?put?File?數據結構_Android

作者:Loken1 ? 更新時間: 2022-12-03 編程語言

struct OutputFile

struct OutputFile?是單個輸出文件的管理器。之前在?parse_optgroup()?處理好的?OptionsContext o?變量,有一部分字段會賦值給?OutputFile?管理器

如下:

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

欄目分類
最近更新