音视频学习 FFmpeg frame的复制和拷贝

深拷贝

连同数据也被复制一份

浅拷贝

只拷贝参数,具有相同的数据指针

相关 api

av_frame_ref()

【函数原型】

/**
 * Set up a new reference to the data described by the source frame.
 *
 * Copy frame properties from src to dst and create a new reference for each
 * AVBufferRef from src.
 *
 * If src is not reference counted, new buffers are allocated and the data is
 * copied.
 *
 * @warning: dst MUST have been either unreferenced with av_frame_unref(dst),
 *           or newly allocated with av_frame_alloc() before calling this
 *           function, or undefined behavior will occur.
 *
 * @return 0 on success, a negative AVERROR on error
 */
  • 将帧属性从 src 复制到 dst,并为 src 中的每个 AVBufferRef 创建一个新引用,即对AVFrame中的uint8_t *data[AV_NUM_DATA_POINTERS]字段引用计数+1。
  • dst 必须在调用此函数之前已被 av_frame_unref(dst) 未引用,或新分配 av_frame_alloc(),否则将发生未定义的行为。(即dst不能是空指针)
  • 返回0表示成功,复数表示失败
av_frame_unref()

【函数原型】

/**
 * Unreference all the buffers referenced by frame and reset the frame fields.
 */
void av_frame_unref(AVFrame *frame);
  • 取消引用帧引用的所有缓冲区并重置帧字段,相当于重新申请的frame。
av_frame_move_ref()

【函数原型】

/**
 * Move everything contained in src to dst and reset src.
 *
 * @warning: dst is not unreferenced, but directly overwritten without reading
 *           or deallocating its contents. Call av_frame_unref(dst) manually
 *           before calling this function to ensure that no memory is leaked.
 */
void av_frame_move_ref(AVFrame *dst, AVFrame *src);
  • 将 src 中包含的所有内容移动到 dst 并重置 src。
  • 相当于 av_frame_ref(dst,src) + av_frame_unref(src)
  • dst 不是未引用的,而是直接覆盖而不读取或释放其内容。 在调用此函数之前手动调用 av_frame_unref(dst) 以确保没有内存泄漏。
av_frame_clone()

【函数原型】

/**
 * Create a new frame that references the same data as src.
 *
 * This is a shortcut for av_frame_alloc()+av_frame_ref().
 *
 * @return newly created AVFrame on success, NULL on error.
 */
AVFrame *av_frame_clone(const AVFrame *src);
  • 创建一个引用与 src 相同数据的新框架。 这是 av_frame_alloc()+av_frame_ref() 的快捷方式。
  • 此时 src 和 dst 相同,并有相同的数据引用,dst不用提前申请
  • return 成功时新创建的 AVFrame*,错误时返回 NULL
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 相同的参数。
  • 此函数仅复制帧数据(即数据扩展数据数组的内容),不复制任何其他属性。
  • return >= 0 成功,负 AVERROR 错误。

.
.
.
.

音视频开发 视频教程:https://ke.qq.com/course/3202131?flowToken=1031864(免费订阅不迷路)
音视频开发学习资料、教学视频,免费分享有需要的可以自行添加学习交流群:739729163领取
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值