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

學(xué)無先后,達(dá)者為師

網(wǎng)站首頁 編程語言 正文

FFmpeg?Principle分析Out?put?File?數(shù)據(jù)結(jié)構(gòu)_Android

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

struct OutputFile

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

如下:

OptionsContext o?變量的另一部分字段,會在?open_output_file()?里面?zhèn)鬟f給 API 函數(shù),例如:avformat_write_header(),或者賦值給?OutputStream?的一些字段。

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

output_files?全局變量是一個(gè)數(shù)組,里面的成員正是?OutputFile,所以你在二次開發(fā)?ffmpeg.exe?的時(shí)候,可以通過?output_files?全局變量獲取到所有的輸出文件的信息。

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

我們接下來仔細(xì)學(xué)習(xí)一下?struct OutputFile?的結(jié)構(gòu),如下:

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?數(shù)據(jù)結(jié)構(gòu)的字段簡直太少了,讀起來太爽了。

struct OutputFile?字段解析

1, AVFormatContext *ctx,容器上下文,也叫容器實(shí)例。

2, AVDictionary *opts,容器格式的參數(shù),是從?OptionsContext?里面 的?OptionGroup?的?format_opts?復(fù)制過來的,如下:

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

opts?會傳遞給?avformat_write_header()?函數(shù),如下:

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

3, int ost_index,輸出文件的第一個(gè)流在?output_streams?數(shù)組里面的索引,output_streams?數(shù)組是一個(gè)全局變量,里面包含所有輸出文件的所有輸出流。你二次開發(fā)?ffmpeg.exe?的時(shí)候,可以使用?output_streams?數(shù)組,獲取到所有的輸出流。

4, int64_t recording_time,命令行選項(xiàng)?-t?的值,設(shè)置輸出文件的時(shí)長,單位是微秒,具體的功能是通過?trim?濾鏡來實(shí)現(xiàn)的。

5, int64_t start_time,標(biāo)記輸出文件的開始時(shí)間,例如一個(gè)輸入文件本來是 6 分鐘的,你可以用?-ss 120?指定?start_time,這樣,輸出文件就會裁剪成 第 2 ~ 6分鐘 的視頻,前面 2 分鐘丟棄。

6, uint64_t limit_filesize,限制輸出文件的大小,一旦達(dá)到這個(gè)大小,輸出文件立即結(jié)束。

7, int shortest,命令行選項(xiàng)?-shortest?的值,當(dāng)最短的輸出流結(jié)束的時(shí)候,整個(gè)文件就結(jié)束了,例如一個(gè)輸出文件里面有 音頻流 跟 視頻流,視頻流 3 分鐘,音頻流 5 分鐘。如果啟用了這個(gè)選項(xiàng),音頻流就會被裁剪成 3 分鐘。

8, int header_written,是否已經(jīng)調(diào)用了?avformat_write_header()?函數(shù),往輸出文件寫入了頭部信息。

原文鏈接:https://juejin.cn/post/7159422966650896415

欄目分類
最近更新