-
-
Notifications
You must be signed in to change notification settings - Fork 52
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[GSoC'21] Livestreaming v2 #387
base: main
Are you sure you want to change the base?
Changes from 11 commits
9e5ab05
4760cfe
191bd62
3e95458
5e68c40
cc20258
4ff7c68
f5cc65c
37e9b12
700462d
5615637
4a1b580
6bb177e
ad1f2b2
f4290ce
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -291,13 +291,14 @@ Sets up the livestream configuration. | |
**NOTE:** Twitch not fully implemented, do not use. | ||
""" | ||
function setup_stream( | ||
livestreamto::Symbol = :local; | ||
livestreamto::Symbol = :local, | ||
frames::Union{UnitRange{Int},Symbol} = :all; | ||
protocol::String = "udp", | ||
address::String = "0.0.0.0", | ||
port::Int = 14015, | ||
twitch_key::String = "", | ||
) | ||
StreamConfig(livestreamto, protocol, address, port, twitch_key) | ||
StreamConfig(livestreamto, protocol, address, port, twitch_key, frames) | ||
end | ||
|
||
""" | ||
|
@@ -332,7 +333,7 @@ function cancel_stream() | |
), | ||
), | ||
) | ||
return "Livestream Cancelled!" | ||
return @info "Livestream Cancelled!" | ||
end | ||
|
||
""" | ||
|
@@ -342,20 +343,37 @@ Internal method for livestreaming | |
""" | ||
function _livestream( | ||
streamconfig::StreamConfig, | ||
framerate::Int, | ||
width::Int, | ||
height::Int, | ||
pathname::String, | ||
framerate, | ||
video, | ||
objects, | ||
layers, | ||
frames, | ||
tempdirectory, | ||
) | ||
# kill any existing stream | ||
cancel_stream() | ||
|
||
livestreamto = streamconfig.livestreamto | ||
config_frames = streamconfig.frames | ||
twitch_key = streamconfig.twitch_key | ||
|
||
if livestreamto == :twitch && isempty(twitch_key) | ||
return error("Please enter your twitch stream key") | ||
end | ||
|
||
stream_frames = config_frames == :all ? frames : config_frames | ||
stream_filecounter = 1 | ||
for frame in stream_frames | ||
frame_image = convert.(RGB, get_javis_frame(video, objects, frame; layers = layers)) | ||
if !isempty(tempdirectory) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what happens if tempdirectory is empty? It just generates the frames but can't use it? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No tempdir is created before if it's empty (as before) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah what I mean is: it should never be empty so we don't need the if. The problem is if we have an mp4 as the pathname without a temp directory but want to stream it will fail, right? |
||
Images.save( | ||
"$(tempdirectory)/$(lpad(stream_filecounter, 10, "0")).png", | ||
frame_image, | ||
) | ||
end | ||
stream_filecounter += 1 | ||
end | ||
|
||
command = [ | ||
"-stream_loop", # loop the stream -1 times i.e. indefinitely | ||
"-1", | ||
|
@@ -366,15 +384,14 @@ function _livestream( | |
"error", | ||
"-re", # read input at native frame rate | ||
"-i", # input file | ||
"$pathname", | ||
"$(tempdirectory)/%10d.png", | ||
] | ||
|
||
if livestreamto == :twitch | ||
if isempty(twitch_key) | ||
error("Please enter your twitch api key") | ||
error("Please enter your twitch stream key") | ||
end | ||
|
||
# | ||
twitch_cmd = [ | ||
"-f", | ||
"flv", # force the file to flv format | ||
|
@@ -396,11 +413,3 @@ function _livestream( | |
ffmpeg_exe(`$command`) | ||
end) | ||
end | ||
|
||
_livestream( | ||
streamconfig::Nothing, | ||
framerate::Int, | ||
width::Int, | ||
height::Int, | ||
pathname::String, | ||
) = return |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what do you mean by faster? Is it live? 😉