FFmpeg
vidstabutils.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2013 Georg Martius <georg dot martius at web dot de>
3  *
4  * This file is part of FFmpeg.
5  *
6  * FFmpeg is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * FFmpeg is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with FFmpeg; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19  */
20 
21 #include "libavutil/mem.h"
22 #include "vidstabutils.h"
23 
30 };
31 
32 /** convert AV's pixelformat to vid.stab pixelformat */
34 {
35  switch (pf) {
36  case AV_PIX_FMT_YUV420P: return PF_YUV420P;
37  case AV_PIX_FMT_YUV422P: return PF_YUV422P;
38  case AV_PIX_FMT_YUV444P: return PF_YUV444P;
39  case AV_PIX_FMT_YUV410P: return PF_YUV410P;
40  case AV_PIX_FMT_YUV411P: return PF_YUV411P;
41  case AV_PIX_FMT_YUV440P: return PF_YUV440P;
42  case AV_PIX_FMT_YUVA420P: return PF_YUVA420P;
43  case AV_PIX_FMT_GRAY8: return PF_GRAY8;
44  case AV_PIX_FMT_RGB24: return PF_RGB24;
45  case AV_PIX_FMT_BGR24: return PF_BGR24;
46  case AV_PIX_FMT_RGBA: return PF_RGBA;
47  default:
48  av_log(ctx, AV_LOG_ERROR, "cannot deal with pixel format %i\n", pf);
49  return PF_NONE;
50  }
51 }
52 
53 /** struct to hold a valid context for logging from within vid.stab lib */
54 typedef struct VS2AVLogCtx {
55  const AVClass *class;
56 } VS2AVLogCtx;
57 
58 /** wrapper to log vs_log into av_log */
59 static int vs2av_log(int type, const char *tag, const char *format, ...)
60 {
61  va_list ap;
63  AVClass class = {
64  .class_name = tag,
65  .item_name = av_default_item_name,
66  .option = 0,
67  .version = LIBAVUTIL_VERSION_INT,
68  .category = AV_CLASS_CATEGORY_FILTER,
69  };
70  ctx.class = &class;
71  va_start(ap, format);
72  av_vlog(&ctx, type, format, ap);
73  va_end(ap);
74  return VS_OK;
75 }
76 
77 /** sets the memory allocation function and logging constants to av versions */
78 void ff_vs_init(void)
79 {
80  vs_malloc = av_malloc;
81  vs_zalloc = av_mallocz;
82  vs_realloc = av_realloc;
83  vs_free = av_free;
84 
85  VS_ERROR_TYPE = AV_LOG_ERROR;
86  VS_WARN_TYPE = AV_LOG_WARNING;
87  VS_INFO_TYPE = AV_LOG_INFO;
88  VS_MSG_TYPE = AV_LOG_VERBOSE;
89 
90  vs_log = vs2av_log;
91 
92  VS_ERROR = 0;
93  VS_OK = 1;
94 }
av_vlog
void av_vlog(void *avcl, int level, const char *fmt, va_list vl)
Send the specified message to the log if the level is less than or equal to the current av_log_level.
Definition: log.c:431
AV_LOG_WARNING
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:215
AVPixelFormat
AVPixelFormat
Pixel format.
Definition: pixfmt.h:71
vidstabutils.h
AV_LOG_VERBOSE
#define AV_LOG_VERBOSE
Detailed information.
Definition: log.h:225
AV_PIX_FMT_BGR24
@ AV_PIX_FMT_BGR24
packed RGB 8:8:8, 24bpp, BGRBGR...
Definition: pixfmt.h:76
AV_PIX_FMT_YUV440P
@ AV_PIX_FMT_YUV440P
planar YUV 4:4:0 (1 Cr & Cb sample per 1x2 Y samples)
Definition: pixfmt.h:106
av_malloc
#define av_malloc(s)
Definition: tableprint_vlc.h:30
type
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
Definition: writing_filters.txt:86
VS2AVLogCtx
struct to hold a valid context for logging from within vid.stab lib
Definition: vidstabutils.c:54
AV_LOG_ERROR
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:209
AV_PIX_FMT_YUVA420P
@ AV_PIX_FMT_YUVA420P
planar YUV 4:2:0, 20bpp, (1 Cr & Cb sample per 2x2 Y & A samples)
Definition: pixfmt.h:108
format
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 format(the sample packing is implied by the sample format) and sample rate. The lists are not just lists
ff_av2vs_pixfmt
VSPixelFormat ff_av2vs_pixfmt(AVFilterContext *ctx, enum AVPixelFormat pf)
convert AV's pixelformat to vid.stab pixelformat
Definition: vidstabutils.c:33
ctx
AVFormatContext * ctx
Definition: movenc.c:49
ff_vidstab_pix_fmts
enum AVPixelFormat ff_vidstab_pix_fmts[]
Definition: vidstabutils.c:24
AV_PIX_FMT_YUV420P
@ AV_PIX_FMT_YUV420P
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
Definition: pixfmt.h:73
AV_PIX_FMT_RGBA
@ AV_PIX_FMT_RGBA
packed RGBA 8:8:8:8, 32bpp, RGBARGBA...
Definition: pixfmt.h:100
LIBAVUTIL_VERSION_INT
#define LIBAVUTIL_VERSION_INT
Definition: version.h:85
AVClass
Describe the class of an AVClass context structure.
Definition: log.h:75
av_default_item_name
const char * av_default_item_name(void *ptr)
Return the context name.
Definition: log.c:237
AV_PIX_FMT_GRAY8
@ AV_PIX_FMT_GRAY8
Y , 8bpp.
Definition: pixfmt.h:81
AV_CLASS_CATEGORY_FILTER
@ AV_CLASS_CATEGORY_FILTER
Definition: log.h:36
AV_PIX_FMT_RGB24
@ AV_PIX_FMT_RGB24
packed RGB 8:8:8, 24bpp, RGBRGB...
Definition: pixfmt.h:75
AV_LOG_INFO
#define AV_LOG_INFO
Standard information.
Definition: log.h:220
vs2av_log
static int vs2av_log(int type, const char *tag, const char *format,...)
wrapper to log vs_log into av_log
Definition: vidstabutils.c:59
av_mallocz
void * av_mallocz(size_t size)
Allocate a memory block with alignment suitable for all memory accesses (including vectors if availab...
Definition: mem.c:256
tag
uint32_t tag
Definition: movenc.c:1876
ff_vs_init
void ff_vs_init(void)
sets the memory allocation function and logging constants to av versions
Definition: vidstabutils.c:78
AVClass::class_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...
Definition: log.h:80
AV_PIX_FMT_NONE
@ AV_PIX_FMT_NONE
Definition: pixfmt.h:72
AV_PIX_FMT_YUV444P
@ AV_PIX_FMT_YUV444P
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
Definition: pixfmt.h:78
AVFilterContext
An instance of a filter.
Definition: avfilter.h:457
AV_PIX_FMT_YUV422P
@ AV_PIX_FMT_YUV422P
planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
Definition: pixfmt.h:77
mem.h
av_free
#define av_free(p)
Definition: tableprint_vlc.h:33
AV_PIX_FMT_YUV411P
@ AV_PIX_FMT_YUV411P
planar YUV 4:1:1, 12bpp, (1 Cr & Cb sample per 4x1 Y samples)
Definition: pixfmt.h:80
AV_PIX_FMT_YUV410P
@ AV_PIX_FMT_YUV410P
planar YUV 4:1:0, 9bpp, (1 Cr & Cb sample per 4x4 Y samples)
Definition: pixfmt.h:79
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:27
av_realloc
void * av_realloc(void *ptr, size_t size)
Allocate, reallocate, or free a block of memory.
Definition: mem.c:155