new script
srt-trim
freebsd-bin-xps. Contribute to NapoleonWils0n/freebsd-bin-xps development by creating an account on GitHub.
github.com
srt-yt can stream a whole video supported by yt-dlp to a srt receiver
ether obs studio or using srt-live-transmit and mpv with the srt-mpv script
srt-trim lets you stream a clip with a start and end point from any site supported by yt-dlp
to a srt receiver which could be obs studio or using srt-mpv
srt-trim uses ffmpeg to create a start and a to point
with the -s and -t options
you define a start point and then the amount of time after the start you want to stream for
to stream a video from 1 minute for 1 minute the command would look like this
with the default ip and port define in the script which you can change
Code:
srt-trim -u 'https://www.youtube.com/watch?v=dQw4w9WgXcQ' -s 00:01:00 -t 00:01:00
or over ride the default ip and port with the -i and -p options
Code:
srt-trim -i 192.168.1.131 -p 6882 -u 'https://www.youtube.com/watch?v=dQw4w9WgXcQ' -s 00:01:00 -t 00:01:00
so you dont set the -t option to 00:02:00
that would record from 1 minute for 2 mintues
thats just the way ffmpeg works
dont blame me
to make things easier i created a script that allows you to put in the start and end times
and then it will give you the duration for the -t option
Code:
calculate sexagesimal duration by subtacting end time from start time
sexagesimal-time -s 00:00:00 -e 00:00:00
freebsd-bin-xps. Contribute to NapoleonWils0n/freebsd-bin-xps development by creating an account on GitHub.
github.com
the srt-trim script has a default ip and port set
so you can just edit the script and change those
you can also over ride the defaults on the command line
Code:
#===============================================================================
# defaults
#===============================================================================
# default ip
ip_default='192.168.1.131'
# default port
port_default='6882'
Code:
srt-trim -i ip/dns -p port -u input -s 00:00:00 -t 00:00:00
you can create a media source in obs studio that acts as a receiver for the srt stream
Code:
srt://192.168.1.131:6882?mode=listener&latency=1000&timeout=500000
remember to open a udp port with pf
in the above example im using port 6882
and then set obs to bind to a specific ip
srt-trim with obs studio as the receiver
using the default ip and port in the script
Code:
srt-trim -u 'https://www.youtube.com/watch?v=Wmc8bQoL-J0' -s 00:01:00 -t 00:01:00
srt-mpv as the receiver
srt-trim script code
Code:
#!/bin/sh
#===============================================================================
# srt-trim - trim an online clip and stream it
#===============================================================================
#===============================================================================
# script usage
#===============================================================================
usage () {
# if argument passed to function echo it
[ -z "${1}" ] || echo "! ${1}"
# display help
echo "\
$(basename "$0") -i ip/dns -p port -u input -s 00:00:00 -t 00:00:00"
exit 2
}
#===============================================================================
# error messages
#===============================================================================
INVALID_OPT_ERR='Invalid option:'
REQ_ARG_ERR='requires an argument'
WRONG_ARGS_ERR='wrong number of arguments passed to script'
#===============================================================================
# check number of aruments passed to script
#===============================================================================
[ $# -gt 0 ] || usage "${WRONG_ARGS_ERR}"
#===============================================================================
# getopts check options passed to script
#===============================================================================
while getopts 'i:p:u:s:t:h' opt
do
case ${opt} in
u) input="${OPTARG}";;
i) ip="${OPTARG}";;
p) port="${OPTARG}";;
s) start="${OPTARG}";;
t) end="${OPTARG}";;
h) usage;;
\?) usage "${INVALID_OPT_ERR} ${OPTARG}" 1>&2;;
:) usage "${INVALID_OPT_ERR} ${OPTARG} ${REQ_ARG_ERR}" 1>&2;;
esac
done
shift $((OPTIND-1))
#===============================================================================
# defaults
#===============================================================================
# default ip
ip_default='192.168.1.131'
# default port
port_default='6882'
#===============================================================================
# url
#===============================================================================
# yt-dlp url
url=$(yt-dlp -f b -g --no-playlist "${input}")
# check number of stream links
streamcount=$(echo "${url}" | awk 'END{print NR}')
#===============================================================================
# one stream containing audio and video
#===============================================================================
# copy audio and video streams
one_stream () {
ffmpeg \
-hide_banner \
-y \
-re \
-i "${url}" \
-c:a copy -c:v copy \
-tune zerolatency \
-f mpegts "srt://${ip:=${ip_default}}:${port:=${port_default}}?pkt_size=1316"
}
# trim video and re-encode
one_stream_trim () {
ffmpeg \
-hide_banner \
-y \
-re \
-ss "${start}" \
-i "${url}" \
-t "${end}" \
-c:a aac \
-c:v libx264 -profile:v high \
-tune zerolatency \
-f mpegts "srt://${ip:=${ip_default}}:${port:=${port_default}}?pkt_size=1316"
}
#===============================================================================
# two streams containing audio and video
#===============================================================================
# copy audio and video streams
two_streams () {
video_url=$(echo "${url}" | awk 'BEGIN{ RS ="" ; FS ="\n" }{print $1}')
audio_url=$(echo "${url}" | awk 'BEGIN{ RS ="" ; FS ="\n" }{print $2}')
# ffmpeg join audio and video and stream
ffmpeg \
-hide_banner \
-y \
-re \
-i "${video_url}" \
-i "${audio_url}" \
-c:a copy -c:v copy \
-tune zerolatency \
-map 0:0 -map 1:0 \
-f mpegts "srt://${ip:=${ip_default}}:${port:=${port_default}}?pkt_size=1316"
}
# trim video and re-encode
two_streams_trim () {
video_url=$(echo "${url}" | awk 'BEGIN{ RS ="" ; FS ="\n" }{print $1}')
audio_url=$(echo "${url}" | awk 'BEGIN{ RS ="" ; FS ="\n" }{print $2}')
# ffmpeg join audio and video and stream
ffmpeg \
-hide_banner \
-y \
-re \
-ss "${start}" \
-i "${video_url}" \
-i "${audio_url}" \
-t "${end}" \
-c:a aac \
-c:v libx264 -profile:v high \
-tune zerolatency \
-map 0:0 -map 1:0 \
-f mpegts "srt://${ip:=${ip_default}}:${port:=${port_default}}?pkt_size=1316"
}
#===============================================================================
# case statement check for number of streams
#===============================================================================
if [ -z "${start}" ]; then
case "${streamcount}" in
1) one_stream;; # single stream
2) two_streams;; # audio and video stream
*) usage;;
esac
else
case "${streamcount}" in
1) one_stream_trim;; # single stream
2) two_streams_trim;; # audio and video stream
*) usage;;
esac
fi