flv-mux.h 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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,
  51. bool write_header);
  52. extern void flv_packet_mux(struct encoder_packet *packet, int32_t dts_offset,
  53. uint8_t **output, size_t *size, bool is_header);
  54. // Y2023 spec
  55. extern void flv_packet_start(struct encoder_packet *packet,
  56. enum video_id_t codec, uint8_t **output,
  57. size_t *size, size_t idx);
  58. extern void flv_packet_frames(struct encoder_packet *packet,
  59. enum video_id_t codec, int32_t dts_offset,
  60. uint8_t **output, size_t *size, size_t idx);
  61. extern void flv_packet_end(struct encoder_packet *packet, enum video_id_t codec,
  62. uint8_t **output, size_t *size, size_t idx);
  63. extern void flv_packet_metadata(enum video_id_t codec, uint8_t **output,
  64. size_t *size, int bits_per_raw_sample,
  65. uint8_t color_primaries, int color_trc,
  66. int color_space, int min_luminance,
  67. int max_luminance, size_t idx);
  68. extern void flv_packet_audio_start(struct encoder_packet *packet,
  69. enum audio_id_t codec, uint8_t **output,
  70. size_t *size, size_t idx);
  71. extern void flv_packet_audio_frames(struct encoder_packet *packet,
  72. enum audio_id_t codec, int32_t dts_offset,
  73. uint8_t **output, size_t *size, size_t idx);