2022-10-13 10:50:19 +00:00
|
|
|
/*
|
|
|
|
* Muxer internal APIs - should not be included outside of ffmpeg_mux*
|
|
|
|
*
|
|
|
|
* This file is part of FFmpeg.
|
|
|
|
*
|
|
|
|
* FFmpeg is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* FFmpeg is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with FFmpeg; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef FFTOOLS_FFMPEG_MUX_H
|
|
|
|
#define FFTOOLS_FFMPEG_MUX_H
|
|
|
|
|
|
|
|
#include <stdatomic.h>
|
|
|
|
#include <stdint.h>
|
|
|
|
|
2023-05-18 14:56:15 +00:00
|
|
|
#include "ffmpeg_sched.h"
|
2022-10-13 10:50:19 +00:00
|
|
|
|
|
|
|
#include "libavformat/avformat.h"
|
|
|
|
|
|
|
|
#include "libavcodec/packet.h"
|
|
|
|
|
|
|
|
#include "libavutil/dict.h"
|
|
|
|
#include "libavutil/fifo.h"
|
|
|
|
|
|
|
|
typedef struct MuxStream {
|
2024-02-14 18:08:18 +00:00
|
|
|
OutputStream ost;
|
2022-10-13 11:14:34 +00:00
|
|
|
|
2023-01-28 09:06:20 +00:00
|
|
|
// name used for logging
|
2024-02-14 18:08:18 +00:00
|
|
|
char log_name[32];
|
2023-01-28 09:06:20 +00:00
|
|
|
|
2024-02-14 18:08:18 +00:00
|
|
|
AVBSFContext *bsf_ctx;
|
|
|
|
AVPacket *bsf_pkt;
|
2022-10-14 09:34:26 +00:00
|
|
|
|
2024-02-14 18:08:18 +00:00
|
|
|
AVPacket *pkt;
|
2023-05-31 10:14:05 +00:00
|
|
|
|
2024-02-14 18:08:18 +00:00
|
|
|
EncStats stats;
|
2023-02-06 12:14:53 +00:00
|
|
|
|
2024-02-14 18:08:18 +00:00
|
|
|
int sch_idx;
|
|
|
|
int sch_idx_enc;
|
|
|
|
int sch_idx_src;
|
2023-05-18 14:56:15 +00:00
|
|
|
|
2024-02-14 18:08:18 +00:00
|
|
|
int sq_idx_mux;
|
2023-12-13 18:33:27 +00:00
|
|
|
|
2024-02-14 18:08:18 +00:00
|
|
|
int64_t max_frames;
|
2022-10-25 20:37:13 +00:00
|
|
|
|
2023-04-13 12:45:58 +00:00
|
|
|
// timestamp from which the streamcopied streams should start,
|
|
|
|
// in AV_TIME_BASE_Q;
|
|
|
|
// everything before it should be discarded
|
2024-02-14 18:08:18 +00:00
|
|
|
int64_t ts_copy_start;
|
2023-04-13 12:45:58 +00:00
|
|
|
|
2022-10-13 10:50:19 +00:00
|
|
|
/* dts of the last packet sent to the muxer, in the stream timebase
|
|
|
|
* used for making up missing dts values */
|
2024-02-14 18:08:18 +00:00
|
|
|
int64_t last_mux_dts;
|
2023-03-28 09:24:42 +00:00
|
|
|
|
2024-02-14 18:08:18 +00:00
|
|
|
int64_t stream_duration;
|
|
|
|
AVRational stream_duration_tb;
|
2023-05-28 08:43:36 +00:00
|
|
|
|
2023-07-25 14:28:07 +00:00
|
|
|
// state for av_rescale_delta() call for audio in write_packet()
|
2024-02-14 18:08:18 +00:00
|
|
|
int64_t ts_rescale_delta_last;
|
2023-04-13 12:32:57 +00:00
|
|
|
|
2023-03-28 09:24:42 +00:00
|
|
|
// combined size of all the packets sent to the muxer
|
2024-02-14 18:08:18 +00:00
|
|
|
uint64_t data_size_mux;
|
2023-04-13 12:45:58 +00:00
|
|
|
|
2024-02-14 18:08:18 +00:00
|
|
|
int copy_initial_nonkeyframes;
|
|
|
|
int copy_prior_start;
|
|
|
|
int streamcopy_started;
|
2022-10-13 10:50:19 +00:00
|
|
|
} MuxStream;
|
|
|
|
|
2022-10-13 11:14:34 +00:00
|
|
|
typedef struct Muxer {
|
2024-02-14 18:08:18 +00:00
|
|
|
OutputFile of;
|
2022-10-13 11:14:34 +00:00
|
|
|
|
2023-01-28 09:06:20 +00:00
|
|
|
// name used for logging
|
2024-02-14 18:08:18 +00:00
|
|
|
char log_name[32];
|
2023-01-28 09:06:20 +00:00
|
|
|
|
2024-02-14 18:08:18 +00:00
|
|
|
AVFormatContext *fc;
|
2022-10-13 10:50:19 +00:00
|
|
|
|
2024-02-14 18:08:18 +00:00
|
|
|
Scheduler *sch;
|
|
|
|
unsigned sch_idx;
|
2023-05-18 14:56:15 +00:00
|
|
|
|
|
|
|
// OutputStream indices indexed by scheduler stream indices
|
2024-02-14 18:08:18 +00:00
|
|
|
int *sch_stream_idx;
|
|
|
|
int nb_sch_stream_idx;
|
2023-05-18 14:56:15 +00:00
|
|
|
|
2024-02-14 18:08:18 +00:00
|
|
|
AVDictionary *opts;
|
2022-10-13 10:50:19 +00:00
|
|
|
|
|
|
|
/* filesize limit expressed in bytes */
|
2024-02-14 18:08:18 +00:00
|
|
|
int64_t limit_filesize;
|
|
|
|
atomic_int_least64_t last_filesize;
|
|
|
|
int header_written;
|
2022-10-13 10:50:19 +00:00
|
|
|
|
2024-02-14 18:08:18 +00:00
|
|
|
SyncQueue *sq_mux;
|
|
|
|
AVPacket *sq_pkt;
|
2022-10-13 11:14:34 +00:00
|
|
|
} Muxer;
|
2022-10-13 10:50:19 +00:00
|
|
|
|
2023-07-18 14:37:52 +00:00
|
|
|
int mux_check_init(void *arg);
|
2022-10-13 13:24:33 +00:00
|
|
|
|
2022-10-25 20:37:13 +00:00
|
|
|
static MuxStream *ms_from_ost(OutputStream *ost)
|
|
|
|
{
|
|
|
|
return (MuxStream*)ost;
|
|
|
|
}
|
|
|
|
|
2022-10-13 10:50:19 +00:00
|
|
|
#endif /* FFTOOLS_FFMPEG_MUX_H */
|