zoukankan      html  css  js  c++  java
  • 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 分配的任何緩衝區) 釋放它。

  • 相关阅读:
    poj-1017 Packets (贪心)
    poj-2393 Yogurt factory (贪心)
    POJ -3190 Stall Reservations (贪心+优先队列)
    hihoCoder 1082然而沼跃鱼早就看穿了一切 (字符串处理)
    kafka:一个分布式消息系统
    Kafka+Storm+HDFS整合实践
    使用Storm实现实时大数据分析
    Kafka使用入门教程 简单介绍
    Zookeeper 的学习与运用
    Kafka 分布式消息队列介绍
  • 原文地址:https://www.cnblogs.com/lidabo/p/15048236.html
Copyright © 2011-2022 走看看