swscaler@0dd9e620:已弃用的像素格式,请确保您正确设置了范围”

2024-04-13

我正在使用 FFMpeg 解码 RTSP 视频流。 在显示时间(调用cv::imshow(...)),我得到以下异常:

[swscaler @ 0d55e5c0] 已弃用像素格式,请确保您这样做了 正确设置范围

我正在将像素格式从“AV_PIX_FMT_YUVJ420P”转换为“AV_PIX_FMT_YUV420P”。仍然出现上述异常。任何帮助表示赞赏;

int Decodestream()
{
    av_register_all();
    avdevice_register_all();
    avcodec_register_all();
    avformat_network_init();

    const char  *filenameSrc = "rtsp://192.168.1.67/gnz_media/second";

    AVCodecContext  *pCodecCtx;
    AVFormatContext *pFormatCtx = avformat_alloc_context();

    AVCodec * pCodec;
    AVFrame *pFrame, *pFrameRGB;

    if(avformat_open_input(&pFormatCtx,filenameSrc,NULL,NULL) != 0)
    {return -1;}

    if(av_find_stream_info(pFormatCtx) < 0)   
    {return -1;}

    av_dump_format(pFormatCtx, 0, filenameSrc, 0);

    int videoStream = 1;

    for(int i=0; i < pFormatCtx->nb_streams; i++)
    {
        if(pFormatCtx->streams[i]->codec->coder_type==AVMEDIA_TYPE_VIDEO)
        {
            videoStream = i;
            break;
        }
    }

    if(videoStream == -1) return -1 ;

    pCodecCtx = pFormatCtx->streams[videoStream]->codec;

    pCodec =avcodec_find_decoder(pCodecCtx->codec_id);

    if(pCodec==NULL)
    {return -1;} //codec not found

    if(avcodec_open2(pCodecCtx,pCodec,NULL) < 0)
    { return -1;}

    pFrame    = avcodec_alloc_frame();
    pFrameRGB = avcodec_alloc_frame();

    uint8_t *buffer;

    int numBytes;

    AVPixelFormat  pFormat;

    switch (pFormatCtx->streams[videoStream]->codec->pix_fmt) 
    {
    case AV_PIX_FMT_YUVJ420P : pFormat = AV_PIX_FMT_YUV420P; break;
    case AV_PIX_FMT_YUVJ422P : pFormat = AV_PIX_FMT_YUV422P; break;
    case AV_PIX_FMT_YUVJ444P : pFormat = AV_PIX_FMT_YUV444P; break;
    case AV_PIX_FMT_YUVJ440P : pFormat = AV_PIX_FMT_YUV440P; 
    default:
        pFormat = pFormatCtx->streams[videoStream]->codec->pix_fmt;
        break;
    }

    numBytes = avpicture_get_size(pFormat,pCodecCtx->width,pCodecCtx->height) ; 

    buffer = (uint8_t *) av_malloc(numBytes*sizeof(uint8_t));

    avpicture_fill((AVPicture *) pFrameRGB,buffer,pFormat,pCodecCtx->width,pCodecCtx->height);

    int res, frameFinished;

    AVPacket packet;

    while(res = av_read_frame(pFormatCtx,&packet)>=0)
    {

        if(packet.stream_index == videoStream){

            avcodec_decode_video2(pCodecCtx,pFrame,&frameFinished,&packet);

            if(frameFinished){

                struct SwsContext * img_convert_ctx;

                img_convert_ctx = sws_getCachedContext(NULL,pCodecCtx->width, pCodecCtx->height, pCodecCtx->pix_fmt,   pCodecCtx->width, pCodecCtx->height, AV_PIX_FMT_BGR24, SWS_BICUBIC, NULL, NULL,NULL);

                sws_scale(img_convert_ctx, ((AVPicture*)pFrame)->data, ((AVPicture*)pFrame)->linesize, 0, pCodecCtx->height, ((AVPicture *)pFrameRGB)->data, ((AVPicture *)pFrameRGB)->linesize);

                cv::Mat img(pFrame->height,pFrame->width,CV_8UC3,pFrameRGB->data[0]);
                cv::imshow("display",img);
                cvWaitKey(10);          
            }
        }

    }
    //Memory clean up code goes here 
}

None

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

swscaler@0dd9e620:已弃用的像素格式,请确保您正确设置了范围” 的相关文章

  • 使用 FFmpeg 在特定时间将一个视频叠加在另一个视频上

    我正在尝试将一个视频与另一个视频叠加 我按照OP发布的原始命令进行操作here https stackoverflow com questions 35269387 ffmpeg overlay one video onto another
  • Python 子进程中的 ffmpeg - 无法找到“管道:”的合适输出格式

    尝试通过 Python 使用 ffmpeg 将字幕刻录到视频中 在命令行中工作正常 但是当从 Python 子进程调用时 p subprocess Popen cd Downloads yt ffmpeg i video vf subtit
  • 使用 ffmpeg 处理流的解码数据时出错

    我正在使用以下命令 ffmpeg i video1a flv i video1b flv i video1c flv i video2a flv i video3a flv i video4a flv i video4b flv i vid
  • FFMPEG - 连续的非单调 DTS

    我有几个需要连接的文件 有时文件工作和连接似乎没有问题 然后在其他文件上 文件不会连接 我得到 非单调 DTS 我一直在谷歌上搜索我应该对这些文件进行哪些处理 以便它们正确连接 但我仍然没有找到 有没有办法让所有文件的 DTS 完全相同 我
  • 使用 FFMPEG 的 HLS FLAC 流

    我使用以下命令从 FLAC 文件创建了一个 HLS 流 并输出 FLAC ffmpeg i 10 brass in pocket flac map 0 a c a 0 flac f hls hls playlist type vod mas
  • 在 Android 4.1/4.2 设备中使用 MediaCodec.getOutputFormat() 作为编码器的问题

    我正在尝试使用 MediaCodec 将帧 通过相机或解码器 编码为视频 当通过 dequeueOutputBuffer 处理编码器输出时 我期望收到返回索引 MediaCodec INFO OUTPUT FORMAT CHANGED 因此
  • 将ffmpeg安装到虚拟环境中

    我正在尝试安装ffmpeg以便在 OpenAI 上使用它来录制视频 我已经使用它安装了brew install ffmpeg但不知怎的 当我编译我的代码时 我得到了同样的错误 就像我的包无法识别一样virtualenv我工作的地方 Pyth
  • 使用 Python 从原始帧创建 MPEG4 视频文件

    我有一个原始视频帧源 我可以在 Python 中访问它 我想用它创建一个 MPEG4 视频 并带有 MP3 背景音乐 Python 中有哪些类型的工具和库可用于此类任务 最好我想要一个 API 我可以为其提供输出文件名 然后将各个帧作为 2
  • ffmpeg 使用 -movflags faststart

    我尝试使用命令 movflags 快速启动 并得到以下错误 Microsoft Windows 版本 6 0 6002 版权所有 c 2006 Microsoft 公司 版权所有 C uploads 1 videos gt ffmpeg i
  • 从 Perl 守护程序运行时,为什么 FFMpeg 在五秒后停止?

    我用 Perl 编写了一个小守护程序 它调用 FFMpeg 对视频进行编码 但编码在 5 秒左右后停止 我用这段代码来启动它 my t echo ffmpeg command gt gt self gt FFMPEG OUTPUT my l
  • 防止 ffmpeg 在降低视频分辨率的同时改变颜色强度

    我有一个用例 我需要缩小规模716x1280mp4 视频到358x640 原件的一半 我使用的命令是 ffmpeg i input mp4 vf scale 640 640 force original aspect ratio decre
  • ffmpeg创建RTP流

    我正在尝试使用 ffmpeg 进行编码和流式传输 libavcodec libavformat MSVC x64 with Zeranoe builds 这是我的代码 很大程度上改编自编码示例 删除了错误处理 include stdafx
  • Android 上的 GStreamer

    谁能给我一些关于让 GStreamer 在 Android 上工作的提示 我以前从未使用过它 我想将它与 FFmpeg 一起使用 我已经编译了 FFmpeg 并且在 Android 上运行良好 我只是想使用 GStreamer 来帮助完成一
  • 使用 libx264 为 Raspberry pi 编译 Xuggler 时的问题 #2

    我正在尝试编译Xuggler http www xuggle com xuggler 对于 Raspberry Pi 在 Debian 操作系统上运行 又名 Raspbian 我遵循了可用的 基本构建说明 here http www xug
  • C# - 捕获 RTP 流并发送到语音识别

    我正在努力实现的目标 在 C 中捕获 RTP 流 将该流转发到 System Speech SpeechRecognitionEngine 我正在创建一个基于 Linux 的机器人 它将接受麦克风输入 将其发送给 Windows 机器 Wi
  • 使用 ffmpeg 提取帧的最快方法?

    您好 我需要使用 ffmpeg 从视频中提取帧 有没有比这更快的方法 ffmpeg i file mpg r 1 1 filename 03d jpg 如果 JPEG 编码步骤对性能要求太高 您可以始终将未压缩的帧存储为 BMP 图像 ff
  • Python 用静态图像将 mp3 转换为 mp4

    我有x文件包含一个列表mp3我想转换的文件mp3文件至mp4文件带有static png photo 似乎这里唯一的方法是使用ffmpeg但我不知道如何实现它 我编写了脚本来接受输入mp3文件夹和一个 png photo 然后它将创建新文件
  • H264 字节流到图像文件

    第一次来这里所以要温柔 我已经在给定的 H 264 字节流上工作了几个星期 一般注意事项 字节流不是来自文件 它是从外部源实时提供给我的 字节流使用 Android 的媒体编解码器进行编码 当将流写入扩展名为 H264的文件时 VLC能够正
  • 使用 ffmpeg 或 OpenCV 处理原始图像

    看完之后维基百科页面 http en wikipedia org wiki Raw image format原始图像格式 是任何图像的数字负片 为了查看或打印 相机图像传感器的输出具有 进行处理 即转换为照片渲染 场景 然后以标准光栅图形格
  • ffmpeg:音频样本的字节顺序

    我使用 ffmpeg 的 avcodec 从我的 C 应用程序中的音乐文件中检索原始音频样本 对于我测试的文件 这些文件样本的字节序似乎是小字节序 但我想知道对于我尝试解码的所有文件是否总是如此 即来自 ffmpeg 的实现或至少它的体系结

随机推荐