Ffmpeg 使用 h264_nvmpi 硬件编码 YUV420P 为 H264 文件出现掉帧

系统环境:
Jetson 型号:NVIDIA Jetson Orin NX (16GB ram)
Jetpack :5.1.3
输入文件格式:
YUV文件:分辨率1920x1080,帧率25,像素格式YUV420P

问题描述:
FFmpeg命令:
ffmpeg -f rawvideo -pix_fmt yuv420p -s 1920x1080 -r 25 -i input.yuv -c:v h264_nvmpi -b:v 2400k -maxrate 2800k -bufsize 4800k -preset p4 -profile:v high -g 50 -rc vbr -f h264 output_vbr.h264

  1. 使用该命令进行硬件编码时,输出的h264文件播放的时候会出现掉帧。

sudo tegrastats 状态:

  1. 用Jetpack 5.1.3和Jetpack 6.2版本的官方SDK提供的API sample(jetson_multimedia_api/samples/01_video_encode)进行编码YUV420P文件为H264文件,编码过程中没有报错,能够正常完成,但H264文件播放时会出现掉帧情况。

  2. 通过代码调用(h264_nvmpi)硬件编码YUV420P文件为H264文件,也会出现播放H264文件掉帧的情况。

想问下有没有什么办法能排查这些硬件编码掉帧的情况呢?

*** Please note that this reply is generated by LLM automatically ***

The question appears to be about the performance of the Jetson Orin NX 16GB platform, specifically with regards to video encoding using FFmpeg and the H.264 codec. Here’s a comprehensive answer:

Platform: The Jetson Orin NX 16GB platform is a part of the NVIDIA Jetson Orin NX series, which is a series of modules for AI and computer vision applications.

RAM: The platform has 16GB of RAM, which is a significant amount of memory for a module of its size.

Jetpack: The question mentions Jetpack 5.13, which is a software development kit (SDK) provided by NVIDIA for the Jetson platform. Jetpack includes a set of tools, libraries, and APIs for developing AI and computer vision applications.

Video Encoding: The question shows a command-line example of using FFmpeg to encode a YUV 1920x1080 video at 25 frames per second (FPS) using the H.264 codec. The command-line options specify the input video format, resolution, frame rate, and codec settings.

Performance: The question includes a screenshot of the tegrastats command, which shows the system’s performance metrics, including the CPU usage, memory usage, and power consumption. The screenshot shows that the system is using around 692 MB of memory and consuming around 13.5W of power.

Comparison: To put this into perspective, the Jetson Orin NX 16GB platform is a relatively powerful module compared to other Jetson platforms. For example, the Jetson Orin Nano Developer Kit, which has 8GB of RAM, consumes around 10W of power. The Jetson AGX Orin 64GB module, which has 64GB of RAM, consumes around 30W of power.

H.264 Encoding: The H.264 codec is a widely used video compression standard, and the h264nvmpi codec is a NVIDIA-specific implementation of the H.264 codec that is optimized for the Jetson platform. The h264nvmpi codec is known for its high performance and low power consumption.

Conclusion: In summary, the Jetson Orin NX 16GB platform is a powerful module that is capable of encoding high-quality video using the H.264 codec. The platform’s performance metrics, including CPU usage, memory usage, and power consumption, are reasonable for a module of its size and capabilities.

*** Please give the thumbs up if you get answers you like. Or provide feedback to help us improve the answer. ***

ffmpeg -f rawvideo -pix_fmt yuv420p -s 1920x1080 -r 25 -i input.yuv -c:v h264_nvmpi -b:v 2400k -maxrate 2800k -bufsize 4800k -preset p4 -profile:v high -g 50 -rc vbr -f h264 output_vbr.h264
为什么使用这个命令进行硬件编码时,输出的h264文件播放的时候会出现掉帧,需要怎么解决呢?

Hi,
You should use h264_nvv4l2dec on Jetson platforms. Please refer to
Ffmpeg failed to decode with h264_nvv4l2dec, Segmentation fault! - #6 by DaneLLL
About the Accelerated Computing category
Accelerated Decode with ffmpeg — NVIDIA Jetson Linux Developer Guide 1 documentation

我解码是没有问题的,编码使用 h264_nvmpi 出现丢帧,要怎么排查呢?

Hi,
Hardware video encoding is not enabled in ffmpeg. Please run 01_video_encode sample.

但是我用 01_video_encode 去编码YUV为H264还是出现了掉帧的情况,要怎么解决呢?

Hi,
It’s unlikely that encoder drops the frames. Would suggest check if source YUV file is good.

我可以确定我用来编码的YUV文件是没有问题的,逐帧播放是没有出现丢帧的情况。会不会是还有其他原因导致的呢?

能不能帮忙提供一个测试的YUV文件让我尝试一下编码会不会有问题呢?

Hi,
Probably it’s because 25 fps content is played in 30 fps, making you think some frames gets dropped?

./video_encode ../../../output.yuv 1920 1080 H264 ../../../output.h264
01_video_encode这个sample默认是编码30fps嘛?那要怎样设置为25fps呢?

Hi,
Please check
NvVideoEncoder::setFrameRate - #5 by DaneLLL

./video_encode ../../../swim_output.yuv 1920 1080 H264 ../../../swim_output.h264 --insert-vui -fps 25 1
我更换了带有时间戳的视频重新尝试编码,在yuv播放正常的情况下,用上述命令控制视频编码在25帧的情况下,得到的h264文件还是会出现丢帧,大约每秒丢失14帧,请问还有其他的排查方向吗?

Hi,
It looks like decoding is not fast enough so frames gets dropped. Encoding should be good. You may add prints in 01_video_encode sample to check how many frames are fed to encoder, and how many frames are encoded.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.