FFmpeg  4.3
video.c
Go to the documentation of this file.
1 /*
2  * Copyright 2007 Bobby Bingham
3  * Copyright Stefano Sabatini <stefasab gmail com>
4  * Copyright Vitor Sessak <vitor1001 gmail com>
5  *
6  * This file is part of FFmpeg.
7  *
8  * FFmpeg is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public
10  * License as published by the Free Software Foundation; either
11  * version 2.1 of the License, or (at your option) any later version.
12  *
13  * FFmpeg is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  * Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with FFmpeg; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21  */
22 
23 #include <string.h>
24 #include <stdio.h>
25 
26 #include "libavutil/avassert.h"
27 #include "libavutil/buffer.h"
28 #include "libavutil/hwcontext.h"
29 #include "libavutil/imgutils.h"
30 #include "libavutil/mem.h"
31 
32 #include "avfilter.h"
33 #include "internal.h"
34 #include "video.h"
35 
36 #define BUFFER_ALIGN 32
37 
38 
40 {
41  return ff_get_video_buffer(link->dst->outputs[0], w, h);
42 }
43 
45 {
46  AVFrame *frame = NULL;
47  int pool_width = 0;
48  int pool_height = 0;
49  int pool_align = 0;
50  enum AVPixelFormat pool_format = AV_PIX_FMT_NONE;
51 
52  if (link->hw_frames_ctx &&
53  ((AVHWFramesContext*)link->hw_frames_ctx->data)->format == link->format) {
54  int ret;
56 
57  if (!frame)
58  return NULL;
59 
61  if (ret < 0)
63 
64  return frame;
65  }
66 
67  if (!link->frame_pool) {
70  if (!link->frame_pool)
71  return NULL;
72  } else {
73  if (ff_frame_pool_get_video_config(link->frame_pool,
74  &pool_width, &pool_height,
75  &pool_format, &pool_align) < 0) {
76  return NULL;
77  }
78 
79  if (pool_width != w || pool_height != h ||
80  pool_format != link->format || pool_align != BUFFER_ALIGN) {
81 
82  ff_frame_pool_uninit((FFFramePool **)&link->frame_pool);
85  if (!link->frame_pool)
86  return NULL;
87  }
88  }
89 
90  frame = ff_frame_pool_get(link->frame_pool);
91  if (!frame)
92  return NULL;
93 
94  frame->sample_aspect_ratio = link->sample_aspect_ratio;
95 
96  return frame;
97 }
98 
100 {
101  AVFrame *ret = NULL;
102 
104 
105  if (link->dstpad->get_video_buffer)
106  ret = link->dstpad->get_video_buffer(link, w, h);
107 
108  if (!ret)
110 
111  return ret;
112 }
ff_get_video_buffer
AVFrame * ff_get_video_buffer(AVFilterLink *link, int w, int h)
Request a picture buffer with a specific set of permissions.
Definition: video.c:99
AVPixelFormat
AVPixelFormat
Pixel format.
Definition: pixfmt.h:64
AVBufferRef::data
uint8_t * data
The data buffer.
Definition: buffer.h:89
av_frame_free
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
Definition: frame.c:203
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:300
BUFFER_ALIGN
#define BUFFER_ALIGN
Definition: video.c:36
av_buffer_allocz
AVBufferRef * av_buffer_allocz(int size)
Same as av_buffer_alloc(), except the returned buffer will be initialized to zero.
Definition: buffer.c:83
video.h
ff_default_get_video_buffer
AVFrame * ff_default_get_video_buffer(AVFilterLink *link, int w, int h)
Definition: video.c:44
FFFramePool
Frame pool.
Definition: framepool.c:30
ff_frame_pool_get_video_config
int ff_frame_pool_get_video_config(FFFramePool *pool, int *width, int *height, enum AVPixelFormat *format, int *align)
Get the video frame pool configuration.
Definition: framepool.c:157
av_frame_alloc
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
Definition: frame.c:190
avassert.h
ff_frame_pool_get
AVFrame * ff_frame_pool_get(FFFramePool *pool)
Allocate a new AVFrame, reussing old buffers from the pool when available.
Definition: framepool.c:195
link
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
Definition: filter_design.txt:23
NULL
#define NULL
Definition: coverity.c:32
ff_frame_pool_uninit
void ff_frame_pool_uninit(FFFramePool **pool)
Deallocate the frame pool.
Definition: framepool.c:284
FF_TPRINTF_START
#define FF_TPRINTF_START(ctx, func)
Definition: internal.h:239
AVFrame::format
int format
format of the frame, -1 if unknown or unset Values correspond to enum AVPixelFormat for video frames,...
Definition: frame.h:373
buffer.h
ff_null_get_video_buffer
AVFrame * ff_null_get_video_buffer(AVFilterLink *link, int w, int h)
Definition: video.c:39
internal.h
AVHWFramesContext
This struct describes a set or pool of "hardware" frames (i.e.
Definition: hwcontext.h:124
ret
ret
Definition: filter_design.txt:187
frame
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
Definition: filter_design.txt:264
w
FFmpeg Automated Testing Environment ************************************Introduction Using FATE from your FFmpeg source directory Submitting the results to the FFmpeg result aggregation server Uploading new samples to the fate suite FATE makefile targets and variables Makefile targets Makefile variables Examples Introduction **************FATE is an extended regression suite on the client side and a means for results aggregation and presentation on the server side The first part of this document explains how you can use FATE from your FFmpeg source directory to test your ffmpeg binary The second part describes how you can run FATE to submit the results to FFmpeg’s FATE server In any way you can have a look at the publicly viewable FATE results by visiting this as it can be seen if some test on some platform broke with their recent contribution This usually happens on the platforms the developers could not test on The second part of this document describes how you can run FATE to submit your results to FFmpeg’s FATE server If you want to submit your results be sure to check that your combination of OS and compiler is not already listed on the above mentioned website In the third part you can find a comprehensive listing of FATE makefile targets and variables Using FATE from your FFmpeg source directory **********************************************If you want to run FATE on your machine you need to have the samples in place You can get the samples via the build target fate rsync Use this command from the top level source this will cause FATE to fail NOTE To use a custom wrapper to run the pass ‘ target exec’ to ‘configure’ or set the TARGET_EXEC Make variable Submitting the results to the FFmpeg result aggregation server ****************************************************************To submit your results to the server you should run fate through the shell script ‘tests fate sh’ from the FFmpeg sources This script needs to be invoked with a configuration file as its first argument tests fate sh path to fate_config A configuration file template with comments describing the individual configuration variables can be found at ‘doc fate_config sh template’ Create a configuration that suits your based on the configuration template The ‘slot’ configuration variable can be any string that is not yet but it is suggested that you name it adhering to the following pattern ‘ARCH OS COMPILER COMPILER VERSION’ The configuration file itself will be sourced in a shell therefore all shell features may be used This enables you to setup the environment as you need it for your build For your first test runs the ‘fate_recv’ variable should be empty or commented out This will run everything as normal except that it will omit the submission of the results to the server The following files should be present in $workdir as specified in the configuration it may help to try out the ‘ssh’ command with one or more ‘ v’ options You should get detailed output concerning your SSH configuration and the authentication process The only thing left is to automate the execution of the fate sh script and the synchronisation of the samples directory Uploading new samples to the fate suite *****************************************If you need a sample uploaded send a mail to samples request This is for developers who have an account on the fate suite server If you upload new please make sure they are as small as space on each network bandwidth and so on benefit from smaller test cases Also keep in mind older checkouts use existing sample that means in practice generally do not remove or overwrite files as it likely would break older checkouts or releases Also all needed samples for a commit should be ideally before the push If you need an account for frequently uploading samples or you wish to help others by doing that send a mail to ffmpeg devel rsync vauL Duo ug o o w
Definition: fate.txt:150
AVFrame::sample_aspect_ratio
AVRational sample_aspect_ratio
Sample aspect ratio for the video frame, 0/1 if unknown/unspecified.
Definition: frame.h:388
AVFrame::hw_frames_ctx
AVBufferRef * hw_frames_ctx
For hwaccel-format frames, this should be a reference to the AVHWFramesContext describing the frame.
Definition: frame.h:639
AV_PIX_FMT_NONE
@ AV_PIX_FMT_NONE
Definition: pixfmt.h:65
avfilter.h
ff_tlog_link
void ff_tlog_link(void *ctx, AVFilterLink *link, int end)
Definition: avfilter.c:383
mem.h
imgutils.h
hwcontext.h
ff_frame_pool_video_init
FFFramePool * ff_frame_pool_video_init(AVBufferRef *(*alloc)(int size), int width, int height, enum AVPixelFormat format, int align)
Allocate and initialize a video frame pool.
Definition: framepool.c:51
h
h
Definition: vp9dsp_template.c:2038
av_hwframe_get_buffer
int av_hwframe_get_buffer(AVBufferRef *hwframe_ref, AVFrame *frame, int flags)
Allocate a new frame attached to the given AVHWFramesContext.
Definition: hwcontext.c:502
get_video_buffer
static AVFrame * get_video_buffer(AVFilterLink *inlink, int w, int h)
Definition: avf_concat.c:199