首页 > 其他分享 >FFmpeg学习:frame的复制和拷贝

FFmpeg学习:frame的复制和拷贝

时间:2022-08-15 10:15:28浏览次数:37  
标签:src FFmpeg frame av 拷贝 AVFrame data dst

实践中经常遇到 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
 */
int av_frame_ref(AVFrame *dst, const AVFrame *src);
  • 将帧属性从 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 错误。

标签:src,FFmpeg,frame,av,拷贝,AVFrame,data,dst
From: https://www.cnblogs.com/zjacky/p/16587147.html

相关文章

  • ffmpeg以RTP协议推送视频
    docker编译环境dockerpullabdulachik/ffmpeg.js:latestdockerrun-it-p8080:8080-v/Users/workspace/Downloads/ffmpeg_wasm:/tmp--privileged=trueabdulachik/......
  • 浏览器运行ffmpeg
    docker编译环境docker镜像dockerpullabdulachik/ffmpeg.js:latestdockerrun-it-p8090:8090-v/Users/workspace/Downloads/ffmpeg_wasm:/tmp--privileged=true......
  • 利用ffmpeg合并音频和视频
    一、当视频文件中没有音频时将audioname音频与videoname视频替换ffmpeg-ivideoname.mp4-imusic.mp3-c:vcopy-c:aaac-strictexperimentaloutputname.mp4二、当......
  • ffmpeg截取视频的片段
    1、执行如下命令:ffmpeg-ss00:00:00-to00:05:23-iimput.mp4-y-fmp4-vcodeccopy-acodeccopy-q:v1output.mp42、参数说明:-ss指定要截取的视频的起始时间。......
  • Django-rest-framework开发api接口
    django-rest-framework开发api接口(1)创建django项目drfdemo1并且创建一个名为app的应用django-adminstartprojectdrfdemo1pythonmanage.pystartappapp(2)安......
  • django restframework 后端接口权限
    REST_FRAMEWORK={'EXCEPTION_HANDLER':'djangoProject.utils.exception.custom_exception_handler',#在不需要权限就能访问的视图设置permissions_classes......
  • 拷贝构造函数
    c++中的拷贝构造函数调用时机通常有三种情况1.使用一个已经创建完毕的对象来初始化一个新的对象2.值传递的方式给函数参数传值3.以值方式返回局部对象//情况1classP......
  • VS2010 + Mysql5.7 使用ADO.Net Entity Framework
        系统很LOW,不想花太多时间来升级,可想做点什么,总是这也不行那也不行,更种安装要不就是vs版本太低,要不不支持低版本的mysql,调试起来很费时。用老版办法写代码又太费......
  • 简述 Python 的深浅拷贝以及应用场景
    简述Python的深浅拷贝以及应用场景导入模块:importcopy浅拷贝:copy.copy深拷贝:copy.deepcopy浅拷贝指仅仅拷贝数据集合的第一层数据,深拷贝指拷贝数据集合的所有层。所......
  • 使用网关Zuul的时候,报java.lang.NoSuchMethodError: org.springframework.boot.web.s
    最近遇到一个困扰了我很久的问题(关于Zuul):报错界面如下:  原因是因为:Zuul与SpringBoot版本冲突,而SpringCloud又和SpringBoot版本关联,SpringCloud与SpringBoot......