SQ6QV script

From BATC Wiki
Revision as of 16:31, 20 May 2020 by SQ6QV (talk | contribs)
Jump to navigation Jump to search

This script is used to encode video and audio from programs like OBS Studio or VMix using their webcam emulation interfaces. You can also stream webcam directly without any of these programs (on slow computers).

This version is simplified one for use on low bitrate streams.

You should start changing resolution settings: OBS: Settings-Picture-resolution: 1280x720 VMix: Settings-Display-output size: 1280x720

On OBS You need to install OBS-VirtualCam Plugin: https://obsproject.com/forum/resources/obs-virtualcam.539/

Next You need to download ffmpeg and unpack it to the same directory as script https://www.ffmpeg.org/download.html

Next You must customize script a little. Change CALL, fill Your name and change where output stream will go (192.168.10.208:2244) in this example

It is configured now for 442 kbit/s H.265 1280x720 and 32kbit AAC and use of OBS

You can change bitrate in this line set TS=442

Sorry, but I do not have time to respond to emails about this script, just ask on chat, many will help You.

@echo off
set STATION=CALL
set NAME=First Name

rem 726  333 8PSK FEC 3/4 long + pilots
rem 646  333 8PSK FEC 2/3 long +pilots
rem 442  333 QPSK FEC 2/3 long no pilots


set TS=442
set AUDIO_RATE=32

set AUDIO_SAMPLE_RATE=22050
rem set AUDIO_SAMPLE_RATE=44100

SET OUTPUT_IP=192.168.10.208:2244
rem SET OUTPUT_IP=192.168.0.101:10000

 
set /a TS_NO_AUDIO=%TS%-%AUDIO_RATE%
set /a VIDEO_RATE=%TS_NO_AUDIO% * 50 / 100 
set /a BUFSIZE=%VIDEO_RATE% *4 / 10 

set /a TSBITRATE=%TS% * 1000 
echo -------------------------
echo TS rate: %TS% kbit
echo Video: %VIDEO_RATE% kbit
echo Audio: %AUDIO_RATE% kbit

set /a MAX_VIDEO_RATE=%VIDEO_RATE%
set /a MIN_VIDEO_RATE=%VIDEO_RATE% / 10

set TEXTY=660
set /a TEXTYY=%TEXTY% +22
set TEXTCOL=0x33CCFFEE
set DATECOL=0xFFCC00FF
set T2_SIZE=50

set TEXT_CMD=-vf "drawtext=text=%%{gmtime\\:%%d %%b %%Y %%X}:x=10:y=10:fontsize=%T2_SIZE%:fontcolor=%DATECOL%:shadowcolor=0x00007f9f:shadowx=2:shadowy=2, drawtext=text='%STATION%':x=25:y=%TEXTY%:fontsize=%T2_SIZE%:fontcolor=%TEXTCOL%:shadowcolor=0x00007f9f:shadowx=2:shadowy=2"

rem WITHOUT DATE
set TEXT_CMD=-vf "drawtext=text='%STATION%':x=25:y=%TEXTY%:fontsize=%T2_SIZE%:fontcolor=%TEXTCOL%:shadowcolor=0x00007f9f:shadowx=2:shadowy=2"

rem NO OVERLAY
set TEXT_CMD=

set OUTPUT_STREAM=-f mpegts -avoid_negative_ts 1 -max_delay 300000  -muxrate %TS%k  -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="%STATION%" -metadata service_name="%NAME%" -y "udp://%OUTPUT_IP%?pkt_size=1316"

set VIDEO_DEVICE="OBS-Camera"
set AUDIO_SOURCE="OBS-Audio"

rem set VIDEO_DEVICE="vMix Video"
rem set AUDIO_SOURCE="vMix Audio"


set RESOLUTION=640x480
rem set RESOLUTION=640x360
set RESOLUTION=1280x720
rem set RESOLUTION=1920x1080

rem set RESCALE=
rem set RESCALE=-vf crop=1440:1080,scale=640:480

set FPS=-r 30

rem set AUDIO_PARAMS=-acodec aac -aac_coder twoloop -aac_pns disable
rem set AUDIO_PARAMS=-af "highpass=f=250, lowpass=f=4000" -acodec ac3 -ar 22050 -ac 1
rem set AUDIO_PARAMS=-af "highpass=f=250, lowpass=f=4000" -acodec mp2 -ar 22050 -ac 1
set AUDIO_PARAMS=-af "highpass=f=250,lowpass=f=3000" -acodec aac -aac_coder twoloop -aac_pns disable -ar %AUDIO_SAMPLE_RATE% -ac 1
 	
rem ENCODING VIDEO ON GTX:
set VIDEO_CODEC=-pix_fmt yuv420p -vcodec hevc_nvenc -preset slow -tune psnr -profile:v main -rc-lookahead 20 -spatial_aq 1 -cbr 1 -rc cbr_hq -surfaces 64
rem set VIDEO_CODEC=-pix_fmt yuv420p  -vcodec hevc_nvenc -preset slow -profile:v main -rc-lookahead 35 -spatial_aq 1 -cbr 1 -rc cbr_hq -surfaces 20
rem set VIDEO_CODEC=-pix_fmt yuv420p -vcodec nvenc_h264 -preset medium -profile:v main -cbr 1 -rc cbr_hq -forced-idr 1

rem ENCODING VIDEO ON CPU:
rem set VIDEO_CODEC=-pix_fmt yuv420p -vcodec libx265 -preset faster -profile:v main -rc-lookahead 25 -spatial_aq 1 -temporal-aq 1 -rc cbr_hq -surfaces 16

ffmpeg -f dshow -i video=%VIDEO_DEVICE% -f dshow -i audio=%AUDIO_SOURCE% -sample_rate %AUDIO_SAMPLE_RATE% -audio_buffer_size 100k %FILTERS% -s %RESOLUTION% %FPS% %RESCALE% %VIDEO_CODEC% -b:v %VIDEO_RATE%k -minrate:v %MIN_VIDEO_RATE%k -maxrate:v %MAX_VIDEO_RATE%k -bufsize:v %BUFSIZE%k -ab %AUDIO_RATE%k %AUDIO_PARAMS% %TEXT_CMD% %OUTPUT_STREAM%