|
217
|
1 # media_processor
|
|
|
2
|
|
|
3 Reusable media processing library for images and videos.
|
|
|
4
|
|
|
5 ## Features
|
|
|
6
|
|
|
7 - **Image Processing**: Convert images to WebP format with quality/size options
|
|
|
8 - **Video Processing**: Convert videos to HLS format for streaming
|
|
|
9 - **Auto-detection**: Automatically detects media type from file extension
|
|
|
10 - **Thumbnail Generation**: Creates thumbnails for videos
|
|
|
11 - **Original Preservation**: Keeps original files alongside processed versions
|
|
|
12
|
|
|
13 ## Usage
|
|
|
14
|
|
|
15 ```c
|
|
|
16 #include "media_processor/media_processor.h"
|
|
|
17
|
|
|
18 // Process any media file (auto-detects type)
|
|
|
19 MediaProcessorOpts opts = media_processor_opts_default("./output");
|
|
|
20 opts.image_quality = 85;
|
|
|
21 opts.video_max_width = 1920;
|
|
|
22
|
|
|
23 char* id = media_generate_id();
|
|
|
24 MediaResult* result = media_process_file("upload.mp4", id, &opts);
|
|
|
25
|
|
|
26 if (result->status == MEDIA_STATUS_COMPLETED) {
|
|
|
27 printf("HLS playlist: %s\n", result->hls_playlist);
|
|
|
28 printf("Thumbnail: %s\n", result->thumbnail_path);
|
|
|
29 }
|
|
|
30
|
|
|
31 media_result_free(result);
|
|
|
32 free(id);
|
|
|
33 ```
|
|
|
34
|
|
|
35 ## Output Structure
|
|
|
36
|
|
|
37 For images:
|
|
|
38 ```
|
|
|
39 output/
|
|
|
40 └── {id}/
|
|
|
41 ├── original.jpg # Original file
|
|
|
42 └── image.webp # Converted WebP
|
|
|
43 ```
|
|
|
44
|
|
|
45 For videos:
|
|
|
46 ```
|
|
|
47 output/
|
|
|
48 └── {id}/
|
|
|
49 ├── original.mp4 # Original file
|
|
|
50 ├── video.m3u8 # HLS playlist
|
|
|
51 ├── video_000.ts # HLS segments
|
|
|
52 ├── video_001.ts
|
|
|
53 └── video_thumb.jpg # Thumbnail
|
|
|
54 ```
|
|
|
55
|
|
|
56 ## Options
|
|
|
57
|
|
|
58 ### Image Options
|
|
|
59
|
|
|
60 | Option | Default | Description |
|
|
|
61 |--------|---------|-------------|
|
|
|
62 | `image_quality` | 80 | WebP quality (0-100) |
|
|
|
63 | `image_max_width` | 0 | Max width (0 = no limit) |
|
|
|
64 | `image_max_height` | 0 | Max height (0 = no limit) |
|
|
|
65
|
|
|
66 ### Video Options
|
|
|
67
|
|
|
68 | Option | Default | Description |
|
|
|
69 |--------|---------|-------------|
|
|
|
70 | `video_segment_duration` | 6 | HLS segment length in seconds |
|
|
|
71 | `video_bitrate` | 0 | Video bitrate in kbps (0 = auto) |
|
|
|
72 | `video_max_width` | 0 | Max width (0 = no limit) |
|
|
|
73 | `video_max_height` | 0 | Max height (0 = no limit) |
|
|
|
74 | `generate_thumbnail` | true | Generate video thumbnail |
|
|
|
75
|
|
|
76 ## Building
|
|
|
77
|
|
|
78 ```bash
|
|
|
79 bazel build //media_processor:media_processor
|
|
|
80 ```
|
|
|
81
|
|
|
82 ## Dependencies
|
|
|
83
|
|
|
84 - `//third_party/ffmpeg:ffmpeg_cli` - FFmpeg CLI wrapper
|
|
|
85 - `//dowa:dowa` - Memory and string utilities
|