From b96ee520efd5024310f1b82c0edd295a637a2815 Mon Sep 17 00:00:00 2001 From: Morgan Aldridge Date: Fri, 3 Oct 2025 12:17:25 -0400 Subject: [PATCH 1/3] Removing use of -thread_queue_size in hopes of reducing/removing desync as my understanding is that will let ffmpeg drop packets it couldn't process fast enough instead of forcing them to be queued and processed in order, regardless of timing. Issue #5 --- fauxstream | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) mode change 100755 => 100644 fauxstream diff --git a/fauxstream b/fauxstream old mode 100755 new mode 100644 index e4fad15..a88e579 --- a/fauxstream +++ b/fauxstream @@ -213,12 +213,10 @@ echo "): ${resolution}${offset}\n" GLOBAL="\ -hide_banner \ -loglevel error \ --thread_queue_size 512 \ -threads $threads\ " VIDEO_IN="\ --thread_queue_size 512 \ -show_region 1 \ ${video_device} \ -f x11grab \ @@ -244,13 +242,11 @@ ${video_format} \ " MON_IN="\ --thread_queue_size 512 \ -f sndio \ -i snd/mon\ " MIC_IN="\ --thread_queue_size 512 \ -f sndio \ -i "$mic_device"\ " @@ -272,15 +268,24 @@ AUDIOMERGE="\ if [ $noaudio -lt 1 -a $mic -lt 1 ]; then #only monitoring stream - RUN="ffmpeg $GLOBAL $MON_IN $AUDIO_CONV -f nut pipe:1 | \ - ffmpeg $GLOBAL -thread_queue_size 512 -f nut -itsoffset $audiooffset -i pipe:0 \ - $VIDEO_IN $VIDEO_CONV -c:a copy -f "${container}" \"$filename\"" + RUN="ffmpeg $GLOBAL \ + $MON_IN \ + $AUDIO_CONV -f nut pipe:1 | \ + ffmpeg $GLOBAL \ + -f nut -itsoffset $audiooffset -i pipe:0 \ + $VIDEO_IN $VIDEO_CONV -c:a copy \ + -f "${container}" \"$filename\"" elif [ $noaudio -lt 1 ]; then #mon + mic stream - RUN="ffmpeg $GLOBAL $MIC_IN $MON_IN -filter_complex \"${AUDIOMERGE}\" \ - -map '[a]' $AUDIO_CONV -f nut pipe:1 | \ - ffmpeg $GLOBAL -thread_queue_size 512 -f nut -itsoffset $audiooffset -i pipe:0 \ - $VIDEO_IN $VIDEO_CONV -c:a copy -f "${container}" \"$filename\"" + RUN="ffmpeg $GLOBAL \ + $MIC_IN \ + $MON_IN \ + -filter_complex \"${AUDIOMERGE}\" -map '[a]' \ + $AUDIO_CONV -f nut pipe:1 | \ + ffmpeg $GLOBAL \ + -f nut -itsoffset $audiooffset -i pipe:0 \ + $VIDEO_IN $VIDEO_CONV -c:a copy \ + -f "${container}" \"$filename\"" else #no audio RUN="ffmpeg $GLOBAL $VIDEO_IN $VIDEO_CONV -f "${container}" \"$filename\"" From b5de6a92cde34b0b71c646288162805c2308f73f Mon Sep 17 00:00:00 2001 From: Morgan Aldridge Date: Mon, 13 Oct 2025 21:08:00 -0400 Subject: [PATCH 2/3] Reintroduce conservative use of -thread_queue_size ('64' instead of '512', plus only on the video & audio input when encoding, not on the raw audio inputs being merged). Also introduces the use of the filter on the individual audio streams being merged/mixed-down _and_ when merging the video and audio. The latter required moving the audio encoding to the ffmpeg process which is encoding the video. By using the 'async=1' option, the 'aresample' filter will fill and/or trim audio to keep it synced, but will not perform the more advanced stretch and/or sqeezing (I think this makes sense for our uses and _should_ be more efficient). Issue #5 --- fauxstream | 38 +++++++++++++++++++++++++------------- 1 file changed, 25 insertions(+), 13 deletions(-) diff --git a/fauxstream b/fauxstream index a88e579..e1f96df 100644 --- a/fauxstream +++ b/fauxstream @@ -217,6 +217,7 @@ GLOBAL="\ " VIDEO_IN="\ +-thread_queue_size 64 \ -show_region 1 \ ${video_device} \ -f x11grab \ @@ -258,8 +259,8 @@ AUDIO_CONV="\ " AUDIOMERGE="\ -[0]volume=$volume_mic,aformat=channel_layouts=stereo$hilopass[l];\ -[1]volume=$volume_mon,aformat=channel_layouts=stereo[m];\ +[0]aresample=async=1,volume=$volume_mic,aformat=channel_layouts=stereo$hilopass[l];\ +[1]aresample=async=1,volume=$volume_mon,aformat=channel_layouts=stereo[m];\ [l][m]amix=inputs=2[a]\ " @@ -269,26 +270,37 @@ AUDIOMERGE="\ if [ $noaudio -lt 1 -a $mic -lt 1 ]; then #only monitoring stream RUN="ffmpeg $GLOBAL \ - $MON_IN \ - $AUDIO_CONV -f nut pipe:1 | \ + $MON_IN \ + -f nut pipe:1 | \ ffmpeg $GLOBAL \ - -f nut -itsoffset $audiooffset -i pipe:0 \ - $VIDEO_IN $VIDEO_CONV -c:a copy \ - -f "${container}" \"$filename\"" + -thread_queue_size 64 \ + -f nut -itsoffset $audiooffset -i pipe:0 \ + -filter_complex aresample=async=1 \ + $VIDEO_IN \ + $VIDEO_CONV \ + $AUDIO_CONV \ + -f "${container}" \"$filename\"" elif [ $noaudio -lt 1 ]; then #mon + mic stream RUN="ffmpeg $GLOBAL \ - $MIC_IN \ + $MIC_IN \ $MON_IN \ -filter_complex \"${AUDIOMERGE}\" -map '[a]' \ - $AUDIO_CONV -f nut pipe:1 | \ + -f nut pipe:1 | \ ffmpeg $GLOBAL \ - -f nut -itsoffset $audiooffset -i pipe:0 \ - $VIDEO_IN $VIDEO_CONV -c:a copy \ - -f "${container}" \"$filename\"" + -thread_queue_size 64 \ + -f nut -itsoffset $audiooffset -i pipe:0 \ + -filter_complex aresample=async=1 \ + $VIDEO_IN \ + $VIDEO_CONV \ + $AUDIO_CONV \ + -f "${container}" \"$filename\"" else #no audio - RUN="ffmpeg $GLOBAL $VIDEO_IN $VIDEO_CONV -f "${container}" \"$filename\"" + RUN="ffmpeg $GLOBAL \ + $VIDEO_IN \ + $VIDEO_CONV \ + -f "${container}" \"$filename\"" fi echo "$RUN\n" From ef19a7c03343a2f58b578e2b840973b3fc49cb3d Mon Sep 17 00:00:00 2001 From: Morgan Aldridge Date: Fri, 14 Nov 2025 11:57:35 -0500 Subject: [PATCH 3/3] Restored original line break formatting (one ffmpeg instance per line; if line is too long, break with additional indentation) and tabs for indentation --- fauxstream | 32 +++++++------------------------- 1 file changed, 7 insertions(+), 25 deletions(-) diff --git a/fauxstream b/fauxstream index e1f96df..9966f72 100644 --- a/fauxstream +++ b/fauxstream @@ -269,38 +269,20 @@ AUDIOMERGE="\ if [ $noaudio -lt 1 -a $mic -lt 1 ]; then #only monitoring stream - RUN="ffmpeg $GLOBAL \ - $MON_IN \ - -f nut pipe:1 | \ - ffmpeg $GLOBAL \ - -thread_queue_size 64 \ - -f nut -itsoffset $audiooffset -i pipe:0 \ - -filter_complex aresample=async=1 \ - $VIDEO_IN \ - $VIDEO_CONV \ - $AUDIO_CONV \ + RUN="ffmpeg $GLOBAL $MON_IN -f nut pipe:1 | \ + ffmpeg $GLOBAL -thread_queue_size 64 -f nut -itsoffset $audiooffset -i pipe:0 \ + -filter_complex aresample=async=1 $VIDEO_IN $VIDEO_CONV $AUDIO_CONV \ -f "${container}" \"$filename\"" elif [ $noaudio -lt 1 ]; then #mon + mic stream - RUN="ffmpeg $GLOBAL \ - $MIC_IN \ - $MON_IN \ - -filter_complex \"${AUDIOMERGE}\" -map '[a]' \ + RUN="ffmpeg $GLOBAL $MIC_IN $MON_IN -filter_complex \"${AUDIOMERGE}\" -map '[a]' \ -f nut pipe:1 | \ - ffmpeg $GLOBAL \ - -thread_queue_size 64 \ - -f nut -itsoffset $audiooffset -i pipe:0 \ - -filter_complex aresample=async=1 \ - $VIDEO_IN \ - $VIDEO_CONV \ - $AUDIO_CONV \ + ffmpeg $GLOBAL -thread_queue_size 64 -f nut -itsoffset $audiooffset -i pipe:0 \ + -filter_complex aresample=async=1 $VIDEO_IN $VIDEO_CONV $AUDIO_CONV \ -f "${container}" \"$filename\"" else #no audio - RUN="ffmpeg $GLOBAL \ - $VIDEO_IN \ - $VIDEO_CONV \ - -f "${container}" \"$filename\"" + RUN="ffmpeg $GLOBAL $VIDEO_IN $VIDEO_CONV -f "${container}" \"$filename\"" fi echo "$RUN\n"