Skip to content

Commit

Permalink
feat: Allow specifying the video safe directory
Browse files Browse the repository at this point in the history
For #6
  • Loading branch information
sbernauer committed Jun 16, 2023
1 parent b4d54cf commit 9c18284
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 20 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ Options:
Disable periodical saving of statistics into save file
--rtmp-address <RTMP_ADDRESS>
Enable rtmp streaming to configured address, e.g. `rtmp://127.0.0.1:1935/live/test`
--save-video-to-file
Enable dump of video stream into file. File name will be `pixelflut_dump_{timestamp}.mp4
--video-save-folder <VIDEO_SAVE_FOLDER>
Enable dump of video stream into file. File location will be `<VIDEO_SAVE_FOLDER>/pixelflut_dump_{timestamp}.mp4
-v, --vnc-port <VNC_PORT>
Port of the VNC server [default: 5900]
-h, --help
Expand Down
4 changes: 2 additions & 2 deletions src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ pub struct Args {
#[clap(long)]
pub rtmp_address: Option<String>,

/// Enable dump of video stream into file. File name will be `pixelflut_dump_{timestamp}.mp4
/// Enable dump of video stream into file. File location will be `<VIDEO_SAVE_FOLDER>/pixelflut_dump_{timestamp}.mp4
#[clap(long)]
pub save_video_to_file: bool,
pub video_save_folder: Option<String>,

/// Port of the VNC server.
// #[cfg_attr(feature = "vnc", clap(short, long, default_value_t = 5900))]
Expand Down
38 changes: 22 additions & 16 deletions src/sinks/ffmpeg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,17 @@ use crate::{args::Args, framebuffer::FrameBuffer};
pub struct FfmpegSink {
fb: Arc<FrameBuffer>,
rtmp_address: Option<String>,
save_video_to_file: bool,
video_save_folder: Option<String>,
fps: u32,
}

impl FfmpegSink {
pub fn new(args: &Args, fb: Arc<FrameBuffer>) -> Option<Self> {
if args.rtmp_address.is_some() || args.save_video_to_file {
if args.rtmp_address.is_some() || args.video_save_folder.is_some() {
Some(FfmpegSink {
fb,
rtmp_address: args.rtmp_address.clone(),
save_video_to_file: args.save_video_to_file,
video_save_folder: args.video_save_folder.clone(),
fps: args.fps,
})
} else {
Expand All @@ -33,19 +33,19 @@ impl FfmpegSink {
.flat_map(|(arg, value)| [format!("-{arg}"), value])
.collect();

let video_file = format!(
"pixelflut_dump_{}.mp4",
Local::now().format("%Y-%m-%d_%H-%M-%S")
);
match &self.rtmp_address {
Some(rtmp_address) => {
if self.save_video_to_file {
Some(rtmp_address) => match &self.video_save_folder {
Some(video_save_folder) => {
ffmpeg_args.extend(
self.ffmpeg_rtmp_sink_args()
.into_iter()
.flat_map(|(arg, value)| [format!("-{arg}"), value])
.collect::<Vec<_>>(),
);
let video_file = format!(
"{video_save_folder}/pixelflut_dump_{}.mp4",
Local::now().format("%Y-%m-%d_%H-%M-%S")
);
ffmpeg_args.extend([
"-f".to_string(),
"tee".to_string(),
Expand All @@ -59,7 +59,8 @@ impl FfmpegSink {
),
]);
todo!("Writing to file and rtmp sink simultaneously currently not supported");
} else {
}
None => {
ffmpeg_args.extend(
self.ffmpeg_rtmp_sink_args()
.into_iter()
Expand All @@ -68,14 +69,19 @@ impl FfmpegSink {
);
ffmpeg_args.extend(["-f".to_string(), "flv".to_string(), rtmp_address.clone()])
}
}
None => {
if self.save_video_to_file {
},
None => match &self.video_save_folder {
Some(video_save_folder) => {
let video_file = format!(
"{video_save_folder}/pixelflut_dump_{}.mp4",
Local::now().format("%Y-%m-%d_%H-%M-%S")
);
ffmpeg_args.extend([video_file])
} else {
unreachable!("FfmpegSink can only be created when either rtmp or video file is activated")
}
}
None => unreachable!(
"FfmpegSink can only be created when either rtmp or video file is activated"
),
},
}

log::info!("ffmpeg {}", ffmpeg_args.join(" "));
Expand Down

0 comments on commit 9c18284

Please sign in to comment.