FileAnalyzer.hpp 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. #pragma once
  2. #include <stddef.h>
  3. #include <optional>
  4. #include <string>
  5. namespace QuickMedia {
  6. class FileAnalyzer;
  7. struct Dimensions {
  8. int width;
  9. int height;
  10. };
  11. enum class ContentType {
  12. UNKNOWN,
  13. VIDEO_AVI,
  14. VIDEO_MP4,
  15. VIDEO_MPEG,
  16. VIDEO_WEBM,
  17. VIDEO_FLV,
  18. VIDEO_WMV,
  19. AUDIO_BASIC,
  20. AUDIO_AIFF,
  21. AUDIO_MPEG,
  22. AUDIO_MIDI,
  23. AUDIO_WAVE,
  24. AUDIO_FLAC,
  25. AUDIO_VORBIS,
  26. AUDIO_OPUS,
  27. IMAGE_JPEG,
  28. IMAGE_PNG,
  29. IMAGE_GIF,
  30. IMAGE_BMP,
  31. IMAGE_AVIF,
  32. IMAGE_WEBP
  33. };
  34. bool is_content_type_video(ContentType content_type);
  35. bool is_content_type_audio(ContentType content_type);
  36. bool is_content_type_image(ContentType content_type);
  37. const char* content_type_to_string(ContentType content_type);
  38. bool is_image_ext(const char *ext);
  39. bool is_video_ext(const char *ext);
  40. bool is_music_ext(const char *ext);
  41. // Set |width| or |height| to 0 to disable scaling.
  42. // TODO: Make this async
  43. bool video_get_middle_frame(const FileAnalyzer &file, const char *destination_path, int width = 0, int height = 0);
  44. class FileAnalyzer {
  45. public:
  46. FileAnalyzer();
  47. bool load_file(const char *filepath, bool load_file_metadata = true);
  48. // Cached
  49. bool load_metadata();
  50. const std::string& get_filepath() const;
  51. ContentType get_content_type() const;
  52. int64_t get_file_size() const;
  53. std::optional<Dimensions> get_dimensions() const;
  54. std::optional<double> get_duration_seconds() const;
  55. private:
  56. FileAnalyzer(FileAnalyzer&) = delete;
  57. FileAnalyzer& operator=(FileAnalyzer&) = delete;
  58. private:
  59. std::string filepath;
  60. ContentType content_type;
  61. int64_t file_size;
  62. std::optional<Dimensions> dimensions;
  63. std::optional<double> duration_seconds;
  64. bool loaded;
  65. bool metadata_loaded;
  66. };
  67. }