Streaming from OBS freezes and stutters.

Discussion about this major DATV Project. See https://wiki.batc.org.uk/The_Portsdown_Transmitter
Nick
Posts: 121
Joined: Sat Oct 03, 2015 10:09 am

Streaming from OBS freezes and stutters.

Post by Nick » Fri Feb 05, 2021 10:16 pm

Hello,

I am finally beginning to understand and use OBS and have now a hopefully small issue when using Recording to send video/audio using ffmpeg.

I am using the batch file and ini file as per Wiki https://wiki.batc.org.uk/OBS_-_Open_Broadcast_Studio

For testing purposes I have replaced the IP address for Portsdown with the IP address for another computer to view the stream using VLC player. Occasionally I get a number of errors at startup but the steam does send to VLC on the second computer.

However, after a minute or two the steam stops with the error message shown in Red in the image below.

Errors displayed when recording from OBS.
Errors displayed when recording from OBS.
TS Errors.jpg (472.85 KiB) Viewed 2492 times

The batch file I am using is as below:-

@echo off
rem FEC 2/3
rem edited By G7JTT May 2019
rem Feb 2019 by Evariste F5OEO - QO-100 Release 0.9 (Completely rewritten)
rem Started from original tool
rem Idea from Portsdown vmix ffmpeg script

rem ================= SETUP ONCE ===========

set callsign=G4NKV
rem Set appropriately
rem set raspi_ip=230.0.0.10
set raspi_ip=192.168.1.27
rem set raspi_ip=10.0.0.1
set ip=%raspi_ip%:10000

rem ================= INTERACTIVE =======================
rem --- SR asked only once ----
rem set SR=250
cls
:promptme
rem ADD THE PROMPT TEXT TO THE LINE BELOW IE ==== Enter 125, 250,333,500,1M ====
echo ==== FEC 2/3 --- Enter SR 125, 250, 333, 500, 1000 ====
echo.
set /p SR="SymbolRate(Ks) (%SR%) "
rem DUPLICATE THE LINE BELOW FOR EXTRA SR/FEC COMBOS
IF "%SR%"=="125" (SET TSBITRATE=165300)
IF "%SR%"=="250" (SET TSBITRATE=330600)
IF "%SR%"=="333" (SET TSBITRATE=440300)
IF "%SR%"=="500" (SET TSBITRATE=661100)
IF "%SR%"=="1000" (SET TSBITRATE=1322300)
IF "%TSBITRATE%"=="" (GOTO :promptme)
echo.
echo SR=%SR%
echo Muxrate=%TSBITRATE%
echo ip=%ip%
echo callsign=%callsign%
echo TSBITRATE=%TSBITRATE%

rem ======================== Launch ffmpeg OBS =========================
echo.
echo launch ffmpeg OBS
echo.
pause
start "OBS to udp/ts" /high ^
C:\ffmpeg\bin\ffmpeg ^
-i udp://230.0.0.11:20000 -c:v copy -max_delay 1000000 -muxrate %TSBITRATE% -c:a copy ^
-f mpegts -mpegts_original_network_id 1 -mpegts_transport_stream_id 1 -mpegts_service_id 1 -mpegts_pmt_start_pid 4096 -streamid 0:256 -streamid 1:257 ^
-metadata service_provider="QO-100" -metadata service_name=%callsign% ^
-flush_packets 0 -f mpegts "udp://%ip%:?overrun_nonfatal=1&fifo_size=2000000&pkt_size=1316&bitrate=%TSBITRATE%"


I have made a few changes. The text "1000" in "udp://%ip%:10000?pkt_size=1316&bitrate=%TSBITRATE%" was removed as it seemed to duplicate the IP address, but this did not cure the issue with the stream freezing (red errors shown in image above).

After some searching on Google I added "overrun_nonfatal=1&fifo_size=2000000&" to the script above. This seems to have stopped the script from freezing, but I don't know enough about ffmpeg to know why this works or if I should have put this in.

While the freezing has stopped I am still getting some stuttering on the VLC player on the other computer. This occurs when there is quick movement on the video and results in the Yellow errors "TS is invalid" in the image above. When the quick movement stops VLC resumes showing the video.

The computer I am running OBS on is an Intel I7 at 4GHz, with 16GByte of memory. Task manager shows there is not much load on the processor and only 4GByte of memory in use. All tests have been done with FEC 2/3 and SR of 250ks.

How can I alter the script to make the stream smooth and remove these error messages ?

Any advice will be much appreciated.

Regards,

Nick -G4NKV

g0mjw
Posts: 2346
Joined: Sat Sep 20, 2014 9:15 am

Re: Streaming from OBS freezes and stutters.

Post by g0mjw » Sat Feb 06, 2021 12:12 am

That's a very old script. Did you look at my CQTV article?

Nick
Posts: 121
Joined: Sat Oct 03, 2015 10:09 am

Re: Streaming from OBS freezes and stutters.

Post by Nick » Sat Feb 06, 2021 12:45 am

Hi Mike,

Are you referring to the article on how to use a Pluto in the Winter 2020 issue. I see there is a part on using OBS with a virtual camera ???, but I have not tried to follow it as I do not have a Pluto.

Regards,

Nick - G4NKV

g0mjw
Posts: 2346
Joined: Sat Sep 20, 2014 9:15 am

Re: Streaming from OBS freezes and stutters.

Post by g0mjw » Sat Feb 06, 2021 9:49 am

Nick,

Yes it was about the Pluto, but fundamentally it is producing a UDP transport stream, which is what you are trying to do. Look at the format of the ffmpeg commands. Until you understand ffmpeg it's unlikely you will get anywhere trying to edit that script as you don't know what you are doing. For example I think you deleted a key command at the end because you saw it as duplication.

The problem you have with dts < pcr is a audio / video timing error that usually appears from combination of trying to put too much video information through too small a multiplex pipe and also not having sufficient buffering to allow the codec to work with that content. If you set the video bitrate too high these errors will occur. If you set it too low the video will be terrible. Larger buffers help but add to the latency. If you try to put too high a resolution through the H264 encoder it will be very blocky with anything that moves. Some compromise is needed to get good results and it depends on the content. If you look at the example in the article you can see what settings I used for H264 2/3 333ks QPSK.

When that script was developed in 2019 we were in the early stages of understanding how to operate low bitrates successfully. There has been huge progress since then.

You should be able to take the H264 script, or an H265 script if you have a suitable graphics card or very fast CPU, and parameterise it if you want.

Mike

By the way, your script doesn't seem to do any coding, only copying, so if you are using OBS record you need to have the correct settings there too. That's quite a detailed thing to set up and covered in John G7JTTs article. Again there have been developments since that was written. If you don't match the TS rate coming out of OBS to that in the script it's going to overflow. The other way to do this is to either use OBS Camera plugin (not the built in version) or set a high quality UDP output from OBS and re-encode it in the batch script. This saves needing multiple OBS profiles for each bitrate.

G7JTT
Posts: 338
Joined: Fri Jun 10, 2016 5:05 pm

Re: Streaming from OBS freezes and stutters.

Post by G7JTT » Sat Feb 06, 2021 10:59 am

Hi Nick as Mike has suggested things have moved on since I first used OBS. I'm tending to agree using the virtual camera output from OBS seems the way to go as you don't need to set anything up in OBS other than screen res and FPS. I've started playing with this using Thomasz SQ6QV script as a starting point. Have a look here viewtopic.php?t=6496. The thing to remember though is no one script will work on all systems, there are just too many variables. So you'll need to tweak parameters within the script to match your actual setup.

Good luck John G7JTT

Nick
Posts: 121
Joined: Sat Oct 03, 2015 10:09 am

Re: Streaming from OBS freezes and stutters.

Post by Nick » Sun Feb 07, 2021 12:39 pm

Hi Mike and John,

Thanks for the replies. As suggested I will delete the scripts I am using and try the ones suggested. Hopefully it will be easier as I will not have to change the .ini file in the OBS profile directory. I have installed the OBS camera plugin ready to try it out.

My graphics card is an old Nvidia GTX960, and according to Nvidia website it has a GM206 GPU and should be suitable for H265 encoding with nvenc encoder so I will give it a try.

Regards,

Nick - G4NKV.

Nick
Posts: 121
Joined: Sat Oct 03, 2015 10:09 am

Re: Streaming from OBS freezes and stutters.

Post by Nick » Sun Feb 14, 2021 11:40 pm

Hello,

I have been making some progress with getting a script to work using OBS with the virtual camera plugin.

Based on the script by SQ6QV I can obtain reasonably good results when testing on the same computer using IP address of 127.0.0.1 and viewing on VLC player.

I can obtain basically stable results at SR's of 250, 333, 500 and 1000ks.

However, I can not get a symbol rate of 125ks to work. I was trying to use 125ks at 2/3 FEC which requires a TS bitrate of 166 kbit.

From my testing it seems that any setting below around 200 kbit fails with an error "dis < pcr TS is invalid"

I have tried other scripts such as those in CQ-TV 270 but with no success.

Can 125ks be used with ffmpeg, or am I expecting too much here ?

If it is possible, what do I need to do to get it to work ?

Regards,

Nick - G4NKV

g0mjw
Posts: 2346
Joined: Sat Sep 20, 2014 9:15 am

Re: Streaming from OBS freezes and stutters.

Post by g0mjw » Mon Feb 15, 2021 12:53 am

The script in CQTV should work, but if the content is too complex it might struggle. Try reducing frame rate, try reducing the video bandwidth.

This is working fine for me showing Bunny at 160k

c:\ffmpeg\bin\ffmpeg -f dshow -rtbufsize 1M -i video="OBS-Camera" -thread_queue_size 512 -f dshow -i audio="OBS-Audio" -vcodec hevc_nvenc -r 10 -s 1280x720 -pix_fmt yuv420p -preset slow -rc cbr -rc-lookahead 5 -b:v 90k -acodec aac -aac_coder twoloop -ar 48000 -ac 1 -b:a 24k -f mpegts -muxrate 160k -streamid 0:256 -streamid 1:257 -max_delay 3000000 -pcr_period 40 -pat_period 0.4 "udp://127.0.0.1:1234?pkt_size=1316"
Capture.JPG
Capture.JPG (564.08 KiB) Viewed 2096 times
Mike

Nick
Posts: 121
Joined: Sat Oct 03, 2015 10:09 am

Re: Streaming from OBS freezes and stutters.

Post by Nick » Mon Feb 15, 2021 1:24 am

Hi Mike,

Just tried that and it seems to be basically working, although on two occasions the video did freeze but the audio continued to work. When I restarted VLC player it started working again.

I will do some more testing tomorrow (sorry - later today) - probably at a smaller screen resolution and see if that makes any difference.

What is the video bandwidth setting ?

Thanks for the help.

Regards,

Nick - G4NKV

g0mjw
Posts: 2346
Joined: Sat Sep 20, 2014 9:15 am

Re: Streaming from OBS freezes and stutters.

Post by g0mjw » Mon Feb 15, 2021 10:56 pm

The video is set to 90k but it's not well behaved. It could be graphics card differences or codec differences but it should work. The problem I have is latency building, but not always.

Mike

Post Reply

Return to “The Portsdown Digital ATV System”