ffmpeg-utils.hpp 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. /******************************************************************************
  2. Copyright (C) 2023 by Dennis Sädtler <[email protected]>
  3. This program is free software: you can redistribute it and/or modify
  4. it under the terms of the GNU General Public License as published by
  5. the Free Software Foundation, either version 2 of the License, or
  6. (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program. If not, see <http://www.gnu.org/licenses/>.
  13. ******************************************************************************/
  14. #pragma once
  15. #include <qmetatype.h>
  16. #include <string>
  17. #include <vector>
  18. extern "C" {
  19. #include <libavcodec/avcodec.h>
  20. #include <libavdevice/avdevice.h>
  21. }
  22. enum FFmpegCodecType { AUDIO, VIDEO, UNKNOWN };
  23. struct FFmpegFormat {
  24. const char *name;
  25. const char *long_name;
  26. const char *mime_type;
  27. const char *extensions;
  28. AVCodecID audio_codec;
  29. AVCodecID video_codec;
  30. const AVCodecTag *const *codec_tags;
  31. FFmpegFormat() = default;
  32. const char *GetDefaultName(FFmpegCodecType codec_type) const;
  33. bool HasAudio() const { return audio_codec != AV_CODEC_ID_NONE; }
  34. bool HasVideo() const { return video_codec != AV_CODEC_ID_NONE; }
  35. bool operator==(const FFmpegFormat &format) const
  36. {
  37. if (strcmp(name, format.name) != 0)
  38. return false;
  39. return strcmp(mime_type, format.mime_type) != 0;
  40. }
  41. };
  42. Q_DECLARE_METATYPE(FFmpegFormat)
  43. struct FFmpegCodec {
  44. const char *name;
  45. const char *long_name;
  46. int id;
  47. bool alias;
  48. const char *base_name;
  49. FFmpegCodecType type;
  50. FFmpegCodec() = default;
  51. bool operator==(const FFmpegCodec &codec) const
  52. {
  53. if (id != codec.id)
  54. return false;
  55. return strcmp(name, codec.name) != 0;
  56. }
  57. };
  58. Q_DECLARE_METATYPE(FFmpegCodec)
  59. std::vector<FFmpegFormat> GetSupportedFormats();
  60. std::vector<FFmpegCodec> GetFormatCodecs(const FFmpegFormat &format,
  61. bool ignore_compatibility);
  62. bool FFCodecAndFormatCompatible(const char *codec, const char *format);
  63. bool IsBuiltinCodec(const char *codec);
  64. bool ContainerSupportsCodec(const std::string &container,
  65. const std::string &codec);