2010-10-19 00:29:37 +03:00
|
|
|
/*
|
2010-11-28 12:22:58 +02:00
|
|
|
* Copyright (c) 2010 Stefano Sabatini
|
|
|
|
* Copyright (c) 2008 Vitor Sessak
|
2010-10-19 00:29:37 +03:00
|
|
|
*
|
|
|
|
* This file is part of FFmpeg.
|
|
|
|
*
|
|
|
|
* FFmpeg is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* FFmpeg is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with FFmpeg; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @file
|
|
|
|
* transposition filter
|
|
|
|
* Based on MPlayer libmpcodecs/vf_rotate.c.
|
|
|
|
*/
|
|
|
|
|
2012-08-06 16:49:32 +03:00
|
|
|
#include <stdio.h>
|
|
|
|
|
2018-01-24 20:38:05 +02:00
|
|
|
#include "libavutil/avassert.h"
|
2011-02-07 15:37:08 +02:00
|
|
|
#include "libavutil/imgutils.h"
|
2012-08-06 16:49:32 +03:00
|
|
|
#include "libavutil/internal.h"
|
2014-03-25 10:39:24 +03:00
|
|
|
#include "libavutil/intreadwrite.h"
|
2013-02-25 23:21:29 +03:00
|
|
|
#include "libavutil/opt.h"
|
2014-03-25 10:39:24 +03:00
|
|
|
#include "libavutil/pixdesc.h"
|
|
|
|
|
2010-10-19 00:29:37 +03:00
|
|
|
#include "avfilter.h"
|
2024-08-12 15:29:00 +02:00
|
|
|
#include "filters.h"
|
2012-05-30 11:12:55 +03:00
|
|
|
#include "formats.h"
|
2012-05-30 12:20:32 +03:00
|
|
|
#include "video.h"
|
2018-11-28 04:27:38 +02:00
|
|
|
#include "transpose.h"
|
2013-02-25 23:21:29 +03:00
|
|
|
|
2014-04-11 12:54:15 +03:00
|
|
|
typedef struct TransContext {
|
2012-09-30 14:03:08 +03:00
|
|
|
const AVClass *class;
|
2010-10-19 00:29:37 +03:00
|
|
|
int hsub, vsub;
|
2018-01-24 20:38:05 +02:00
|
|
|
int planes;
|
2010-10-19 00:29:37 +03:00
|
|
|
int pixsteps[4];
|
|
|
|
|
2015-03-23 20:31:17 +02:00
|
|
|
int passthrough; ///< PassthroughType, landscape passthrough mode enabled
|
|
|
|
int dir; ///< TransposeDir
|
2017-08-15 20:12:32 +02:00
|
|
|
|
2018-02-22 06:01:51 +02:00
|
|
|
TransVtable vtables[4];
|
2010-10-19 00:29:37 +03:00
|
|
|
} TransContext;
|
|
|
|
|
2024-10-15 11:24:35 +02:00
|
|
|
static int query_formats(const AVFilterContext *ctx,
|
|
|
|
AVFilterFormatsConfig **cfg_in,
|
|
|
|
AVFilterFormatsConfig **cfg_out)
|
2010-10-19 00:29:37 +03:00
|
|
|
{
|
2013-02-12 16:45:23 +03:00
|
|
|
AVFilterFormats *pix_fmts = NULL;
|
2021-10-05 21:16:44 +02:00
|
|
|
const AVPixFmtDescriptor *desc;
|
2015-10-05 05:39:25 +02:00
|
|
|
int fmt, ret;
|
2013-02-12 16:45:23 +03:00
|
|
|
|
2021-10-05 21:16:44 +02:00
|
|
|
for (fmt = 0; desc = av_pix_fmt_desc_get(fmt); fmt++) {
|
2013-05-15 12:23:14 +03:00
|
|
|
if (!(desc->flags & AV_PIX_FMT_FLAG_PAL ||
|
|
|
|
desc->flags & AV_PIX_FMT_FLAG_HWACCEL ||
|
|
|
|
desc->flags & AV_PIX_FMT_FLAG_BITSTREAM ||
|
2015-10-05 05:39:25 +02:00
|
|
|
desc->log2_chroma_w != desc->log2_chroma_h) &&
|
|
|
|
(ret = ff_add_format(&pix_fmts, fmt)) < 0)
|
|
|
|
return ret;
|
2013-02-12 16:45:23 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2024-10-15 11:24:35 +02:00
|
|
|
return ff_set_common_formats2(ctx, cfg_in, cfg_out, pix_fmts);
|
2010-10-19 00:29:37 +03:00
|
|
|
}
|
|
|
|
|
2017-08-15 20:12:32 +02:00
|
|
|
static inline void transpose_block_8_c(uint8_t *src, ptrdiff_t src_linesize,
|
|
|
|
uint8_t *dst, ptrdiff_t dst_linesize,
|
|
|
|
int w, int h)
|
|
|
|
{
|
|
|
|
int x, y;
|
|
|
|
for (y = 0; y < h; y++, dst += dst_linesize, src++)
|
|
|
|
for (x = 0; x < w; x++)
|
|
|
|
dst[x] = src[x*src_linesize];
|
|
|
|
}
|
|
|
|
|
|
|
|
static void transpose_8x8_8_c(uint8_t *src, ptrdiff_t src_linesize,
|
|
|
|
uint8_t *dst, ptrdiff_t dst_linesize)
|
|
|
|
{
|
|
|
|
transpose_block_8_c(src, src_linesize, dst, dst_linesize, 8, 8);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void transpose_block_16_c(uint8_t *src, ptrdiff_t src_linesize,
|
|
|
|
uint8_t *dst, ptrdiff_t dst_linesize,
|
|
|
|
int w, int h)
|
|
|
|
{
|
|
|
|
int x, y;
|
|
|
|
for (y = 0; y < h; y++, dst += dst_linesize, src += 2)
|
|
|
|
for (x = 0; x < w; x++)
|
|
|
|
*((uint16_t *)(dst + 2*x)) = *((uint16_t *)(src + x*src_linesize));
|
|
|
|
}
|
|
|
|
|
|
|
|
static void transpose_8x8_16_c(uint8_t *src, ptrdiff_t src_linesize,
|
|
|
|
uint8_t *dst, ptrdiff_t dst_linesize)
|
|
|
|
{
|
|
|
|
transpose_block_16_c(src, src_linesize, dst, dst_linesize, 8, 8);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void transpose_block_24_c(uint8_t *src, ptrdiff_t src_linesize,
|
|
|
|
uint8_t *dst, ptrdiff_t dst_linesize,
|
|
|
|
int w, int h)
|
|
|
|
{
|
|
|
|
int x, y;
|
|
|
|
for (y = 0; y < h; y++, dst += dst_linesize) {
|
|
|
|
for (x = 0; x < w; x++) {
|
|
|
|
int32_t v = AV_RB24(src + x*src_linesize + y*3);
|
|
|
|
AV_WB24(dst + 3*x, v);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void transpose_8x8_24_c(uint8_t *src, ptrdiff_t src_linesize,
|
|
|
|
uint8_t *dst, ptrdiff_t dst_linesize)
|
|
|
|
{
|
|
|
|
transpose_block_24_c(src, src_linesize, dst, dst_linesize, 8, 8);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void transpose_block_32_c(uint8_t *src, ptrdiff_t src_linesize,
|
|
|
|
uint8_t *dst, ptrdiff_t dst_linesize,
|
|
|
|
int w, int h)
|
|
|
|
{
|
|
|
|
int x, y;
|
|
|
|
for (y = 0; y < h; y++, dst += dst_linesize, src += 4) {
|
|
|
|
for (x = 0; x < w; x++)
|
|
|
|
*((uint32_t *)(dst + 4*x)) = *((uint32_t *)(src + x*src_linesize));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void transpose_8x8_32_c(uint8_t *src, ptrdiff_t src_linesize,
|
|
|
|
uint8_t *dst, ptrdiff_t dst_linesize)
|
|
|
|
{
|
|
|
|
transpose_block_32_c(src, src_linesize, dst, dst_linesize, 8, 8);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void transpose_block_48_c(uint8_t *src, ptrdiff_t src_linesize,
|
|
|
|
uint8_t *dst, ptrdiff_t dst_linesize,
|
|
|
|
int w, int h)
|
|
|
|
{
|
|
|
|
int x, y;
|
|
|
|
for (y = 0; y < h; y++, dst += dst_linesize, src += 6) {
|
|
|
|
for (x = 0; x < w; x++) {
|
|
|
|
int64_t v = AV_RB48(src + x*src_linesize);
|
|
|
|
AV_WB48(dst + 6*x, v);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void transpose_8x8_48_c(uint8_t *src, ptrdiff_t src_linesize,
|
|
|
|
uint8_t *dst, ptrdiff_t dst_linesize)
|
|
|
|
{
|
|
|
|
transpose_block_48_c(src, src_linesize, dst, dst_linesize, 8, 8);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void transpose_block_64_c(uint8_t *src, ptrdiff_t src_linesize,
|
|
|
|
uint8_t *dst, ptrdiff_t dst_linesize,
|
|
|
|
int w, int h)
|
|
|
|
{
|
|
|
|
int x, y;
|
|
|
|
for (y = 0; y < h; y++, dst += dst_linesize, src += 8)
|
|
|
|
for (x = 0; x < w; x++)
|
|
|
|
*((uint64_t *)(dst + 8*x)) = *((uint64_t *)(src + x*src_linesize));
|
|
|
|
}
|
|
|
|
|
|
|
|
static void transpose_8x8_64_c(uint8_t *src, ptrdiff_t src_linesize,
|
|
|
|
uint8_t *dst, ptrdiff_t dst_linesize)
|
|
|
|
{
|
|
|
|
transpose_block_64_c(src, src_linesize, dst, dst_linesize, 8, 8);
|
|
|
|
}
|
|
|
|
|
2010-10-19 00:29:37 +03:00
|
|
|
static int config_props_output(AVFilterLink *outlink)
|
|
|
|
{
|
|
|
|
AVFilterContext *ctx = outlink->src;
|
2015-09-03 17:18:59 +02:00
|
|
|
TransContext *s = ctx->priv;
|
2010-10-19 00:29:37 +03:00
|
|
|
AVFilterLink *inlink = ctx->inputs[0];
|
2012-10-06 14:29:37 +03:00
|
|
|
const AVPixFmtDescriptor *desc_out = av_pix_fmt_desc_get(outlink->format);
|
|
|
|
const AVPixFmtDescriptor *desc_in = av_pix_fmt_desc_get(inlink->format);
|
2010-10-19 00:29:37 +03:00
|
|
|
|
2015-09-03 17:18:59 +02:00
|
|
|
if (s->dir&4) {
|
2012-09-30 14:46:01 +03:00
|
|
|
av_log(ctx, AV_LOG_WARNING,
|
|
|
|
"dir values greater than 3 are deprecated, use the passthrough option instead\n");
|
2015-09-03 17:18:59 +02:00
|
|
|
s->dir &= 3;
|
|
|
|
s->passthrough = TRANSPOSE_PT_TYPE_LANDSCAPE;
|
2012-09-30 14:46:01 +03:00
|
|
|
}
|
|
|
|
|
2015-09-03 17:18:59 +02:00
|
|
|
if ((inlink->w >= inlink->h && s->passthrough == TRANSPOSE_PT_TYPE_LANDSCAPE) ||
|
|
|
|
(inlink->w <= inlink->h && s->passthrough == TRANSPOSE_PT_TYPE_PORTRAIT)) {
|
2012-09-30 14:46:01 +03:00
|
|
|
av_log(ctx, AV_LOG_VERBOSE,
|
|
|
|
"w:%d h:%d -> w:%d h:%d (passthrough mode)\n",
|
|
|
|
inlink->w, inlink->h, inlink->w, inlink->h);
|
|
|
|
return 0;
|
|
|
|
} else {
|
2015-09-03 17:18:59 +02:00
|
|
|
s->passthrough = TRANSPOSE_PT_TYPE_NONE;
|
2012-09-01 12:14:27 +03:00
|
|
|
}
|
|
|
|
|
2015-09-03 17:18:59 +02:00
|
|
|
s->hsub = desc_in->log2_chroma_w;
|
|
|
|
s->vsub = desc_in->log2_chroma_h;
|
2018-01-28 03:46:56 +02:00
|
|
|
s->planes = av_pix_fmt_count_planes(outlink->format);
|
2018-01-24 20:38:05 +02:00
|
|
|
|
|
|
|
av_assert0(desc_in->nb_components == desc_out->nb_components);
|
|
|
|
|
2010-10-19 00:29:37 +03:00
|
|
|
|
2015-09-03 17:18:59 +02:00
|
|
|
av_image_fill_max_pixsteps(s->pixsteps, NULL, desc_out);
|
2010-10-19 00:29:37 +03:00
|
|
|
|
|
|
|
outlink->w = inlink->h;
|
|
|
|
outlink->h = inlink->w;
|
|
|
|
|
2014-03-25 10:39:24 +03:00
|
|
|
if (inlink->sample_aspect_ratio.num)
|
|
|
|
outlink->sample_aspect_ratio = av_div_q((AVRational) { 1, 1 },
|
|
|
|
inlink->sample_aspect_ratio);
|
|
|
|
else
|
2011-01-31 19:51:47 +02:00
|
|
|
outlink->sample_aspect_ratio = inlink->sample_aspect_ratio;
|
|
|
|
|
2018-02-22 06:01:51 +02:00
|
|
|
for (int i = 0; i < 4; i++) {
|
|
|
|
TransVtable *v = &s->vtables[i];
|
|
|
|
switch (s->pixsteps[i]) {
|
|
|
|
case 1: v->transpose_block = transpose_block_8_c;
|
|
|
|
v->transpose_8x8 = transpose_8x8_8_c; break;
|
|
|
|
case 2: v->transpose_block = transpose_block_16_c;
|
|
|
|
v->transpose_8x8 = transpose_8x8_16_c; break;
|
|
|
|
case 3: v->transpose_block = transpose_block_24_c;
|
|
|
|
v->transpose_8x8 = transpose_8x8_24_c; break;
|
|
|
|
case 4: v->transpose_block = transpose_block_32_c;
|
|
|
|
v->transpose_8x8 = transpose_8x8_32_c; break;
|
|
|
|
case 6: v->transpose_block = transpose_block_48_c;
|
|
|
|
v->transpose_8x8 = transpose_8x8_48_c; break;
|
|
|
|
case 8: v->transpose_block = transpose_block_64_c;
|
|
|
|
v->transpose_8x8 = transpose_8x8_64_c; break;
|
|
|
|
}
|
2017-08-15 20:12:32 +02:00
|
|
|
}
|
|
|
|
|
2022-06-12 05:51:12 +02:00
|
|
|
#if ARCH_X86
|
|
|
|
for (int i = 0; i < 4; i++) {
|
|
|
|
TransVtable *v = &s->vtables[i];
|
2019-10-21 16:43:26 +02:00
|
|
|
|
2022-06-12 05:51:12 +02:00
|
|
|
ff_transpose_init_x86(v, s->pixsteps[i]);
|
2019-10-21 16:43:26 +02:00
|
|
|
}
|
2022-06-12 05:51:12 +02:00
|
|
|
#endif
|
2019-10-21 16:43:26 +02:00
|
|
|
|
2014-03-25 10:39:24 +03:00
|
|
|
av_log(ctx, AV_LOG_VERBOSE,
|
|
|
|
"w:%d h:%d dir:%d -> w:%d h:%d rotation:%s vflip:%d\n",
|
2015-09-03 17:18:59 +02:00
|
|
|
inlink->w, inlink->h, s->dir, outlink->w, outlink->h,
|
|
|
|
s->dir == 1 || s->dir == 3 ? "clockwise" : "counterclockwise",
|
|
|
|
s->dir == 0 || s->dir == 3);
|
2010-10-19 00:29:37 +03:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-03-10 03:30:30 +03:00
|
|
|
static AVFrame *get_video_buffer(AVFilterLink *inlink, int w, int h)
|
2012-09-01 12:14:27 +03:00
|
|
|
{
|
2015-09-03 17:18:59 +02:00
|
|
|
TransContext *s = inlink->dst->priv;
|
2012-09-01 12:14:27 +03:00
|
|
|
|
2015-09-03 17:18:59 +02:00
|
|
|
return s->passthrough ?
|
2013-03-10 03:30:30 +03:00
|
|
|
ff_null_get_video_buffer (inlink, w, h) :
|
|
|
|
ff_default_get_video_buffer(inlink, w, h);
|
2012-09-01 12:14:27 +03:00
|
|
|
}
|
|
|
|
|
2013-08-14 22:01:06 +03:00
|
|
|
typedef struct ThreadData {
|
|
|
|
AVFrame *in, *out;
|
|
|
|
} ThreadData;
|
|
|
|
|
|
|
|
static int filter_slice(AVFilterContext *ctx, void *arg, int jobnr,
|
|
|
|
int nb_jobs)
|
2010-10-19 00:29:37 +03:00
|
|
|
{
|
2015-09-03 17:18:59 +02:00
|
|
|
TransContext *s = ctx->priv;
|
2013-08-14 22:01:06 +03:00
|
|
|
ThreadData *td = arg;
|
|
|
|
AVFrame *out = td->out;
|
|
|
|
AVFrame *in = td->in;
|
2012-11-28 23:46:23 +03:00
|
|
|
int plane;
|
2010-10-19 00:29:37 +03:00
|
|
|
|
2018-01-24 20:38:05 +02:00
|
|
|
for (plane = 0; plane < s->planes; plane++) {
|
2015-09-03 17:18:59 +02:00
|
|
|
int hsub = plane == 1 || plane == 2 ? s->hsub : 0;
|
|
|
|
int vsub = plane == 1 || plane == 2 ? s->vsub : 0;
|
|
|
|
int pixstep = s->pixsteps[plane];
|
2016-01-27 17:19:38 +02:00
|
|
|
int inh = AV_CEIL_RSHIFT(in->height, vsub);
|
|
|
|
int outw = AV_CEIL_RSHIFT(out->width, hsub);
|
|
|
|
int outh = AV_CEIL_RSHIFT(out->height, vsub);
|
2014-03-25 21:17:38 +03:00
|
|
|
int start = (outh * jobnr ) / nb_jobs;
|
|
|
|
int end = (outh * (jobnr+1)) / nb_jobs;
|
2012-11-28 23:46:23 +03:00
|
|
|
uint8_t *dst, *src;
|
|
|
|
int dstlinesize, srclinesize;
|
2010-10-19 00:29:37 +03:00
|
|
|
int x, y;
|
2018-02-22 06:01:51 +02:00
|
|
|
TransVtable *v = &s->vtables[plane];
|
2010-10-19 00:29:37 +03:00
|
|
|
|
2012-11-28 23:46:23 +03:00
|
|
|
dstlinesize = out->linesize[plane];
|
2014-03-25 21:17:38 +03:00
|
|
|
dst = out->data[plane] + start * dstlinesize;
|
2014-03-25 10:39:24 +03:00
|
|
|
src = in->data[plane];
|
2012-11-28 23:46:23 +03:00
|
|
|
srclinesize = in->linesize[plane];
|
2010-10-19 00:29:37 +03:00
|
|
|
|
2015-09-03 17:18:59 +02:00
|
|
|
if (s->dir & 1) {
|
2014-03-25 10:39:24 +03:00
|
|
|
src += in->linesize[plane] * (inh - 1);
|
2012-11-28 23:46:23 +03:00
|
|
|
srclinesize *= -1;
|
2010-10-19 00:29:37 +03:00
|
|
|
}
|
|
|
|
|
2015-09-03 17:18:59 +02:00
|
|
|
if (s->dir & 2) {
|
2014-03-25 21:17:38 +03:00
|
|
|
dst = out->data[plane] + dstlinesize * (outh - start - 1);
|
2012-11-28 23:46:23 +03:00
|
|
|
dstlinesize *= -1;
|
2010-10-19 00:29:37 +03:00
|
|
|
}
|
|
|
|
|
2017-08-15 20:12:32 +02:00
|
|
|
for (y = start; y < end - 7; y += 8) {
|
|
|
|
for (x = 0; x < outw - 7; x += 8) {
|
2018-02-22 06:01:51 +02:00
|
|
|
v->transpose_8x8(src + x * srclinesize + y * pixstep,
|
2017-08-15 20:12:32 +02:00
|
|
|
srclinesize,
|
|
|
|
dst + (y - start) * dstlinesize + x * pixstep,
|
|
|
|
dstlinesize);
|
2013-09-11 17:56:46 +03:00
|
|
|
}
|
2017-08-15 20:12:32 +02:00
|
|
|
if (outw - x > 0 && end - y > 0)
|
2018-02-22 06:01:51 +02:00
|
|
|
v->transpose_block(src + x * srclinesize + y * pixstep,
|
2017-08-15 20:12:32 +02:00
|
|
|
srclinesize,
|
|
|
|
dst + (y - start) * dstlinesize + x * pixstep,
|
|
|
|
dstlinesize, outw - x, end - y);
|
2010-10-19 00:29:37 +03:00
|
|
|
}
|
2017-08-15 20:12:32 +02:00
|
|
|
|
|
|
|
if (end - y > 0)
|
2018-02-22 06:01:51 +02:00
|
|
|
v->transpose_block(src + 0 * srclinesize + y * pixstep,
|
2017-08-15 20:12:32 +02:00
|
|
|
srclinesize,
|
|
|
|
dst + (y - start) * dstlinesize + 0 * pixstep,
|
|
|
|
dstlinesize, outw, end - y);
|
2010-10-19 00:29:37 +03:00
|
|
|
}
|
|
|
|
|
2013-08-14 22:01:06 +03:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int filter_frame(AVFilterLink *inlink, AVFrame *in)
|
|
|
|
{
|
2021-12-09 11:36:52 +02:00
|
|
|
int err = 0;
|
2013-08-14 22:01:06 +03:00
|
|
|
AVFilterContext *ctx = inlink->dst;
|
2015-09-03 17:18:59 +02:00
|
|
|
TransContext *s = ctx->priv;
|
2013-08-14 22:01:06 +03:00
|
|
|
AVFilterLink *outlink = ctx->outputs[0];
|
|
|
|
ThreadData td;
|
|
|
|
AVFrame *out;
|
|
|
|
|
2015-09-03 17:18:59 +02:00
|
|
|
if (s->passthrough)
|
2013-08-14 22:01:06 +03:00
|
|
|
return ff_filter_frame(outlink, in);
|
|
|
|
|
|
|
|
out = ff_get_video_buffer(outlink, outlink->w, outlink->h);
|
|
|
|
if (!out) {
|
2021-12-09 11:36:52 +02:00
|
|
|
err = AVERROR(ENOMEM);
|
|
|
|
goto fail;
|
2013-08-14 22:01:06 +03:00
|
|
|
}
|
2021-12-09 11:36:52 +02:00
|
|
|
|
|
|
|
err = av_frame_copy_props(out, in);
|
|
|
|
if (err < 0)
|
|
|
|
goto fail;
|
2013-08-14 22:01:06 +03:00
|
|
|
|
|
|
|
if (in->sample_aspect_ratio.num == 0) {
|
|
|
|
out->sample_aspect_ratio = in->sample_aspect_ratio;
|
|
|
|
} else {
|
|
|
|
out->sample_aspect_ratio.num = in->sample_aspect_ratio.den;
|
|
|
|
out->sample_aspect_ratio.den = in->sample_aspect_ratio.num;
|
|
|
|
}
|
|
|
|
|
|
|
|
td.in = in, td.out = out;
|
2021-08-15 21:33:25 +02:00
|
|
|
ff_filter_execute(ctx, filter_slice, &td, NULL,
|
|
|
|
FFMIN(outlink->h, ff_filter_get_nb_threads(ctx)));
|
2012-11-28 10:41:07 +03:00
|
|
|
av_frame_free(&in);
|
2012-11-28 23:46:23 +03:00
|
|
|
return ff_filter_frame(outlink, out);
|
2021-12-09 11:36:52 +02:00
|
|
|
|
|
|
|
fail:
|
|
|
|
av_frame_free(&in);
|
|
|
|
av_frame_free(&out);
|
|
|
|
return err;
|
2012-09-01 12:14:27 +03:00
|
|
|
}
|
2011-07-29 21:19:04 +03:00
|
|
|
|
2013-02-25 23:21:29 +03:00
|
|
|
#define OFFSET(x) offsetof(TransContext, x)
|
2013-04-11 01:32:50 +03:00
|
|
|
#define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM
|
|
|
|
|
|
|
|
static const AVOption transpose_options[] = {
|
2024-02-11 16:41:05 +02:00
|
|
|
{ "dir", "set transpose direction", OFFSET(dir), AV_OPT_TYPE_INT, { .i64 = TRANSPOSE_CCLOCK_FLIP }, 0, 7, FLAGS, .unit = "dir" },
|
2016-12-27 10:36:18 +02:00
|
|
|
{ "cclock_flip", "rotate counter-clockwise with vertical flip", 0, AV_OPT_TYPE_CONST, { .i64 = TRANSPOSE_CCLOCK_FLIP }, .flags=FLAGS, .unit = "dir" },
|
|
|
|
{ "clock", "rotate clockwise", 0, AV_OPT_TYPE_CONST, { .i64 = TRANSPOSE_CLOCK }, .flags=FLAGS, .unit = "dir" },
|
|
|
|
{ "cclock", "rotate counter-clockwise", 0, AV_OPT_TYPE_CONST, { .i64 = TRANSPOSE_CCLOCK }, .flags=FLAGS, .unit = "dir" },
|
|
|
|
{ "clock_flip", "rotate clockwise with vertical flip", 0, AV_OPT_TYPE_CONST, { .i64 = TRANSPOSE_CLOCK_FLIP }, .flags=FLAGS, .unit = "dir" },
|
2013-04-11 01:32:50 +03:00
|
|
|
|
|
|
|
{ "passthrough", "do not apply transposition if the input matches the specified geometry",
|
2024-02-11 16:41:05 +02:00
|
|
|
OFFSET(passthrough), AV_OPT_TYPE_INT, {.i64=TRANSPOSE_PT_TYPE_NONE}, 0, INT_MAX, FLAGS, .unit = "passthrough" },
|
|
|
|
{ "none", "always apply transposition", 0, AV_OPT_TYPE_CONST, {.i64=TRANSPOSE_PT_TYPE_NONE}, INT_MIN, INT_MAX, FLAGS, .unit = "passthrough" },
|
|
|
|
{ "portrait", "preserve portrait geometry", 0, AV_OPT_TYPE_CONST, {.i64=TRANSPOSE_PT_TYPE_PORTRAIT}, INT_MIN, INT_MAX, FLAGS, .unit = "passthrough" },
|
|
|
|
{ "landscape", "preserve landscape geometry", 0, AV_OPT_TYPE_CONST, {.i64=TRANSPOSE_PT_TYPE_LANDSCAPE}, INT_MIN, INT_MAX, FLAGS, .unit = "passthrough" },
|
2013-04-11 01:32:50 +03:00
|
|
|
|
2013-09-07 15:13:50 +03:00
|
|
|
{ NULL }
|
2013-02-25 23:21:29 +03:00
|
|
|
};
|
|
|
|
|
2013-04-11 01:32:50 +03:00
|
|
|
AVFILTER_DEFINE_CLASS(transpose);
|
2013-02-25 23:21:29 +03:00
|
|
|
|
2012-07-24 16:14:01 +03:00
|
|
|
static const AVFilterPad avfilter_vf_transpose_inputs[] = {
|
|
|
|
{
|
2014-03-25 10:39:24 +03:00
|
|
|
.name = "default",
|
|
|
|
.type = AVMEDIA_TYPE_VIDEO,
|
2021-08-17 05:48:27 +02:00
|
|
|
.get_buffer.video = get_video_buffer,
|
2012-11-27 09:49:45 +03:00
|
|
|
.filter_frame = filter_frame,
|
2012-07-24 16:14:01 +03:00
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
static const AVFilterPad avfilter_vf_transpose_outputs[] = {
|
|
|
|
{
|
|
|
|
.name = "default",
|
|
|
|
.config_props = config_props_output,
|
|
|
|
.type = AVMEDIA_TYPE_VIDEO,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2021-04-19 18:33:56 +02:00
|
|
|
const AVFilter ff_vf_transpose = {
|
2013-09-07 15:13:50 +03:00
|
|
|
.name = "transpose",
|
|
|
|
.description = NULL_IF_CONFIG_SMALL("Transpose input video."),
|
|
|
|
.priv_size = sizeof(TransContext),
|
|
|
|
.priv_class = &transpose_class,
|
2021-08-12 13:05:31 +02:00
|
|
|
FILTER_INPUTS(avfilter_vf_transpose_inputs),
|
|
|
|
FILTER_OUTPUTS(avfilter_vf_transpose_outputs),
|
2024-10-15 11:24:35 +02:00
|
|
|
FILTER_QUERY_FUNC2(query_formats),
|
2013-09-07 15:13:50 +03:00
|
|
|
.flags = AVFILTER_FLAG_SLICE_THREADS,
|
2010-10-19 00:29:37 +03:00
|
|
|
};
|