32 #include "libavutil/attributes.h"
33 #include "libavutil/avstring.h"
34 #include "libavutil/avassert.h"
35 #include "libavutil/opt.h"
36 #include "libavutil/imgutils.h"
37 #include "libavutil/timestamp.h"
38 #include "libavformat/avformat.h"
72 #define OFFSET(x) offsetof(MovieContext, x)
73 #define FLAGS AV_OPT_FLAG_FILTERING_PARAM | AV_OPT_FLAG_AUDIO_PARAM | AV_OPT_FLAG_VIDEO_PARAM
94 int i,
ret, already = 0, stream_id = -1;
95 char type_char[2],
dummy;
99 ret = sscanf(spec,
"d%1[av]%d%c", type_char, &stream_id, &dummy);
100 if (ret >= 1 && ret <= 2) {
114 "Invalid stream specifier \"%s\"\n", spec);
125 "Ambiguous stream specifier \"%s\", using #%d\n", spec, i);
132 already ?
"matched only already used streams" :
133 "did not match any stream");
139 "currently unsupported by libavfilter\n", spec,
175 "Channel layout is not set in stream %d, and could not "
176 "be guessed from the number of channels (%d)\n",
183 "Channel layout is not set in output stream %d, "
184 "guessed channel layout is '%s'\n",
195 int nb_streams,
ret, i;
196 char default_streams[16], *stream_specs, *spec, *cursor;
209 snprintf(default_streams,
sizeof(default_streams),
"d%c%d",
210 !strcmp(ctx->
filter->
name,
"amovie") ?
'a' :
'v',
212 stream_specs = default_streams;
214 for (cursor = stream_specs, nb_streams = 1; *cursor; cursor++)
218 if (movie->
loop_count != 1 && nb_streams != 1) {
220 "Loop with several streams is currently unsupported\n");
232 "Failed to avformat_open_input '%s'\n", movie->
file_name);
245 "%s: seek value overflow with start_time:%"PRId64
" seek_point:%"PRId64
"\n",
265 for (i = 0; i < nb_streams; i++) {
266 spec =
av_strtok(stream_specs,
"+", &cursor);
274 movie->
st[i].
st = st;
286 for (i = 0; i < nb_streams; i++)
289 for (i = 0; i < nb_streams; i++) {
291 snprintf(name,
sizeof(name),
"out%d", i);
308 av_log(ctx,
AV_LOG_VERBOSE,
"seek_point:%"PRIi64
" format_name:%s file_name:%s stream_index:%d\n",
335 int list[] = { 0, -1 };
336 int64_t list64[] = { 0, -1 };
391 switch (frame->
type) {
394 "video pts:%s time:%s size:%dx%d aspect:%d/%d",
402 "audio pts:%s time:%s samples:%d",
413 #define describe_frameref(f, link) \
414 describe_frame_to_str((char[1024]){0}, 1024, f, link)
455 int ret, got_frame = 0, pkt_out_id;
460 if (movie->
st[out_id].
done) {
490 if (pkt_out_id < 0) {
496 st = &movie->
st[pkt_out_id];
497 outlink = ctx->
outputs[pkt_out_id];
527 if (pkt->
size <= 0) {
548 return pkt_out_id == out_id;
560 return FFMIN(ret, 0);
564 #if CONFIG_MOVIE_FILTER
572 .priv_class = &movie_class,
584 #if CONFIG_AMOVIE_FILTER
586 #define amovie_options movie_options
599 .priv_class = &amovie_class,
static AVStream * find_stream(void *log, AVFormatContext *avf, const char *spec)
void * av_calloc(size_t nmemb, size_t size) av_malloc_attrib
Allocate a block of nmemb * size bytes with alignment suitable for all memory accesses (including vec...
#define AVERROR_PATCHWELCOME
void av_free_packet(AVPacket *pkt)
Free a packet.
This structure describes decoded (raw) audio or video data.
const char * name
Filter name.
static av_cold void movie_uninit(AVFilterContext *ctx)
void * priv
private data for use by the filter
#define AV_LOG_WARNING
Something somehow does not look correct.
static const AVFilterPad outputs[]
#define av_ts2timestr(ts, tb)
Convenience macro, the return value should be used only directly in function arguments but never stan...
int avformat_open_input(AVFormatContext **ps, const char *filename, AVInputFormat *fmt, AVDictionary **options)
Open an input stream and read the header.
AVFilterFormats * in_samplerates
Lists of channel layouts and sample rates used for automatic negotiation.
char * av_strdup(const char *s) av_malloc_attrib
Duplicate the string s.
static av_cold int init(AVCodecContext *avctx)
int h
agreed upon image height
AVCodecContext * codec
Codec context associated with this stream.
int index
stream index in AVFormatContext
static const AVOption movie_options[]
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...
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
enum AVMediaType type
AVFilterPad type.
#define FF_OUTLINK_IDX(link)
av_dlog(ac->avr,"%d samples - audio_convert: %s to %s (%s)\n", len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt), use_generic?ac->func_descr_generic:ac->func_descr)
static int query_formats(AVFilterContext *ctx)
char * stream_specs
user-provided list of streams, separated by +
void av_freep(void *ptr)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc() and set the pointer ...
const char * name
Pad name.
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
enum AVSampleFormat sample_fmt
audio sample format
struct AVFilterChannelLayouts * in_channel_layouts
int(* request_frame)(AVFilterLink *link)
Frame request callback.
static av_cold int uninit(AVCodecContext *avctx)
libavcodec/libavfilter gluing utilities
int avformat_match_stream_specifier(AVFormatContext *s, AVStream *st, const char *spec)
Check if the stream st contained in s is matched by the stream specifier spec.
int64_t pts
Presentation timestamp in time_base units (time when frame should be shown to user).
AVFrame * frame
video frame to store the decoded images in
#define AV_LOG_VERBOSE
Detailed information.
#define AVFILTER_FLAG_DYNAMIC_OUTPUTS
The number of the filter outputs is not determined just by AVFilter.outputs.
A filter pad used for either input or output.
A link between two filters.
int av_find_best_stream(AVFormatContext *ic, enum AVMediaType type, int wanted_stream_nb, int related_stream, AVCodec **decoder_ret, int flags)
Find the "best" stream in the file.
int avcodec_close(AVCodecContext *avctx)
Close a given AVCodecContext and free all the data associated with it (but not the AVCodecContext its...
#define av_err2str(errnum)
int width
width and height of the video frame
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
int avcodec_decode_video2(AVCodecContext *avctx, AVFrame *picture, int *got_picture_ptr, const AVPacket *avpkt)
Decode the video frame of size avpkt->size from avpkt->data into picture.
AVRational frame_rate
Frame rate of the stream on the link, or 1/0 if unknown; if left to 0/0, will be automatically be cop...
unsigned nb_outputs
number of output pads
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
AVRational time_base
Define the time base used by the PTS of the frames/samples which will pass through this link...
AVFilterContext * src
source filter
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
static int guess_channel_layout(MovieStream *st, int st_index, void *log_ctx)
uint64_t channel_layout
Audio channel layout.
int w
agreed upon image width
const char * av_get_media_type_string(enum AVMediaType media_type)
Return a string describing the media_type enum, NULL if media_type is unknown.
unsigned int nb_streams
A list of all streams in the file.
int width
picture width / height.
const AVFilter * filter
the AVFilter of which this is an instance
static int movie_config_output_props(AVFilterLink *outlink)
int avcodec_decode_audio4(AVCodecContext *avctx, AVFrame *frame, int *got_frame_ptr, const AVPacket *avpkt)
Decode the audio frame of size avpkt->size from avpkt->data into frame.
int refcounted_frames
If non-zero, the decoded audio and video frames returned from avcodec_decode_video2() and avcodec_dec...
int max_stream_index
max stream # actually used for output
static av_cold int movie_common_init(AVFilterContext *ctx)
Main libavfilter public API header.
void avcodec_flush_buffers(AVCodecContext *avctx)
Reset the internal decoder state / flush internal buffers.
AVCodec * avcodec_find_decoder(enum AVCodecID id)
Find a registered decoder with a matching codec ID.
AVFilterLink ** outputs
array of pointers to output links
int * out_index
stream number -> output number map, or -1
static AVInputFormat * iformat
enum AVMediaType codec_type
int sample_rate
samples per second
main external API structure.
AVRational sample_aspect_ratio
Sample aspect ratio for the video frame, 0/1 if unknown/unspecified.
Describe the class of an AVClass context structure.
static const AVFilterPad inputs[]
int64_t seek_point
seekpoint in microseconds
static int movie_push_frame(AVFilterContext *ctx, unsigned out_id)
Try to push a frame to the requested output.
discard useless packets like 0 size packets in avi
int avcodec_open2(AVCodecContext *avctx, const AVCodec *codec, AVDictionary **options)
Initialize the AVCodecContext to use the given AVCodec.
int av_read_frame(AVFormatContext *s, AVPacket *pkt)
Return the next frame of a stream.
int64_t start_time
Decoding: position of the first frame of the component, in AV_TIME_BASE fractional seconds...
int stream_index
for compatibility
int av_seek_frame(AVFormatContext *s, int stream_index, int64_t timestamp, int flags)
Seek to the keyframe at timestamp.
int64_t av_frame_get_best_effort_timestamp(const AVFrame *frame)
Accessors for some AVFrame fields.
static int movie_request_frame(AVFilterLink *outlink)
static int open_stream(void *log, MovieStream *st)
#define describe_frameref(f, link)
int avformat_find_stream_info(AVFormatContext *ic, AVDictionary **options)
Read packets of a media file to get stream information.
char * av_strtok(char *s, const char *delim, char **saveptr)
Split the string into several tokens which can be accessed by successive calls to av_strtok()...
void av_init_packet(AVPacket *pkt)
Initialize optional fields of a packet with default values.
static AVCodecContext * dec_ctx
void avformat_close_input(AVFormatContext **s)
Close an opened input AVFormatContext.
static int movie_query_formats(AVFilterContext *ctx)
int channels
number of audio channels
#define AVFILTER_DEFINE_CLASS(fname)
AVFilterPad * output_pads
array of output pads
static int rewind_file(AVFilterContext *ctx)
AVFormatContext * format_ctx
static char * describe_frame_to_str(char *dst, size_t dst_size, AVFrame *frame, AVFilterLink *link)
int(* config_props)(AVFilterLink *link)
Link configuration callback.
AVFilterFormats * in_formats
Lists of formats and channel layouts supported by the input and output filters respectively.
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented...
attribute_deprecated int type
enum AVDiscard discard
Selects which packets can be discarded at will and do not need to be demuxed.
AVRational r_frame_rate
Real base framerate of the stream.
static int ff_insert_outpad(AVFilterContext *f, unsigned index, AVFilterPad *p)
Insert a new output pad for the filter.
This structure stores compressed data.
void av_register_all(void)
Initialize libavformat and register all the muxers, demuxers and protocols.
int nb_samples
number of audio samples (per channel) described by this frame
#define av_ts2str(ts)
Convenience macro, the return value should be used only directly in function arguments but never stan...
#define AV_NOPTS_VALUE
Undefined timestamp value.
AVInputFormat * av_find_input_format(const char *short_name)
Find AVInputFormat based on the short name of the input format.
void av_get_channel_layout_string(char *buf, int buf_size, int nb_channels, uint64_t channel_layout)
Return a description of a channel layout.
MovieStream * st
array of all streams, one per output
int64_t av_get_default_channel_layout(int nb_channels)
Return default channel layout for a given number of channels.