obs-ffmpeg-output.h 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. #pragma once
  2. #include <libavutil/opt.h>
  3. #include <libavutil/pixdesc.h>
  4. #include <libavcodec/avcodec.h>
  5. #include <libavformat/avformat.h>
  6. #include <libswscale/swscale.h>
  7. #ifdef NEW_MPEGTS_OUTPUT
  8. #include "obs-ffmpeg-url.h"
  9. #endif
  10. struct ffmpeg_cfg {
  11. const char *url;
  12. const char *format_name;
  13. const char *format_mime_type;
  14. const char *muxer_settings;
  15. const char *protocol_settings; // not used yet for SRT nor RIST
  16. int gop_size;
  17. int video_bitrate;
  18. int audio_bitrate;
  19. const char *video_encoder;
  20. int video_encoder_id;
  21. const char *audio_encoder;
  22. int audio_encoder_id;
  23. const char *video_settings;
  24. const char *audio_settings;
  25. int audio_mix_count;
  26. int audio_tracks;
  27. enum AVPixelFormat format;
  28. enum AVColorRange color_range;
  29. enum AVColorPrimaries color_primaries;
  30. enum AVColorTransferCharacteristic color_trc;
  31. enum AVColorSpace colorspace;
  32. int max_luminance;
  33. int scale_width;
  34. int scale_height;
  35. int width;
  36. int height;
  37. int frame_size; // audio frame size
  38. const char *username;
  39. const char *password;
  40. const char *stream_id;
  41. const char *encrypt_passphrase;
  42. };
  43. struct ffmpeg_audio_info {
  44. AVStream *stream;
  45. AVCodecContext *ctx;
  46. };
  47. struct ffmpeg_data {
  48. AVStream *video;
  49. AVCodecContext *video_ctx;
  50. struct ffmpeg_audio_info *audio_infos;
  51. const AVCodec *acodec;
  52. const AVCodec *vcodec;
  53. AVFormatContext *output;
  54. struct SwsContext *swscale;
  55. int64_t total_frames;
  56. AVFrame *vframe;
  57. int frame_size;
  58. uint64_t start_timestamp;
  59. int64_t total_samples[MAX_AUDIO_MIXES];
  60. uint32_t audio_samplerate;
  61. enum audio_format audio_format;
  62. size_t audio_planes;
  63. size_t audio_size;
  64. int num_audio_streams;
  65. /* audio_tracks is a bitmask storing the indices of the mixes */
  66. int audio_tracks;
  67. struct circlebuf excess_frames[MAX_AUDIO_MIXES][MAX_AV_PLANES];
  68. uint8_t *samples[MAX_AUDIO_MIXES][MAX_AV_PLANES];
  69. AVFrame *aframe[MAX_AUDIO_MIXES];
  70. struct ffmpeg_cfg config;
  71. bool initialized;
  72. char *last_error;
  73. };
  74. struct ffmpeg_output {
  75. obs_output_t *output;
  76. volatile bool active;
  77. struct ffmpeg_data ff_data;
  78. bool connecting;
  79. pthread_t start_thread;
  80. uint64_t total_bytes;
  81. uint64_t audio_start_ts;
  82. uint64_t video_start_ts;
  83. uint64_t stop_ts;
  84. volatile bool stopping;
  85. bool write_thread_active;
  86. pthread_mutex_t write_mutex;
  87. pthread_t write_thread;
  88. os_sem_t *write_sem;
  89. os_event_t *stop_event;
  90. DARRAY(AVPacket *) packets;
  91. #ifdef NEW_MPEGTS_OUTPUT
  92. /* used for SRT & RIST */
  93. URLContext *h;
  94. AVIOContext *s;
  95. bool got_headers;
  96. #endif
  97. };
  98. bool ffmpeg_data_init(struct ffmpeg_data *data, struct ffmpeg_cfg *config);
  99. void ffmpeg_data_free(struct ffmpeg_data *data);