InputStream數(shù)據(jù)結(jié)構(gòu)示例解析
正文
struct InputStream 是單個輸入流的管理器。是由 add_input_stream() 函數(shù)申請內(nèi)存,以及賦值 InputStream 的各個字段的。
而 input_streams 數(shù)組是一個全局變量,包含了所有輸入文件里面的所有輸入流。
nputStream **input_streams = NULL; int nb_input_streams = 0;
你在二次開發(fā) ffmpeg.exe 的時候,可以用 input_streams 全局變量來獲取到所有的輸入流。
struct InputStream數(shù)據(jù)結(jié)構(gòu)定義
typedef struct InputStream {
int file_index;
AVStream *st;
int discard; /* true if stream data should be discarded */
int user_set_discard;
int decoding_needed; /* non zero if the packets must be decoded in 'raw_fifo', see DECODING_FOR_* */
#define DECODING_FOR_OST 1
#define DECODING_FOR_FILTER 2
AVCodecContext *dec_ctx;
const AVCodec *dec;
AVFrame *decoded_frame;
AVFrame *filter_frame; /* a ref of decoded_frame, to be sent to filters */
AVPacket *pkt;
int64_t start; /* time when read started */
/* predicted dts of the next packet read for this stream or (when there are
* several frames in a packet) of the next frame in current packet (in AV_TIME_BASE units) */
int64_t next_dts;
int64_t dts; ///< dts of the last packet read for this stream (in AV_TIME_BASE units)
int64_t next_pts; ///< synthetic pts for the next decode frame (in AV_TIME_BASE units)
int64_t pts; ///< current pts of the decoded frame (in AV_TIME_BASE units)
int wrap_correction_done;
int64_t filter_in_rescale_delta_last;
int64_t min_pts; /* pts with the smallest value in a current stream */
int64_t max_pts; /* pts with the higher value in a current stream */
// when forcing constant input framerate through -r,
// this contains the pts that will be given to the next decoded frame
int64_t cfr_next_pts;
int64_t nb_samples; /* number of samples in the last decoded audio frame before looping */
double ts_scale;
int saw_first_ts;
AVDictionary *decoder_opts;
AVRational framerate; /* framerate forced with -r */
int top_field_first;
int guess_layout_max;
int autorotate;
...省略字幕相關(guān)字段...
int dr1;
/* decoded data from this stream goes into all those filters
* currently video and audio only */
InputFilter **filters;
int nb_filters;
int reinit_filters;
/* hwaccel options */
...省略硬件解碼相關(guān)字段...
/* hwaccel context */
...省略硬件解碼相關(guān)字段...
/* stats */
// combined size of all the packets read
uint64_t data_size;
/* number of packets successfully read for this stream */
uint64_t nb_packets;
// number of frames/samples retrieved from the decoder
uint64_t frames_decoded;
uint64_t samples_decoded;
int64_t *dts_buffer;
int nb_dts_buffer;
int got_output;
} InputStream;
各個字段的解析
(省略了字幕相關(guān)的字段):
1, int file_index,input_files 數(shù)組里面的下標,代表 InputStream 對應(yīng)的 InputFile。
2, AVStream *st,AVFormatContext 里面的 AVStream 。
3, int discard,如果是 1 會丟棄讀取到的 AVPacket,剛開始的時候都是 1。例如文件里面有多個視頻流,會全部都把 discard 設(shè)置為 1,然后再從中選出質(zhì)量最好的視頻流,把它的 discard 設(shè)置為 0 。
或者當(dāng)輸出流需要這個輸入流的時候,也會置為 0 ,如下:
if (source_index >= 0) {
ost->sync_ist = input_streams[source_index];
input_streams[source_index]->discard = 0;
input_streams[source_index]->st->discard = input_streams[source_index]->user_set_discard;
}
因此,如果你用 ffmpeg.exe 對一個有多個視頻流的文件進行轉(zhuǎn)換,默認只會輸出一個視頻流。
4, int user_set_discard,命令行選項 -discard 的值,默認是 AVDISCARD_NONE,可選的值在 AVDiscard 枚舉里面。
enum AVDiscard{
/* We leave some space between them for extensions (drop some
* keyframes for intra-only or drop just some bidir frames). */
AVDISCARD_NONE =-16, ///< discard nothing
AVDISCARD_DEFAULT = 0, ///< discard useless packets like 0 size packets in avi
AVDISCARD_NONREF = 8, ///< discard all non reference
AVDISCARD_BIDIR = 16, ///< discard all bidirectional frames
AVDISCARD_NONINTRA= 24, ///< discard all non intra frames
AVDISCARD_NONKEY = 32, ///< discard all frames except keyframes
AVDISCARD_ALL = 48, ///< discard all
};
5, int decoding_needed,大于 0 代表輸入流需要進行解碼操作,有兩個值,DECODING_FOR_OST ,DECODING_FOR_FILTER
6, AVCodecContext *dec_ctx,解碼器上下文/解碼器實例,輸入流的 AVPacket 會丟給解碼實例進行解碼。
7, const AVCodec *dec,解碼器信息
8, AVFrame *decoded_frame,從解碼器上下文 解碼出來的 AVFrame
9, AVFrame *filter_frame,這個字段主要是用來增加引用計數(shù)的,可能在調(diào)用 av_buffersrc_add_frame_flags() 之后,AVFrame 的引用技術(shù)會減一,所以需要先復(fù)制一份引用,如下:

10, AVPacket *pkt,從 av_read_frame() 里面讀出來的 AVPacket,只是復(fù)制了一下引用。

11, int64_t start,記錄此流是什么時候開始處理的,主要是給 -re 選項使用的,模擬幀率速度,錄制視頻模擬直播用的。
12, int64_t next_dts,下一幀的 解碼時間,這是通過計算得到的預(yù)估值,如果讀取出來的 AVPacket 沒有 dts ,會用這個值代替。
13, int64_t dts,最近一次從 av_read_frame() 讀出來的 AVPacket 的 dts
14, int64_t next_pts,下一個 AVFrame 的 pts,通過當(dāng)前 AVFrame 的 pts 加上 duration 計算出來的,應(yīng)該是給一些沒有 pts 值的 AVFrame 用的。
15, int64_t pts,最近一次從解碼器里面解碼出來的 AVFrame 的 pts,記錄這個值主要是給 send_filter_eof() 用的,防止回滾。

15, int64_t wrap_correction_done,在一些流格式,例如 TS,會有時間戳環(huán)回的問題,int64 是有大小限制的,超過這個大小會環(huán)回,ffmpeg.exe 需要處理環(huán)回的邏輯。
16, int64_t filter_in_rescale_delta_last,專門給音頻幀轉(zhuǎn)換時間基用的,因為音頻的連續(xù)性太強,如果有些許誤差需要保存下來,在下次轉(zhuǎn)換的時候進行補償。

17, int64_t min_pts, 從 av_read_frame() 讀出來的 AVPacket 的最小 pts ,不一定是第一幀的 pts,因為命令行參數(shù)通過 -ss 選項,指定從哪里開始處理。
18, int64_t max_pts,從 av_read_frame() 讀出來的 AVPacket 的最大 pts ,不一定是最后一幀的 pts,因為命令行參數(shù)通過 -t 選項,指定只處理多久的時長。
19, int64_t cfr_next_pts,給 -r 選項用的。
20, int64_t nb_samples,記錄的是最近一次解碼出來的 AVFrame 里面的 nb_samples。用途我也不清楚,后面補充。
21, double ts_scale,默認值是 1.0,可通過命令行選項 -itsscale 進行改變,主要作用是將 pts ,dts 進行放大,放大的方法是乘以 ts_scale。
22, int saw_first_ts,標記是不是已經(jīng)讀取到屬于該流的第一個 AVPacket
23, AVDictionary *decoder_opts,從 OptionsContext 里面轉(zhuǎn)移過來的解碼器參數(shù)。

24, AVRational framerate,命令行選項 -r 的值。
25, int top_field_first,命令行選項 -top 的值,好像是給隔行掃描視頻用的。
26, int guess_layout_max,命令行選項 -guess_layout_max 的值,猜測的最大的聲道布局。
27, int autorotate,命令行選項 -autorotate 的值,是否插入糾正旋轉(zhuǎn)的 filter 濾鏡,有些視頻的畫面中途會上下旋轉(zhuǎn),設(shè)置這個選項可以自動糾正旋轉(zhuǎn),不會上下顛倒。
28, int dr1,用 Find Useage 找不到使用這個字段的代碼,所以是沒用的字段。
29, InputFilter **filters 跟 int nb_filters,輸入流綁定的 入口濾鏡,可以是綁定多個入口濾鏡的,輸入流解碼出來的 AVFrame 會往多個入口濾鏡發(fā)送。
30, int reinit_filters,命令行選項 -reinit_filter 的值,0 代表輸入信息如果產(chǎn)生變化也不重新初始化 FilterGraph,輸入信息產(chǎn)生變化是指 解碼出來的 AVFrame 的寬高中途變大或者變小之類的。reinit_filters 默認是 -1,就是會重新初始化 FilterGraph。
下面這些都是統(tǒng)計相關(guān)的字段。
31, uint64_t data_size,從 av_read_frame() 讀出來的 AVPacket 的 size 的總和。也就是統(tǒng)計當(dāng)前流一共讀出出來了多少字節(jié)的數(shù)據(jù)。
32, uint64_t nb_packets,從 av_read_frame() 讀出來的 AVPacket 數(shù)量的總和。
33, uint64_t frames_decoded,uint64_t samples_decoded,從解碼器解碼出來的 AVFrame 的數(shù)量。
34, int64_t *dts_buffer,int nb_dts_buffer,我沒看懂這兩個字段干什么的,可能是舊代碼沒有刪除。
35, int got_output,只要解碼器已經(jīng)解碼出一幀 AVFrame,這個字段就會置為 1。
以上就是InputStream數(shù)據(jù)結(jié)構(gòu)示例解析的詳細內(nèi)容,更多關(guān)于InputStream 數(shù)據(jù)結(jié)構(gòu)的資料請關(guān)注腳本之家其它相關(guān)文章!
相關(guān)文章
java創(chuàng)建線程池的7種實現(xiàn)方法
在Java中線程池是一種管理線程的機制,它可以創(chuàng)建一組線程并重復(fù)使用它們,避免了創(chuàng)建和銷毀線程的開銷,這篇文章主要給大家介紹了關(guān)于java創(chuàng)建線程池的7種實現(xiàn)方法,需要的朋友可以參考下2023-10-10
Java實現(xiàn)公用實體類轉(zhuǎn)Tree結(jié)構(gòu)
這篇文章主要為大家介紹了一個Java工具類,可以實現(xiàn)Java公用實體類轉(zhuǎn)Tree結(jié)構(gòu),文中的示例代碼簡潔易懂,感興趣的小伙伴可以參考一下2024-10-10
JAVA8 stream中三個參數(shù)的reduce方法對List進行分組統(tǒng)計操作
這篇文章主要介紹了JAVA8 stream中三個參數(shù)的reduce方法對List進行分組統(tǒng)計操作,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2020-08-08

