This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

[参考译文] TDA4VH-Q1:视频编码器延迟

Guru**** 2387060 points
请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

https://e2e.ti.com/support/processors-group/processors/f/processors-forum/1489892/tda4vh-q1-video-encoder-delay

器件型号:TDA4VH-Q1
Thread 中讨论的其他器件:TDA4VH

工具/软件:

您好、
我将 在应用中将 TDA4VH 的视频编码器与 SDK9.2一起使用。

有时、视频编码器会返回一个空帧(大小0)、然后输出始终有延迟(即输出帧始终比输入帧晚一帧)。

我将 ffmpeg C++ API 与 h264_v4l2m2m 编解码器配合使用。

我尝试通过发送空帧来刷新编码器、但如果不完全重新创建上下文、则无法正确地重新启动编码。

重新创建上下文也不起作用、因为我不得不经常重新创建上下文、这样会破坏性能。

您是否知道解决此问题的方法?

谢谢、

Matthieu

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    您能否发送 正在使用的命令或应用程序? 我不知道这个问题,将不得不调查一些事情。

    谢谢、
    Sarabesh S.

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    没问题。

    以下是编解码器初始化代码:

    const AVCodec* codec = avcodec_find_encoder_by_name("h264_v4l2m2m");
    if (!codec)
    {
        throw std::runtime_error("Codec h264_v4l2m2m not found");
    }
    
    m_codecContext = avcodec_alloc_context3(codec);
    if (!m_codecContext)
    {
        throw std::runtime_error("Could not allocate video codec context");
    }
    
    m_pkt = av_packet_alloc();
    if (!m_pkt)
    {
        throw std::runtime_error("Could not allocate AVPacket");
    }
    
    m_codecContext->bit_rate = 4000000;
    m_codecContext->width = width;
    m_codecContext->height = height;
    
    m_codecContext->time_base = {
        1, m_framerate
    };
    m_codecContext->framerate = {
        m_framerate, 1
    };
    
    m_codecContext->gop_size = 10;
    m_codecContext->max_b_frames = 0;
    m_codecContext->pix_fmt = AV_PIX_FMT_NV12;
    
    
    int ret = avcodec_open2(m_codecContext, codec, nullptr);
    if (ret < 0)
    {
        throw std::runtime_error("Could not open codec " + CODEC_NAME);
    }
    
    m_frame = av_frame_alloc();
    if (!m_frame)
    {
        throw std::runtime_error("Could not allocate video frame");
    }
    m_frame->format = m_codecContext->pix_fmt;
    m_frame->width = m_codecContext->width;
    m_frame->height = m_codecContext->height;
    
    ret = av_frame_get_buffer(m_frame, 0);
    if (ret < 0)
    {
        throw std::runtime_error("Could not allocate the video frame data");
    }

    下面是为每个输入帧调用的 frameEncode 函数:

    ret = avcodec_send_frame(m_codecContext, m_frame);
    if (ret < 0)
    {
        LOG_ERROR("Error sending a frame for encoding");
        success = false;
    }
    
    while (ret >= 0)
    {
        ret = avcodec_receive_packet(m_codecContext, m_pkt);
        if (ret == AVERROR(EAGAIN) || ret == AVERROR(EOF))
        {
            LOG_INFO2("End of stream or packet not ready");
        }
        else if (ret < 0)
        {
            LOG_ERROR("Error during encoding");
            success = false;
        }
        else
        {
            int offset = (int)result.size();
            result.resize(result.size() + m_pkt->size);
            memcpy(result.data() + offset, m_pkt->data, m_pkt->size);
            av_packet_unref(m_pkt);
        }
    }

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    您没有为您的应用使用 GStreamer 吗? 您是否能够在最新的10.1 SDK 上尝试此操作并告诉我您的结果?

    谢谢、
    Sarabesh S.

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    尊敬的 Sarabesh:  

    我正在帮助 Matthieu 解决这个问题。  

    我们使用了 ffmpeg(libavcodec)、因为我们已经在我们的应用程序中使用了它。  
    我们 可以尝试10.1、但我们的产品在9.2 SDK 上运行、因此需要针对该版本提供权变措施。  
    对于 wave5编码器、是否有一些补丁已移植到 SDK 9.2?

    谢谢、  

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    如果您可以在 SDK 10.1上试用、这样我们就可以看到运行时可能需要或可能不需要哪些补丁。 我必须在内部讨论、以确定此处的支持级别。

    谢谢、
    Sarabesh S、

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    尊敬的 Sarabesh:  

    我正在尝试使用 SDK 10.1 (Linux j784s4-EVM 6.6.44-ti-01478-g541c20281af7-dirty #1 SMP 抢占、11月14日19:20:24 UTC 2024 AArch64 GNU/Linux)、并且使用我在 SDK 9.2上运行的相同代码、编解码器似乎卡住了。  

    我使用 h264_v4l2m2m 编码器对虚拟帧进行编码测试

    ffmpeg -f lavfi -i testsrc=size=1920x1080:rate=30 -pix_fmt yuv420p -c:v h264_v4l2m2m -b:v 4M -t 2 output.mp4


    在 SDK 9.2上、不会产生虚拟输出

    root@j784s4-ecu:~# ffmpeg -f lavfi -i testsrc=size=1920x1080:rate=30 -pix_fmt yuv420p -c:v h264_v4l2m2m -b:v 4M -t 2 output.mp4
    ffmpeg version 5.0.1 Copyright (c) 2000-2022 the FFmpeg developers
      built with gcc 11.4.0 (GCC)
      configuration: --cross-prefix=aarch64-oe-linux- --ld='aarch64-oe-linux-gcc -mbranch-protection=standard --sysroot=/recipe-sysroot' --cc='aarch64-oe-linux-gcc -mbranch-protection=standard --sysroot=/recipe-sysroot' --cxx='aarch64-oe-linux-g++ -mbranch-protection=standard --sysroot=/recipe-sysroot' --arch=aarch64 --target-os=linux --enable-cross-compile --extra-cflags=' -O2 -pipe -g -feliminate-unused-debug-types -fmacro-prefix-map==/usr/src/debug/ffmpeg/5.0.1-r0.arago0 -fdebug-prefix-map==/usr/src/debug/ffmpeg/5.0.1-r0.arago0 -fdebug-prefix-map=/recipe-sysroot= -fdebug-prefix-map=/recipe-sysroot-native= -mbranch-protection=standard --sysroot=/recipe-sysroot' --extra-ldflags='-Wl,-O1 -Wl,--hash-style=gnu -Wl,--as-needed -fmacro-prefix-map==/usr/src/debug/ffmpeg/5.0.1-r0.arago0 -fdebug-prefix-map==/usr/src/debug/ffmpeg/5.0.1-r0.arago0 -fdebug-prefix-map=/recipe-sysroot= -fdebug-prefix-map=/recipe-sysroot-native= ' --sysroot=/recipe-sysroot --libdir=/usr/lib --shlibdir=/usr/lib --datadir=/usr/share/ffmpeg --cpu=generic --pkg-config=pkg-config --enable-alsa --disable-altivec --enable-avcodec --enable-avdevice --enable-avfilter --enable-avformat --enable-bzlib --disable-libfdk-aac --disable-gpl --disable-libgsm --disable-indev=jack --disable-libopus --disable-libvorbis --enable-lzma --disable-libmfx --disable-mipsdsp --disable-mipsdspr2 --disable-libmp3lame --disable-openssl --enable-pic --enable-postproc --enable-pthreads --disable-sdl2 --enable-shared --disable-libspeex --disable-libsrt --disable-stripping --enable-swresample --enable-swscale --enable-libtheora --disable-vaapi --disable-vdpau --disable-libvpx --disable-libx264 --disable-libx265 --disable-libxcb --disable-outdev=xv --enable-zlib
      libavutil      57. 17.100 / 57. 17.100
      libavcodec     59. 18.100 / 59. 18.100
      libavformat    59. 16.100 / 59. 16.100
      libavdevice    59.  4.100 / 59.  4.100
      libavfilter     8. 24.100 /  8. 24.100
      libswscale      6.  4.100 /  6.  4.100
      libswresample   4.  3.100 /  4.  3.100
    Input #0, lavfi, from 'testsrc=size=1920x1080:rate=30':
      Duration: N/A, start: 0.000000, bitrate: N/A
      Stream #0:0: Video: rawvideo (RGB[24] / 0x18424752), rgb24, 1920x1080 [SAR 1:1 DAR 16:9], 30 tbr, 30 tbn
    File 'output.mp4' already exists. Overwrite? [y/N] y
    Stream mapping:
      Stream #0:0 -> #0:0 (rawvideo (native) -> h264 (h264_v4l2m2m))
    Press [q] to stop, [?] for help
    [h264_v4l2m2m @ 0xa885330] Using device /dev/video3
    [h264_v4l2m2m @ 0xa885330] driver 'wave5-enc' on card 'wave5-enc' in mplane mode
    [h264_v4l2m2m @ 0xa885330] requesting formats: output=YU12 capture=H264
    Output #0, mp4, to 'output.mp4':
      Metadata:
        encoder         : Lavf59.16.100
      Stream #0:0: Video: h264 (avc1 / 0x31637661), yuv420p(tv, progressive), 1920x1080 [SAR 1:1 DAR 16:9], q=2-31, 4000 kb/s, 30 fps, 15360 tbn
        Metadata:
          encoder         : Lavc59.18.100 h264_v4l2m2m
    frame=   60 fps= 21 q=-0.0 Lsize=     898kB time=00:00:01.96 bitrate=3738.7kbits/s speed= 0.7x    
    video:897kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.116442%
    root@j784s4-ecu:~# 

    在 SDK 10.1上、不会创建虚拟输出、ffmpeg 会因分段故障而失败

    root@j784s4-evm:~# ffmpeg -f lavfi -i testsrc=size=1920x1080:rate=30 -pix_fmt yuv420p -c:v h264_v4l2m2m -b:v 4M -t 2 output.mp4
    ffmpeg version 6.1.1 Copyright (c) 2000-2023 the FFmpeg developers
      built with gcc 13.3.0 (GCC)
      configuration: --disable-stripping --enable-pic --enable-shared --enable-pthreads --cross-prefix=aarch64-oe-linux- --ld='aarch64-oe-linux-gcc -mbranch-protection=standard --sysroot=/recipe-sysroot' --cc='aarch64-oe-linux-gcc -mbranch-protection=standard --sysroot=/recipe-sysroot' --cxx='aarch64-oe-linux-g++ -mbranch-protection=standard --sysroot=/recipe-sysroot' --arch=aarch64 --target-os=linux --enable-cross-compile --extra-cflags=' -O2 -pipe -g -feliminate-unused-debug-types -fcanon-prefix-map -fmacro-prefix-map=/ffmpeg-6.1.1=/usr/src/debug/ffmpeg/6.1.1 -fdebug-prefix-map=/ffmpeg-6.1.1=/usr/src/debug/ffmpeg/6.1.1 -fmacro-prefix-map=/build=/usr/src/debug/ffmpeg/6.1.1 -fdebug-prefix-map=/build=/usr/src/debug/ffmpeg/6.1.1 -fdebug-prefix-map=/recipe-sysroot= -fmacro-prefix-map=/recipe-sysroot= -fdebug-prefix-map=/recipe-sysroot-native= -mbranch-protection=standard --sysroot=/recipe-sysroot' --extra-ldflags='-Wl,-O1 -Wl,--hash-style=gnu -Wl,--as-needed -fcanon-prefix-map -fmacro-prefix-map=/ffmpeg-6.1.1=/usr/src/debug/ffmpeg/6.1.1 -fdebug-prefix-map=/ffmpeg-6.1.1=/usr/src/debug/ffmpeg/6.1.1 -fmacro-prefix-map=/build=/usr/src/debug/ffmpeg/6.1.1 -fdebug-prefix-map=/build=/usr/src/debug/ffmpeg/6.1.1 -fdebug-prefix-map=/recipe-sysroot= -fmacro-prefix-map=/recipe-sysroot= -fdebug-prefix-map=/recipe-sysroot-native= ' --sysroot=/recipe-sysroot --libdir=/usr/lib --shlibdir=/usr/lib --datadir=/usr/share/ffmpeg --disable-mipsdsp --disable-mipsdspr2 --cpu=generic --pkg-config=pkg-config --enable-alsa --disable-altivec --enable-avcodec --enable-avdevice --enable-avfilter --enable-avformat --enable-bzlib --disable-libfdk-aac --disable-gpl --disable-libgsm --disable-indev=jack --disable-libopus --disable-libvorbis --enable-lzma --disable-libmfx --disable-libmp3lame --disable-openssl --enable-postproc --disable-sdl2 --disable-libspeex --disable-libsrt --enable-swresample --enable-swscale --enable-libtheora --disable-libv4l2 --disable-vaapi --disable-vdpau --disable-libvpx --disable-libx264 --disable-libx265 --disable-libxcb --disable-outdev=xv --enable-zlib
      libavutil      58. 29.100 / 58. 29.100
      libavcodec     60. 31.102 / 60. 31.102
      libavformat    60. 16.100 / 60. 16.100
      libavdevice    60.  3.100 / 60.  3.100
      libavfilter     9. 12.100 /  9. 12.100
      libswscale      7.  5.100 /  7.  5.100
      libswresample   4. 12.100 /  4. 12.100
    Input #0, lavfi, from 'testsrc=size=1920x1080:rate=30':
      Duration: N/A, start: 0.000000, bitrate: N/A
      Stream #0:0: Video: wrapped_avframe, rgb24, 1920x1080 [SAR 1:1 DAR 16:9], 30 fps, 30 tbr, 30 tbn
    Stream mapping:
      Stream #0:0 -> #0:0 (wrapped_avframe (native) -> h264 (h264_v4l2m2m))
    Press [q] to stop, [?] for help
    [h264_v4l2m2m @ 0x8d1e3f0] Using device /dev/video1
    [h264_v4l2m2m @ 0x8d1e3f0] driver 'wave5-enc' on card 'wave5-enc' in mplane mode
    [h264_v4l2m2m @ 0x8d1e3f0] requesting formats: output=YU12/yuv420p capture=H264/none
    Output #0, mp4, to 'output.mp4':
      Metadata:
        encoder         : Lavf60.16.100
      Stream #0:0: Video: h264 (avc1 / 0x31637661), yuv420p(tv, progressive), 1920x1080 [SAR 1:1 DAR 16:9], q=2-31, 4000 kb/s, 30 fps, 15360 tbn
        Metadata:
          encoder         : Lavc60.31.102 h264_v4l2m2m
    Segmentation fault (core dumped)
    root@j784s4-evm:~#


  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    您好、David:  

    对延迟深表歉意。 今天我将尝试复制这一点。 我目前正在与我们的开发团队讨论、因此我应该会很快获得最新信息。

    谢谢、
    Sarabesh S.

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    您好、David:  

    感谢您在10.1中查看此信息。 在9.2上,我们不要求 ffmpeg 支持,甚至不应该在默认文件系统中启用它。 对于10.0 SDK、您是否参考了 SDK 文档来确认您是否启用了所有必要的参数?

    您可以在以下位置查看我们的 ffmpeg 示例和参数: https://software-dl.ti.com/jacinto7/esd/processor-sdk-linux-j784s4/10_01_00_05/exports/docs/linux/Foundational_Components_Multimedia_ pwave5.html#ffmpeg-plugins-for-multimedia

    请尝试在10.x 上运行我们的一个示例流水线 此外、要获得更好的调试日志、可以在命令前添加 strace。 请在可用时分享您的结果。

    此致、
    Sarabesh S.

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    尊敬的 Sarabesh:  

    因此我们需要支持9.2、我们尝试了 gstreamer 而不是 ffmpeg、使用该库、问题似乎已经解决。
    感谢您的帮助!

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    您好、David:  

    这是个好消息! 很高兴听到这个消息、如果您需要其他任何信息、请告诉我。

    此致、
    Sarabesh S.