GStreamer 管道同步启动和停止

问题描述 投票:0回答:1

我有两个 GStreamer 管道,当前正在使用控制台中的

gst-launch-1.0
运行。它们将两个 UDP 流(一个用于 H.264 数据,一个用于 RAW)存储在两个单独的文件中。 UDP 流来自同一来源:循环播放的视频。我希望这两个文件能够完美匹配帧,这样当我使用 VMAF 进行质量测量时,帧不匹配就不会起作用。

目前,我有一个 bash 脚本,可以在两个不同的 konsole 窗口中执行两个

gst-launch-1.0
命令:

...
# Save the AVC stream.
konsole --hold -e "gst-launch-1.0 -v -e udpsrc uri=udp://0.0.0.0 port=$port_avc ! \
        \"application/x-rtp, media=(string)video, clock-rate=(int)90000, \
        encoding-name=(string)H264, payload=(int)96\" ! \
        rtph264depay ! h264parse ! mp4mux ! filesink location=$loc_avc" &
# Save the RAW stream.
konsole --hold -e "gst-launch-1.0 -v -e udpsrc uri=udp://0.0.0.0 port=$port_raw ! \
        \"application/x-rtp, media=(string)video, \
        clock-rate=(int)90000, encoding-name=(string)RAW, sampling=(string)YCbCr-4:2:0, \
        depth=(string)8, width=(string)1024, height=(string)768, colorimetry=(string)SMPTE240M, \
        payload=(int)96, a-framerate=(string)60\" ! rtpvrawdepay ! videorate ! \
        \"video/x-raw, framerate=(fraction)60/1\" ! \
        y4menc ! filesink location=$loc_raw" &
...

但是,此设置存在一些问题。首先,这两个命令并不是真正同时启动的;有几分之一秒的延迟。其次,我需要手动进入窗口并使用 Ctrl + C 关闭管道才能正确保存文件;之后,我需要转到运行脚本的控制台并手动终止 Konsole 窗口。

我尝试通过在脚本中添加

trap 'kill 0' SIGINT
来修复此问题;当我按 Ctrl + C 时,它会自动终止窗口来完成这项工作;但是,由于 gstreamer 管道未收到 EOS,因此文件永远无法正确保存。我也尝试过在 konsole 命令中使用
trap 'kill 0' SIGINT
(通过使用
konsole -e bash -c <command>
),但我仍然没有达到预期的效果。

我可以做什么来解决这个问题?有没有办法使用控制台命令确保两个管道同时启动和结束?或者有没有更好的方法使用 gstreamer 本身来做到这一点?

bash gstreamer konsole vmaf
1个回答
0
投票

您可以仅使用一个 gst-launch-1.0 命令启动两个管道:

gst-launch-1.0 -ev  \
udpsrc uri=udp://0.0.0.0 port=$port_avc ! \
 \"application/x-rtp, media=(string)video, clock-rate=(int)90000, \
 encoding-name=(string)H264, payload=(int)96\" ! \
 rtph264depay ! h264parse ! mp4mux ! filesink location=$loc_avc    \
udpsrc uri=udp://0.0.0.0 port=$port_raw ! \
 \"application/x-rtp, media=(string)video, \
 clock-rate=(int)90000, encoding-name=(string)RAW, sampling=(string)YCbCr-4:2:0, \
 depth=(string)8, width=(string)1024, height=(string)768, colorimetry=(string)SMPTE240M, \
 payload=(int)96, a-framerate=(string)60\" ! rtpvrawdepay ! videorate ! \
 \"video/x-raw, framerate=(fraction)60/1\" ! \
 y4menc ! filesink location=$loc_raw
© www.soinside.com 2019 - 2024. All rights reserved.