Skip to content
This repository was archived by the owner on Dec 5, 2025. It is now read-only.

Commit b2be94a

Browse files
author
ferzu13
committed
updated ReadME + timestamp on dumped png/mp4
1 parent d7ec56c commit b2be94a

2 files changed

Lines changed: 40 additions & 11 deletions

File tree

README.md

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,22 @@
1+
# k21
12

2-
k21-screen - A CLI tool to handle screen captures
3-
k21-processor - A CLI tool to handle processing of screen captures
3+
A collection of tools and libraries for screen capture and processing:
44

5-
## Compilation
5+
- `k21` - Core library that can be consumed by external applications
6+
- `k21-screen` - A CLI tool to handle screen captures
7+
- `k21-processor` - A CLI tool to handle processing of screen captures
8+
- `k21-server` - A server that provides HTTP endpoints for screen capture and processing
9+
10+
## Library Usage
11+
12+
The `k21` library can be used as a dependency in your Rust projects:
13+
14+
```toml
15+
[dependencies]
16+
k21 = { git = "https://github.com/kontext21/k21" }
17+
```
18+
19+
## CLI Tools Compilation
620

721
```bash
822
cargo build
@@ -11,15 +25,22 @@ cargo build
1125
## Usage
1226

1327
```bash
28+
# Screen capture
1429
./k21-screen
30+
./k21-screen --fps 1 --output captures/
31+
32+
# Processing
1533
./k21-processor --mp4 file.mp4
1634
./k21-processor --image file.png
1735
./k21-screen --stdout | ./k21-processor --stdin
36+
37+
# Server
38+
./k21-server
1839
```
19-
Will run and capture until process is stopp
2040

2141
## Options
2242

43+
### k21-screen
2344
- `--fps`: Screen refresh rate in fps (frames per second) - default: 1
2445

2546
## TODO k21-screen
@@ -34,7 +55,8 @@ Will run and capture until process is stopp
3455
- [ ] `--count`: Number of captures to take
3556
- [ ] `--quality`: Output quality (0-100)
3657

37-
## ideas
58+
## Ideas
3859
- processor could just be able to handle inputs without having to specify the input type
3960
- maybe processor could handle multiple images / inputs at once
40-
- how do we preserve the original time stamp
61+
- how do we preserve the original time stamp
62+
- add websocket support to server for real-time updates

libs/k21/src/capture/utils.rs

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ use crate::capture::screen_record;
99
use super::screen_record::get_screenshot;
1010
use tokio::sync::watch;
1111
use super::ScreenCaptureConfig;
12+
use chrono::Local;
1213

1314
pub async fn capture(config: ScreenCaptureConfig) -> Result<()> {
1415
capture_with_stdout(config, false).await
@@ -113,7 +114,7 @@ pub async fn handle_captured_frames(
113114
close_rx,
114115
&mut chunk_number,
115116
).await;
116-
117+
117118
// Save final video chunk if needed
118119
if config.get_save_video_to().is_some() && !screen_record.is_buf_empty() {
119120
save_video_chunk(
@@ -206,16 +207,22 @@ async fn send_frame_to_stdout(frame_number: u64, image: &DynamicImage) {
206207
}
207208

208209
fn save_video_chunk(screen_record: &mut screen_record::ScreenCapturer, chunk_number: &mut u64, fps: f32, output_dir_video: &str) {
209-
// save video chunk to disk with unique name using the provided output directory
210-
let path = std::path::PathBuf::from(output_dir_video).join(format!("output-{}.mp4", chunk_number));
210+
211+
let timestamp = Local::now().format("%Y%m%d_%H%M%S");
212+
let path = std::path::PathBuf::from(output_dir_video)
213+
.join(format!("output-{}-{}.mp4", timestamp, chunk_number));
214+
211215
screen_record.save(&path, fps);
212216
*chunk_number += 1;
213217
}
214218

215219
fn save_screenshot(frame_number: u64, image: DynamicImage, output_dir: &str) {
216-
let output_dir = std::path::PathBuf::from(output_dir);
220+
221+
let timestamp = Local::now().format("%Y%m%d_%H%M%S");
222+
let path = std::path::PathBuf::from(output_dir)
223+
.join(format!("screenshot-{}-{}.png", timestamp, frame_number));
224+
217225
tokio::task::spawn(async move {
218-
let path = output_dir.join(format!("screenshot-{}.png", frame_number));
219226
match image.save_with_format(&path, image::ImageFormat::Png) {
220227
Ok(_) => log::info!("Saved screenshot to {}", path.display()),
221228
Err(e) => log::error!("Failed to save screenshot: {}", e),

0 commit comments

Comments
 (0)