【Android FFMPEG 开发】FFMPEG 获取 AVStream 音视频流 ( AVFormatContext 结构体 | 获取音视频流信息 | 获取音视频流个数 | 获取音视频流 )
文章目錄
- 博客簡介 . FFMPEG 音視頻流 獲取流程
- I . FFMPEG 獲取音視頻流信息 ( AVFormatContext 結構體 )
- II . FFMPEG 獲取 音視頻流 數量
- III . FFMPEG 獲取音視頻流
博客簡介 . FFMPEG 音視頻流 獲取流程
FFMPEG 音視頻流 AVStream ( 結構體 ) 獲取流程 :
① 獲取音視頻流信息 : avformat_find_stream_info ( ) , 在 【Android FFMPEG 開發】FFMPEG 初始化 ( 網絡初始化 | 打開音視頻 | 查找音視頻流 ) 博客中 , FFMPEG 初始化完畢后 , 獲取了音視頻流 , 本博客中講解獲取該音視頻流對應的編解碼器 , 從獲取該音視頻流開始 ;
int avformat_find_stream_info(AVFormatContext *ic, AVDictionary **options);② 音視頻流數量 : 獲取的音視頻流信息存儲在 AVFormatContext *formatContext 結構體中 , nb_streams 元素的值就是音視頻流的個數 ;
//音視頻流的個數 formatContext->nb_streams③ 音視頻流 : AVFormatContext *formatContext 結構體中的 音視頻流數組元素 AVStream **streams 元素 , 通過數組下標可以獲取指定位置索引的音視頻流 ;
//取出一個媒體流 ( 視頻流 / 音頻流 ) AVStream *stream = formatContext->streams[i];I . FFMPEG 獲取音視頻流信息 ( AVFormatContext 結構體 )
1 . 獲取音視頻流信息 : avformat_find_stream_info ( ) , 在 【Android FFMPEG 開發】FFMPEG 初始化 ( 網絡初始化 | 打開音視頻 | 查找音視頻流 ) 博客中 , FFMPEG 初始化完畢后 , 獲取了音視頻流 , 本博客中講解獲取該音視頻流對應的編解碼器 , 從獲取該音視頻流開始 ;
2 . 信息存放載體 : 調用 avformat_find_stream_info ( ) 方法 , 獲取音視頻流信息存儲在 AVFormatContext *formatContext 結構體中 ; 可以通過 formatContext->結構體元素 獲取相應的 FFMPEG 數據 ;
II . FFMPEG 獲取 音視頻流 數量
1 . 結構體元素 : 音視頻流數量信息存儲在 AVFormatContext *formatContext 結構體中 的 unsigned int nb_streams 元素中 ;
/*** Number of elements in AVFormatContext.streams.** Set by avformat_new_stream(), must not be modified by any other code.*/ unsigned int nb_streams;2 . 獲取示例 : 調用 AVFormatContext *formatContext 結構體指針的 “->” 運算符獲取其結構體中的元素值 ;
//stream_count 是音視頻流數量 int stream_count = formatContext->nb_streams;III . FFMPEG 獲取音視頻流
1 . 音視頻流結構體 AVStream : 音視頻流在 FFMPEG 中被定義成了結構體 , typedef struct AVStream , 該結構體定義在了 avformat.h 中 ;
/*** Stream structure.* New fields can be added to the end with minor version bumps.* Removal, reordering and changes to existing fields require a major* version bump.* sizeof(AVStream) must not be used outside libav*.*/ typedef struct AVStream {... } AVStream2 . 結構體元素 : 音視頻流結構體 AVStream 存儲在 AVFormatContext *formatContext 結構體中 的 AVStream **streams 元素中 , 這是一個 AVStream 結構體指針數組 ;
/*** A list of all streams in the file. New streams are created with* avformat_new_stream().** - demuxing: streams are created by libavformat in avformat_open_input().* If AVFMTCTX_NOHEADER is set in ctx_flags, then new streams may also* appear in av_read_frame().* - muxing: streams are created by the user before avformat_write_header().** Freed by libavformat in avformat_free_context().*/ AVStream **streams;2 . 使用 AVStream ** 數組下標獲取音視頻流 :
① 獲取 AVStream **streams 數組 : 調用 AVFormatContext *formatContext 結構體指針的 “->” 運算符獲取其結構體中的 AVStream **streams 元素值 ;
② 獲取 AVStream *stream 音視頻流 : 再使用數組下標獲取指定索引的 AVStream * 音視頻流 ;
③ 常用使用場景 : 一般是在 for 循環中遍歷解析音視頻流 ;
//formatContext->nb_streams 是 音頻流 / 視頻流 個數 ; // 循環解析 視頻流 / 音頻流 , 一般是兩個 , 一個視頻流 , 一個音頻流 for(int i = 0; i < formatContext->nb_streams; i ++){//取出一個媒體流 ( 視頻流 / 音頻流 )AVStream *stream = formatContext->streams[i];}總結
以上是生活随笔為你收集整理的【Android FFMPEG 开发】FFMPEG 获取 AVStream 音视频流 ( AVFormatContext 结构体 | 获取音视频流信息 | 获取音视频流个数 | 获取音视频流 )的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 【Android FFMPEG 开发】F
- 下一篇: 【Android FFMPEG 开发】F