Linux 36.3 + JetPack v6.0@jetson-inference之视频操作

2024-06-01 09:28

本文主要是介绍Linux 36.3 + JetPack v6.0@jetson-inference之视频操作,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

Linux 36.3 + JetPack v6.0@jetson-inference之视频操作

  • 1. 源由
  • 2. 输入输出源
    • 2.1 输入
    • 2.2 输出
  • 3. 示例
    • 3.1 MIPI CSI 摄像头
    • 3.2 V4L2 摄像头
    • 3.3 WebRTC
    • 3.4 RTP
    • 3.5 RTSP
    • 3.6 Video 文件
    • 3.7 Image 文件
  • 4. 代码分析
    • 4.1 Python
    • 4.2 C++
  • 5. 参考资料

1. 源由

对jetson-inference示例代码完成编译之后,首先确保视频、图像方面的操作没有问题。

因为是所有示例基本上都是针对视频或者图像进行深度机器学习操作的。

2. 输入输出源

2.1 输入

InputProtocolResource URINotes
MIPI CSI cameracsi://csi://0CSI camera 0 (substitute other camera numbers for 0)
V4L2 camerav4l2://v4l2:///dev/video0V4L2 device 0 (substitute other camera numbers for 0)
WebRTC streamwebrtc://webrtc://@:8554/my_inputFrom browser webcam to localhost, port 8554 (requires HTTPS/SSL)
RTP streamrtp://rtp://@:1234localhost, port 1234 (requires additional configuration)
RTSP streamrtsp://rtsp://:1234Replace with remote host’s IP or hostname
Video filefile://file://my_video.mp4Supports loading MP4, MKV, AVI, FLV (see codecs below)
Image filefile://file://my_image.jpgSupports loading JPG, PNG, TGA, BMP, GIF, etc.
Image sequencefile://file://my_directory/Searches for images in alphanumeric order
    input                resource URI of the input stream, for example:* /dev/video0               (V4L2 camera #0)* csi://0                   (MIPI CSI camera #0)* rtp://@:1234              (RTP stream)* rtsp://user:pass@ip:1234  (RTSP stream)* webrtc://@:1234/my_stream (WebRTC stream)* file://my_image.jpg       (image file)* file://my_video.mp4       (video file)* file://my_directory/      (directory of images)--input-width=WIDTH    explicitly request a width of the stream (optional)--input-height=HEIGHT  explicitly request a height of the stream (optional)--input-rate=RATE      explicitly request a framerate of the stream (optional)--input-save=FILE      path to video file for saving the input stream to disk--input-codec=CODEC    RTP requires the codec to be set, one of these:* h264, h265* vp8, vp9* mpeg2, mpeg4* mjpeg--input-decoder=TYPE   the decoder engine to use, one of these:* cpu* omx  (aarch64/JetPack4 only)* v4l2 (aarch64/JetPack5 only)--input-flip=FLIP      flip method to apply to input:* none (default)* counterclockwise* rotate-180* clockwise* horizontal* vertical* upper-right-diagonal* upper-left-diagonal--input-loop=LOOP      for file-based inputs, the number of loops to run:* -1 = loop forever*  0 = don't loop (default)* >0 = set number of loops

2.2 输出

OutputProtocolResource URINotes
WebRTC streamwebrtc://webrtc://@:8554/my_outputSend to browser, port 8554, stream name “my_output”
RTP streamrtp://rtp://:1234Replace with remote host’s IP or hostname
RTSP streamrtsp://rtsp://@:1234/my_outputReachable at rtsp://:1234/my_output
Video filefile://file://my_video.mp4Supports saving MP4, MKV, AVI, FLV (see codecs below)
Image filefile://file://my_image.jpgSupports saving JPG, PNG, TGA, BMP
Image sequencefile://file://image_%i.jpg%i is replaced by the image number in the sequence
OpenGL windowdisplay://display://0Creates GUI window on screen 0
    output               resource URI of the output stream, for example:* file://my_image.jpg       (image file)* file://my_video.mp4       (video file)* file://my_directory/      (directory of images)* rtp://<remote-ip>:1234    (RTP stream)* rtsp://@:8554/my_stream   (RTSP stream)* webrtc://@:1234/my_stream (WebRTC stream)* display://0               (OpenGL window)--output-codec=CODEC   desired codec for compressed output streams:* h264 (default), h265* vp8, vp9* mpeg2, mpeg4* mjpeg--output-encoder=TYPE  the encoder engine to use, one of these:* cpu* omx  (aarch64/JetPack4 only)* v4l2 (aarch64/JetPack5 only)--output-save=FILE     path to a video file for saving the compressed streamto disk, in addition to the primary output above--bitrate=BITRATE      desired target VBR bitrate for compressed streams,in bits per second. The default is 4000000 (4 Mbps)--headless             don't create a default OpenGL GUI window

3. 示例

3.1 MIPI CSI 摄像头

$ video-viewer csi://0                        # MIPI CSI camera 0 (substitue other camera numbers)
$ video-viewer csi://0 output.mp4             # save output stream to MP4 file (H.264 by default)
$ video-viewer csi://0 rtp://<remote-ip>:1234 # broadcast output stream over RTP to <remote-ip>

3.2 V4L2 摄像头

$ video-viewer v4l2:///dev/video0                 # /dev/video0 can be replaced with /dev/video1, ect.
$ video-viewer /dev/video0                        # dropping the v4l2:// protocol prefix is fine
$ video-viewer /dev/video0 output.mp4             # save output stream to MP4 file (H.264 by default)
$ video-viewer /dev/video0 rtp://<remote-ip>:1234 # broadcast output stream over RTP to <remote-ip>

3.3 WebRTC

$ video-viewer /dev/video0 webrtc://@:8554/my_output               # send V4L2 webcam to browser
$ video-viewer webrtc://@:8554/my_input output.mp4                 # receive browser webcam (requires HTTPS/SSL) and save to MP4
$ video-viewer webrtc://@:8554/my_input webrtc://@:8554/my_output  # receieve + send (full-duplex loopback)

3.4 RTP

$ video-viewer --input-codec=h264 rtp://@:1234         # recieve on localhost port 1234
$ video-viewer --input-codec=h264 rtp://224.0.0.0:1234 # subscribe to multicast group
$ video-viewer --bitrate=1000000 csi://0 rtp://<remote-ip>:1234         # transmit camera over RTP, encoded as H.264 @ 1Mbps 
$ video-viewer --output-codec=h265 my_video.mp4 rtp://<remote-ip>:1234  # transmit a video file over RTP, encoded as H.265

3.5 RTSP

$ video-viewer rtsp://<remote-ip>:1234 my_video.mp4      # subscribe to RTSP feed from <remote-ip>, port 1234 (and save it to file)
$ video-viewer rtsp://username:password@<remote-ip>:1234 # with authentication (replace username/password with credentials)
$ video-viewer /dev/video0 rtsp://@:1234/my_output                 # stream a V4L2 camera out over RTSP 
$ video-viewer rtsp://<remote-ip>:1234/input rtsp://@:1234/output  # subscribe to an RTSP feed, and relay it (loopback)

3.6 Video 文件

# playback
$ video-viewer my_video.mp4                              # display the video file
$ video-viewer my_video.mp4 rtp://<remote-ip>:1234       # transmit the video over RTP# recording
$ video-viewer csi://0 my_video.mp4                      # record CSI camera to video file
$ video-viewer /dev/video0 my_video.mp4                  # record V4L2 camera to video file

3.7 Image 文件

$ video-viewer input.jpg output.jpg	# load/save an image
$ video-viewer input_dir/ output_dir/   # load all images from input_dir and save them to output_dir
$ video-viewer "*.jpg" output_%i.jpg    # load all jpg images and save them to output_0.jpg, output_1.jpg, ect

4. 代码分析

4.1 Python

代码:video-viewer.py

Root
├── Imports
│   ├── import sys
│   ├── import argparse
│   └── from jetson_utils import videoSource, videoOutput, Log
├── Command-line Argument Parsing
│   ├── Create Argument Parser
│   │   ├── Description: "View various types of video streams"
│   │   ├── Formatter Class: argparse.RawTextHelpFormatter
│   │   └── Epilog: videoSource.Usage() + videoOutput.Usage() + Log.Usage()
│   ├── Add Arguments
│   │   ├── input (URI of the input stream)
│   │   └── output (URI of the output stream, optional)
│   └── Parse Arguments
│       ├── args = parser.parse_known_args()[0]
│       └── Handle Parsing Exceptions
│           ├── Print Help
│           └── Exit
├── Create Video Sources & Outputs
│   ├── input = videoSource(args.input, argv=sys.argv)
│   └── output = videoOutput(args.output, argv=sys.argv)
├── Capture Frames Loop├── Initialize Frame Counter│   └── numFrames = 0├── while True Loop├── Capture Image│   └── img = input.Capture()├── Handle Timeout│   └── if img is None: continue├── Log Verbose Information│   └── if numFrames % 25 == 0 or numFrames < 15:│       └── Log.Verbose(...)├── Increment Frame Counter│   └── numFrames += 1├── Render Image│   └── output.Render(img)├── Update Title Bar│   └── output.SetStatus(...)└── Exit on EOS├── if not input.IsStreaming() or not output.IsStreaming():└── break

4.2 C++

代码:video-viewer.cpp

#include statements
├── "videoSource.h"
├── "videoOutput.h"
├── "logging.h"
├── "commandLine.h"
└── <signal.h>Global variables
└── bool signal_recieved = false;Function definitions
├── void sig_handler(int signo)
│   └── if (signo == SIGINT)
│       ├── LogInfo("received SIGINT\n");
│       └── signal_recieved = true;
└── int usage()├── printf("usage: video-viewer [--help] input_URI [output_URI]\n\n");├── printf("View/output a video or image stream.\n");├── printf("See below for additional arguments that may not be shown above.\n\n");├── printf("positional arguments:\n");├── printf("    input_URI       resource URI of input stream  (see videoSource below)\n");├── printf("    output_URI      resource URI of output stream (see videoOutput below)\n\n");├── printf("%s", videoSource::Usage());├── printf("%s", videoOutput::Usage());└── printf("%s", Log::Usage());main function
├── Parse command line
│   ├── commandLine cmdLine(argc, argv);
│   └── if (cmdLine.GetFlag("help"))
│       └── return usage();
├── Attach signal handler
│   └── if (signal(SIGINT, sig_handler) == SIG_ERR)
│       └── LogError("can't catch SIGINT\n");
├── Create input video stream
│   ├── videoSource* input = videoSource::Create(cmdLine, ARG_POSITION(0));
│   └── if (!input)
│       ├── LogError("video-viewer:  failed to create input stream\n");
│       └── return 0;
├── Create output video stream
│   ├── videoOutput* output = videoOutput::Create(cmdLine, ARG_POSITION(1));
│   └── if (!output)
│       ├── LogError("video-viewer:  failed to create output stream\n");
│       └── return 0;
├── Capture/display loop
│   ├── uint32_t numFrames = 0;
│   └── while (!signal_recieved)
│       ├── uchar3* image = NULL;
│       ├── int status = 0;
│       ├── if (!input->Capture(&image, &status))
│       │   └── if (status == videoSource::TIMEOUT)
│       │       └── continue;
│       │   └── break; // EOS
│       ├── if (numFrames % 25 == 0 || numFrames < 15)
│       │   └── LogVerbose("video-viewer:  captured %u frames (%ux%u)\n", numFrames, input->GetWidth(), input->GetHeight());
│       ├── numFrames++;
│       └── if (output != NULL)
│           ├── output->Render(image, input->GetWidth(), input->GetHeight());
│           ├── char str[256];
│           ├── sprintf(str, "Video Viewer (%ux%u) | %.1f FPS", input->GetWidth(), input->GetHeight(), output->GetFrameRate());
│           ├── output->SetStatus(str);
│           └── if (!output->IsStreaming())
│               └── break;
├── Destroy resources
│   ├── printf("video-viewer:  shutting down...\n");
│   ├── SAFE_DELETE(input);
│   └── SAFE_DELETE(output);
└── printf("video-viewer:  shutdown complete\n");

5. 参考资料

【1】jetson-inference - Camera Streaming and Multimedia

这篇关于Linux 36.3 + JetPack v6.0@jetson-inference之视频操作的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/1020611

相关文章

流媒体平台/视频监控/安防视频汇聚EasyCVR播放暂停后视频画面黑屏是什么原因?

视频智能分析/视频监控/安防监控综合管理系统EasyCVR视频汇聚融合平台,是TSINGSEE青犀视频垂直深耕音视频流媒体技术、AI智能技术领域的杰出成果。该平台以其强大的视频处理、汇聚与融合能力,在构建全栈视频监控系统中展现出了独特的优势。视频监控管理系统EasyCVR平台内置了强大的视频解码、转码、压缩等技术,能够处理多种视频流格式,并以多种格式(RTMP、RTSP、HTTP-FLV、WebS

linux-基础知识3

打包和压缩 zip 安装zip软件包 yum -y install zip unzip 压缩打包命令: zip -q -r -d -u 压缩包文件名 目录和文件名列表 -q:不显示命令执行过程-r:递归处理,打包各级子目录和文件-u:把文件增加/替换到压缩包中-d:从压缩包中删除指定的文件 解压:unzip 压缩包名 打包文件 把压缩包从服务器下载到本地 把压缩包上传到服务器(zip

综合安防管理平台LntonAIServer视频监控汇聚抖动检测算法优势

LntonAIServer视频质量诊断功能中的抖动检测是一个专门针对视频稳定性进行分析的功能。抖动通常是指视频帧之间的不必要运动,这种运动可能是由于摄像机的移动、传输中的错误或编解码问题导致的。抖动检测对于确保视频内容的平滑性和观看体验至关重要。 优势 1. 提高图像质量 - 清晰度提升:减少抖动,提高图像的清晰度和细节表现力,使得监控画面更加真实可信。 - 细节增强:在低光条件下,抖

Linux 网络编程 --- 应用层

一、自定义协议和序列化反序列化 代码: 序列化反序列化实现网络版本计算器 二、HTTP协议 1、谈两个简单的预备知识 https://www.baidu.com/ --- 域名 --- 域名解析 --- IP地址 http的端口号为80端口,https的端口号为443 url为统一资源定位符。CSDNhttps://mp.csdn.net/mp_blog/creation/editor

【Python编程】Linux创建虚拟环境并配置与notebook相连接

1.创建 使用 venv 创建虚拟环境。例如,在当前目录下创建一个名为 myenv 的虚拟环境: python3 -m venv myenv 2.激活 激活虚拟环境使其成为当前终端会话的活动环境。运行: source myenv/bin/activate 3.与notebook连接 在虚拟环境中,使用 pip 安装 Jupyter 和 ipykernel: pip instal

Linux_kernel驱动开发11

一、改回nfs方式挂载根文件系统         在产品将要上线之前,需要制作不同类型格式的根文件系统         在产品研发阶段,我们还是需要使用nfs的方式挂载根文件系统         优点:可以直接在上位机中修改文件系统内容,延长EMMC的寿命         【1】重启上位机nfs服务         sudo service nfs-kernel-server resta

【Linux 从基础到进阶】Ansible自动化运维工具使用

Ansible自动化运维工具使用 Ansible 是一款开源的自动化运维工具,采用无代理架构(agentless),基于 SSH 连接进行管理,具有简单易用、灵活强大、可扩展性高等特点。它广泛用于服务器管理、应用部署、配置管理等任务。本文将介绍 Ansible 的安装、基本使用方法及一些实际运维场景中的应用,旨在帮助运维人员快速上手并熟练运用 Ansible。 1. Ansible的核心概念

Linux服务器Java启动脚本

Linux服务器Java启动脚本 1、初版2、优化版本3、常用脚本仓库 本文章介绍了如何在Linux服务器上执行Java并启动jar包, 通常我们会使用nohup直接启动,但是还是需要手动停止然后再次启动, 那如何更优雅的在服务器上启动jar包呢,让我们一起探讨一下吧。 1、初版 第一个版本是常用的做法,直接使用nohup后台启动jar包, 并将日志输出到当前文件夹n

[Linux]:进程(下)

✨✨ 欢迎大家来到贝蒂大讲堂✨✨ 🎈🎈养成好习惯,先赞后看哦~🎈🎈 所属专栏:Linux学习 贝蒂的主页:Betty’s blog 1. 进程终止 1.1 进程退出的场景 进程退出只有以下三种情况: 代码运行完毕,结果正确。代码运行完毕,结果不正确。代码异常终止(进程崩溃)。 1.2 进程退出码 在编程中,我们通常认为main函数是代码的入口,但实际上它只是用户级