zoukankan      html  css  js  c++  java
  • ffmpeg 使用小结

    1.第一种
    
            m_pFrameVideoOut = av_frame_alloc();
            m_pFrameVideoOut->format = AV_PIX_FMT_BGR24;
            m_pFrameVideoOut->width = m_VideoCodecCtx->width;
            m_pFrameVideoOut->height = m_VideoCodecCtx->height;
            if (av_image_alloc(m_pFrameVideoOut->data, m_pFrameVideoOut->linesize, m_pFrameVideoOut->width, m_pFrameVideoOut->height, AV_PIX_FMT_BGR24, 16) < 0)
            {
                return ;
            }
    
    2.第二种
    
            m_pFrameVideoOut = av_frame_alloc();
            m_pFrameVideoOut->format = AV_PIX_FMT_BGR24;
            m_pFrameVideoOut->width = m_VideoCodecCtx->width;
            m_pFrameVideoOut->height = m_VideoCodecCtx->height;
            av_frame_get_buffer(m_pFrameVideoOut, 16);
    
     
    
    3.第三种
    
        int bufferSize = av_image_get_buffer_size(AV_PIX_FMT_YUV420P, nWidth, nHeight, 1);;
        m_InputFrame = av_frame_alloc();
        m_InputFrame->width = nWidth;
        m_InputFrame->height = nHeight;
        m_InputFrame->format = AV_PIX_FMT_YUV420P;
        m_Buffer = (unsigned char *)av_malloc(bufferSize);
        av_image_fill_arrays(m_InputFrame->data, m_InputFrame->linesize, m_Buffer, AV_PIX_FMT_YUV420P, nWidth, nHeight, 1);
    ————————————————
    版权声明:本文为CSDN博主「小小的熊OnlyOne」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
    原文链接:https://blog.csdn.net/xionglifei2014/article/details/90693048
    

     以上是avframe的申请方式,在项目中用的是第三种,而且收到的数据是有内存的,就不用av_malloc空间了。fill_array就是直接把指针指一下而已;

    现在遇到的问题:

    收到流后解封装-解码-进滤镜模块-...卡在给视频加一个水印,水印模块分为三个text-picture & qrcode,这三个用的相同的init-filter和destroy函数。

    现象是text水印可以添加上。但是picture和qrcode 添加不上,其实添加不上的就是图片。qrcode就是给一个串,生成一个图片,然后显示。

    大方向认为是init函数有问题,可能是init的时候movie参数啥的需要特殊处理?不晓得原因,且正在排查中。

    望早日排查出来,写结尾。

    ----------------------------------------------------------------------------

    现在来补充结尾,经过N次检查、测试和debug,猜想是av_image_fill_arrays函数的问题。

    然后用个从flv文件拿出来frame加图片水印的例子来修改,修改过程如下:

    从文件中取出来frame后,用av_image_copy_to_buffer函数把数据拷贝到buf中,

    然后再把buf中的数据通过av_image_fill_arrays函数填充tmp_frame;

    给tmp_frame加水印。

    结果是没有给tmp_frame加上水印。证明这样得到的frame是没法加上水印的。

    接下来用函数 av_frame_ref(AVFrame *dst, AVFrame *src);填充dst,然后发现这样是可以加上水印的。

    然后就是gdb对比dst和tmp_frame的区别。发现了有十几个结构体参数不一样。

    没办法,一个个试。

    Finally,发现了frame->pts对图片水印能不能加上起到了决定性作用!

    static int pts=0;

    frame->pts=++pts;

    最终解决了视频水印加不上的问题!

  • 相关阅读:
    Innodb存储引擎
    Innodb学习之MySQL体系结构
    C# sql查询数据库返回单个值方法
    Welcome To SWPUNC-ACM
    P2184 贪婪大陆 题解
    线上Java调优-Arthas入门
    JVM调优学习笔记
    RabbitMQ博文收藏
    System.Net.WebException: 远程服务器返回错误: (405) 不允许的方法。
    随机过程-Brown运动
  • 原文地址:https://www.cnblogs.com/micoblog/p/12797399.html
Copyright © 2011-2022 走看看