21 #include "libavutil/avstring.h"
22 #include "libavutil/opt.h"
23 #include "libavutil/parseutils.h"
46 return memcmp(probe->
buf,
"ffconcat version 1.0", 20) ?
63 const char *
start = f;
67 if (!((
unsigned)((*f | 32) -
'a') < 26 ||
68 (
unsigned)(*f -
'0') < 10 || *f ==
'_' || *f ==
'-')) {
80 #define FAIL(retcode) do { ret = (retcode); goto fail; } while(0)
83 unsigned *nb_files_alloc)
95 url_len = strlen(avf->
filename) + strlen(filename) + 16;
101 if (cat->
nb_files >= *nb_files_alloc) {
102 size_t n =
FFMAX(*nb_files_alloc * 2, 16);
104 if (n <= cat->nb_files || n > SIZE_MAX /
sizeof(*cat->
files) ||
107 cat->
files = new_files;
112 memset(file, 0,
sizeof(*file));
167 unsigned nb_files_alloc = 0;
178 if (!*keyword || *keyword ==
'#')
181 if (!strcmp(keyword,
"file")) {
187 if ((ret =
add_file(avf, filename, &file, &nb_files_alloc)) < 0)
189 }
else if (!strcmp(keyword,
"duration")) {
203 }
else if (!strcmp(keyword,
"ffconcat")) {
206 if (strcmp(ver_kw,
"version") || strcmp(ver_val,
"1.0")) {
223 for (i = 0; i < cat->
nb_files; i++) {
293 int64_t *min_ts, int64_t *ts, int64_t *max_ts)
303 int64_t min_ts, int64_t ts, int64_t max_ts,
int flags)
309 min_ts = min_ts == INT64_MIN ? INT64_MIN : min_ts -
t0;
310 max_ts = max_ts == INT64_MAX ? INT64_MAX : max_ts -
t0;
315 &min_ts, &ts, &max_ts);
321 int64_t min_ts, int64_t ts, int64_t max_ts,
int flags)
324 int ret, left, right;
330 &min_ts, &ts, &max_ts);
335 while (right - left > 1) {
336 int mid = (left + right) / 2;
346 ret =
try_seek(avf, stream, min_ts, ts, max_ts, flags);
348 left < cat->nb_files - 1 &&
350 if ((ret =
open_file(avf, left + 1)) < 0)
352 ret =
try_seek(avf, stream, min_ts, ts, max_ts, flags);
358 int64_t min_ts, int64_t ts, int64_t max_ts,
int flags)
370 if ((ret =
real_seek(avf, stream, min_ts, ts, max_ts, flags)) < 0) {
373 cat->
avf = cur_avf_saved;
381 #define OFFSET(x) offsetof(ConcatContext, x)
382 #define DEC AV_OPT_FLAG_DECODING_PARAM
385 {
"safe",
"enable safe mode",
407 .priv_class = &concat_class,
void 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.
static int concat_read_close(AVFormatContext *avf)
#define LIBAVUTIL_VERSION_INT
int avformat_open_input(AVFormatContext **ps, const char *filename, AVInputFormat *fmt, AVDictionary **options)
Open an input stream and read the header.
AVCodecContext * codec
Codec context associated with this stream.
AVRational sample_aspect_ratio
sample aspect ratio (0 if unknown)
static void rescale_interval(AVRational tb_in, AVRational tb_out, int64_t *min_ts, int64_t *ts, int64_t *max_ts)
void av_log(void *avcl, int level, const char *fmt,...) av_printf_format(3
Send the specified message to the log if the level is less than or equal to the current av_log_level...
int avcodec_copy_context(AVCodecContext *dest, const AVCodecContext *src)
Copy the settings of the source AVCodecContext into the destination AVCodecContext.
void av_freep(void *ptr)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc() and set the pointer ...
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...
static int concat_seek(AVFormatContext *avf, int stream, int64_t min_ts, int64_t ts, int64_t max_ts, int flags)
static int64_t start_time
const char * av_default_item_name(void *ctx)
Return the context name.
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
unsigned char * buf
Buffer must have AVPROBE_PADDING_SIZE of extra allocated bytes filled with zero.
AVInputFormat ff_concat_demuxer
static av_cold int read_close(AVFormatContext *ctx)
AVStream * avformat_new_stream(AVFormatContext *s, const AVCodec *c)
Add a new stream to a media file.
static int probe(AVProbeData *p)
const OptionDef options[]
static int concat_read_header(AVFormatContext *avf)
int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq) av_const
Rescale a 64-bit integer by 2 rational numbers.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
void av_free(void *ptr)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc(). ...
void * priv_data
Format private data.
char filename[1024]
input or output filename
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
static int concat_probe(AVProbeData *probe)
AVRational avg_frame_rate
Average framerate.
unsigned int nb_streams
A list of all streams in the file.
int64_t av_rescale_q_rnd(int64_t a, AVRational bq, AVRational cq, enum AVRounding) av_const
Rescale a 64-bit integer by 2 rational numbers with specified rounding.
static int try_seek(AVFormatContext *avf, int stream, int64_t min_ts, int64_t ts, int64_t max_ts, int flags)
void * av_realloc(void *ptr, size_t size) 1(2)
Allocate or reallocate a block of memory.
void * av_malloc(size_t size) av_malloc_attrib 1(1)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
static const AVClass concat_class
static int open_file(AVFormatContext *avf, unsigned fileno)
int ff_get_line(AVIOContext *s, char *buf, int maxlen)
Read a whole line of text from AVIOContext.
static int read_header(FFV1Context *f)
#define AV_TIME_BASE_Q
Internal time base represented as fractional value.
AVIOContext * pb
I/O context.
static int read_packet(AVFormatContext *ctx, AVPacket *pkt)
Describe the class of an AVClass context structure.
rational number numerator/denominator
int av_parse_time(int64_t *timeval, const char *timestr, int duration)
Parse timestr and return in *time a corresponding number of microseconds.
This structure contains the data a format has to probe a file.
int av_read_frame(AVFormatContext *s, AVPacket *pkt)
Return the next frame of a stream.
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.
static int concat_read_packet(AVFormatContext *avf, AVPacket *pkt)
int64_t start_time
Decoding: position of the first frame of the component, in AV_TIME_BASE fractional seconds...
static char * get_keyword(uint8_t **cursor)
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.
Flag to pass INT64_MIN/MAX through instead of rescaling, this avoids special cases for AV_NOPTS_VALUE...
static int open_next_file(AVFormatContext *avf)
#define AVERROR_INVALIDDATA
static int real_seek(AVFormatContext *avf, int stream, int64_t min_ts, int64_t ts, int64_t max_ts, int flags)
int64_t dts
Decompression timestamp in AVStream->time_base units; the time at which the packet is decompressed...
int64_t duration
Decoding: duration of the stream, in AV_TIME_BASE fractional seconds.
static int add_file(AVFormatContext *avf, char *filename, ConcatFile **rfile, unsigned *nb_files_alloc)
unbuffered private I/O API
static int safe_filename(const char *f)
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.
This structure stores compressed data.
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
#define AV_NOPTS_VALUE
Undefined timestamp value.