1 Copyright (c) 2014-2017, NVIDIA CORPORATION. All rights reserved.
3 @page l4t_mm_video_cuda_enc_group 03_video_cuda_enc
6 - [Overview](#overview)
7 - [Building and Running](#build_and_run)
9 - [Key Structure and Classes](#key)
11 - - - - - - - - - - - - - - -
15 The Video CUDA Encoder sample demonstrates how to capture use libv4l2 API to encode
16 H.264/H.265 video streams. Before beginning encoding, it uses the
17 NVIDIA<sup>®</sup> CUDA<sup>®</sup> API to render a black rectangle on
18 the input YUV image data; the same buffer is used and shared by the decode
22 <a name=
"build_and_run">
23 - - - - - - - - - - - - - - -
24 ## Building and Running ##
26 #### Prerequisites ####
27 * You have followed Steps 1-3 in @ref mmapi_build.
28 * If you are building from your host Linux PC (x86), you have
29 followed Step 4 in @ref mmapi_build.
35 $ cd $HOME/multimedia_api/samples/03_video_cuda_enc
41 $ ./video_cuda_enc <in-file> <in-width> <in-height> <encoder-type> <out-file> [OPTIONS]
45 $ ./video_cuda_enc ../../data/Video/sample_outdoor_car_1080p_10fps.yuv 1920 1080 H264 test.h264
47 @note The `video_cuda_enc` sample consumes a YUV file. If you
do not already have a YUV file,
48 you can use the `video_dec_cuda` sample to generate one. For example:
50 $ cd $HOME/multimedia_api/samples/02_video_dec_cuda/
51 $ ./video_dec_cuda ../../data/Video/sample_outdoor_car_1080p_10fps.h264 H264 --disable-rendering \
52 -o ../../data/Video/sample_outdoor_car_1080p_10fps.yuv -f 2
55 - - - - - - - - - - - - - - -
57 The following diagram shows the flow through
this sample.
59 
62 from the file descriptor buffer that is allocated by Tegra. CUDA then uses
63 EGLImage buffer to render the rectangle. The buffer then performs the video encode
64 operation and encodes it to either an H.264 or H.265 video stream.
68 - - - - - - - - - - - - - - -
69 ## Key Structure and Classes ##
71 The `
struct context_t` global structure manages all of the resources in the application.
74 | ---------------- | ----------- |
75 |
class [
NvVideoEncoder](classNvVideoEncoder.html) | This
class contains all video encode related elements and functions. |
76 | EGLImageHKR | Specifies the EGLImage used for CUDA processing. |
78 The [
NvVideoConverter](classNvVideoConverter.html) class packages all video converting related elements and functions. The
79 sample uses the following key members:
82 | ---------------- | ----------- |
83 | [output_plane](classNvV4l2Element.html#aaba251827cef1b23e7c42f776e95fee5) | Specifies the output plane. |
84 | [capture_plane](classNvV4l2Element.html#a91806d7ed13b4b2c48758e8a02f46c6d) | Specifies the capture plane. |
85 | [createVideoEncoder](classNvVideoEncoder.html#aabb707f9188805ab7f097f82b3648351) | Static function to create video encode object. |
86 | [setExtControls](classNvV4l2Element.html#aaec1f40b777bb98870f18766690d7984) | Sets external control to V4l2 device. |
87 | [setOutputPlaneFormat](#NvVideoConverter::setOutputPlaneFormat) | Sets the output plane format. |
88 | [setCapturePlaneFormat](#NvVideoConverter::setCapturePlaneFormat] | Sets the capture plane format. |
89 | [isInError](classNvElement.html#a3ecd42c9dda2cec9506cf2ea8fa021fe) | Checks if under error state. |
91 Class %NvVideoEncoder contains two key elements: `output_plane` and `capture_plane`. These objects
92 are derived from class type [NvV4l2ElementPlane](group__l4t_mm__nvv4lelementplane__group.html). The sample uses the following key members:
94 | %NvV4l2ElementPlane | Description |
95 | ---------------- | ----------- |
96 | [setupPlane](classNvV4l2ElementPlane.html#a89959f455e5222f686187cc826b1b345) | Sets up the plane of V4l2 element. |
97 | [deinitPlane](classNvV4l2ElementPlane.html#af89cfe87d8f818beb0478bcf5b72574c) | Destroys the plane of V4l2 element. |
98 | [setStreamStatus](classNvV4l2ElementPlane.html#a03164dde4d7ab41f3e92b41e13059316) | Starts/stops the stream. |
99 | [setDQThreadCallback](classNvV4l2ElementPlane.html#a37f213325e0e4857180f5b2319317d6a) | Sets the callback function of dqueue buffer thread. |
100 | [startDQThread](classNvV4l2ElementPlane.html#a31f77f5e5ed1f320caa44a868a7cbedd) | Starts the thread of dqueue buffer. |
101 | [stopDQThread](classNvV4l2ElementPlane.html#aa798d14493de321fa90aeab6d944ca87) | Stops the thread of dqueue buffer. |
102 | [qBuffer](classNvV4l2ElementPlane.html#af4d52964fcfd37082f47682e457f5e95) | Queues the V4l2 buffer. |
103 | [dqBuffer](classNvV4l2ElementPlane.html#a8dfcbc666ee6f36a02abfb1170ae05cd) | Dqueues V4l2 buffer. |
104 | [getNumBuffers](classNvV4l2ElementPlane.html#ac5cd394a7e0a4afd69395759aeac8787) | Gets the number of V4l2 buffers. |
105 | [getNthBuffer](classNvV4l2ElementPlane.html#a868d438908f3d267dd4af1033133892f) | Gets the nth V4l2 buffer. |
107 Two global functions are used to create and destroy EGLImage from the dmabuf file descriptor:
109 | Global Function | Description |
110 | ---------------- | ----------- |
111 | NvEGLImageFromFd | Creates an EGLImage from dmabuf fd. |
112 | NvDestroyEGLImage | Destroys the EGLImage. |
Defines a helper class for V4L2 Video Encoder.
EGLImageKHR NvEGLImageFromFd(EGLDisplay display, int dmabuf_fd)
Creates an EGLImage instance from dmabuf-fd.
Defines a helper class for V4L2 Video Converter.