• ffmpeg


    VFrame可以被解釋為一個AVPicture來填充 data 和 linesize 欄位。 填充這些欄位最簡單的方法是使用 avpicture_fill 函數。

    要填充AVFrame和V 緩衝區的Y,它取決於輸入數據和想要使用框架( 要寫入 AVFrame ) 。 或者保留副本) 。

    如果緩衝區足夠大( 至少為 linesize[0] * height 數據,則為), linesize[1 or 2] * height/2 對於u/v 數據,可以直接使用輸入緩衝區:

    
    //Initialize the AVFrame
    
    
    AVFrame* frame = avcodec_alloc_frame();
    
    
    frame->width = width;
    
    
    frame->height = height;
    
    
    frame->format = AV_PIX_FMT_YUV420P;
    
    
    
    //Initialize frame->linesize
    
    
    avpicture_fill((AVPicture*)frame, NULL, frame->format, frame->width, frame->height);
    
    
    
    //Set frame->data pointers manually
    
    
    frame->data[0] = inputBufferY;
    
    
    frame->data[1] = inputBufferU;
    
    
    frame->data[2] = inputBufferV;
    
    
    
    //Or if your Y, U, V buffers are contiguous and have the correct size, simply use:
    
    
    //avpicture_fill((AVPicture*)frame, inputBufferYUV, frame->format, frame->width, frame->height);
    
    
    
    

    如果需要操作輸入數據,則需要計算所需的緩衝區大小,並在其中複製輸入數據。

    
    //Initialize the AVFrame
    
    
    AVFrame* frame = avcodec_alloc_frame();
    
    
    frame->width = width;
    
    
    frame->height = height;
    
    
    frame->format = AV_PIX_FMT_YUV420P;
    
    
    
    //Allocate a buffer large enough for all data
    
    
    int size = avpicture_get_size(frame->format, frame->width, frame->height);
    
    
    uint8_t* buffer = (uint8_t*)av_malloc(size);
    
    
    
    //Initialize frame->linesize and frame->data pointers
    
    
    avpicture_fill((AVPicture*)frame, buffer, frame->format, frame->width, frame->height);
    
    
    
    //Copy data from the 3 input buffers
    
    
    memcpy(frame->data[0], inputBufferY, frame->linesize[0] * frame->height);
    
    
    memcpy(frame->data[1], inputBufferU, frame->linesize[1] * frame->height/2);
    
    
    memcpy(frame->data[2], inputBufferV, frame->linesize[2] * frame->height/2);
    
    
    
    

    完成AVFrame之後,不要忘了用 av_frame_free ( 以及 av_malloc 分配的任何緩衝區) 釋放它。

  • 相关阅读:
    让超链接点击后不跳转,可以用href = "#",但是这个#就会锚点到页面最上边 点击链接后不跳转可以设置成
    js 小数取整的函数
    谷歌浏览器常用快捷键
    Vi问题
    UbuntuFAQ
    Ubuntu下配置C/C++开发环境
    win7硬盘安装ubuntu双系统——注意项
    怎样判断自己是否在平庸者之列?
    2012年软件开发者薪资调查报告
    VIM常用快捷键~网页上查找
  • 原文地址:https://www.cnblogs.com/lidabo/p/15048236.html
Copyright © 2020-2023  润新知