FFMPEG 接口
1.打開輸入流
avformat_open_input()
| int?avformat_open_input | ( | AVFormatContext?**? | ps, |
| const char *? | url, | ||
| const?AVInputFormat?*? | fmt, | ||
| AVDictionary?**? | options? | ||
| ) |
Open an input stream and read the header.
打開輸入流, 讀取header, 并分配format 上下文 (allocate format context),具體參見AVFormatContext 結(jié)構(gòu)體
The codecs are not opened. The stream must be closed with?avformat_close_input().
Parameters
| ps | Pointer to user-supplied?AVFormatContext?(allocated by avformat_alloc_context). May be a pointer to NULL, in which case an?AVFormatContext?is allocated by this function and written into ps. Note that a user-supplied?AVFormatContext?will be freed on failure. |
| url | URL of the stream to open. |
| fmt | If non-NULL, this parameter forces a specific input format. Otherwise the format is autodetected. |
| options | A dictionary filled with?AVFormatContext?and demuxer-private options. On return this parameter will be destroyed and replaced with a dict containing options that were not found. May be NULL. |
Returns
0 on success, a negative AVERROR on failure.
Note
If you want to use custom IO, preallocate the format context and set its pb field.
2.? 檢索流信息
avformat_find_stream_info()
| int?avformat_find_stream_info | ( | AVFormatContext?*? | ic, |
| AVDictionary?**? | options? | ||
| ) |
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.
Parameters
| ic | media file handle |
| 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. |
Returns
>=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.
3.?
open_codec_context()
|
4.?創(chuàng)建用于存放解碼視頻幀的image
av_image_alloc()
| int?av_image_alloc | ( | uint8_t *? | pointers[4], |
| int | linesizes[4], | ||
| int | w, | ||
| int | h, | ||
| enum?AVPixelFormat? | pix_fmt, | ||
| int | align? | ||
| ) |
Allocate an image with size w and h and pixel format pix_fmt, and fill pointers and linesizes accordingly.
The allocated image buffer has to be freed by using?av_freep(&pointers[0]).
Parameters
| align | the value to use for buffer size alignment |
Returns
the size in bytes required for the image buffer, a negative error code in case of failure
5.?
av_image_copy av_image_copy()void av_image_copy ( uint8_t * dst_data[4],int dst_linesizes[4],const uint8_t * src_data[4],const int src_linesizes[4],enum AVPixelFormat pix_fmt,int width,int height ) Copy image in src_data to dst_data.Parameters dst_linesizes linesizes for the image in dst_data src_linesizes linesizes for the image in src_data6.?
av_sample_fmt_is_planar()
| int?av_sample_fmt_is_planar | ( | enum?AVSampleFormat? | sample_fmt | ) |
Check if the sample format is planar.
Parameters
| sample_fmt | the sample format to inspect |
Returns
1 if the sample format is planar, 0 if it is interleaved
7.?傳入planar類型的采樣格式,返回其可轉(zhuǎn)換的packed類型的采樣格式。例如傳入?AV_SAMPLE_FMT_S32P,其返回值為?AV_SAMPLE_FMT_S32。
av_get_packed_sample_fmt()
| enum?AVSampleFormat?av_get_packed_sample_fmt | ( | enum?AVSampleFormat? | sample_fmt | ) |
Get the packed alternative form of the given sample format.
If the passed sample_fmt is already in packed format, the format returned is the same as the input.
Returns
the packed alternative form of the given sample format or AV_SAMPLE_FMT_NONE on error.
ffmpeg 音頻存儲格式:
packed:多個聲道數(shù)據(jù)交錯存放,所有聲道的數(shù)據(jù)交錯排放在frame->data[0](即frame->extended_data[0])地址處,數(shù)據(jù)長度為linesize[0](單位:字節(jié))
planar:每個聲道數(shù)據(jù)單獨存放,聲道0的起始地址為 frame->data[0](或frame->extended_data[0]),聲道1的起始地址為 frame->data[1](或frame->extended_data[1]) . . . 每個聲道的數(shù)據(jù)長度都為linesize[0](單位:字節(jié))
判斷是否是 planar類型:av_sample_fmt_is_planar(sample_fmt)
FFmpeg音頻解碼后的數(shù)據(jù)是存放在AVFrame結(jié)構(gòu)中的。
1)Packed格式,frame.data[0]或frame.extended_data[0]包含所有的音頻數(shù)據(jù)中。
2)Planar格式,frame.data[i]或者frame.extended_data[i]表示第i個聲道的數(shù)據(jù)(假設(shè)聲道0是第一個), AVFrame.data數(shù)組大小固定為8,如果聲道數(shù)超過8,需要從frame.extended_data獲取聲道數(shù)據(jù)。
參考:FFmpeg: Image related
總結(jié)
- 上一篇: 2021博客之星,请帮忙投上宝贵一票
- 下一篇: YUV 之解读