* commit 'bddd8cbf68551f6405b2bf77cc3e212af9fbe834': Add transformation matrix API. Conflicts: libavcodec/avcodec.h libavcodec/utils.c libavutil/version.h
Unified · Split
| @@ -24,6 +24,7 @@ version <next>: · 23 unmodified lines | ||
| 24 | 24 | - libbs2b-based stereo-to-binaural audio filter |
| 25 | 25 | - libx264 reference frames count limiting depending on level |
| 26 | 26 | - native Opus decoder |
| 27 | +- display matrix export and rotation api | |
| 27 | 28 | |
| 28 | 29 | |
| 29 | 30 | version 2.2: |
| @@ -15,6 +15,14 @@ libavutil: 2012-10-22 · 14 unmodified lines | ||
| 15 | 15 | |
| 16 | 16 | API changes, most recent first: |
| 17 | 17 | |
| 18 | +2014-05-xx - xxxxxxx - lavu 53.15.0 - frame.h, display.h | |
| 19 | + Add AV_FRAME_DATA_DISPLAYMATRIX for exporting frame-level | |
| 20 | + spatial rendering on video frames for proper display. | |
| 21 | + | |
| 22 | +2014-05-xx - xxxxxxx - lavc 55.52.0 - avcodec.h | |
| 23 | + Add AV_PKT_DATA_DISPLAYMATRIX for exporting packet-level | |
| 24 | + spatial rendering on video frames for proper display. | |
| 25 | + | |
| 18 | 26 | 2014-05-xx - xxxxxxx - lavf 55.17.1 - avformat.h |
| 19 | 27 | Deprecate AVStream.pts and the AVFrac struct, which was its only use case. |
| 20 | 28 | Those fields were poorly defined and not meant to be public, so there is |
| @@ -1052,6 +1052,15 @@ enum AVPacketSideDataType { · 1051 unmodified lines | ||
| 1052 | 1052 | */ |
| 1053 | 1053 | AV_PKT_DATA_REPLAYGAIN, |
| 1054 | 1054 | |
| 1055 | + /** | |
| 1056 | + * This side data contains a 3x3 transformation matrix describing an affine | |
| 1057 | + * transformation that needs to be applied to the decoded video frames for | |
| 1058 | + * correct presentation. | |
| 1059 | + * | |
| 1060 | + * See libavutil/display.h for a detailed description of the data. | |
| 1061 | + */ | |
| 1062 | + AV_PKT_DATA_DISPLAYMATRIX, | |
| 1063 | + | |
| 1055 | 1064 | /** |
| 1056 | 1065 | * Recommmends skipping the specified number of samples |
| 1057 | 1066 | * @code |
| @@ -767,6 +767,16 @@ int ff_init_buffer_info(AVCodecContext *avctx, AVFrame *frame) · 766 unmodified lines | ||
| 767 | 767 | |
| 768 | 768 | memcpy(frame_sd->data, packet_sd, size); |
| 769 | 769 | } |
| 770 | + | |
| 771 | + /* copy the displaymatrix to the output frame */ | |
| 772 | + packet_sd = av_packet_get_side_data(pkt, AV_PKT_DATA_DISPLAYMATRIX, &size); | |
| 773 | + if (packet_sd) { | |
| 774 | + frame_sd = av_frame_new_side_data(frame, AV_FRAME_DATA_DISPLAYMATRIX, size); | |
| 775 | + if (!frame_sd) | |
| 776 | + return AVERROR(ENOMEM); | |
| 777 | + | |
| 778 | + memcpy(frame_sd->data, packet_sd, size); | |
| 779 | + } | |
| 770 | 780 | } else { |
| 771 | 781 | frame->pkt_pts = AV_NOPTS_VALUE; |
| 772 | 782 | av_frame_set_pkt_pos (frame, -1); |
| @@ -19,6 +19,7 @@ HEADERS = adler32.h \ · 18 unmodified lines | ||
| 19 | 19 | common.h \ |
| 20 | 20 | cpu.h \ |
| 21 | 21 | crc.h \ |
| 22 | + display.h \ | |
| 22 | 23 | downmix_info.h \ |
| 23 | 24 | error.h \ |
| 24 | 25 | eval.h \ |
| @@ -82,6 +83,7 @@ OBJS = adler32.o \ · 57 unmodified lines | ||
| 82 | 83 | cpu.o \ |
| 83 | 84 | crc.o \ |
| 84 | 85 | des.o \ |
| 86 | + display.o \ | |
| 85 | 87 | downmix_info.o \ |
| 86 | 88 | error.o \ |
| 87 | 89 | eval.o \ |
| @@ -0,0 +1,64 @@ | ||
| 1 | +/* | |
| 2 | + * Copyright (c) 2014 Vittorio Giovara <vittorio.giovara@gmail.com> | |
| 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 <stdint.h> | |
| 22 | +#include <string.h> | |
| 23 | +#include <math.h> | |
| 24 | + | |
| 25 | +#include "display.h" | |
| 26 | + | |
| 27 | +// fixed point to double | |
| 28 | +#define CONV_FP(x) ((double) (x)) / (1 << 16) | |
| 29 | + | |
| 30 | +// double to fixed point | |
| 31 | +#define CONV_DB(x) (int32_t) ((x) * (1 << 16)) | |
| 32 | + | |
| 33 | +double av_display_rotation_get(const int32_t matrix[9]) | |
| 34 | +{ | |
| 35 | + double rotation, scale[2]; | |
| 36 | + | |
| 37 | + scale[0] = sqrt(CONV_FP(matrix[0]) * CONV_FP(matrix[0]) + | |
| 38 | + CONV_FP(matrix[3]) * CONV_FP(matrix[3])); | |
| 39 | + scale[1] = sqrt(CONV_FP(matrix[1]) * CONV_FP(matrix[1]) + | |
| 40 | + CONV_FP(matrix[4]) * CONV_FP(matrix[4])); | |
| 41 | + | |
| 42 | + if (scale[0] == 0.0 || scale[1] == 0.0) | |
| 43 | + return NAN; | |
| 44 | + | |
| 45 | + rotation = atan2(CONV_FP(matrix[1]) / scale[1], | |
| 46 | + CONV_FP(matrix[0]) / scale[0]) * 180 / M_PI; | |
| 47 | + | |
| 48 | + return rotation; | |
| 49 | +} | |
| 50 | + | |
| 51 | +void av_display_rotation_set(int32_t matrix[9], double angle) | |
| 52 | +{ | |
| 53 | + double radians = angle * M_PI / 180.0f; | |
| 54 | + double c = cos(radians); | |
| 55 | + double s = sin(radians); | |
| 56 | + | |
| 57 | + memset(matrix, 0, 9 * sizeof(int32_t)); | |
| 58 | + | |
| 59 | + matrix[0] = CONV_DB(c); | |
| 60 | + matrix[1] = CONV_DB(-s); | |
| 61 | + matrix[3] = CONV_DB(s); | |
| 62 | + matrix[4] = CONV_DB(c); | |
| 63 | + matrix[8] = 1 << 30; | |
| 64 | +} | |
| @@ -0,0 +1,77 @@ | ||
| 1 | +/* | |
| 2 | + * Copyright (c) 2014 Vittorio Giovara <vittorio.giovara@gmail.com> | |
| 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 | +#ifndef AVUTIL_DISPLAY_H | |
| 22 | +#define AVUTIL_DISPLAY_H | |
| 23 | + | |
| 24 | +#include <stdint.h> | |
| 25 | + | |
| 26 | +/** | |
| 27 | + * The display transformation matrix specifies an affine transformation that | |
| 28 | + * should be applied to video frames for correct presentation. It is compatible | |
| 29 | + * with the matrices stored in the ISO/IEC 14496-12 container format. | |
| 30 | + * | |
| 31 | + * The data is a 3x3 matrix represented as a 9-element array: | |
| 32 | + * | |
| 33 | + * | a b u | | |
| 34 | + * (a, b, u, c, d, v, x, y, w) -> | c d v | | |
| 35 | + * | x y w | | |
| 36 | + * | |
| 37 | + * All numbers are stored in native endianness, as 16.16 fixed-point values, | |
| 38 | + * except for u, v and w, which are stored as 2.30 fixed-point values. | |
| 39 | + * | |
| 40 | + * The transformation maps a point (p, q) in the source (pre-transformation) | |
| 41 | + * frame to the point (p', q') in the destination (post-transformation) frame as | |
| 42 | + * follows: | |
| 43 | + * | a b u | | |
| 44 | + * (p, q, 1) . | c d v | = z * (p', q', 1) | |
| 45 | + * | x y w | | |
| 46 | + * | |
| 47 | + * The transformation can also be more explicitly written in components as | |
| 48 | + * follows: | |
| 49 | + * p' = (a * p + c * q + x) / z; | |
| 50 | + * q' = (b * p + d * q + y) / z; | |
| 51 | + * z = u * p + v * q + w | |
| 52 | + */ | |
| 53 | + | |
| 54 | +/** | |
| 55 | + * Extract the rotation component of the transformation matrix. | |
| 56 | + * | |
| 57 | + * @param matrix the transformation matrix | |
| 58 | + * @return the angle (in degrees) by which the transformation rotates the frame. | |
| 59 | + * The angle will be in range [-180.0, 180.0], or NaN if the matrix is | |
| 60 | + * singular. | |
| 61 | + * | |
| 62 | + * @note floating point numbers are inherently inexact, so callers are | |
| 63 | + * recommended to round the return value to nearest integer before use. | |
| 64 | + */ | |
| 65 | +double av_display_rotation_get(const int32_t matrix[9]); | |
| 66 | + | |
| 67 | +/** | |
| 68 | + * Initialize a transformation matrix describing a pure rotation by the | |
| 69 | + * specified angle (in degrees). | |
| 70 | + * | |
| 71 | + * @param matrix an allocated transformation matrix (will be fully overwritten | |
| 72 | + * by this function) | |
| 73 | + * @param angle rotation angle in degrees. | |
| 74 | + */ | |
| 75 | +void av_display_rotation_set(int32_t matrix[9], double angle); | |
| 76 | + | |
| 77 | +#endif /* AVUTIL_DISPLAY_H */ | |
| @@ -96,6 +96,14 @@ enum AVFrameSideDataType { · 95 unmodified lines | ||
| 96 | 96 | * ReplayGain information in the form of the AVReplayGain struct. |
| 97 | 97 | */ |
| 98 | 98 | AV_FRAME_DATA_REPLAYGAIN, |
| 99 | + /** | |
| 100 | + * This side data contains a 3x3 transformation matrix describing an affine | |
| 101 | + * transformation that needs to be applied to the frame for correct | |
| 102 | + * presentation. | |
| 103 | + * | |
| 104 | + * See libavutil/display.h for a detailed description of the data. | |
| 105 | + */ | |
| 106 | + AV_FRAME_DATA_DISPLAYMATRIX, | |
| 99 | 107 | }; |
| 100 | 108 | |
| 101 | 109 | typedef struct AVFrameSideData { |
| @@ -56,7 +56,7 @@ · 55 unmodified lines | ||
| 56 | 56 | */ |
| 57 | 57 | |
| 58 | 58 | #define LIBAVUTIL_VERSION_MAJOR 52 |
| 59 | −#define LIBAVUTIL_VERSION_MINOR 84 | |
| 59 | +#define LIBAVUTIL_VERSION_MINOR 85 | |
| 60 | 60 | #define LIBAVUTIL_VERSION_MICRO 100 |
| 61 | 61 | |
| 62 | 62 | #define LIBAVUTIL_VERSION_INT AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \ |