FFmpegFormat.cpp 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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. #include "FFmpegFormat.hpp"
  15. #include "FFmpegCodec.hpp"
  16. using namespace std;
  17. static bool is_output_device(const AVClass *avclass)
  18. {
  19. if (!avclass)
  20. return false;
  21. switch (avclass->category) {
  22. case AV_CLASS_CATEGORY_DEVICE_VIDEO_OUTPUT:
  23. case AV_CLASS_CATEGORY_DEVICE_AUDIO_OUTPUT:
  24. case AV_CLASS_CATEGORY_DEVICE_OUTPUT:
  25. return true;
  26. default:
  27. return false;
  28. }
  29. }
  30. vector<FFmpegFormat> GetSupportedFormats()
  31. {
  32. vector<FFmpegFormat> formats;
  33. const AVOutputFormat *output_format;
  34. void *i = 0;
  35. while ((output_format = av_muxer_iterate(&i)) != nullptr) {
  36. if (is_output_device(output_format->priv_class))
  37. continue;
  38. formats.emplace_back(output_format);
  39. }
  40. return formats;
  41. }
  42. FFmpegCodec FFmpegFormat::GetDefaultEncoder(FFmpegCodecType codec_type) const
  43. {
  44. const AVCodecID codec_id = codec_type == VIDEO ? video_codec : audio_codec;
  45. if (codec_type == UNKNOWN || codec_id == AV_CODEC_ID_NONE)
  46. return {};
  47. if (auto codec = avcodec_find_encoder(codec_id))
  48. return {codec};
  49. /* Fall back to using the format name as the encoder,
  50. * this works for some formats such as FLV. */
  51. return FFmpegCodec{name, codec_id, codec_type};
  52. }