h264视频中VUI info是什么
时间: 2024-06-08 17:07:10 浏览: 10
VUI (Video Usability Information) 是 H.264 视频编码标准中的一个参数集,它描述了视频的使用规范和特殊要求。VUI 参数集包含了一些重要的信息,例如视频的宽度和高度、帧率、颜色空间、色度采样方式、显示方面比例、色彩特性等。
VUI info 的作用在于帮助解码器正确地解析和显示视频,确保视频的质量和兼容性。VUI info 中的各个参数对视频的可用性和显示效果都有着重要影响,因此在 H.264 编码过程中需要仔细设置和调整 VUI 参数集。
相关问题
Insert VUI NAL in stream
VUI(Video Usability Information)是一种包含视频使用信息的数据结构,它可以在视频编码时通过NAL(Network Abstraction Layer)单元插入视频流中。VUI NAL通常包含视频的一些元数据,例如帧率、颜色空间、色度采样等,这些信息可以帮助播放设备或播放器正确地解码视频流。
在x264enc编码器中,可以使用“insert-vui=true”参数来启用VUI NAL的插入。例如,下面是一个使用x264enc编码器并启用VUI NAL插入的GStreamer命令:
```
gst-launch-1.0 videotestsrc ! x264enc insert-vui=true ! rtph264pay ! udpsink host=127.0.0.1 port=5000
```
这个命令会创建一个测试视频源,并使用x264enc编码器将视频编码为H.264格式,并启用VUI NAL插入。最后,使用rtph264pay将编码后的视频打包为RTP数据包,并使用udpsink元素将数据包发送到127.0.0.1的5000端口。你可以根据自己的需求修改这个命令。
需要注意的是,启用VUI NAL插入会增加视频流的大小和编码器的计算负担,可能会导致网络传输速度变慢和编码速度变慢。如果你不需要这些元数据信息,可以禁用VUI NAL插入。
生成一个rk3399 mpi接口使用mppencrccfg 的h264编码 包含#define TAG "mpi_h264enc_test" 完整程序
很抱歉,我无法提供完整的程序代码。但我可以给出一些参考:
```c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <pthread.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <sys/mman.h>
#include <sys/time.h>
#include <linux/videodev2.h>
#include "rk_mpi.h"
#include "rk_venc.h"
#define TAG "mpi_h264enc_test"
#define VIDEO_WIDTH 1920
#define VIDEO_HEIGHT 1080
#define VIDEO_FPS 30
#define FRAME_NUM 1000
typedef struct
{
int fd;
void *start;
size_t length;
} camera_t;
static camera_t *camera_open(int id)
{
camera_t *camera = (camera_t *)malloc(sizeof(camera_t));
if (camera == NULL)
{
printf("[%s] malloc camera_t failed\n", TAG);
return NULL;
}
char dev_name[16];
sprintf(dev_name, "/dev/video%d", id);
camera->fd = open(dev_name, O_RDWR);
if (camera->fd < 0)
{
printf("[%s] open %s failed\n", TAG, dev_name);
free(camera);
return NULL;
}
struct v4l2_capability cap;
if (ioctl(camera->fd, VIDIOC_QUERYCAP, &cap) < 0)
{
printf("[%s] VIDIOC_QUERYCAP failed\n", TAG);
close(camera->fd);
free(camera);
return NULL;
}
if (!(cap.capabilities & V4L2_CAP_VIDEO_CAPTURE))
{
printf("[%s] %s is not a video capture device\n", TAG, dev_name);
close(camera->fd);
free(camera);
return NULL;
}
if (!(cap.capabilities & V4L2_CAP_STREAMING))
{
printf("[%s] %s does not support streaming i/o\n", TAG, dev_name);
close(camera->fd);
free(camera);
return NULL;
}
struct v4l2_format fmt;
memset(&fmt, 0, sizeof(fmt));
fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
fmt.fmt.pix.width = VIDEO_WIDTH;
fmt.fmt.pix.height = VIDEO_HEIGHT;
fmt.fmt.pix.pixelformat = V4L2_PIX_FMT_YUYV;
fmt.fmt.pix.field = V4L2_FIELD_NONE;
if (ioctl(camera->fd, VIDIOC_S_FMT, &fmt) < 0)
{
printf("[%s] VIDIOC_S_FMT failed\n", TAG);
close(camera->fd);
free(camera);
return NULL;
}
struct v4l2_requestbuffers req;
memset(&req, 0, sizeof(req));
req.count = 4;
req.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
req.memory = V4L2_MEMORY_MMAP;
if (ioctl(camera->fd, VIDIOC_REQBUFS, &req) < 0)
{
printf("[%s] VIDIOC_REQBUFS failed\n", TAG);
close(camera->fd);
free(camera);
return NULL;
}
struct v4l2_buffer buf;
for (int i = 0; i < req.count; i++)
{
memset(&buf, 0, sizeof(buf));
buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
buf.memory = V4L2_MEMORY_MMAP;
buf.index = i;
if (ioctl(camera->fd, VIDIOC_QUERYBUF, &buf) < 0)
{
printf("[%s] VIDIOC_QUERYBUF failed\n", TAG);
close(camera->fd);
free(camera);
return NULL;
}
camera->start = mmap(NULL, buf.length, PROT_READ | PROT_WRITE, MAP_SHARED, camera->fd, buf.m.offset);
if (camera->start == MAP_FAILED)
{
printf("[%s] mmap failed\n", TAG);
close(camera->fd);
free(camera);
return NULL;
}
camera->length = buf.length;
if (ioctl(camera->fd, VIDIOC_QBUF, &buf) < 0)
{
printf("[%s] VIDIOC_QBUF failed\n", TAG);
munmap(camera->start, camera->length);
close(camera->fd);
free(camera);
return NULL;
}
}
enum v4l2_buf_type type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
if (ioctl(camera->fd, VIDIOC_STREAMON, &type) < 0)
{
printf("[%s] VIDIOC_STREAMON failed\n", TAG);
close(camera->fd);
free(camera);
return NULL;
}
return camera;
}
static void camera_close(camera_t *camera)
{
if (camera != NULL)
{
enum v4l2_buf_type type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
ioctl(camera->fd, VIDIOC_STREAMOFF, &type);
for (int i = 0; i < 4; i++)
{
munmap(camera->start, camera->length);
}
close(camera->fd);
free(camera);
}
}
static int camera_capture(camera_t *camera, unsigned char *buffer, int *length)
{
struct v4l2_buffer buf;
memset(&buf, 0, sizeof(buf));
buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
buf.memory = V4L2_MEMORY_MMAP;
if (ioctl(camera->fd, VIDIOC_DQBUF, &buf) < 0)
{
return -1;
}
memcpy(buffer, camera->start, buf.bytesused);
*length = buf.bytesused;
if (ioctl(camera->fd, VIDIOC_QBUF, &buf) < 0)
{
return -1;
}
return 0;
}
static void *camera_thread(void *arg)
{
camera_t *camera = (camera_t *)arg;
unsigned char *buffer = (unsigned char *)malloc(camera->length);
if (buffer == NULL)
{
printf("[%s] malloc buffer failed\n", TAG);
return NULL;
}
int length = 0;
while (1)
{
if (camera_capture(camera, buffer, &length) == 0)
{
// do something with captured frame
}
usleep(1000);
}
free(buffer);
return NULL;
}
int main(int argc, char **argv)
{
RK_MPI_SYS_Init();
RK_U32 u32Width = VIDEO_WIDTH;
RK_U32 u32Height = VIDEO_HEIGHT;
RK_U32 u32Fps = VIDEO_FPS;
RK_U32 u32BitRate = u32Width * u32Height * 3 / 2 * u32Fps;
RK_U32 u32KeyFrameInterval = u32Fps;
RK_U32 u32Profile = 66; // H264 PROFILE_HIGH
MPP_CHN_S stChnAttr;
stChnAttr.mChnId = 0;
stChnAttr.mModId = RK_ID_VENC;
stChnAttr.mDevId = 0;
stChnAttr.mWidth = u32Width;
stChnAttr.mHeight = u32Height;
stChnAttr.mFps = u32Fps;
stChnAttr.mBitRate = u32BitRate;
stChnAttr.mProfile = u32Profile;
stChnAttr.mLevel = 41; // H264 LEVEL4_1
stChnAttr.mPixelFormat = RK_FMT_YUV420SP;
stChnAttr.mRotation = 0;
stChnAttr.mMirror = 0;
stChnAttr.mFlip = 0;
stChnAttr.mDrmMode = 0;
stChnAttr.mDrmFd = -1;
if (RK_MPI_VENC_CreateChn(0, &stChnAttr) != RK_SUCCESS)
{
printf("[%s] create venc chn failed\n", TAG);
return -1;
}
if (RK_MPI_VENC_RegisterChn(0, 0, 0) != RK_SUCCESS)
{
printf("[%s] register venc chn failed\n", TAG);
return -1;
}
MPP_CHN_S stSrcChn;
stSrcChn.mModId = RK_ID_VI;
stSrcChn.mDevId = 0;
stSrcChn.mChnId = 0;
MPP_CHN_S stDestChn;
stDestChn.mModId = RK_ID_VENC;
stDestChn.mDevId = 0;
stDestChn.mChnId = 0;
RK_MPI_SYS_Bind(&stSrcChn, &stDestChn);
camera_t *camera = camera_open(0);
if (camera != NULL)
{
pthread_t tid;
pthread_create(&tid, NULL, camera_thread, camera);
}
RK_S32 s32Ret = RK_SUCCESS;
MPP_FRAME_S stFrame;
memset(&stFrame, 0, sizeof(stFrame));
stFrame.mModId = RK_ID_VENC;
stFrame.mChannelId = 0;
stFrame.mWidth = u32Width;
stFrame.mHeight = u32Height;
stFrame.mField = RK_FIELD_NONE;
stFrame.mFrameType = RK_CODEC_FRAME_SPS_PPS_I;
stFrame.mCompressMode = COMPRESS_MODE_NONE;
stFrame.mBitWidth = 10;
stFrame.mColor = MPP_FMT_YUV420SP;
for (int i = 0; i < FRAME_NUM; i++)
{
s32Ret = RK_MPI_VENC_GetFrm(0, &stFrame, RK_TRUE);
if (s32Ret != RK_SUCCESS)
{
printf("[%s] venc get frame failed\n", TAG);
goto done;
}
unsigned char *y = (unsigned char *)stFrame.mVirAddr[0];
unsigned char *uv = (unsigned char *)stFrame.mVirAddr[1];
int y_len = stFrame.mWidth * stFrame.mHeight;
int uv_len = stFrame.mWidth * stFrame.mHeight / 2;
RK_MPI_VENC_RcCfg rc_cfg;
memset(&rc_cfg, 0, sizeof(rc_cfg));
rc_cfg.mRcMode = VENC_RC_MODE_H264CBR;
rc_cfg.mBitRate = u32BitRate;
rc_cfg.mFrmRate = u32Fps;
rc_cfg.mGop = u32KeyFrameInterval;
rc_cfg.mQpMin = 30;
rc_cfg.mQpMax = 51;
rc_cfg.mQpInit = 35;
rc_cfg.mMaxReEncodeTimes = 5;
rc_cfg.mMaxQPDelta = 10;
rc_cfg.mMaxBitRateTolerance = 1000;
RK_MPI_VENC_SetRcCfg(0, &rc_cfg);
RK_MPI_VENC_H264Cfg h264_cfg;
memset(&h264_cfg, 0, sizeof(h264_cfg));
h264_cfg.mProfile = u32Profile;
h264_cfg.mLevel = 41;
h264_cfg.mEntropyMode = VENC_ENTROPY_MODE_CABAC;
h264_cfg.mCabacInitIdc = 0;
h264_cfg.mSliceNum = 2;
h264_cfg.mSliceMode = VENC_H264_SLICEMODE_SINGLE;
RK_MPI_VENC_SetH264Cfg(0, &h264_cfg);
RK_MPI_VENC_H264Vui h264_vui;
memset(&h264_vui, 0, sizeof(h264_vui));
h264_vui.mAspectRatioIdc = 0;
h264_vui.mOverScanInfo = 0;
h264_vui.mBitstreamRestriction = 0;
RK_MPI_VENC_SetH264Vui(0, &h264_vui);
RK_MPI_VENC_H264Sei h264_sei;
memset(&h264_sei, 0, sizeof(h264_sei));
h264_sei.mRecoveryPoint = 0;
h264_sei.mRecoveryPointInfoPresent = 0;
h264_sei.mBufferingPeriod = 0;
h264_sei.mPictureTiming = 0;
RK_MPI_VENC_SetH264Sei(0, &h264_sei);
MPP_ENC_CFG_S stMppEncCfg;
memset(&stMppEncCfg, 0, sizeof(stMppEncCfg));
stMppEncCfg.mRcCfg = &rc_cfg;
stMppEncCfg.mGopCfg = NULL;
stMppEncCfg.mH264Cfg = &h264_cfg;
stMppEncCfg.mH264VuiCfg = &h264_vui;
stMppEncCfg.mH264SeiCfg = &h264_sei;
RK_MPI_VENC_SetMppCfg(0, &stMppEncCfg);
MPP_ENC_SEI_S stEncSei;
memset(&stEncSei, 0, sizeof(stEncSei));
stEncSei.mEncSeiMode = MPP_ENC_SEI_MODE_ALL;
RK_MPI_VENC_SetExtCfg(0, ENC_CFG_SEI, &stEncSei);
RK_MPI_VENC_SendFrame(0, y, uv, y_len, uv_len);
RK_MPI_VENC_ReleaseFrm(0, &stFrame);
usleep(1000 * 1000 / u32Fps);
}
done:
if (RK_MPI_VENC_UnRegisterChn(0, 0, 0) != RK_SUCCESS)
{
printf("[%s] unregister venc chn failed\n", TAG);
}
if (RK_MPI_VENC_DestroyChn(0) != RK_SUCCESS)
{
printf("[%s] destroy venc chn failed\n", TAG);
}
RK_MPI_SYS_UnBind(&stSrcChn, &stDestChn);
if (camera != NULL)
{
camera_close(camera);
}
RK_MPI_SYS_Exit();
return 0;
}
```
这是一个基于 Rockchip RK3399 平台的 H.264 编码程序,程序中包含了使用 MPP 接口对 H.264 编码器进行配置的相关代码,可以根据需要进行修改。注意,本程序只是一个示例程序,不保证可以直接编译通过并运行。
相关推荐
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![bz2](https://img-home.csdnimg.cn/images/20210720083646.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![doc](https://img-home.csdnimg.cn/images/20210720083327.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)