降低 H.264 视频的分辨率,仅在视频高于 1080p 时执行。

huangapple go评论57阅读模式
英文:

Downscale h264 video only if video is more than 1080p

问题

我的总体目标是确保只在必要时才会导致过多的CPU使用率。我将从GStreamer获取H.264 RTSP视频并保存它。想知道是否可以根据缓冲区大小和持续时间将视频保存为块(如果分辨率低于1080p,则无需重新编码H.264以降低CPU利用率,仅在分辨率高于1080p时降低视频分辨率)。有没有任何想法或示例GStreamer管道可以帮助我实现我想要的内容?

英文:

My overall objective is to ensure that i am not causing too much cpu usage unless necessary. I will be fetching h264 rtsp video from gstreamer and saving it. Wondering if i can save video in chunks (based on buffer size and duration) without re-encoding h264 if the resolution is less than 1080p (for less cpu utilization) and downscale the video only if it is more than 1080p.

Any idea or example gstreamer pipeline which can help me achieve what i wanted ?

答案1

得分: 1

你可以解码视频流的一个帧,检查其分辨率,然后根据分辨率启动相应的管道。

使用C/C++,你可以使用pad probe来获取解码器源pad上的pad caps,然后暂停并链接适当的文件sink或重新编码管道。

GstCaps *caps = gst_pad_get_current_caps(decoder_src_pad);
GstStructure *structure = gst_caps_get_structure(caps, 0);

gint width, height;
gst_structure_get_int(structure, "width", &width);
gst_structure_get_int(structure, "height", &height);

或者

只使用bash运行gst-discover-1.0来查找宽度和高度,然后解析文本。

user@computer:~$ gst-discoverer-1.0 -v rtsp://localhost:8554/test_stream
分析 rtsp://localhost:8554/test_stream
完成对 rtsp://localhost:8554/test_stream 的发现

属性:
  时长:99:99:99.999999999
  可寻址:否
  实时:是
  标签:
      视频编解码器:H.264(高级配置文件)
  未知 #0:application/x-rtp,媒体=(字符串)video,payload=(整数)96,clock-rate=(整数)90000,encoding-name=(字符串)H264,packetization-mode=(字符串)1,profile-level-id=(字符串)64001e,sprop-parameter-sets=(字符串)"Z2QAHqzZQKA9sBagICCoAAADAAgAAAMB5HixbLA\=\,aOvjyyLA",a-tool=(字符串)"vlc\ 3.0.16",a-recvonly=(字符串)"",a-type=(字符串)broadcast,a-charset=(字符串)UTF-8,ssrc=(无符号整数)1465660118,clock-base=(无符号整数)4212403521,seqnum-base=(无符号整数)49262,npt-start=(无符号整数)415603480000,play-speed=(双精度)1,play-scale=(双精度)1,onvif-mode=(布尔)false
    视频 #1:video/x-h264,流格式=(字符串)avc,对齐=(字符串)au,codec_data=(缓冲区)0164001effe1001d6764001eacd940a03db016a02020a8000003000800000301e478b16cb001000668ebe3cb22c0,level=(字符串)3,profile=(字符串)high,pixel-aspect-ratio=(分数)1/1,宽度=(整数)640,高度=(整数)480,帧速率=(分数)30/1,色度格式=(字符串)4:2:0,亮度位深度=(整数)8,色度位深度=(整数)8,色度度量标准=(字符串)2:4:5:1,解析=(布尔)true
      标签:
        视频编解码器:H.264(高级配置文件)
      
      编解码器:
        video/x-h264,流格式=(字符串)avc,对齐=(字符串)au,codec_data=(缓冲区)0164001effe1001d6764001eacd940a03db016a02020a8000003000800000301e478b16cb001000668ebe3cb22c0,level=(字符串)3,profile=(字符串)high,pixel-aspect-ratio=(分数)1/1,宽度=(整数)640,高度=(整数)480,帧速率=(分数)30/1,色度格式=(字符串)4:2:0,亮度位深度=(整数)8,色度位深度=(整数)8,色度度量标准=(字符串)2:4:5:1,解析=(布尔)true
      流 ID:1b3bae77f33eae0e586433000678603a00eb5148824d7cb146fe50e009eb5bf7/video:0:0:RTP:AVP:96
      宽度:640
      高度:480
      深度:24
      帧速率:30/1
      像素宽高比:1/1
      隔行扫描:否
      比特率:0
      最大比特率:0

希望这能帮助你理解如何获取视频分辨率并根据其启动适当的管道。

英文:

You could decode one frame of the video stream check its resolution then launch the appropriate pipeline depending on the resolution.

With C/C++ you could use a pad probe to get the pad caps on the src pad of the decoder then pause and link the appropriate file sink ore re-encode pipeline.

GstCaps *caps = gst_pad_get_current_caps(decoder_src_pad);
GstStructure *structure = gst_caps_get_structure(caps, 0);

gint width, height;
gst_structure_get_int(structure, "width", &width);
gst_structure_get_int(structure, "height", &height);

or

Using just bash run gst-discover-1.0 to find the width and height and just parse the text

user@computer:~$ gst-discoverer-1.0 -v rtsp://localhost:8554/test_stream
Analyzing rtsp://localhost:8554/test_stream
Done discovering rtsp://localhost:8554/test_stream

Properties:
  Duration: 99:99:99.999999999
  Seekable: no
  Live: yes
  Tags: 
      video codec: H.264 (High Profile)
  unknown #0: application/x-rtp, media=(string)video, payload=(int)96, clock-rate=(int)90000, encoding-name=(string)H264, packetization-mode=(string)1, profile-level-id=(string)64001e, sprop-parameter-sets=(string)"Z2QAHqzZQKA9sBagICCoAAADAAgAAAMB5HixbLA\=\,aOvjyyLA", a-tool=(string)"vlc\ 3.0.16", a-recvonly=(string)"", a-type=(string)broadcast, a-charset=(string)UTF-8, ssrc=(uint)1465660118, clock-base=(uint)4212403521, seqnum-base=(uint)49262, npt-start=(guint64)415603480000, play-speed=(double)1, play-scale=(double)1, onvif-mode=(boolean)false
    video #1: video/x-h264, stream-format=(string)avc, alignment=(string)au, codec_data=(buffer)0164001effe1001d6764001eacd940a03db016a02020a8000003000800000301e478b16cb001000668ebe3cb22c0, level=(string)3, profile=(string)high, pixel-aspect-ratio=(fraction)1/1, width=(int)640, height=(int)480, framerate=(fraction)30/1, chroma-format=(string)4:2:0, bit-depth-luma=(uint)8, bit-depth-chroma=(uint)8, colorimetry=(string)2:4:5:1, parsed=(boolean)true
      Tags:
        video codec: H.264 (High Profile)
      
      Codec:
        video/x-h264, stream-format=(string)avc, alignment=(string)au, codec_data=(buffer)0164001effe1001d6764001eacd940a03db016a02020a8000003000800000301e478b16cb001000668ebe3cb22c0, level=(string)3, profile=(string)high, pixel-aspect-ratio=(fraction)1/1, width=(int)640, height=(int)480, framerate=(fraction)30/1, chroma-format=(string)4:2:0, bit-depth-luma=(uint)8, bit-depth-chroma=(uint)8, colorimetry=(string)2:4:5:1, parsed=(boolean)true
      Stream ID: 1b3bae77f33eae0e586433000678603a00eb5148824d7cb146fe50e009eb5bf7/video:0:0:RTP:AVP:96
      Width: 640
      Height: 480
      Depth: 24
      Frame rate: 30/1
      Pixel aspect ratio: 1/1
      Interlaced: false
      Bitrate: 0
      Max bitrate: 0

huangapple
  • 本文由 发表于 2023年2月26日 21:20:01
  • 转载请务必保留本文链接:https://go.coder-hub.com/75572259.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定