FFmpeg
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Data Structures | Macros | Enumerations | Functions | Variables
mpegtsenc.c File Reference
#include "libavutil/avassert.h"
#include "libavutil/bswap.h"
#include "libavutil/crc.h"
#include "libavutil/dict.h"
#include "libavutil/intreadwrite.h"
#include "libavutil/mathematics.h"
#include "libavutil/opt.h"
#include "libavcodec/internal.h"
#include "avformat.h"
#include "avio_internal.h"
#include "internal.h"
#include "mpegts.h"

Go to the source code of this file.

Data Structures

struct  MpegTSSection
 
struct  MpegTSService
 
struct  MpegTSWrite
 
struct  MpegTSWriteStream
 

Macros

#define PCR_TIME_BASE   27000000
 
#define DVB_PRIVATE_NETWORK_START   0xff01
 
#define MPEGTS_FLAG_REEMIT_PAT_PMT   0x01
 
#define MPEGTS_FLAG_AAC_LATM   0x02
 
#define MPEGTS_FLAG_PAT_PMT_AT_FRAMES   0x04
 
#define MPEGTS_FLAG_SYSTEM_B   0x08
 
#define MPEGTS_FLAG_DISCONT   0x10
 
#define DEFAULT_PES_HEADER_FREQ   16
 
#define DEFAULT_PES_PAYLOAD_SIZE   ((DEFAULT_PES_HEADER_FREQ - 1) * 184 + 170)
 
#define SECTION_LENGTH   1020
 
#define DEFAULT_PROVIDER_NAME   "FFmpeg"
 
#define DEFAULT_SERVICE_NAME   "Service01"
 
#define SDT_RETRANS_TIME   500
 
#define PAT_RETRANS_TIME   100
 
#define PCR_RETRANS_TIME   20
 

Enumerations

enum  {
  MPEGTS_SERVICE_TYPE_DIGITAL_TV = 0x01, MPEGTS_SERVICE_TYPE_DIGITAL_RADIO = 0x02, MPEGTS_SERVICE_TYPE_TELETEXT = 0x03, MPEGTS_SERVICE_TYPE_ADVANCED_CODEC_DIGITAL_RADIO = 0x0A,
  MPEGTS_SERVICE_TYPE_MPEG2_DIGITAL_HDTV = 0x11, MPEGTS_SERVICE_TYPE_ADVANCED_CODEC_DIGITAL_SDTV = 0x16, MPEGTS_SERVICE_TYPE_ADVANCED_CODEC_DIGITAL_HDTV = 0x19, MPEGTS_SERVICE_TYPE_HEVC_DIGITAL_HDTV = 0x1F
}
 

Functions

static void mpegts_write_section (MpegTSSection *s, uint8_t *buf, int len)
 
static void put16 (uint8_t **q_ptr, int val)
 
static int mpegts_write_section1 (MpegTSSection *s, int tid, int id, int version, int sec_num, int last_sec_num, uint8_t *buf, int len)
 
static void mpegts_write_pat (AVFormatContext *s)
 
static void putstr8 (uint8_t **q_ptr, const char *str, int write_len)
 
static int mpegts_write_pmt (AVFormatContext *s, MpegTSService *service)
 
static void mpegts_write_sdt (AVFormatContext *s)
 
static MpegTSServicempegts_add_service (MpegTSWrite *ts, int sid, const char *provider_name, const char *name)
 
static int64_t get_pcr (const MpegTSWrite *ts, AVIOContext *pb)
 
static void mpegts_prefix_m2ts_header (AVFormatContext *s)
 
static void section_write_packet (MpegTSSection *s, const uint8_t *packet)
 
static int mpegts_init (AVFormatContext *s)
 
static void retransmit_si_info (AVFormatContext *s, int force_pat, int64_t dts)
 
static int write_pcr_bits (uint8_t *buf, int64_t pcr)
 
static void mpegts_insert_null_packet (AVFormatContext *s)
 
static void mpegts_insert_pcr_only (AVFormatContext *s, AVStream *st)
 
static void write_pts (uint8_t *q, int fourbits, int64_t pts)
 
static void set_af_flag (uint8_t *pkt, int flag)
 
static void extend_af (uint8_t *pkt, int size)
 
static uint8_tget_ts_payload_start (uint8_t *pkt)
 
static void mpegts_write_pes (AVFormatContext *s, AVStream *st, const uint8_t *payload, int payload_size, int64_t pts, int64_t dts, int key, int stream_id)
 
int ff_check_h264_startcode (AVFormatContext *s, const AVStream *st, const AVPacket *pkt)
 Check presence of H264 startcode. More...
 
static int check_hevc_startcode (AVFormatContext *s, const AVStream *st, const AVPacket *pkt)
 
static int opus_get_packet_samples (AVFormatContext *s, AVPacket *pkt)
 
static int mpegts_write_packet_internal (AVFormatContext *s, AVPacket *pkt)
 
static void mpegts_write_flush (AVFormatContext *s)
 
static int mpegts_write_packet (AVFormatContext *s, AVPacket *pkt)
 
static int mpegts_write_end (AVFormatContext *s)
 
static void mpegts_deinit (AVFormatContext *s)
 
static int mpegts_check_bitstream (struct AVFormatContext *s, const AVPacket *pkt)
 

Variables

static const AVOption options []
 
static const AVClass mpegts_muxer_class
 
AVOutputFormat ff_mpegts_muxer
 

Macro Definition Documentation

#define PCR_TIME_BASE   27000000

Definition at line 37 of file mpegtsenc.c.

Referenced by get_pcr(), and mpegts_init().

#define DVB_PRIVATE_NETWORK_START   0xff01

Definition at line 41 of file mpegtsenc.c.

#define MPEGTS_FLAG_REEMIT_PAT_PMT   0x01

Definition at line 104 of file mpegtsenc.c.

Referenced by mpegts_write_packet_internal().

#define MPEGTS_FLAG_AAC_LATM   0x02

Definition at line 105 of file mpegtsenc.c.

Referenced by mpegts_init(), and mpegts_write_pmt().

#define MPEGTS_FLAG_PAT_PMT_AT_FRAMES   0x04

Definition at line 106 of file mpegtsenc.c.

Referenced by mpegts_write_pes().

#define MPEGTS_FLAG_SYSTEM_B   0x08

Definition at line 107 of file mpegtsenc.c.

Referenced by mpegts_write_pmt().

#define MPEGTS_FLAG_DISCONT   0x10

Definition at line 108 of file mpegtsenc.c.

Referenced by mpegts_init().

#define DEFAULT_PES_HEADER_FREQ   16

Definition at line 121 of file mpegtsenc.c.

#define DEFAULT_PES_PAYLOAD_SIZE   ((DEFAULT_PES_HEADER_FREQ - 1) * 184 + 170)

Definition at line 122 of file mpegtsenc.c.

#define SECTION_LENGTH   1020

Definition at line 126 of file mpegtsenc.c.

Referenced by mpegts_write_pat(), mpegts_write_pmt(), and mpegts_write_sdt().

#define DEFAULT_PROVIDER_NAME   "FFmpeg"

Definition at line 222 of file mpegtsenc.c.

Referenced by mpegts_init().

#define DEFAULT_SERVICE_NAME   "Service01"

Definition at line 223 of file mpegtsenc.c.

Referenced by mpegts_init().

#define SDT_RETRANS_TIME   500

Definition at line 226 of file mpegtsenc.c.

Referenced by mpegts_init().

#define PAT_RETRANS_TIME   100

Definition at line 227 of file mpegtsenc.c.

Referenced by mpegts_init().

#define PCR_RETRANS_TIME   20

Definition at line 228 of file mpegtsenc.c.

Enumeration Type Documentation

anonymous enum
Enumerator
MPEGTS_SERVICE_TYPE_DIGITAL_TV 
MPEGTS_SERVICE_TYPE_DIGITAL_RADIO 
MPEGTS_SERVICE_TYPE_TELETEXT 
MPEGTS_SERVICE_TYPE_ADVANCED_CODEC_DIGITAL_RADIO 
MPEGTS_SERVICE_TYPE_MPEG2_DIGITAL_HDTV 
MPEGTS_SERVICE_TYPE_ADVANCED_CODEC_DIGITAL_SDTV 
MPEGTS_SERVICE_TYPE_ADVANCED_CODEC_DIGITAL_HDTV 
MPEGTS_SERVICE_TYPE_HEVC_DIGITAL_HDTV 

Definition at line 66 of file mpegtsenc.c.

Function Documentation

static void mpegts_write_section ( MpegTSSection s,
uint8_t buf,
int  len 
)
static

Definition at line 129 of file mpegtsenc.c.

Referenced by mpegts_write_section1().

static void put16 ( uint8_t **  q_ptr,
int  val 
)
inlinestatic
static int mpegts_write_section1 ( MpegTSSection s,
int  tid,
int  id,
int  version,
int  sec_num,
int  last_sec_num,
uint8_t buf,
int  len 
)
static

Definition at line 192 of file mpegtsenc.c.

Referenced by mpegts_write_pat(), mpegts_write_pmt(), and mpegts_write_sdt().

static void mpegts_write_pat ( AVFormatContext s)
static

Definition at line 250 of file mpegtsenc.c.

Referenced by retransmit_si_info().

static void putstr8 ( uint8_t **  q_ptr,
const char *  str,
int  write_len 
)
static

Definition at line 268 of file mpegtsenc.c.

Referenced by mpegts_write_pmt(), and mpegts_write_sdt().

static int mpegts_write_pmt ( AVFormatContext s,
MpegTSService service 
)
static

Definition at line 289 of file mpegtsenc.c.

Referenced by retransmit_si_info().

static void mpegts_write_sdt ( AVFormatContext s)
static

Definition at line 674 of file mpegtsenc.c.

Referenced by retransmit_si_info().

static MpegTSService* mpegts_add_service ( MpegTSWrite ts,
int  sid,
const char *  provider_name,
const char *  name 
)
static

Definition at line 712 of file mpegtsenc.c.

Referenced by mpegts_init().

static int64_t get_pcr ( const MpegTSWrite ts,
AVIOContext pb 
)
static
static void mpegts_prefix_m2ts_header ( AVFormatContext s)
static
static void section_write_packet ( MpegTSSection s,
const uint8_t packet 
)
static

Definition at line 757 of file mpegtsenc.c.

Referenced by mpegts_init().

static int mpegts_init ( AVFormatContext s)
static

Definition at line 764 of file mpegtsenc.c.

static void retransmit_si_info ( AVFormatContext s,
int  force_pat,
int64_t  dts 
)
static

Definition at line 1030 of file mpegtsenc.c.

Referenced by mpegts_write_pes().

static int write_pcr_bits ( uint8_t buf,
int64_t  pcr 
)
static

Definition at line 1057 of file mpegtsenc.c.

Referenced by mpegts_insert_pcr_only(), and mpegts_write_pes().

static void mpegts_insert_null_packet ( AVFormatContext s)
static

Definition at line 1072 of file mpegtsenc.c.

Referenced by mpegts_write_pes().

static void mpegts_insert_pcr_only ( AVFormatContext s,
AVStream st 
)
static

Definition at line 1088 of file mpegtsenc.c.

Referenced by mpegts_write_pes().

static void write_pts ( uint8_t q,
int  fourbits,
int64_t  pts 
)
static

Definition at line 1117 of file mpegtsenc.c.

Referenced by mpegts_write_pes().

static void set_af_flag ( uint8_t pkt,
int  flag 
)
static

Definition at line 1132 of file mpegtsenc.c.

Referenced by mpegts_write_pes().

static void extend_af ( uint8_t pkt,
int  size 
)
static

Definition at line 1148 of file mpegtsenc.c.

Referenced by mpegts_write_pes().

static uint8_t* get_ts_payload_start ( uint8_t pkt)
static

Definition at line 1156 of file mpegtsenc.c.

Referenced by mpegts_write_pes().

static void mpegts_write_pes ( AVFormatContext s,
AVStream st,
const uint8_t payload,
int  payload_size,
int64_t  pts,
int64_t  dts,
int  key,
int  stream_id 
)
static

Definition at line 1168 of file mpegtsenc.c.

Referenced by mpegts_write_flush(), and mpegts_write_packet_internal().

int ff_check_h264_startcode ( AVFormatContext s,
const AVStream st,
const AVPacket pkt 
)

Check presence of H264 startcode.

Returns
<0 to stop processing

Definition at line 1430 of file mpegtsenc.c.

Referenced by avi_write_packet(), mpegts_write_packet_internal(), and write_packet().

static int check_hevc_startcode ( AVFormatContext s,
const AVStream st,
const AVPacket pkt 
)
static

Definition at line 1447 of file mpegtsenc.c.

Referenced by mpegts_write_packet_internal().

static int opus_get_packet_samples ( AVFormatContext s,
AVPacket pkt 
)
static

Definition at line 1466 of file mpegtsenc.c.

Referenced by mpegts_write_packet_internal().

static int mpegts_write_packet_internal ( AVFormatContext s,
AVPacket pkt 
)
static

Definition at line 1514 of file mpegtsenc.c.

Referenced by mpegts_write_packet().

static void mpegts_write_flush ( AVFormatContext s)
static

Definition at line 1786 of file mpegtsenc.c.

Referenced by mpegts_write_end(), and mpegts_write_packet().

static int mpegts_write_packet ( AVFormatContext s,
AVPacket pkt 
)
static

Definition at line 1804 of file mpegtsenc.c.

static int mpegts_write_end ( AVFormatContext s)
static

Definition at line 1814 of file mpegtsenc.c.

static void mpegts_deinit ( AVFormatContext s)
static

Definition at line 1822 of file mpegtsenc.c.

static int mpegts_check_bitstream ( struct AVFormatContext s,
const AVPacket pkt 
)
static

Definition at line 1849 of file mpegtsenc.c.

Variable Documentation

const AVOption options[]
static

Definition at line 1871 of file mpegtsenc.c.

const AVClass mpegts_muxer_class
static
Initial value:
= {
.class_name = "MPEGTS muxer",
.item_name = av_default_item_name,
.option = options,
}
#define LIBAVUTIL_VERSION_INT
Definition: version.h:85
const char * av_default_item_name(void *ptr)
Return the context name.
Definition: log.c:191
static const AVOption options[]
Definition: mpegtsenc.c:1871

Definition at line 1966 of file mpegtsenc.c.

AVOutputFormat ff_mpegts_muxer
Initial value:
= {
.name = "mpegts",
.long_name = NULL_IF_CONFIG_SMALL("MPEG-TS (MPEG-2 Transport Stream)"),
.mime_type = "video/MP2T",
.extensions = "ts,m2t,m2ts,mts",
.priv_data_size = sizeof(MpegTSWrite),
.audio_codec = AV_CODEC_ID_MP2,
.video_codec = AV_CODEC_ID_MPEG2VIDEO,
.deinit = mpegts_deinit,
.check_bitstream = mpegts_check_bitstream,
.priv_class = &mpegts_muxer_class,
}
static void write_packet(OutputFile *of, AVPacket *pkt, OutputStream *ost, int unqueue)
Definition: ffmpeg.c:689
static av_cold int init(AVCodecContext *avctx)
Definition: avrndec.c:35
static int mpegts_init(AVFormatContext *s)
Definition: mpegtsenc.c:764
#define AVFMT_ALLOW_FLUSH
Format allows flushing.
Definition: avformat.h:478
static int mpegts_check_bitstream(struct AVFormatContext *s, const AVPacket *pkt)
Definition: mpegtsenc.c:1849
static int mpegts_write_packet(AVFormatContext *s, AVPacket *pkt)
Definition: mpegtsenc.c:1804
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
Definition: internal.h:186
static int write_trailer(AVFormatContext *s1)
Definition: v4l2enc.c:94
preferred ID for MPEG-1/2 video decoding
Definition: avcodec.h:220
static void mpegts_deinit(AVFormatContext *s)
Definition: mpegtsenc.c:1822
static int mpegts_write_end(AVFormatContext *s)
Definition: mpegtsenc.c:1814
#define flags(name, subs,...)
Definition: cbs_av1.c:596
#define AVFMT_VARIABLE_FPS
Format allows variable fps.
Definition: avformat.h:472
#define AVFMT_NODIMENSIONS
Format does not need width/height.
Definition: avformat.h:473
static const AVClass mpegts_muxer_class
Definition: mpegtsenc.c:1966

Definition at line 1973 of file mpegtsenc.c.