Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
N
nginx-rtmp-stream
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Package Registry
Operate
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
best69number
nginx-rtmp-stream
Commits
741a26d7
Commit
741a26d7
authored
4 years ago
by
flisk
Browse files
Options
Downloads
Patches
Plain Diff
iterating
parent
fbad2db9
Branches
Branches containing commit
No related merge requests found
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
.gitignore
+1
-1
1 addition, 1 deletion
.gitignore
config.sample
+20
-0
20 additions, 0 deletions
config.sample
lainstream
+131
-0
131 additions, 0 deletions
lainstream
stream
+0
-63
0 additions, 63 deletions
stream
tmp/.gitignore
+2
-0
2 additions, 0 deletions
tmp/.gitignore
with
154 additions
and
64 deletions
.gitignore
+
1
−
1
View file @
741a26d7
url
config
This diff is collapsed.
Click to expand it.
config.sample
0 → 100644
+
20
−
0
View file @
741a26d7
# vim: ft=sh
# Copy this file to 'config' and adjust the variables as needed.
#
# NOTE: Your streaming credentials will be in this file, so you should make
# sure unauthorized users don't have access to it:
#
# $ umask 077
# $ cp config.sample config
#
# How much bandwidth you want the stream to consume. If it's not plentiful, run
# a speed test and subtract ~100 kB/s from your upload result.
upload_bandwidth_kibs
=
400
# This should be fine as-is.
audio_bitrate
=
192
# Your streaming credentials go into this URL.
# If you don't yet have streaming credentials, ask on IRC.
url
=
"rtmp://lainchan.org/show/stream?user=changeme&pass=changeme"
This diff is collapsed.
Click to expand it.
lainstream
0 → 100755
+
131
−
0
View file @
741a26d7
#!/usr/bin/env bash
scriptname
=
"
$(
basename
"
$0
"
)
"
tmp_file
=
tmp/stream.flv
fail
()
{
>
&2
echo
"
$scriptname
:
$*
"
exit
1
}
fail_usage
()
{
>
&2
echo
"
$scriptname
:
$*
"
>
&2 usage
exit
1
}
usage
()
{
cat
<<
EOF
usage:
$scriptname
transcode|stream ...
$scriptname
transcode <video file> [<subtitles file>]
Prepares a stream by transcoding the given video file into a
streamable format. The subtitles argument is optional, but
please consider Lainons with impaired hearing.
The transcoded file will be '
$tmp_file
'. After you're done
streaming, you will have to delete this file manually for now.
Technically the script could auto-delete it after the 'stream'
command finishes, but this would go wrong when transcoding
speed falls below 1x, and transcoding is expensive.
$scriptname
stream
Transmit the transcoded file to the configured server.
You should be able to start streaming while the transcode is
still running. Use some common sense in deciding when/if it's
appropriate to start a stream based on the speed reported by
ffmpeg (1x or higher should be fine).
EOF
}
load_config
()
{
.
config
upload_bandwidth_kbits
=
$((
upload_bandwidth_kibs
*
8
))
video_bitrate
=
$((
$upload_bandwidth_kbits
-
$audio_bitrate
))
buffer_size
=
$((
$video_bitrate
+
$audio_bitrate
))
}
transcode
()
{
if
[[
$#
< 1
||
$#
>
2
]]
;
then
fail_usage
"invalid number of arguments"
fi
if
[[
-e
"
$tmp_file
"
]]
;
then
fail
"
$tmp_file
exists; is a transcode running already?"
fi
load_config
filter_complex
=
"scale=-1:720"
if
[[
$#
>
1
]]
;
then
filter_complex
=
"subtitles=
$(
printf
%q
"
$2
"
)
:force_style='Fontname=JMH Typewriter':fontsdir=fonts,
$filter_complex
"
fi
opts
=(
-hide_banner
-threads
$(
nproc
)
-i
"
$1
"
# audio
-b
:a
${
audio_bitrate
}
k
-c
:a aac
-ac
2
# video
-b
:v
${
video_bitrate
}
k
-c
:v h264
-preset
faster
-tune
zerolatency
-filter_complex
"
$filter_complex
"
# streaming
-maxrate
${
buffer_size
}
k
-bufsize
${
buffer_size
}
k
-f
flv
"
$tmp_file
"
)
ffmpeg
"
${
opts
[@]
}
"
}
stream
()
{
if
[[
$#
!=
0
]]
;
then
fail
"too many arguments"
fi
load_config
opts
=(
-hide_banner
-re
-i
"
$tmp_file
"
-c
copy
-maxrate
"
${
buffer_size
}
k"
-bufsize
"
${
buffer_size
}
k"
-f
flv
"
$url
"
)
ffmpeg
"
${
opts
[@]
}
"
}
if
[[
$#
==
0
]]
;
then
fail_usage
"missing command"
fi
command
=
"
$1
"
shift
case
"
$command
"
in
transcode
)
transcode
"
$@
"
;;
stream
)
stream
"
$@
"
;;
*
)
fail_usage
"unknown command:
$command
"
esac
This diff is collapsed.
Click to expand it.
stream
deleted
100755 → 0
+
0
−
63
View file @
fbad2db9
#!/usr/bin/env bash
if
[[
$#
< 1
||
$#
>
3
]]
;
then
>
&2
echo
"usage:
$(
basename
"
$0
"
)
<video file> [<subtitles file>] [<timestamp>]"
exit
1
fi
# How much bandwidth you want the stream to consume. If it's not plentiful, run
# a speed test and subtract 100 kB/s from your upload result.
upload_bandwidth_kibs
=
350
upload_bandwidth_kbits
=
$((
upload_bandwidth_kibs
*
8
))
audio_bitrate
=
192
video_bitrate
=
$((
$upload_bandwidth_kbits
-
$audio_bitrate
))
buffer_size
=
$((
$video_bitrate
+
$audio_bitrate
))
filter_complex
=
"scale=-1:720"
if
[[
$#
>
1
]]
;
then
filter_complex
=
"subtitles=
$(
printf
%q
"
$2
"
)
:force_style='Fontname=JMH Typewriter':fontsdir=fonts,
$filter_complex
"
fi
input_opts
=()
if
[[
$#
>
2
]]
;
then
input_opts+
=(
-ss
"
$3
"
)
fi
opts
=(
-threads
$(
nproc
)
-re
"
${
input_opts
[@]
}
"
-i
"
$1
"
# audio
-b
:a
${
audio_bitrate
}
k
-c
:a aac
-ac
2
# video
-b
:v
${
video_bitrate
}
k
-c
:v h264
-preset
faster
-tune
zerolatency
-filter_complex
"
$filter_complex
"
# streaming
-maxrate
${
buffer_size
}
k
-bufsize
${
buffer_size
}
k
-f
flv
"
$(
cat
url
)
"
)
echo
"audio bitrate :
$audio_bitrate
"
echo
"video bitrate :
$video_bitrate
"
echo
"buffer size :
$buffer_size
"
echo
"ffmpeg options :
${
opts
[@]
}
"
ffmpeg
"
${
opts
[@]
}
"
This diff is collapsed.
Click to expand it.
tmp/.gitignore
0 → 100644
+
2
−
0
View file @
741a26d7
*
!.gitignore
This diff is collapsed.
Click to expand it.
Preview
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment