ffmpeg_mux.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. /*
  2. * Muxer internal APIs - should not be included outside of ffmpeg_mux*
  3. *
  4. * This file is part of FFmpeg.
  5. *
  6. * FFmpeg is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU Lesser General Public
  8. * License as published by the Free Software Foundation; either
  9. * version 2.1 of the License, or (at your option) any later version.
  10. *
  11. * FFmpeg is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * Lesser General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General Public
  17. * License along with FFmpeg; if not, write to the Free Software
  18. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  19. */
  20. #ifndef FFTOOLS_FFMPEG_MUX_H
  21. #define FFTOOLS_FFMPEG_MUX_H
  22. #include <stdatomic.h>
  23. #include <stdint.h>
  24. #include "ffmpeg_sched.h"
  25. #include "libavformat/avformat.h"
  26. #include "libavcodec/packet.h"
  27. #include "libavutil/dict.h"
  28. #include "libavutil/fifo.h"
  29. typedef struct MuxStream {
  30. OutputStream ost;
  31. /**
  32. * Codec parameters for packets submitted to the muxer (i.e. before
  33. * bitstream filtering, if any).
  34. */
  35. AVCodecParameters *par_in;
  36. // name used for logging
  37. char log_name[32];
  38. AVBSFContext *bsf_ctx;
  39. AVPacket *bsf_pkt;
  40. AVPacket *pkt;
  41. EncStats stats;
  42. int sch_idx;
  43. int sch_idx_enc;
  44. int sch_idx_src;
  45. int sq_idx_mux;
  46. int64_t max_frames;
  47. // timestamp from which the streamcopied streams should start,
  48. // in AV_TIME_BASE_Q;
  49. // everything before it should be discarded
  50. int64_t ts_copy_start;
  51. /* dts of the last packet sent to the muxer, in the stream timebase
  52. * used for making up missing dts values */
  53. int64_t last_mux_dts;
  54. int64_t stream_duration;
  55. AVRational stream_duration_tb;
  56. // state for av_rescale_delta() call for audio in write_packet()
  57. int64_t ts_rescale_delta_last;
  58. // combined size of all the packets sent to the muxer
  59. uint64_t data_size_mux;
  60. int copy_initial_nonkeyframes;
  61. int copy_prior_start;
  62. int streamcopy_started;
  63. #if FFMPEG_OPT_VSYNC_DROP
  64. int ts_drop;
  65. #endif
  66. AVRational frame_rate;
  67. AVRational max_frame_rate;
  68. int force_fps;
  69. const char *apad;
  70. } MuxStream;
  71. typedef struct Muxer {
  72. OutputFile of;
  73. // name used for logging
  74. char log_name[32];
  75. AVFormatContext *fc;
  76. Scheduler *sch;
  77. unsigned sch_idx;
  78. // OutputStream indices indexed by scheduler stream indices
  79. int *sch_stream_idx;
  80. int nb_sch_stream_idx;
  81. AVDictionary *opts;
  82. // used to validate that all encoder avoptions have been actually used
  83. AVDictionary *enc_opts_used;
  84. /* filesize limit expressed in bytes */
  85. int64_t limit_filesize;
  86. atomic_int_least64_t last_filesize;
  87. int header_written;
  88. SyncQueue *sq_mux;
  89. AVPacket *sq_pkt;
  90. } Muxer;
  91. int mux_check_init(void *arg);
  92. static MuxStream *ms_from_ost(OutputStream *ost)
  93. {
  94. return (MuxStream*)ost;
  95. }
  96. #endif /* FFTOOLS_FFMPEG_MUX_H */