FFmpeg: libavfilter/src_movie.c Source File
Go to the documentation of this file. 1 /*
2 * Copyright (c) 2010 Stefano Sabatini
3 * Copyright (c) 2008 Victor Paesa
4 *
5 * This file is part of FFmpeg.
6 *
7 * FFmpeg is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
12 * FFmpeg is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with FFmpeg; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 */
21
22 /**
23 * @file
24 * movie video source
25 *
26 * @todo use direct rendering (no allocation of a new frame)
27 * @todo support a PTS correction mechanism
28 */
29
31 #include <stdint.h>
32
40
42
44
50
57
59 /* common A/V fields */
65 char *
stream_specs;
/**< user-provided list of streams, separated by + */
70
72
75 int *
out_index;
/**< stream number -> output number map, or -1 */
77
78 #define OFFSET(x) offsetof(MovieContext, x)
79 #define FLAGS AV_OPT_FLAG_FILTERING_PARAM | AV_OPT_FLAG_AUDIO_PARAM | AV_OPT_FLAG_VIDEO_PARAM
80
94 };
95
98
100 {
101 int i,
ret, already = 0, stream_id = -1;
102 char type_char[2],
dummy;
105
106 ret = sscanf(spec,
"d%1[av]%d%c", type_char, &stream_id, &
dummy);
107 if (
ret >= 1 &&
ret <= 2) {
114 }
116 }
121 "Invalid stream specifier \"%s\"\n", spec);
123 }
125 continue;
127 already++;
128 continue;
129 }
130 if (found) {
132 "Ambiguous stream specifier \"%s\", using #%d\n", spec,
i);
133 break;
134 }
136 }
137 if (!found) {
139 already ? "matched only already used streams" :
140 "did not match any stream");
142 }
146 "currently unsupported by libavfilter\n", spec,
149 }
150 return found;
151 }
152
154 {
157
159 if (!codec) {
162 }
163
167
171
173
177 }
178
179 return 0;
180 }
181
183 {
185 char buf[256];
187
188 if (!chl) {
190 "Channel layout is not set in stream %d, and could not "
191 "be guessed from the number of channels (%d)\n",
194 }
195
198 "Channel layout is not set in output stream %d, "
199 "guessed channel layout is '%s'\n",
200 st_index, buf);
202 return 0;
203 }
204
206 {
209 int64_t timestamp;
211 char default_streams[16], *stream_specs, *spec, *cursor;
213
217 }
218
220
222 if (!stream_specs) {
223 snprintf(default_streams,
sizeof(default_streams),
"d%c%d",
224 !strcmp(
ctx->filter->name,
"amovie") ?
'a' :
'v',
226 stream_specs = default_streams;
227 }
228 for (cursor = stream_specs; *cursor; cursor++)
229 if (*cursor == '+')
231
234 "Loop with several streams is currently unsupported\n");
236 }
237
238 // Try to find the movie format (container)
240
244 "Failed to avformat_open_input '%s'\n", movie->
file_name);
246 }
249
250 // if seeking requested, we execute it
253 // add the stream start time, should it exist
257 "%s: seek value overflow with start_time:%"PRId64" seek_point:%"PRId64"\n",
260 }
262 }
267 }
268 }
269
272
276
278 spec =
av_strtok(stream_specs,
"+", &cursor);
279 if (!spec)
281 stream_specs =
NULL;
/* for next strtok */
283 if (!st)
286 movie->
st[
i].
st = st;
290 }
293
312 }
318 }
322 }
323
327
328 return 0;
329 }
330
332 {
335
336 for (
i = 0;
i <
ctx->nb_outputs;
i++) {
340 }
345 }
346
348 {
350 int list[] = { 0, -1 };
351 int64_t list64[] = { 0, -1 };
353
354 for (
i = 0;
i <
ctx->nb_outputs;
i++) {
358
359 switch (
c->codec_type) {
364 break;
369 list[0] =
c->sample_rate;
372 list64[0] =
c->channel_layout;
376 break;
377 }
378 }
379
380 return 0;
381 }
382
384 {
390
392
393 switch (
c->codec_type) {
395 outlink->
w =
c->width;
396 outlink->
h =
c->height;
398 break;
400 break;
401 }
402
403 return 0;
404 }
405
409 {
413 "video pts:%s time:%s size:%dx%d aspect:%d/%d",
416 frame->sample_aspect_ratio.num,
417 frame->sample_aspect_ratio.den);
418 break;
421 "audio pts:%s time:%s samples:%d",
424 break;
425 default:
427 break;
428 }
429 return dst;
430 }
431
433 {
437
445 }
446
447 for (
i = 0;
i <
ctx->nb_outputs;
i++) {
449 }
450 return 0;
451 }
452
454 {
458
459 /* read a new packet from input stream */
462 /* EOF -> set all decoders for flushing */
463 for (
int i = 0;
i <
ctx->nb_outputs;
i++) {
467 }
468
469 return 0;
472
473 /* send the packet to its decoder, if any */
476 if (pkt_out_id >= 0)
479
481 }
482
483 /**
484 * Try to push a frame to the requested output.
485 *
486 * @param ctx filter context
487 * @param out_id number of output where a frame is wanted;
488 * @return 0 if a frame was pushed on the requested output,
489 * AVERROR(EAGAIN) if the decoder requires more input
490 * AVERROR(EOF) if the decoder has been completely flushed
491 * <0 AVERROR code
492 */
494 {
500
504
509
512 }
513
525 }
526 }
527 }
529 }
533
539 );
541 return 0;
542 }
543 }
545
548 return 0;
549 }
550
552 {
556
557 while (1) {
560
561 /* check all decoders for available output */
562 for (
int i = 0;
i <
ctx->nb_outputs;
i++) {
567 got_eof++;
570 else if (
i == out_id)
571 return 0;
572 }
573
575 /* all decoders require more input -> read a new packet */
579 } else if (got_eof) {
580 /* all decoders flushed */
587 continue;
588 }
590 }
591 }
592 }
593
595 char *res,
int res_len,
int flags)
596 {
599
600 if (!strcmp(cmd, "seek")) {
602 int64_t ts;
603 char tail[2];
604
605 if (sscanf(args,
"%i|%"SCNi64
"|%i %1s", &idx, &ts, &
flags, tail) != 3)
607
611
612 for (
i = 0;
i <
ctx->nb_outputs;
i++) {
614 }
616 } else if (!strcmp(cmd, "get_duration")) {
617 int print_len;
618 char tail[2];
619
620 if (!res || res_len <= 0)
622
623 if (args && sscanf(args, "%1s", tail) == 1)
625
627 if (print_len < 0 || print_len >= res_len)
629
630 return 0;
631 }
632
634 }
635
636 #if CONFIG_MOVIE_FILTER
637
639
644 .priv_class = &movie_class,
648
653 };
654
655 #endif /* CONFIG_MOVIE_FILTER */
656
657 #if CONFIG_AMOVIE_FILTER
658
659 #define amovie_options movie_options
661
669
672 .priv_class = &amovie_class,
675 };
676
677 #endif /* CONFIG_AMOVIE_FILTER */
void av_packet_unref(AVPacket *pkt)
Wipe the packet.
#define AV_LOG_WARNING
Something somehow does not look correct.
static av_cold int init(AVCodecContext *avctx)
Filter the word "frame" indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later. That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another. Frame references ownership and permissions
enum AVMediaType codec_type
General type of the encoded data.
static int movie_decode_packet(AVFilterContext *ctx)
This struct describes the properties of an encoded stream.
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
#define AVERROR_EOF
End of file.
enum AVDiscard discard
Selects which packets can be discarded at will and do not need to be demuxed.
static char * describe_frame_to_str(char *dst, size_t dst_size, AVFrame *frame, enum AVMediaType frame_type, AVFilterLink *link)
#define AV_TIME_BASE_Q
Internal time base represented as fractional value.
int stream_index
for compatibility
char * av_asprintf(const char *fmt,...)
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
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.
This structure describes decoded (raw) audio or video data.
AVStream ** streams
A list of all streams in the file.
#define AV_LOG_VERBOSE
Detailed information.
static const AVOption movie_options[]
const char * name
Filter name.
int av_read_frame(AVFormatContext *s, AVPacket *pkt)
Return the next frame of a stream.
A link between two filters.
static int guess_channel_layout(MovieStream *st, int st_index, void *log_ctx)
static int process_command(AVFilterContext *ctx, const char *cmd, const char *args, char *res, int res_len, int flags)
int * out_index
stream number -> output number map, or -1
void avformat_close_input(AVFormatContext **s)
Close an opened input AVFormatContext.
static int got_eagain(void)
static int open_stream(AVFilterContext *ctx, MovieStream *st)
int thread_count
thread count is used to decide how many independent tasks should be passed to execute()
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf type
@ AV_ROUND_UP
Round toward +infinity.
A filter pad used for either input or output.
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
int(* request_frame)(AVFilterLink *link)
Frame request callback.
AVCodecContext * avcodec_alloc_context3(const AVCodec *codec)
Allocate an AVCodecContext and set its fields to default values.
int av_seek_frame(AVFormatContext *s, int stream_index, int64_t timestamp, int flags)
Seek to the keyframe at timestamp.
#define FF_OUTLINK_IDX(link)
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().
int avcodec_receive_frame(AVCodecContext *avctx, AVFrame *frame)
Return decoded output data from a decoder.
static const AVFilterPad outputs[]
AVRational frame_rate
Frame rate of the stream on the link, or 1/0 if unknown or variable; if left to 0/0,...
int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq)
Rescale a 64-bit integer by 2 rational numbers.
AVFormatContext * format_ctx
static AVStream * find_stream(void *log, AVFormatContext *avf, const char *spec)
Filter the word "frame" indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a link
@ AVDISCARD_ALL
discard all
AVCodecParameters * codecpar
Codec parameters associated with this stream.
Describe the class of an AVClass context structure.
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented.
#define AVERROR_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
static int movie_request_frame(AVFilterLink *outlink)
int64_t discontinuity_threshold
void avcodec_free_context(AVCodecContext **avctx)
Free the codec context and everything associated with it and write NULL to the provided pointer.
int64_t discontinuity_threshold
Filter the word "frame" indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining list
int attribute_align_arg avcodec_open2(AVCodecContext *avctx, const AVCodec *codec, AVDictionary **options)
Initialize the AVCodecContext to use the given AVCodec.
these buffered frames must be flushed immediately if a new input produces new the filter must not call request_frame to get more It must just process the frame or queue it The task of requesting more frames is left to the filter s request_frame method or the application If a filter has several inputs
AVCodecContext * codec_ctx
Undefined Behavior In the C some operations are like signed integer dereferencing freed accessing outside allocated Undefined Behavior must not occur in a C it is not safe even if the output of undefined operations is unused The unsafety may seem nit picking but Optimizing compilers have in fact optimized code on the assumption that no undefined Behavior occurs Optimizing code based on wrong assumptions can and has in some cases lead to effects beyond the output of computations The signed integer overflow problem in speed critical code Code which is highly optimized and works with signed integers sometimes has the problem that often the output of the computation does not c
#define AVFILTER_FLAG_DYNAMIC_OUTPUTS
The number of the filter outputs is not determined just by AVFilter.outputs.
unsigned int nb_streams
Number of elements in AVFormatContext.streams.
int(* config_props)(AVFilterLink *link)
Link configuration callback.
int avformat_find_stream_info(AVFormatContext *ic, AVDictionary **options)
Read packets of a media file to get stream information.
static av_cold int movie_common_init(AVFilterContext *ctx)
#define av_ts2timestr(ts, tb)
Convenience macro, the return value should be used only directly in function arguments but never stan...
static int movie_query_formats(AVFilterContext *ctx)
static av_cold void movie_uninit(AVFilterContext *ctx)
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.
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
@ AVDISCARD_DEFAULT
discard useless packets like 0 size packets in avi
#define av_err2str(errnum)
Convenience macro, the return value should be used only directly in function arguments but never stan...
int format
agreed upon media format
#define AV_NOPTS_VALUE
Undefined timestamp value.
AVFilterContext * src
source filter
AVFilterFormatsConfig incfg
Lists of supported formats / etc.
#define AVFILTER_DEFINE_CLASS(fname)
int avcodec_send_packet(AVCodecContext *avctx, const AVPacket *avpkt)
Supply raw packet data as input to a decoder.
ff_const59 AVInputFormat * av_find_input_format(const char *short_name)
Find AVInputFormat based on the short name of the input format.
int avformat_open_input(AVFormatContext **ps, const char *url, ff_const59 AVInputFormat *fmt, AVDictionary **options)
Open an input stream and read the header.
int w
agreed upon image width
static int rewind_file(AVFilterContext *ctx)
int avcodec_parameters_to_context(AVCodecContext *codec, const AVCodecParameters *par)
Fill the codec context based on the values from the supplied codec parameters.
int ff_filter_get_nb_threads(AVFilterContext *ctx)
Get number of threads for current filter instance.
int max_stream_index
max stream # actually used for output
const char * name
Pad name.
enum AVMediaType type
AVFilterPad type.
void avcodec_flush_buffers(AVCodecContext *avctx)
Reset the internal codec state / flush internal buffers.
these buffered frames must be flushed immediately if a new input produces new the filter must not call request_frame to get more It must just process the frame or queue it The task of requesting more frames is left to the filter s request_frame method or the application If a filter has several the filter must be ready for frames arriving randomly on any input any filter with several inputs will most likely require some kind of queuing mechanism It is perfectly acceptable to have a limited queue and to drop frames when the inputs are too unbalanced request_frame For filters that do not use the this method is called when a frame is wanted on an output For a it should directly call filter_frame on the corresponding output For a if there are queued frames already one of these frames should be pushed If the filter should request a frame on one of its repeatedly until at least one frame has been pushed Return or at least make progress towards producing a frame
static int movie_push_frame(AVFilterContext *ctx, unsigned out_id)
Try to push a frame to the requested output.
AVCodec * avcodec_find_decoder(enum AVCodecID id)
Find a registered decoder with a matching codec ID.
static AVInputFormat * iformat
static int movie_config_output_props(AVFilterLink *outlink)
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.
main external API structure.
int index
stream index in AVFormatContext
static int format_name(const char *buf, char **s, int index, const char *varname)
void * av_calloc(size_t nmemb, size_t size)
Non-inlined equivalent of av_mallocz_array().
int h
agreed upon image height
static int ff_insert_outpad(AVFilterContext *f, unsigned index, AVFilterPad *p)
Insert a new output pad for the filter.
AVRational r_frame_rate
Real base framerate of the stream.
AVRational time_base
Define the time base used by the PTS of the frames/samples which will pass through this link.
char * stream_specs
user-provided list of streams, separated by +
int64_t duration
Duration of the stream, in AV_TIME_BASE fractional seconds.
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.
static av_always_inline int diff(const uint32_t a, const uint32_t b)
enum AVCodecID codec_id
Specific type of the encoded data (the codec used).
This structure stores compressed data.
uint64_t channel_layout
Audio only.
static int query_formats(AVFilterContext *ctx)
#define flags(name, subs,...)
#define AVERROR_BUG
Internal bug, also see AVERROR_BUG2.
int64_t seek_point
seekpoint in microseconds
int64_t start_time
Position of the first frame of the component, in AV_TIME_BASE fractional seconds.
#define av_ts2str(ts)
Convenience macro, the return value should be used only directly in function arguments but never stan...
static av_cold int uninit(AVCodecContext *avctx)
int64_t av_rescale_q_rnd(int64_t a, AVRational bq, AVRational cq, enum AVRounding rnd)
Rescale a 64-bit integer by 2 rational numbers with specified rounding.
const char * av_get_pix_fmt_name(enum AVPixelFormat pix_fmt)
Return the short name for a pixel format, NULL in case pix_fmt is unknown.
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.
Generated on Wed Aug 24 2022 21:34:30 for FFmpeg by
doxygen
1.8.17