将src中所有数据拷贝到dst中,并复位src。
为避免内存泄漏,在调用av_frame_move_ref(dst, src)之前应先调用av_frame_unref(dst) 。
2.7 av_frame_get_buffer()
/**
* Allocate new buffer(s) for audio or video data.
*
* The following fields must be set on frame before calling this function:
* - format (pixel format for video, sample format for audio)
* - width and height for video
* - nb_samples and channel_layout for audio
*
* This function will fill AVFrame.data and AVFrame.buf arrays and, if
* necessary, allocate and fill AVFrame.extended_data and AVFrame.extended_buf.
* For planar formats, one buffer will be allocated for each plane.
*
* @warning: if frame already has been allocated, calling this function will
*
leak memory. In addition, undefined behavior can occur in certain
*
cases.
*
* @param frame frame in which to store the new buffers.
* @param align Required buffer size alignment. If equal to 0, alignment will be
*
chosen automatically for the current CPU. It is highly
*
recommended to pass 0 here unless you know what you are doing.
*
* @return 0 on success, a negative AVERROR on error.
*/
int av_frame_get_buffer(AVFrame *frame, int align);
为音频或视频数据分配新的缓冲区。
调用本函数前,帧中的如下成员必须先设置好:
format (视频像素格式或音频采样格式)
width、height(视频画面和宽和高)
nb_samples、channel_layout(音频单个声道中的采样点数目和声道布局)
本函数会填充AVFrame.data和AVFrame.buf数组,如果有需要,还会分配和填充AVFrame.extended_data和AVFrame.extended_buf。
对于planar格式,会为每个plane分配一个缓冲区。
2.8 av_frame_copy()
/**
* Copy the frame data from src to dst.
*
* This function does not allocate anything, dst must be already initialized and
* allocated with the same parameters as src.
*
* This function only copies the frame data (i.e. the contents of the data /
* extended data arrays), not any other properties.
*
* @return >= 0 on success, a negative AVERROR on error.
*/
int av_frame_copy(AVFrame *dst, const AVFrame *src);
将src中的帧数据拷贝到dst中。
本函数并不会有任何分配缓冲区的动作,调用此函数前dst必须已经使用了和src同样的参数完成了初始化。
本函数只拷贝帧中的数据缓冲区的内容(data/extended_data数组中的内容),而不涉及帧中任何其他的属性。
3. 参考资料
[1] FFMPEG结构体分析:AVFrame, https://blog.csdn.net/leixiaohua1020/article/details/14214577
4. 修改记录
2019-01-13 V1.0 初稿