comparison media_processor/media_processor.h @ 217:7ef4c9d2a72d hg-web

[DO NOT PUSH] Random values.
author MrJuneJune <me@mrjunejune.com>
date Sun, 25 Jan 2026 10:44:04 -0800
parents
children
comparison
equal deleted inserted replaced
192:b818a4561a3c 217:7ef4c9d2a72d
1 #ifndef MEDIA_PROCESSOR_H
2 #define MEDIA_PROCESSOR_H
3
4 #include <stdbool.h>
5 #include <stddef.h>
6
7 // Media types
8 typedef enum {
9 MEDIA_TYPE_UNKNOWN = 0,
10 MEDIA_TYPE_IMAGE,
11 MEDIA_TYPE_VIDEO,
12 MEDIA_TYPE_AUDIO,
13 } MediaType;
14
15 // Processing status
16 typedef enum {
17 MEDIA_STATUS_PENDING = 0,
18 MEDIA_STATUS_PROCESSING,
19 MEDIA_STATUS_COMPLETED,
20 MEDIA_STATUS_FAILED,
21 } MediaStatus;
22
23 // Result of a processing operation
24 typedef struct {
25 MediaStatus status;
26 char* error_message;
27
28 // For images
29 char* original_path; // Path to original file
30 char* webp_path; // Path to WebP version
31
32 // For videos
33 char* hls_playlist; // Path to .m3u8 file
34 char* thumbnail_path; // Path to thumbnail
35 double duration; // Duration in seconds
36 } MediaResult;
37
38 // Processing options
39 typedef struct {
40 // Output directory (required)
41 const char* output_dir;
42
43 // Image options
44 int image_quality; // 0-100, default 80
45 int image_max_width; // 0 = no limit
46 int image_max_height; // 0 = no limit
47
48 // Video options
49 int video_segment_duration; // HLS segment duration, default 6
50 int video_bitrate; // kbps, 0 = auto
51 int video_max_width; // 0 = no limit
52 int video_max_height; // 0 = no limit
53 bool generate_thumbnail; // default true
54 } MediaProcessorOpts;
55
56 // Initialize processor options with defaults
57 MediaProcessorOpts media_processor_opts_default(const char* output_dir);
58
59 // Detect media type from file extension
60 MediaType media_detect_type(const char* filename);
61
62 // Get MIME type string
63 const char* media_type_to_mime(MediaType type);
64
65 // Process a single file (auto-detects type)
66 // Returns a MediaResult that must be freed with media_result_free()
67 MediaResult* media_process_file(const char* input_path, const char* id, MediaProcessorOpts* opts);
68
69 // Process image specifically
70 MediaResult* media_process_image(const char* input_path, const char* id, MediaProcessorOpts* opts);
71
72 // Process video specifically
73 MediaResult* media_process_video(const char* input_path, const char* id, MediaProcessorOpts* opts);
74
75 // Free a MediaResult
76 void media_result_free(MediaResult* result);
77
78 // Generate a unique ID for a media file
79 char* media_generate_id(void);
80
81 // Utility: Copy file to destination
82 bool media_copy_file(const char* src, const char* dst);
83
84 // Utility: Get file extension (returns pointer into filename, do not free)
85 const char* media_get_extension(const char* filename);
86
87 // Utility: Check if path is safe (no directory traversal)
88 bool media_path_is_safe(const char* path);
89
90 #endif // MEDIA_PROCESSOR_H