FFmpeg(4)-使用avformat_find_stream_info()來探測獲取封裝格式的上下文信息


 

/**
 * Read packets of a media file to get stream information. This
 * is useful for file formats with no headers such as MPEG. This
 * function also computes the real framerate in case of MPEG-2 repeat
 * frame mode.
 * The logical file position is not changed by this function;
 * examined packets may be buffered for later processing.
 *
 * @param ic media file handle
 * @param options  If non-NULL, an ic.nb_streams long array of pointers to
 *                 dictionaries, where i-th member contains options for
 *                 codec corresponding to i-th stream.
 *                 On return each dictionary will be filled with options that were not found.
 * @return >=0 if OK, AVERROR_xxx on error
 *
 * @note this function isn't guaranteed to open all the codecs, so
 *       options being non-empty at return is a perfectly normal behavior.
 *
 * @todo Let the user decide somehow what information is needed so that
 *       we do not waste time getting stuff the user does not need.
 */
int avformat_find_stream_info(AVFormatContext *ic, AVDictionary **options);

該函數主要用於獲取視頻流信息。

在一些格式當中沒有頭部信息,如flv格式,h264格式,這個時候調用avformat_open_input()在打開文件之后就沒有參數,也就無法獲取到里面的信息。這個時候就可以調用此函數,因為它會試着去探測文件的格式,但是如果格式當中沒有頭部信息,那么它只能獲取到編碼、寬高這些信息,還是無法獲得總時長。如果總時長無法獲取到,則仍需要把整個文件讀一遍,計算一下它的總幀數。

例:

if (avformat_find_stream_info(ic, 0) >=0 ) {
        LOGI("duration is: %lld, nb_stream is: %d", ic->duration, ic->nb_streams);
}

其中的ic就是 AVFormatContext 的指針。

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM