L4T Multimedia API Reference

28.1 Release

 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
multimedia_api/ll_samples/docs/l4t_mm_video_cuda_enc_guide.md
Go to the documentation of this file.
1 Copyright (c) 2014-2017, NVIDIA CORPORATION. All rights reserved.
2 
3 @page l4t_mm_video_cuda_enc_group 03_video_cuda_enc
4 @{
5 
6  - [Overview](#overview)
7  - [Building and Running](#build_and_run)
8  - [Flow](#flow)
9  - [Key Structure and Classes](#key)
10 
11 - - - - - - - - - - - - - - -
12 <a name="overview">
13 ## Overview ##
14 
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>&reg;</sup> CUDA<sup>&reg;</sup> API to render a black rectangle on
18 the input YUV image data; the same buffer is used and shared by the decode
19 component.
20 
21 
22 <a name="build_and_run">
23 - - - - - - - - - - - - - - -
24 ## Building and Running ##
25 
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.
30 
31 
32 ### To build:
33 * Enter:
34 
35  $ cd $HOME/tegra_multimedia_api/samples/03_video_cuda_enc
36  $ make
37 
38 ### To run
39 * Enter:
40 
41  $ ./video_cuda_enc <in-file> <in-width> <in-height> <encoder-type> <out-file> [OPTIONS]
42 
43 <a name="flow">
44 - - - - - - - - - - - - - - -
45 ## Flow
46 The following diagram shows the flow through this sample.
47 
48 ![](l4t_mm_video_cuda_enc.jpg)
49 
50 The `NvEGLImageFromFd` NV-defined API returns an EGLImage pointer
51 from the file descriptor buffer that is allocated by Tegra. CUDA then uses
52 EGLImage buffer to render the rectangle. The buffer then performs the video encode
53 operation and encodes it to either an H.264 or H.265 video stream.
54 
55 
56 <a name="key">
57 - - - - - - - - - - - - - - -
58 ## Key Structure and Classes ##
59 
60 The `struct context_t` global structure manages all of the resources in the application.
61 
62 | %NvVideoConverter | Description |
63 | ---------------- | ----------- |
64 | class [NvVideoEncoder](classNvVideoEncoder.html) | This class contains all video encode related elements and functions. |
65 | EGLImageHKR | Specifies the EGLImage used for CUDA processing. |
66 
67 The [NvVideoConverter](classNvVideoConverter.html) class packages all video converting related elements and functions. The
68 sample uses the following key members:
69 
70 | %NvVideoConverter | Description |
71 | ---------------- | ----------- |
72 | [output_plane](classNvV4l2Element.html#aaba251827cef1b23e7c42f776e95fee5) | Specifies the output plane. |
73 | [capture_plane](classNvV4l2Element.html#a91806d7ed13b4b2c48758e8a02f46c6d) | Specifies the capture plane. |
74 | [createVideoEncoder](classNvVideoEncoder.html#aabb707f9188805ab7f097f82b3648351) | Static function to create video encode object. |
75 | [setExtControls](classNvV4l2Element.html#aaec1f40b777bb98870f18766690d7984) | Sets external control to V4l2 device. |
76 | [setOutputPlaneFormat](#NvVideoConverter::setOutputPlaneFormat) | Sets the output plane format. |
77 | [setCapturePlaneFormat](#NvVideoConverter::setCapturePlaneFormat] | Sets the capture plane format. |
78 | [isInError](classNvElement.html#a3ecd42c9dda2cec9506cf2ea8fa021fe) | Checks if under error state. |
79 
80 Class %NvVideoEncoder contains two key elements: `output_plane` and `capture_plane`. These objects
81 are derived from class type [NvV4l2ElementPlane](group__l4t_mm__nvv4lelementplane__group.html). The sample uses the following key members:
82 
83 | %NvV4l2ElementPlane | Description |
84 | ---------------- | ----------- |
85 | [setupPlane](classNvV4l2ElementPlane.html#a89959f455e5222f686187cc826b1b345) | Sets up the plane of V4l2 element. |
86 | [deinitPlane](classNvV4l2ElementPlane.html#af89cfe87d8f818beb0478bcf5b72574c) | Destroys the plane of V4l2 element. |
87 | [setStreamStatus](classNvV4l2ElementPlane.html#a03164dde4d7ab41f3e92b41e13059316) | Starts/stops the stream. |
88 | [setDQThreadCallback](classNvV4l2ElementPlane.html#a37f213325e0e4857180f5b2319317d6a) | Sets the callback function of dqueue buffer thread. |
89 | [startDQThread](classNvV4l2ElementPlane.html#a31f77f5e5ed1f320caa44a868a7cbedd) | Starts the thread of dqueue buffer. |
90 | [stopDQThread](classNvV4l2ElementPlane.html#aa798d14493de321fa90aeab6d944ca87) | Stops the thread of dqueue buffer. |
91 | [qBuffer](classNvV4l2ElementPlane.html#af4d52964fcfd37082f47682e457f5e95) | Queues the V4l2 buffer. |
92 | [dqBuffer](classNvV4l2ElementPlane.html#a8dfcbc666ee6f36a02abfb1170ae05cd) | Dqueues V4l2 buffer. |
93 | [getNumBuffers](classNvV4l2ElementPlane.html#ac5cd394a7e0a4afd69395759aeac8787) | Gets the number of V4l2 buffers. |
94 | [getNthBuffer](classNvV4l2ElementPlane.html#a868d438908f3d267dd4af1033133892f) | Gets the nth V4l2 buffer. |
95 
96 Two global functions are used to create and destroy EGLImage from the dmabuf file descriptor:
97 
98 | Global Function | Description |
99 | ---------------- | ----------- |
100 | NvEGLImageFromFd | Creates an EGLImage from dmabuf fd. |
101 | NvDestroyEGLImage | Destroys the EGLImage. |
102 
103 
104 @}
105 
Defines a helper class for V4L2 Video Encoder.
EGLImageKHR NvEGLImageFromFd(EGLDisplay display, int dmabuf_fd)
This method must be used for getting EGLImage from dmabuf-fd.
Defines a helper class for V4L2 Video Converter.