2 * This file is part of FFmpeg.
4 * FFmpeg is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * FFmpeg is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with FFmpeg; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 #ifndef AVFILTER_BUFFERSRC_H
20 #define AVFILTER_BUFFERSRC_H
24 * @ingroup lavfi_buffersrc
25 * Memory buffer source API.
31 * @defgroup lavfi_buffersrc Buffer source API
39 * Do not check for format changes.
41 AV_BUFFERSRC_FLAG_NO_CHECK_FORMAT = 1,
44 * Immediately push the frame to the output.
46 AV_BUFFERSRC_FLAG_PUSH = 4,
49 * Keep a reference to the frame.
50 * If the frame if reference-counted, create a new reference; otherwise
51 * copy the frame data.
53 AV_BUFFERSRC_FLAG_KEEP_REF = 8,
58 * Get the number of failed requests.
60 * A failed request is when the request_frame method is called while no
61 * frame is present in the buffer.
62 * The number is reset when a frame is added.
64 unsigned av_buffersrc_get_nb_failed_requests(AVFilterContext *buffer_src);
67 * This structure contains the parameters describing the frames that will be
68 * passed to this filter.
70 * It should be allocated with av_buffersrc_parameters_alloc() and freed with
71 * av_free(). All the allocated fields in it remain owned by the caller.
73 typedef struct AVBufferSrcParameters {
75 * video: the pixel format, value corresponds to enum AVPixelFormat
76 * audio: the sample format, value corresponds to enum AVSampleFormat
80 * The timebase to be used for the timestamps on the input frames.
85 * Video only, the display dimensions of the input frames.
90 * Video only, the sample (pixel) aspect ratio.
92 AVRational sample_aspect_ratio;
95 * Video only, the frame rate of the input video. This field must only be
96 * set to a non-zero value if input stream has a known constant framerate
97 * and should be left at its initial value if the framerate is variable or
100 AVRational frame_rate;
103 * Video with a hwaccel pixel format only. This should be a reference to an
104 * AVHWFramesContext instance describing the input frames.
106 AVBufferRef *hw_frames_ctx;
109 * Audio only, the audio sampling rate in samples per second.
114 * Audio only, the audio channel layout
116 uint64_t channel_layout;
117 } AVBufferSrcParameters;
120 * Allocate a new AVBufferSrcParameters instance. It should be freed by the
121 * caller with av_free().
123 AVBufferSrcParameters *av_buffersrc_parameters_alloc(void);
126 * Initialize the buffersrc or abuffersrc filter with the provided parameters.
127 * This function may be called multiple times, the later calls override the
128 * previous ones. Some of the parameters may also be set through AVOptions, then
129 * whatever method is used last takes precedence.
131 * @param ctx an instance of the buffersrc or abuffersrc filter
132 * @param param the stream parameters. The frames later passed to this filter
133 * must conform to those parameters. All the allocated fields in
134 * param remain owned by the caller, libavfilter will make internal
135 * copies or references when necessary.
136 * @return 0 on success, a negative AVERROR code on failure.
138 int av_buffersrc_parameters_set(AVFilterContext *ctx, AVBufferSrcParameters *param);
141 * Add a frame to the buffer source.
143 * @param ctx an instance of the buffersrc filter
144 * @param frame frame to be added. If the frame is reference counted, this
145 * function will make a new reference to it. Otherwise the frame data will be
148 * @return 0 on success, a negative AVERROR on error
150 * This function is equivalent to av_buffersrc_add_frame_flags() with the
151 * AV_BUFFERSRC_FLAG_KEEP_REF flag.
153 av_warn_unused_result
154 int av_buffersrc_write_frame(AVFilterContext *ctx, const AVFrame *frame);
157 * Add a frame to the buffer source.
159 * @param ctx an instance of the buffersrc filter
160 * @param frame frame to be added. If the frame is reference counted, this
161 * function will take ownership of the reference(s) and reset the frame.
162 * Otherwise the frame data will be copied. If this function returns an error,
163 * the input frame is not touched.
165 * @return 0 on success, a negative AVERROR on error.
167 * @note the difference between this function and av_buffersrc_write_frame() is
168 * that av_buffersrc_write_frame() creates a new reference to the input frame,
169 * while this function takes ownership of the reference passed to it.
171 * This function is equivalent to av_buffersrc_add_frame_flags() without the
172 * AV_BUFFERSRC_FLAG_KEEP_REF flag.
174 av_warn_unused_result
175 int av_buffersrc_add_frame(AVFilterContext *ctx, AVFrame *frame);
178 * Add a frame to the buffer source.
180 * By default, if the frame is reference-counted, this function will take
181 * ownership of the reference(s) and reset the frame. This can be controlled
184 * If this function returns an error, the input frame is not touched.
186 * @param buffer_src pointer to a buffer source context
187 * @param frame a frame, or NULL to mark EOF
188 * @param flags a combination of AV_BUFFERSRC_FLAG_*
189 * @return >= 0 in case of success, a negative AVERROR code
192 av_warn_unused_result
193 int av_buffersrc_add_frame_flags(AVFilterContext *buffer_src,
194 AVFrame *frame, int flags);
197 * Close the buffer source after EOF.
199 * This is similar to passing NULL to av_buffersrc_add_frame_flags()
200 * except it takes the timestamp of the EOF, i.e. the timestamp of the end
203 int av_buffersrc_close(AVFilterContext *ctx, int64_t pts, unsigned flags);
209 #endif /* AVFILTER_BUFFERSRC_H */