flv-mux.h 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /******************************************************************************
  2. Copyright (C) 2023 by Lain Bailey <[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 <obs.h>
  16. #define MILLISECOND_DEN 1000
  17. enum audio_id_t {
  18. AUDIO_CODEC_NONE = 0,
  19. AUDIO_CODEC_AAC = 1,
  20. };
  21. enum video_id_t {
  22. CODEC_NONE = 0, // not valid in rtmp
  23. CODEC_H264 = 1, // legacy & Y2023 spec
  24. CODEC_AV1, // Y2023 spec
  25. CODEC_HEVC,
  26. };
  27. static enum audio_id_t to_audio_type(const char *codec)
  28. {
  29. if (strcmp(codec, "aac") == 0)
  30. return AUDIO_CODEC_AAC;
  31. return AUDIO_CODEC_NONE;
  32. }
  33. static enum video_id_t to_video_type(const char *codec)
  34. {
  35. if (strcmp(codec, "h264") == 0)
  36. return CODEC_H264;
  37. if (strcmp(codec, "av1") == 0)
  38. return CODEC_AV1;
  39. #ifdef ENABLE_HEVC
  40. if (strcmp(codec, "hevc") == 0)
  41. return CODEC_HEVC;
  42. #endif
  43. return 0;
  44. }
  45. static int32_t get_ms_time(struct encoder_packet *packet, int64_t val)
  46. {
  47. return (int32_t)(val * MILLISECOND_DEN / packet->timebase_den);
  48. }
  49. extern void write_file_info(FILE *file, int64_t duration_ms, int64_t size);
  50. extern void flv_meta_data(obs_output_t *context, uint8_t **output, size_t *size, bool write_header);
  51. extern void flv_packet_mux(struct encoder_packet *packet, int32_t dts_offset, uint8_t **output, size_t *size,
  52. bool is_header);
  53. // Y2023 spec
  54. extern void flv_packet_start(struct encoder_packet *packet, enum video_id_t codec, uint8_t **output, size_t *size,
  55. size_t idx);
  56. extern void flv_packet_frames(struct encoder_packet *packet, enum video_id_t codec, int32_t dts_offset,
  57. uint8_t **output, size_t *size, size_t idx);
  58. extern void flv_packet_end(struct encoder_packet *packet, enum video_id_t codec, uint8_t **output, size_t *size,
  59. size_t idx);
  60. extern void flv_packet_metadata(enum video_id_t codec, uint8_t **output, size_t *size, int bits_per_raw_sample,
  61. uint8_t color_primaries, int color_trc, int color_space, int min_luminance,
  62. int max_luminance, size_t idx);
  63. extern void flv_packet_audio_start(struct encoder_packet *packet, enum audio_id_t codec, uint8_t **output, size_t *size,
  64. size_t idx);
  65. extern void flv_packet_audio_frames(struct encoder_packet *packet, enum audio_id_t codec, int32_t dts_offset,
  66. uint8_t **output, size_t *size, size_t idx);