From 55baf868e6982f61e3c52a8cc5c19fabfe31fda1 Mon Sep 17 00:00:00 2001 From: Eli Mallon Date: Fri, 13 Jun 2025 12:57:39 -0700 Subject: [PATCH] app: opusparse on ingest, seems to fix a/v duration mismatch (#286) * app: opusparse on ingest, seems to fix a/v duration mismatch * hack: add segment-durations.sh --- hack/segment-durations.sh | 16 ++++++++++++++++ pkg/media/webrtc_ingest.go | 2 +- 2 files changed, 17 insertions(+), 1 deletion(-) create mode 100755 hack/segment-durations.sh diff --git a/hack/segment-durations.sh b/hack/segment-durations.sh new file mode 100755 index 00000000..491e0b9a --- /dev/null +++ b/hack/segment-durations.sh @@ -0,0 +1,16 @@ +#!/bin/bash + +# Splits a video stream apart into video and audio files and checks the discrepancy between them + +set -euo pipefail + +dir="$(mktemp -d)" +ffmpeg -i "$1" -vn -c:a copy "$dir/audio.mkv" 2>/dev/null >/dev/null +ffmpeg -i "$1" -an -c:v copy "$dir/video.mkv" 2>/dev/null >/dev/null +videoDuration=$(gst-discoverer-1.0 "$dir/video.mkv" | grep "Duration" | sed 's/ Duration: 0:00:0//') +audioDuration=$(gst-discoverer-1.0 "$dir/audio.mkv" | grep "Duration" | sed 's/ Duration: 0:00:0//') + +echo "Video duration: $videoDuration" +echo "Audio duration: $audioDuration" +echo "Difference (negative means audio is longer): $(node -p "$videoDuration - $audioDuration")" +rm -rf "$dir" diff --git a/pkg/media/webrtc_ingest.go b/pkg/media/webrtc_ingest.go index 200bfbc1..4b5e2b62 100644 --- a/pkg/media/webrtc_ingest.go +++ b/pkg/media/webrtc_ingest.go @@ -34,7 +34,7 @@ func (mm *MediaManager) WebRTCIngest(ctx context.Context, offer *webrtc.SessionD pipelineSlice := []string{ "multiqueue name=queue", "appsrc format=time is-live=true do-timestamp=true name=videosrc ! capsfilter caps=application/x-rtp ! rtph264depay ! capsfilter caps=video/x-h264,stream-format=byte-stream,alignment=nal ! h264parse disable-passthrough=true config-interval=-1 ! h264timestamper ! identity ! queue.sink_0", - "appsrc format=time do-timestamp=true name=audiosrc ! capsfilter caps=application/x-rtp,media=audio,encoding-name=OPUS,payload=111 ! rtpopusdepay ! queue.sink_1", + "appsrc format=time do-timestamp=true name=audiosrc ! capsfilter caps=application/x-rtp,media=audio,encoding-name=OPUS,payload=111 ! rtpopusdepay ! opusparse ! queue.sink_1", } pipeline, err := gst.NewPipelineFromString(strings.Join(pipelineSlice, "\n")) -- 2.51.2