80 return memcmp(
probe->buf,
"ffconcat version 1.0", 20) ?
86 char *ret = *cursor += strspn(*cursor,
SPACE_CHARS);
97 const char *start =
f;
101 if (!((
unsigned)((*
f | 32) -
'a') < 26 ||
102 (
unsigned)(*
f -
'0') < 10 || *
f ==
'_' || *
f ==
'-')) {
114#define FAIL(retcode) do { ret = (retcode); goto fail; } while(0)
117 unsigned *nb_files_alloc)
134 (*ptr ==
':' || *ptr ==
',')) {
138 url_len = strlen(avf->
url) + strlen(filename) + 16;
145 if (
cat->nb_files >= *nb_files_alloc) {
146 size_t n =
FFMAX(*nb_files_alloc * 2, 16);
148 if (n <= cat->nb_files || n > SIZE_MAX /
sizeof(*
cat->files) ||
151 cat->files = new_files;
155 file = &
cat->files[
cat->nb_files++];
156 memset(file, 0,
sizeof(*file));
217 "Auto-inserting h264_mp4toannexb bitstream filter\n");
221 "required for H.264 streams\n");
259 cat->cur_file->streams[
i].out_stream_index =
i;
271 st =
cat->avf->streams[
i];
275 "Match slave stream #%d with stream #%d id 0x%x\n",
279 cat->cur_file->streams[
i].out_stream_index = j;
292 if (
cat->cur_file->nb_streams >=
cat->avf->nb_streams)
295 cat->avf->nb_streams *
sizeof(*
map));
298 cat->cur_file->streams =
map;
299 memset(
map +
cat->cur_file->nb_streams, 0,
300 (
cat->avf->nb_streams -
cat->cur_file->nb_streams) *
sizeof(*
map));
303 map[
i].out_stream_index = -1;
307 switch (
cat->stream_match_mode) {
319 cat->cur_file->nb_streams =
cat->avf->nb_streams;
372 cat->cur_file = file;
374 cat->files[fileno - 1].start_time +
375 cat->files[fileno - 1].duration;
380 if (
cat->segment_time_metadata) {
400 for (
i = 0;
i <
cat->nb_files;
i++) {
402 for (j = 0; j <
cat->files[
i].nb_streams; j++) {
403 if (
cat->files[
i].streams[j].bsf)
417#define NEEDS_UNSAFE (1 << 0)
418#define NEEDS_FILE (1 << 1)
419#define NEEDS_STREAM (1 << 2)
464 unsigned nb_files_alloc = 0;
466 uint8_t *cursor, *keyword;
483 if (!*keyword || *keyword ==
'#')
486 if (!strcmp(dir->
keyword, keyword))
531 if (!*arg_str[
arg]) {
545 if (strcmp(arg_kw[0],
"version") || strcmp(arg_kw[1],
"1.0")) {
552 ret =
add_file(avf, arg_str[0], &file, &nb_files_alloc);
583 "'file_packet_metadata key=value:key=value' is deprecated, "
584 "use multiple 'file_packet_meta key value' instead\n");
602 stream->
id = arg_int[0];
633 arg_int[1], arg_int[2],
NULL);
671 if (!
cat->nb_files) {
676 for (
i = 0;
i <
cat->nb_files;
i++) {
678 cat->files[
i].start_time = time;
680 time =
cat->files[
i].start_time;
686 cat->files[
i].user_duration =
cat->files[
i].outpoint -
cat->files[
i].inpoint;
688 cat->files[
i].duration =
cat->files[
i].user_duration;
689 if (time + (uint64_t)
cat->files[
i].user_duration > INT64_MAX)
691 time +=
cat->files[
i].user_duration;
693 if (
i ==
cat->nb_files) {
709 unsigned fileno =
cat->cur_file -
cat->files;
713 if (++fileno >=
cat->nb_files) {
728 "failed to send input packet\n");
737 "failed to receive output packet\n");
787 cs = &
cat->cur_file->streams[
pkt->stream_index];
797 st =
cat->avf->streams[
pkt->stream_index];
800 (
unsigned)(
cat->cur_file -
cat->files),
pkt->stream_index,
806 cat->avf->streams[
pkt->stream_index]->time_base);
814 if (
cat->cur_file->metadata) {
817 if (!packed_metadata)
820 packed_metadata, metadata_len);
830 cat->cur_file->next_dts = next_dts;
842 int64_t t0 =
cat->cur_file->start_time -
cat->cur_file->file_inpoint;
845 min_ts = min_ts == INT64_MIN ? INT64_MIN : min_ts - t0;
846 max_ts = max_ts == INT64_MAX ? INT64_MAX : max_ts - t0;
848 if (stream >=
cat->avf->nb_streams)
851 &min_ts, &ts, &max_ts);
860 int ret,
left, right;
866 &min_ts, &ts, &max_ts);
870 right =
cat->nb_files;
875 else if (!
cat->seekable)
878 while (right -
left > 1) {
879 int mid = (
left + right) / 2;
896 cat->files[
left + 1].start_time < max_ts) {
917 if ((ret =
real_seek(avf, stream, min_ts, ts, max_ts,
flags, cur_avf_saved)) < 0) {
918 if (
cat->cur_file != cur_file_saved) {
922 cat->avf = cur_avf_saved;
923 cat->cur_file = cur_file_saved;
925 if (
cat->cur_file != cur_file_saved) {
933#define OFFSET(x) offsetof(ConcatContext, x)
934#define DEC AV_OPT_FLAG_DECODING_PARAM
937 {
"safe",
"enable safe mode",
939 {
"auto_convert",
"automatically convert bitstream format",
941 {
"segment_time_metadata",
"output file segment start time and duration as packet metadata",
947 .class_name =
"concat demuxer",
static int probe(const AVProbeData *p)
#define attribute_nonstring
simple assert() macros that are a bit more flexible than ISO C assert().
#define av_assert0(cond)
assert() equivalent, that is always enabled.
const char * avio_find_protocol_name(const char *url)
Return the name of the protocol that will handle the passed URL.
int64_t ff_read_line_to_bprint_overwrite(AVIOContext *s, struct AVBPrint *bp)
Read a whole line of text from AVIOContext to an AVBPrint buffer overwriting its contents.
static int read_packet(void *opaque, uint8_t *buf, int buf_size)
static int BS_FUNC left(const BSCTX *bc)
Return the number of the bits left in a buffer.
void av_bprint_init(AVBPrint *buf, unsigned size_init, unsigned size_max)
#define AV_BPRINT_SIZE_UNLIMITED
#define flags(name, subs,...)
#define i(width, name, range_min, range_max)
static int read_probe(const AVProbeData *p)
int avcodec_parameters_copy(AVCodecParameters *dst, const AVCodecParameters *src)
static int64_t concat_seek(URLContext *h, int64_t pos, int whence)
static int concat_read_header(AVFormatContext *avf)
static int match_streams(AVFormatContext *avf)
static int safe_filename(const char *f)
static const ParseSyntax syntax[]
static char * get_keyword(uint8_t **cursor)
static int concat_probe(const AVProbeData *probe)
static int copy_stream_props(AVStream *st, AVStream *source_st)
static int concat_read_packet(AVFormatContext *avf, AVPacket *pkt)
static int add_file(AVFormatContext *avf, char *filename, ConcatFile **rfile, unsigned *nb_files_alloc)
static int packet_after_outpoint(ConcatContext *cat, AVPacket *pkt)
static const AVClass concat_class
static int try_seek(AVFormatContext *avf, int stream, int64_t min_ts, int64_t ts, int64_t max_ts, int flags)
static int filter_packet(AVFormatContext *avf, ConcatStream *cs, AVPacket *pkt)
static int open_next_file(AVFormatContext *avf)
static int concat_seek(AVFormatContext *avf, int stream, int64_t min_ts, int64_t ts, int64_t max_ts, int flags)
static int match_streams_exact_id(AVFormatContext *avf)
static int concat_read_close(AVFormatContext *avf)
static int concat_parse_script(AVFormatContext *avf)
static int open_file(AVFormatContext *avf, unsigned fileno)
static int real_seek(AVFormatContext *avf, int stream, int64_t min_ts, int64_t ts, int64_t max_ts, int flags, AVFormatContext *cur_avf)
static int detect_stream_specific(AVFormatContext *avf, int idx)
static int64_t get_best_effort_duration(ConcatFile *file, AVFormatContext *avf)
static int match_streams_one_to_one(AVFormatContext *avf)
AVChapter * avpriv_new_chapter(AVFormatContext *s, int64_t id, AVRational time_base, int64_t start, int64_t end, const char *title)
Add a new chapter.
void ff_rescale_interval(AVRational tb_in, AVRational tb_out, int64_t *min_ts, int64_t *ts, int64_t *max_ts)
Rescales a timestamp and the endpoints of an interval to which the temstamp belongs,...
#define FF_INFMT_FLAG_INIT_CLEANUP
For an FFInputFormat with this flag set read_close() needs to be called by the caller upon read_heade...
static int safe_filename(const char *f, int allow_subdir)
static int64_t start_time
static unsigned int nb_streams
static int read_header(FFV1Context *f, RangeCoder *c)
@ AV_OPT_TYPE_BOOL
Underlying C type is int.
void av_bsf_free(AVBSFContext **pctx)
Free a bitstream filter context and everything associated with it; write NULL into the supplied point...
int av_bsf_init(AVBSFContext *ctx)
Prepare the filter for use, after all the parameters and options have been set.
int av_bsf_alloc(const AVBitStreamFilter *filter, AVBSFContext **pctx)
Allocate a context for a given bitstream filter.
int av_bsf_receive_packet(AVBSFContext *ctx, AVPacket *pkt)
Retrieve a filtered packet.
int av_bsf_send_packet(AVBSFContext *ctx, AVPacket *pkt)
Submit a packet for filtering.
const AVBitStreamFilter * av_bsf_get_by_name(const char *name)
const AVCodecDescriptor * avcodec_descriptor_get_by_name(const char *name)
@ AV_PKT_DATA_STRINGS_METADATA
A list of zero terminated key/value strings.
void av_packet_unref(AVPacket *pkt)
Wipe the packet.
uint8_t * av_packet_pack_dictionary(const AVDictionary *dict, size_t *size)
Pack a dictionary for use in side_data.
int av_packet_add_side_data(AVPacket *pkt, enum AVPacketSideDataType type, uint8_t *data, size_t size)
Wrap an existing array as a packet side data.
AVStream * avformat_new_stream(AVFormatContext *s, const struct AVCodec *c)
Add a new stream to a media file.
AVFormatContext * avformat_alloc_context(void)
Allocate an AVFormatContext.
int avformat_seek_file(AVFormatContext *s, int stream_index, int64_t min_ts, int64_t ts, int64_t max_ts, int flags)
Seek to timestamp ts.
int av_read_frame(AVFormatContext *s, AVPacket *pkt)
Return the next frame of a stream.
int avformat_open_input(AVFormatContext **ps, const char *url, const AVInputFormat *fmt, AVDictionary **options)
Open an input stream and read the header.
int avformat_find_stream_info(AVFormatContext *ic, AVDictionary **options)
Read packets of a media file to get stream information.
void avformat_close_input(AVFormatContext **s)
Close an opened input AVFormatContext.
int av_bprint_finalize(AVBPrint *buf, char **ret_str)
Finalize a print buffer.
void av_dict_free(AVDictionary **pm)
Free all the memory allocated for an AVDictionary struct and all keys and values.
int av_dict_copy(AVDictionary **dst, const AVDictionary *src, int flags)
Copy entries from one AVDictionary struct into another.
#define AV_DICT_DONT_STRDUP_VAL
Take ownership of a value that's been allocated with av_malloc() or another memory allocation functio...
int av_dict_set(AVDictionary **pm, const char *key, const char *value, int flags)
Set the given entry in *pm, overwriting an existing entry.
int av_dict_parse_string(AVDictionary **pm, const char *str, const char *key_val_sep, const char *pairs_sep, int flags)
Parse the key/value pairs list and add the parsed entries to a dictionary.
int av_dict_set_int(AVDictionary **pm, const char *key, int64_t value, int flags)
Convenience wrapper for av_dict_set() that converts the value to a string and stores it.
#define AVERROR_DECODER_NOT_FOUND
Decoder not found.
#define AVERROR_BSF_NOT_FOUND
Bitstream filter not found.
#define AVERROR_BUG
Internal bug, also see AVERROR_BUG2.
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
#define AVERROR_EOF
End of file.
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
#define AV_LOG_WARNING
Something somehow does not look correct.
#define AV_LOG_VERBOSE
Detailed information.
#define AV_LOG_INFO
Standard information.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
const char * av_default_item_name(void *ptr)
Return the context name.
int av_compare_ts(int64_t ts_a, AVRational tb_a, int64_t ts_b, AVRational tb_b)
Compare two timestamps each in its own time base.
int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq)
Rescale a 64-bit integer by 2 rational numbers.
int av_strstart(const char *str, const char *pfx, const char **ptr)
Return non-zero if pfx is a prefix of str.
char * av_get_token(const char **buf, const char *term)
Unescape the given string until a non escaped terminating char, and return the token corresponding to...
#define AV_NOPTS_VALUE
Undefined timestamp value.
#define AV_TIME_BASE_Q
Internal time base represented as fractional value.
#define LIBAVUTIL_VERSION_INT
const VDPAUPixFmtMap * map
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
static av_cold int read_close(AVFormatContext *ctx)
Memory handling functions.
int av_parse_time(int64_t *timeval, const char *timestr, int duration)
Parse timestr and return in *time a corresponding number of microseconds.
#define FF_ARRAY_ELEMS(a)
The bitstream filter state.
AVCodecParameters * par_in
Parameters of the input stream.
AVCodecParameters * par_out
Parameters of the output stream.
Describe the class of an AVClass context structure.
This struct describes the properties of a single codec described by an AVCodecID.
int extradata_size
Size of the extradata content in bytes.
enum AVMediaType codec_type
General type of the encoded data.
uint8_t * extradata
Extra binary data needed for initializing the decoder, codec-dependent.
enum AVCodecID codec_id
Specific type of the encoded data (the codec used).
unsigned int nb_streams
Number of elements in AVFormatContext.streams.
AVIOContext * pb
I/O context.
int flags
Flags modifying the (de)muxer behaviour.
AVIOInterruptCB interrupt_callback
Custom interrupt callbacks for the I/O layer.
char * url
input or output URL.
void * priv_data
Format private data.
AVStream ** streams
A list of all streams in the file.
int64_t duration
Duration of the stream, in AV_TIME_BASE fractional seconds.
This structure stores compressed data.
This structure contains the data a format has to probe a file.
AVCodecParameters * codecpar
Codec parameters associated with this stream.
AVRational sample_aspect_ratio
sample aspect ratio (0 if unknown)
int id
Format-specific stream ID.
AVRational avg_frame_rate
Average framerate.
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented.
AVRational r_frame_rate
Real base framerate of the stream.
ConcatMatchMode stream_match_mode
int segment_time_metadata
attribute_nonstring char args[MAX_ARGS]
void(* filter)(uint8_t *src, ptrdiff_t stride, int qscale)
timestamp utils, mostly useful for debugging/logging purposes
#define av_ts2str(ts)
Convenience macro, the return value should be used only directly in function arguments but never stan...
#define av_ts2timestr(ts, tb)
Convenience macro, the return value should be used only directly in function arguments but never stan...
int ff_make_absolute_url(char *buf, int size, const char *base, const char *rel)
Convert a relative url into an absolute url, given a base url.
unbuffered private I/O API