The 10-bit decoding support is available now in native decoder.
Unified · Split
| @@ -42,6 +42,8 @@ version <next>: · 41 unmodified lines | |||
| 42 | - OpenExr improvements (tile data and B44/B44A support) | 42 | - OpenExr improvements (tile data and B44/B44A support) |
| 43 | - BitJazz SheerVideo decoder | 43 | - BitJazz SheerVideo decoder |
| 44 | - CUDA CUVID H264/HEVC decoder | 44 | - CUDA CUVID H264/HEVC decoder |
| 45 | - 10-bit depth support in native utvideo decoder | ||
| 46 | - libutvideo wrapper removed | ||
| 45 | 47 | ||
| 46 | 48 | ||
| 47 | version 3.0: | 49 | version 3.0: |
| @@ -17,7 +17,6 @@ Specifically, the GPL parts of FFmpeg are: · 16 unmodified lines | |||
| 17 | - `libavcodec/x86/flac_dsp_gpl.asm` | 17 | - `libavcodec/x86/flac_dsp_gpl.asm` |
| 18 | - `libavcodec/x86/idct_mmx.c` | 18 | - `libavcodec/x86/idct_mmx.c` |
| 19 | - `libavfilter/x86/vf_removegrain.asm` | 19 | - `libavfilter/x86/vf_removegrain.asm` |
| 20 | - libutvideo encoding/decoding wrappers in `libavcodec/libutvideo*.cpp` | ||
| 21 | - the X11 grabber in `libavdevice/x11grab.c` | 20 | - the X11 grabber in `libavdevice/x11grab.c` |
| 22 | - the following building and testing tools | 21 | - the following building and testing tools |
| 23 | - `compat/solaris/make_sunver.pl` | 22 | - `compat/solaris/make_sunver.pl` |
| @@ -87,7 +86,6 @@ The following libraries are under GPL: · 63 unmodified lines | |||
| 87 | - frei0r | 86 | - frei0r |
| 88 | - libcdio | 87 | - libcdio |
| 89 | - librubberband | 88 | - librubberband |
| 90 | - libutvideo | ||
| 91 | - libvidstab | 89 | - libvidstab |
| 92 | - libx264 | 90 | - libx264 |
| 93 | - libx265 | 91 | - libx265 |
| @@ -204,7 +204,6 @@ Codecs: · 203 unmodified lines | |||
| 204 | libschroedinger* David Conrad | 204 | libschroedinger* David Conrad |
| 205 | libspeexdec.c Justin Ruggles | 205 | libspeexdec.c Justin Ruggles |
| 206 | libtheoraenc.c David Conrad | 206 | libtheoraenc.c David Conrad |
| 207 | libutvideo* Carl Eugen Hoyos | ||
| 208 | libvorbis.c David Conrad | 207 | libvorbis.c David Conrad |
| 209 | libvpx* James Zern | 208 | libvpx* James Zern |
| 210 | libx264.c Mans Rullgard, Jason Garrett-Glaser | 209 | libx264.c Mans Rullgard, Jason Garrett-Glaser |
| @@ -263,7 +263,6 @@ External library support: · 262 unmodified lines | |||
| 263 | --enable-libtesseract enable Tesseract, needed for ocr filter [no] | 263 | --enable-libtesseract enable Tesseract, needed for ocr filter [no] |
| 264 | --enable-libtheora enable Theora encoding via libtheora [no] | 264 | --enable-libtheora enable Theora encoding via libtheora [no] |
| 265 | --enable-libtwolame enable MP2 encoding via libtwolame [no] | 265 | --enable-libtwolame enable MP2 encoding via libtwolame [no] |
| 266 | --enable-libutvideo enable Ut Video encoding and decoding via libutvideo [no] | ||
| 267 | --enable-libv4l2 enable libv4l2/v4l-utils [no] | 266 | --enable-libv4l2 enable libv4l2/v4l-utils [no] |
| 268 | --enable-libvidstab enable video stabilization using vid.stab [no] | 267 | --enable-libvidstab enable video stabilization using vid.stab [no] |
| 269 | --enable-libvo-amrwbenc enable AMR-WB encoding via libvo-amrwbenc [no] | 268 | --enable-libvo-amrwbenc enable AMR-WB encoding via libvo-amrwbenc [no] |
| @@ -1510,7 +1509,6 @@ EXTERNAL_LIBRARY_LIST=" · 1240 unmodified lines | |||
| 1510 | libtesseract | 1509 | libtesseract |
| 1511 | libtheora | 1510 | libtheora |
| 1512 | libtwolame | 1511 | libtwolame |
| 1513 | libutvideo | ||
| 1514 | libv4l2 | 1512 | libv4l2 |
| 1515 | libvidstab | 1513 | libvidstab |
| 1516 | libvo_amrwbenc | 1514 | libvo_amrwbenc |
| @@ -2773,8 +2771,6 @@ libspeex_encoder_deps="libspeex" · 1256 unmodified lines | |||
| 2773 | libspeex_encoder_select="audio_frame_queue" | 2771 | libspeex_encoder_select="audio_frame_queue" |
| 2774 | libtheora_encoder_deps="libtheora" | 2772 | libtheora_encoder_deps="libtheora" |
| 2775 | libtwolame_encoder_deps="libtwolame" | 2773 | libtwolame_encoder_deps="libtwolame" |
| 2776 | libutvideo_decoder_deps="libutvideo" | ||
| 2777 | libutvideo_encoder_deps="libutvideo" | ||
| 2778 | libvo_amrwbenc_encoder_deps="libvo_amrwbenc" | 2774 | libvo_amrwbenc_encoder_deps="libvo_amrwbenc" |
| 2779 | libvorbis_decoder_deps="libvorbis" | 2775 | libvorbis_decoder_deps="libvorbis" |
| 2780 | libvorbis_encoder_deps="libvorbis" | 2776 | libvorbis_encoder_deps="libvorbis" |
| @@ -5013,7 +5009,6 @@ die_license_disabled gpl frei0r · 2232 unmodified lines | |||
| 5013 | die_license_disabled gpl libcdio | 5009 | die_license_disabled gpl libcdio |
| 5014 | die_license_disabled gpl librubberband | 5010 | die_license_disabled gpl librubberband |
| 5015 | die_license_disabled gpl libsmbclient | 5011 | die_license_disabled gpl libsmbclient |
| 5016 | die_license_disabled gpl libutvideo | ||
| 5017 | die_license_disabled gpl libvidstab | 5012 | die_license_disabled gpl libvidstab |
| 5018 | die_license_disabled gpl libx264 | 5013 | die_license_disabled gpl libx264 |
| 5019 | die_license_disabled gpl libx265 | 5014 | die_license_disabled gpl libx265 |
| @@ -5685,9 +5680,6 @@ enabled libtheora && require libtheora theora/theoraenc.h th_info_init - · 665 unmodified lines | |||
| 5685 | enabled libtwolame && require libtwolame twolame.h twolame_init -ltwolame && | 5680 | enabled libtwolame && require libtwolame twolame.h twolame_init -ltwolame && |
| 5686 | { check_lib twolame.h twolame_encode_buffer_float32_interleaved -ltwolame || | 5681 | { check_lib twolame.h twolame_encode_buffer_float32_interleaved -ltwolame || |
| 5687 | die "ERROR: libtwolame must be installed and version must be >= 0.3.10"; } | 5682 | die "ERROR: libtwolame must be installed and version must be >= 0.3.10"; } |
| 5688 | enabled libutvideo && { require_cpp utvideo "stdint.h stdlib.h utvideo/utvideo.h utvideo/Codec.h" 'CCodec*' -lutvideo -lstdc++ && | ||
| 5689 | check_cpp_condition utvideo/utvideo.h "!defined(UTVIDEO_VERSION_MAJOR) || UTVIDEO_VERSION_MAJOR < 15 || UTVIDEO_VERSION_MAJOR == 15 && UTVIDEO_VERSION_MINOR < 4" || | ||
| 5690 | die "ERROR: libutvideo version must be <= 15.3.0."; } | ||
| 5691 | enabled libv4l2 && require_pkg_config libv4l2 libv4l2.h v4l2_ioctl | 5683 | enabled libv4l2 && require_pkg_config libv4l2 libv4l2.h v4l2_ioctl |
| 5692 | enabled libvidstab && require_pkg_config "vidstab >= 0.98" vid.stab/libvidstab.h vsMotionDetectInit | 5684 | enabled libvidstab && require_pkg_config "vidstab >= 0.98" vid.stab/libvidstab.h vsMotionDetectInit |
| 5693 | enabled libvo_amrwbenc && require libvo_amrwbenc vo-amrwbenc/enc_if.h E_IF_init -lvo-amrwbenc | 5685 | enabled libvo_amrwbenc && require libvo_amrwbenc vo-amrwbenc/enc_if.h E_IF_init -lvo-amrwbenc |
| @@ -880,8 +880,6 @@ OBJS-$(CONFIG_LIBSPEEX_DECODER) += libspeexdec.o · 879 unmodified lines | |||
| 880 | OBJS-$(CONFIG_LIBSPEEX_ENCODER) += libspeexenc.o | 880 | OBJS-$(CONFIG_LIBSPEEX_ENCODER) += libspeexenc.o |
| 881 | OBJS-$(CONFIG_LIBTHEORA_ENCODER) += libtheoraenc.o | 881 | OBJS-$(CONFIG_LIBTHEORA_ENCODER) += libtheoraenc.o |
| 882 | OBJS-$(CONFIG_LIBTWOLAME_ENCODER) += libtwolame.o | 882 | OBJS-$(CONFIG_LIBTWOLAME_ENCODER) += libtwolame.o |
| 883 | OBJS-$(CONFIG_LIBUTVIDEO_DECODER) += libutvideodec.o | ||
| 884 | OBJS-$(CONFIG_LIBUTVIDEO_ENCODER) += libutvideoenc.o | ||
| 885 | OBJS-$(CONFIG_LIBVO_AMRWBENC_ENCODER) += libvo-amrwbenc.o | 883 | OBJS-$(CONFIG_LIBVO_AMRWBENC_ENCODER) += libvo-amrwbenc.o |
| 886 | OBJS-$(CONFIG_LIBVORBIS_DECODER) += libvorbisdec.o | 884 | OBJS-$(CONFIG_LIBVORBIS_DECODER) += libvorbisdec.o |
| 887 | OBJS-$(CONFIG_LIBVORBIS_ENCODER) += libvorbisenc.o \ | 885 | OBJS-$(CONFIG_LIBVORBIS_ENCODER) += libvorbisenc.o \ |
| @@ -993,7 +991,6 @@ SKIPHEADERS-$(CONFIG_D3D11VA) += d3d11va.h dxva2_internal.h · 105 unmodified lines | |||
| 993 | SKIPHEADERS-$(CONFIG_DXVA2) += dxva2.h dxva2_internal.h | 991 | SKIPHEADERS-$(CONFIG_DXVA2) += dxva2.h dxva2_internal.h |
| 994 | SKIPHEADERS-$(CONFIG_JNI) += ffjni.h | 992 | SKIPHEADERS-$(CONFIG_JNI) += ffjni.h |
| 995 | SKIPHEADERS-$(CONFIG_LIBSCHROEDINGER) += libschroedinger.h | 993 | SKIPHEADERS-$(CONFIG_LIBSCHROEDINGER) += libschroedinger.h |
| 996 | SKIPHEADERS-$(CONFIG_LIBUTVIDEO) += libutvideo.h | ||
| 997 | SKIPHEADERS-$(CONFIG_LIBVPX) += libvpx.h | 994 | SKIPHEADERS-$(CONFIG_LIBVPX) += libvpx.h |
| 998 | SKIPHEADERS-$(CONFIG_LIBWEBP_ENCODER) += libwebpenc_common.h | 995 | SKIPHEADERS-$(CONFIG_LIBWEBP_ENCODER) += libwebpenc_common.h |
| 999 | SKIPHEADERS-$(CONFIG_MEDIACODEC) += mediacodecdec.h mediacodec_wrapper.h mediacodec_sw_buffer.h | 996 | SKIPHEADERS-$(CONFIG_MEDIACODEC) += mediacodecdec.h mediacodec_wrapper.h mediacodec_sw_buffer.h |
| @@ -599,7 +599,6 @@ void avcodec_register_all(void) · 598 unmodified lines | |||
| 599 | REGISTER_ENCDEC (LIBSPEEX, libspeex); | 599 | REGISTER_ENCDEC (LIBSPEEX, libspeex); |
| 600 | REGISTER_ENCODER(LIBTHEORA, libtheora); | 600 | REGISTER_ENCODER(LIBTHEORA, libtheora); |
| 601 | REGISTER_ENCODER(LIBTWOLAME, libtwolame); | 601 | REGISTER_ENCODER(LIBTWOLAME, libtwolame); |
| 602 | REGISTER_ENCDEC (LIBUTVIDEO, libutvideo); | ||
| 603 | REGISTER_ENCODER(LIBVO_AMRWBENC, libvo_amrwbenc); | 602 | REGISTER_ENCODER(LIBVO_AMRWBENC, libvo_amrwbenc); |
| 604 | REGISTER_ENCDEC (LIBVORBIS, libvorbis); | 603 | REGISTER_ENCDEC (LIBVORBIS, libvorbis); |
| 605 | REGISTER_ENCDEC (LIBVPX_VP8, libvpx_vp8); | 604 | REGISTER_ENCDEC (LIBVPX_VP8, libvpx_vp8); |
| @@ -1,72 +0,0 @@ | |||
| 1 | /* | ||
| 2 | * Copyright (c) 2011-2012 Derek Buitenhuis | ||
| 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 General Public | ||
| 8 | * License as published by the Free Software Foundation; | ||
| 9 | * version 2 of the License. | ||
| 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 | * General Public License for more details. | ||
| 15 | * | ||
| 16 | * You should have received a copy of the GNU 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 | /** | ||
| 22 | * @file | ||
| 23 | * Known FOURCCs: | ||
| 24 | * 'ULY0' (YCbCr 4:2:0), 'ULY2' (YCbCr 4:2:2), 'ULRG' (RGB), 'ULRA' (RGBA), | ||
| 25 | * 'ULH0' (YCbCr 4:2:0 BT.709), 'ULH2' (YCbCr 4:2:2 BT.709) | ||
| 26 | */ | ||
| 27 | |||
| 28 | #ifndef AVCODEC_LIBUTVIDEO_H | ||
| 29 | #define AVCODEC_LIBUTVIDEO_H | ||
| 30 | |||
| 31 | #include <stdlib.h> | ||
| 32 | #include <utvideo/utvideo.h> | ||
| 33 | #include <utvideo/Codec.h> | ||
| 34 | |||
| 35 | /* | ||
| 36 | * Ut Video version 12.0.0 changed the RGB format names and removed | ||
| 37 | * the _WIN names, so if the new names are absent, define them | ||
| 38 | * against the old names so compatibility with pre-v12 versions | ||
| 39 | * is maintained. | ||
| 40 | */ | ||
| 41 | #if !defined(UTVF_NFCC_BGR_BU) | ||
| 42 | #define UTVF_NFCC_BGR_BU UTVF_RGB24_WIN | ||
| 43 | #endif | ||
| 44 | |||
| 45 | #if !defined(UTVF_NFCC_BGRA_BU) | ||
| 46 | #define UTVF_NFCC_BGRA_BU UTVF_RGB32_WIN | ||
| 47 | #endif | ||
| 48 | |||
| 49 | /* | ||
| 50 | * Ut Video version 13.0.1 introduced new BT.709 variants. | ||
| 51 | * Special-case these and only use them if v13 is detected. | ||
| 52 | */ | ||
| 53 | #if defined(UTVF_HDYC) | ||
| 54 | #define UTV_BT709 | ||
| 55 | #endif | ||
| 56 | |||
| 57 | typedef struct { | ||
| 58 | uint32_t version; | ||
| 59 | uint32_t original_format; | ||
| 60 | uint32_t frameinfo_size; | ||
| 61 | uint32_t flags; | ||
| 62 | } UtVideoExtra; | ||
| 63 | |||
| 64 | typedef struct { | ||
| 65 | const AVClass *c; | ||
| 66 | CCodec *codec; | ||
| 67 | unsigned int buf_size; | ||
| 68 | uint8_t *buffer; | ||
| 69 | int pred; | ||
| 70 | } UtVideoContext; | ||
| 71 | |||
| 72 | #endif /* AVCODEC_LIBUTVIDEO_H */ | ||
| @@ -1,279 +0,0 @@ | |||
| 1 | /* | ||
| 2 | * Copyright (c) 2011 Derek Buitenhuis | ||
| 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 General Public | ||
| 8 | * License as published by the Free Software Foundation; | ||
| 9 | * version 2 of the License. | ||
| 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 | * General Public License for more details. | ||
| 15 | * | ||
| 16 | * You should have received a copy of the GNU 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 | /** | ||
| 22 | * @file | ||
| 23 | * Known FOURCCs: | ||
| 24 | * 'ULY0' (YCbCr 4:2:0), 'ULY2' (YCbCr 4:2:2), 'ULRG' (RGB), 'ULRA' (RGBA), | ||
| 25 | * 'ULH0' (YCbCr 4:2:0 BT.709), 'ULH2' (YCbCr 4:2:2 BT.709) | ||
| 26 | */ | ||
| 27 | |||
| 28 | extern "C" { | ||
| 29 | #include "avcodec.h" | ||
| 30 | #include "libavutil/imgutils.h" | ||
| 31 | } | ||
| 32 | |||
| 33 | #include "libutvideo.h" | ||
| 34 | #include "get_bits.h" | ||
| 35 | |||
| 36 | static av_cold int utvideo_decode_init(AVCodecContext *avctx) | ||
| 37 | { | ||
| 38 | UtVideoContext *utv = (UtVideoContext *)avctx->priv_data; | ||
| 39 | UtVideoExtra info; | ||
| 40 | int format; | ||
| 41 | int begin_ret; | ||
| 42 | |||
| 43 | if (avctx->extradata_size != 16 && avctx->extradata_size != 8 ) { | ||
| 44 | av_log(avctx, AV_LOG_ERROR, "Extradata size (%d) mismatch.\n", avctx->extradata_size); | ||
| 45 | return -1; | ||
| 46 | } | ||
| 47 | |||
| 48 | /* Read extradata */ | ||
| 49 | info.version = AV_RL32(avctx->extradata); | ||
| 50 | info.original_format = AV_RL32(avctx->extradata + 4); | ||
| 51 | info.frameinfo_size = AV_RL32(avctx->extradata + 8); | ||
| 52 | info.flags = AV_RL32(avctx->extradata + 12); | ||
| 53 | |||
| 54 | /* Pick format based on FOURCC */ | ||
| 55 | switch (avctx->codec_tag) { | ||
| 56 | #ifdef UTV_BT709 | ||
| 57 | case MKTAG('U', 'L', 'H', '0'): | ||
| 58 | avctx->pix_fmt = AV_PIX_FMT_YUV420P; | ||
| 59 | avctx->colorspace = AVCOL_SPC_BT709; | ||
| 60 | format = UTVF_YV12; | ||
| 61 | break; | ||
| 62 | case MKTAG('U', 'L', 'H', '2'): | ||
| 63 | avctx->pix_fmt = AV_PIX_FMT_YUYV422; | ||
| 64 | avctx->colorspace = AVCOL_SPC_BT709; | ||
| 65 | format = UTVF_YUY2; | ||
| 66 | break; | ||
| 67 | #endif | ||
| 68 | case MKTAG('U', 'L', 'Y', '0'): | ||
| 69 | avctx->pix_fmt = AV_PIX_FMT_YUV420P; | ||
| 70 | format = UTVF_YV12; | ||
| 71 | break; | ||
| 72 | case MKTAG('U', 'L', 'Y', '2'): | ||
| 73 | avctx->pix_fmt = AV_PIX_FMT_YUYV422; | ||
| 74 | format = UTVF_YUY2; | ||
| 75 | break; | ||
| 76 | case MKTAG('U', 'L', 'R', 'G'): | ||
| 77 | avctx->pix_fmt = AV_PIX_FMT_BGR24; | ||
| 78 | format = UTVF_NFCC_BGR_BU; | ||
| 79 | break; | ||
| 80 | case MKTAG('U', 'L', 'R', 'A'): | ||
| 81 | avctx->pix_fmt = AV_PIX_FMT_RGB32; | ||
| 82 | format = UTVF_NFCC_BGRA_BU; | ||
| 83 | break; | ||
| 84 | #ifdef UTVF_UQY2 | ||
| 85 | case MKTAG('U', 'Q', 'Y', '2'): | ||
| 86 | avctx->pix_fmt = AV_PIX_FMT_YUV422P10; | ||
| 87 | format = UTVF_v210; | ||
| 88 | break; | ||
| 89 | #endif | ||
| 90 | default: | ||
| 91 | av_log(avctx, AV_LOG_ERROR, | ||
| 92 | "Not a Ut Video FOURCC: %X\n", avctx->codec_tag); | ||
| 93 | return -1; | ||
| 94 | } | ||
| 95 | |||
| 96 | /* Only allocate the buffer once */ | ||
| 97 | utv->buf_size = av_image_get_buffer_size(avctx->pix_fmt, avctx->width, avctx->height, 1); | ||
| 98 | #ifdef UTVF_UQY2 | ||
| 99 | if (format == UTVF_v210) | ||
| 100 | utv->buf_size += avctx->height * ((avctx->width + 47) / 48) * 128; // the linesize used by the decoder, this does not seem to be exported | ||
| 101 | #endif | ||
| 102 | utv->buffer = (uint8_t *)av_malloc(utv->buf_size * sizeof(uint8_t)); | ||
| 103 | |||
| 104 | if (utv->buffer == NULL) { | ||
| 105 | av_log(avctx, AV_LOG_ERROR, "Unable to allocate output buffer.\n"); | ||
| 106 | return -1; | ||
| 107 | } | ||
| 108 | |||
| 109 | /* Allocate the output frame */ | ||
| 110 | avctx->coded_frame = av_frame_alloc(); | ||
| 111 | |||
| 112 | /* Is it interlaced? */ | ||
| 113 | avctx->coded_frame->interlaced_frame = info.flags & 0x800 ? 1 : 0; | ||
| 114 | |||
| 115 | /* Apparently Ut Video doesn't store this info... */ | ||
| 116 | avctx->coded_frame->top_field_first = 1; | ||
| 117 | |||
| 118 | /* | ||
| 119 | * Create a Ut Video instance. Since the function wants | ||
| 120 | * an "interface name" string, pass it the name of the lib. | ||
| 121 | */ | ||
| 122 | utv->codec = CCodec::CreateInstance(UNFCC(avctx->codec_tag), "libavcodec"); | ||
| 123 | |||
| 124 | /* Initialize Decoding */ | ||
| 125 | begin_ret = utv->codec->DecodeBegin(format, avctx->width, avctx->height, | ||
| 126 | CBGROSSWIDTH_WINDOWS, &info, sizeof(UtVideoExtra)); | ||
| 127 | |||
| 128 | /* Check to see if the decoder initlized properly */ | ||
| 129 | if (begin_ret != 0) { | ||
| 130 | av_log(avctx, AV_LOG_ERROR, | ||
| 131 | "Could not initialize decoder: %d\n", begin_ret); | ||
| 132 | return -1; | ||
| 133 | } | ||
| 134 | |||
| 135 | return 0; | ||
| 136 | } | ||
| 137 | |||
| 138 | static int utvideo_decode_frame(AVCodecContext *avctx, void *data, | ||
| 139 | int *got_frame, AVPacket *avpkt) | ||
| 140 | { | ||
| 141 | UtVideoContext *utv = (UtVideoContext *)avctx->priv_data; | ||
| 142 | AVFrame *pic = avctx->coded_frame; | ||
| 143 | int w = avctx->width, h = avctx->height; | ||
| 144 | |||
| 145 | /* Set flags */ | ||
| 146 | pic->pict_type = AV_PICTURE_TYPE_I; | ||
| 147 | pic->key_frame = 1; | ||
| 148 | |||
| 149 | /* Decode the frame */ | ||
| 150 | utv->codec->DecodeFrame(utv->buffer, avpkt->data, true); | ||
| 151 | |||
| 152 | /* Set the output data depending on the colorspace */ | ||
| 153 | switch (avctx->pix_fmt) { | ||
| 154 | case AV_PIX_FMT_YUV420P: | ||
| 155 | pic->linesize[0] = w; | ||
| 156 | pic->linesize[1] = pic->linesize[2] = w / 2; | ||
| 157 | pic->data[0] = utv->buffer; | ||
| 158 | pic->data[2] = utv->buffer + (w * h); | ||
| 159 | pic->data[1] = pic->data[2] + (w * h / 4); | ||
| 160 | break; | ||
| 161 | case AV_PIX_FMT_YUYV422: | ||
| 162 | pic->linesize[0] = w * 2; | ||
| 163 | pic->data[0] = utv->buffer; | ||
| 164 | break; | ||
| 165 | case AV_PIX_FMT_YUV422P10: { | ||
| 166 | uint16_t *y, *u, *v; | ||
| 167 | int i,j; | ||
| 168 | int linesize = ((w + 47) / 48) * 128; | ||
| 169 | |||
| 170 | pic->linesize[0] = w * 2; | ||
| 171 | pic->linesize[1] = | ||
| 172 | pic->linesize[2] = w; | ||
| 173 | pic->data[0] = utv->buffer + linesize * h; | ||
| 174 | pic->data[1] = pic->data[0] + h*pic->linesize[0]; | ||
| 175 | pic->data[2] = pic->data[1] + h*pic->linesize[1]; | ||
| 176 | y = (uint16_t*)pic->data[0]; | ||
| 177 | u = (uint16_t*)pic->data[1]; | ||
| 178 | v = (uint16_t*)pic->data[2]; | ||
| 179 | for (j = 0; j < h; j++) { | ||
| 180 | const uint8_t *in = utv->buffer + j * linesize; | ||
| 181 | |||
| 182 | for (i = 0; i + 1 < w; i += 6, in += 4) { | ||
| 183 | unsigned a,b; | ||
| 184 | a = AV_RL32(in); | ||
| 185 | in += 4; | ||
| 186 | b = AV_RL32(in); | ||
| 187 | *u++ = (a ) & 0x3FF; | ||
| 188 | *y++ = (a>>10) & 0x3FF; | ||
| 189 | *v++ = (a>>20) & 0x3FF; | ||
| 190 | *y++ = (b ) & 0x3FF; | ||
| 191 | |||
| 192 | if (i + 3 >= w) | ||
| 193 | break; | ||
| 194 | |||
| 195 | in += 4; | ||
| 196 | a = AV_RL32(in); | ||
| 197 | *u++ = (b>>10) & 0x3FF; | ||
| 198 | *y++ = (b>>20) & 0x3FF; | ||
| 199 | *v++ = (a ) & 0x3FF; | ||
| 200 | *y++ = (a>>10) & 0x3FF; | ||
| 201 | |||
| 202 | if (i + 5 >= w) | ||
| 203 | break; | ||
| 204 | |||
| 205 | in += 4; | ||
| 206 | b = AV_RL32(in); | ||
| 207 | *u++ = (a>>20) & 0x3FF; | ||
| 208 | *y++ = (b ) & 0x3FF; | ||
| 209 | *v++ = (b>>10) & 0x3FF; | ||
| 210 | *y++ = (b>>20) & 0x3FF; | ||
| 211 | } | ||
| 212 | } | ||
| 213 | break; | ||
| 214 | } | ||
| 215 | case AV_PIX_FMT_BGR24: | ||
| 216 | case AV_PIX_FMT_RGB32: | ||
| 217 | /* Make the linesize negative, since Ut Video uses bottom-up BGR */ | ||
| 218 | pic->linesize[0] = -1 * w * (avctx->pix_fmt == AV_PIX_FMT_BGR24 ? 3 : 4); | ||
| 219 | pic->data[0] = utv->buffer + utv->buf_size + pic->linesize[0]; | ||
| 220 | break; | ||
| 221 | } | ||
| 222 | pic->width = w; | ||
| 223 | pic->height = h; | ||
| 224 | pic->format = avctx->pix_fmt; | ||
| 225 | |||
| 226 | if (avctx->refcounted_frames) { | ||
| 227 | int ret = av_frame_ref((AVFrame*)data, pic); | ||
| 228 | if (ret < 0) | ||
| 229 | return ret; | ||
| 230 | } else { | ||
| 231 | av_frame_move_ref((AVFrame*)data, pic); | ||
| 232 | } | ||
| 233 | |||
| 234 | *got_frame = 1; | ||
| 235 | |||
| 236 | return avpkt->size; | ||
| 237 | } | ||
| 238 | |||
| 239 | static av_cold int utvideo_decode_close(AVCodecContext *avctx) | ||
| 240 | { | ||
| 241 | UtVideoContext *utv = (UtVideoContext *)avctx->priv_data; | ||
| 242 | |||
| 243 | /* Free output */ | ||
| 244 | av_frame_free(&avctx->coded_frame); | ||
| 245 | av_freep(&utv->buffer); | ||
| 246 | |||
| 247 | /* Finish decoding and clean up the instance */ | ||
| 248 | utv->codec->DecodeEnd(); | ||
| 249 | CCodec::DeleteInstance(utv->codec); | ||
| 250 | |||
| 251 | return 0; | ||
| 252 | } | ||
| 253 | |||
| 254 | AVCodec ff_libutvideo_decoder = { | ||
| 255 | "libutvideo", | ||
| 256 | NULL_IF_CONFIG_SMALL("Ut Video"), | ||
| 257 | AVMEDIA_TYPE_VIDEO, | ||
| 258 | AV_CODEC_ID_UTVIDEO, | ||
| 259 | 0, //capabilities | ||
| 260 | NULL, //supported_framerates | ||
| 261 | NULL, //pix_fmts | ||
| 262 | NULL, //supported_samplerates | ||
| 263 | NULL, //sample_fmts | ||
| 264 | NULL, //channel_layouts | ||
| 265 | 0, //max_lowres | ||
| 266 | NULL, //priv_class | ||
| 267 | NULL, //profiles | ||
| 268 | sizeof(UtVideoContext), | ||
| 269 | NULL, //next | ||
| 270 | NULL, //init_thread_copy | ||
| 271 | NULL, //update_thread_context | ||
| 272 | NULL, //defaults | ||
| 273 | NULL, //init_static_data | ||
| 274 | utvideo_decode_init, | ||
| 275 | NULL, //encode | ||
| 276 | NULL, //encode2 | ||
| 277 | utvideo_decode_frame, | ||
| 278 | utvideo_decode_close, | ||
| 279 | }; | ||
| @@ -1,281 +0,0 @@ | |||
| 1 | /* | ||
| 2 | * Copyright (c) 2012 Derek Buitenhuis | ||
| 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 General Public | ||
| 8 | * License as published by the Free Software Foundation; | ||
| 9 | * version 2 of the License. | ||
| 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 | * General Public License for more details. | ||
| 15 | * | ||
| 16 | * You should have received a copy of the GNU 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 | /** | ||
| 22 | * @file | ||
| 23 | * Known FOURCCs: | ||
| 24 | * 'ULY0' (YCbCr 4:2:0), 'ULY2' (YCbCr 4:2:2), 'ULRG' (RGB), 'ULRA' (RGBA), | ||
| 25 | * 'ULH0' (YCbCr 4:2:0 BT.709), 'ULH2' (YCbCr 4:2:2 BT.709) | ||
| 26 | */ | ||
| 27 | |||
| 28 | extern "C" { | ||
| 29 | #include "libavutil/opt.h" | ||
| 30 | #include "libavutil/avassert.h" | ||
| 31 | #include "libavutil/imgutils.h" | ||
| 32 | #include "avcodec.h" | ||
| 33 | #include "internal.h" | ||
| 34 | } | ||
| 35 | |||
| 36 | #include "libutvideo.h" | ||
| 37 | #include "put_bits.h" | ||
| 38 | |||
| 39 | static av_cold int utvideo_encode_init(AVCodecContext *avctx) | ||
| 40 | { | ||
| 41 | UtVideoContext *utv = (UtVideoContext *)avctx->priv_data; | ||
| 42 | UtVideoExtra *info; | ||
| 43 | uint32_t flags, in_format; | ||
| 44 | int ret; | ||
| 45 | |||
| 46 | switch (avctx->pix_fmt) { | ||
| 47 | case AV_PIX_FMT_YUV420P: | ||
| 48 | in_format = UTVF_YV12; | ||
| 49 | avctx->bits_per_coded_sample = 12; | ||
| 50 | if (avctx->colorspace == AVCOL_SPC_BT709) | ||
| 51 | avctx->codec_tag = MKTAG('U', 'L', 'H', '0'); | ||
| 52 | else | ||
| 53 | avctx->codec_tag = MKTAG('U', 'L', 'Y', '0'); | ||
| 54 | break; | ||
| 55 | case AV_PIX_FMT_YUYV422: | ||
| 56 | in_format = UTVF_YUYV; | ||
| 57 | avctx->bits_per_coded_sample = 16; | ||
| 58 | if (avctx->colorspace == AVCOL_SPC_BT709) | ||
| 59 | avctx->codec_tag = MKTAG('U', 'L', 'H', '2'); | ||
| 60 | else | ||
| 61 | avctx->codec_tag = MKTAG('U', 'L', 'Y', '2'); | ||
| 62 | break; | ||
| 63 | case AV_PIX_FMT_BGR24: | ||
| 64 | in_format = UTVF_NFCC_BGR_BU; | ||
| 65 | avctx->bits_per_coded_sample = 24; | ||
| 66 | avctx->codec_tag = MKTAG('U', 'L', 'R', 'G'); | ||
| 67 | break; | ||
| 68 | case AV_PIX_FMT_RGB32: | ||
| 69 | in_format = UTVF_NFCC_BGRA_BU; | ||
| 70 | avctx->bits_per_coded_sample = 32; | ||
| 71 | avctx->codec_tag = MKTAG('U', 'L', 'R', 'A'); | ||
| 72 | break; | ||
| 73 | default: | ||
| 74 | return AVERROR(EINVAL); | ||
| 75 | } | ||
| 76 | |||
| 77 | #if FF_API_PRIVATE_OPT | ||
| 78 | FF_DISABLE_DEPRECATION_WARNINGS | ||
| 79 | if (avctx->prediction_method) | ||
| 80 | utv->pred = avctx->prediction_method; | ||
| 81 | FF_ENABLE_DEPRECATION_WARNINGS | ||
| 82 | #endif | ||
| 83 | |||
| 84 | /* Check before we alloc anything */ | ||
| 85 | if (utv->pred != 0 && utv->pred != 2) { | ||
| 86 | av_log(avctx, AV_LOG_ERROR, "Invalid prediction method.\n"); | ||
| 87 | return AVERROR(EINVAL); | ||
| 88 | } | ||
| 89 | |||
| 90 | flags = ((utv->pred + 1) << 8) | (avctx->thread_count - 1); | ||
| 91 | |||
| 92 | avctx->priv_data = utv; | ||
| 93 | |||
| 94 | /* Alloc extradata buffer */ | ||
| 95 | info = (UtVideoExtra *)av_malloc(sizeof(*info)); | ||
| 96 | |||
| 97 | if (!info) { | ||
| 98 | av_log(avctx, AV_LOG_ERROR, "Could not allocate extradata buffer.\n"); | ||
| 99 | return AVERROR(ENOMEM); | ||
| 100 | } | ||
| 101 | |||
| 102 | /* | ||
| 103 | * We use this buffer to hold the data that Ut Video returns, | ||
| 104 | * since we cannot decode planes separately with it. | ||
| 105 | */ | ||
| 106 | ret = av_image_get_buffer_size(avctx->pix_fmt, avctx->width, avctx->height, 1); | ||
| 107 | if (ret < 0) { | ||
| 108 | av_free(info); | ||
| 109 | return ret; | ||
| 110 | } | ||
| 111 | utv->buf_size = ret; | ||
| 112 | |||
| 113 | utv->buffer = (uint8_t *)av_malloc(utv->buf_size); | ||
| 114 | |||
| 115 | if (utv->buffer == NULL) { | ||
| 116 | av_log(avctx, AV_LOG_ERROR, "Could not allocate output buffer.\n"); | ||
| 117 | av_free(info); | ||
| 118 | return AVERROR(ENOMEM); | ||
| 119 | } | ||
| 120 | |||
| 121 | /* | ||
| 122 | * Create a Ut Video instance. Since the function wants | ||
| 123 | * an "interface name" string, pass it the name of the lib. | ||
| 124 | */ | ||
| 125 | utv->codec = CCodec::CreateInstance(UNFCC(avctx->codec_tag), "libavcodec"); | ||
| 126 | |||
| 127 | /* Initialize encoder */ | ||
| 128 | utv->codec->EncodeBegin(in_format, avctx->width, avctx->height, | ||
| 129 | CBGROSSWIDTH_WINDOWS); | ||
| 130 | |||
| 131 | /* Get extradata from encoder */ | ||
| 132 | avctx->extradata_size = utv->codec->EncodeGetExtraDataSize(); | ||
| 133 | utv->codec->EncodeGetExtraData(info, avctx->extradata_size, in_format, | ||
| 134 | avctx->width, avctx->height, | ||
| 135 | CBGROSSWIDTH_WINDOWS); | ||
| 136 | avctx->extradata = (uint8_t *)info; | ||
| 137 | |||
| 138 | /* Set flags */ | ||
| 139 | utv->codec->SetState(&flags, sizeof(flags)); | ||
| 140 | |||
| 141 | return 0; | ||
| 142 | } | ||
| 143 | |||
| 144 | static int utvideo_encode_frame(AVCodecContext *avctx, AVPacket *pkt, | ||
| 145 | const AVFrame *pic, int *got_packet) | ||
| 146 | { | ||
| 147 | UtVideoContext *utv = (UtVideoContext *)avctx->priv_data; | ||
| 148 | int w = avctx->width, h = avctx->height; | ||
| 149 | int ret, rgb_size, i; | ||
| 150 | bool keyframe; | ||
| 151 | uint8_t *y, *u, *v; | ||
| 152 | uint8_t *dst; | ||
| 153 | |||
| 154 | /* Alloc buffer */ | ||
| 155 | if ((ret = ff_alloc_packet2(avctx, pkt, utv->buf_size, 0)) < 0) | ||
| 156 | return ret; | ||
| 157 | |||
| 158 | dst = pkt->data; | ||
| 159 | |||
| 160 | /* Move input if needed data into Ut Video friendly buffer */ | ||
| 161 | switch (avctx->pix_fmt) { | ||
| 162 | case AV_PIX_FMT_YUV420P: | ||
| 163 | y = utv->buffer; | ||
| 164 | u = y + w * h; | ||
| 165 | v = u + w * h / 4; | ||
| 166 | for (i = 0; i < h; i++) { | ||
| 167 | memcpy(y, pic->data[0] + i * pic->linesize[0], w); | ||
| 168 | y += w; | ||
| 169 | } | ||
| 170 | for (i = 0; i < h / 2; i++) { | ||
| 171 | memcpy(u, pic->data[2] + i * pic->linesize[2], w >> 1); | ||
| 172 | memcpy(v, pic->data[1] + i * pic->linesize[1], w >> 1); | ||
| 173 | u += w >> 1; | ||
| 174 | v += w >> 1; | ||
| 175 | } | ||
| 176 | break; | ||
| 177 | case AV_PIX_FMT_YUYV422: | ||
| 178 | for (i = 0; i < h; i++) | ||
| 179 | memcpy(utv->buffer + i * (w << 1), | ||
| 180 | pic->data[0] + i * pic->linesize[0], w << 1); | ||
| 181 | break; | ||
| 182 | case AV_PIX_FMT_BGR24: | ||
| 183 | case AV_PIX_FMT_RGB32: | ||
| 184 | /* Ut Video takes bottom-up BGR */ | ||
| 185 | rgb_size = avctx->pix_fmt == AV_PIX_FMT_BGR24 ? 3 : 4; | ||
| 186 | for (i = 0; i < h; i++) | ||
| 187 | memcpy(utv->buffer + (h - i - 1) * w * rgb_size, | ||
| 188 | pic->data[0] + i * pic->linesize[0], | ||
| 189 | w * rgb_size); | ||
| 190 | break; | ||
| 191 | default: | ||
| 192 | return AVERROR(EINVAL); | ||
| 193 | } | ||
| 194 | |||
| 195 | /* Encode frame */ | ||
| 196 | pkt->size = utv->codec->EncodeFrame(dst, &keyframe, utv->buffer); | ||
| 197 | |||
| 198 | if (!pkt->size) { | ||
| 199 | av_log(avctx, AV_LOG_ERROR, "EncodeFrame failed!\n"); | ||
| 200 | return AVERROR_INVALIDDATA; | ||
| 201 | } | ||
| 202 | |||
| 203 | /* | ||
| 204 | * Ut Video is intra-only and every frame is a keyframe, | ||
| 205 | * and the API always returns true. In case something | ||
| 206 | * durastic changes in the future, such as inter support, | ||
| 207 | * assert that this is true. | ||
| 208 | */ | ||
| 209 | av_assert2(keyframe == true); | ||
| 210 | |||
| 211 | pkt->flags |= AV_PKT_FLAG_KEY; | ||
| 212 | *got_packet = 1; | ||
| 213 | return 0; | ||
| 214 | } | ||
| 215 | |||
| 216 | static av_cold int utvideo_encode_close(AVCodecContext *avctx) | ||
| 217 | { | ||
| 218 | UtVideoContext *utv = (UtVideoContext *)avctx->priv_data; | ||
| 219 | |||
| 220 | av_freep(&avctx->extradata); | ||
| 221 | av_freep(&utv->buffer); | ||
| 222 | |||
| 223 | utv->codec->EncodeEnd(); | ||
| 224 | CCodec::DeleteInstance(utv->codec); | ||
| 225 | |||
| 226 | return 0; | ||
| 227 | } | ||
| 228 | |||
| 229 | #define OFFSET(x) offsetof(UtVideoContext, x) | ||
| 230 | #define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM | ||
| 231 | static const AVOption options[] = { | ||
| 232 | { "pred", "Prediction method", OFFSET(pred), AV_OPT_TYPE_INT, 0, 0, 2, VE, "pred" }, | ||
| 233 | { "left", NULL, 0, AV_OPT_TYPE_CONST, 0, INT_MIN, INT_MAX, VE, "pred" }, | ||
| 234 | { "median", NULL, 0, AV_OPT_TYPE_CONST, 2, INT_MIN, INT_MAX, VE, "pred" }, | ||
| 235 | { NULL }, | ||
| 236 | }; | ||
| 237 | |||
| 238 | static const AVClass utvideo_class = { | ||
| 239 | "libutvideo", | ||
| 240 | av_default_item_name, | ||
| 241 | options, | ||
| 242 | LIBAVUTIL_VERSION_INT, | ||
| 243 | 0, | ||
| 244 | 0, | ||
| 245 | NULL, | ||
| 246 | NULL, | ||
| 247 | AV_CLASS_CATEGORY_NA, | ||
| 248 | NULL, | ||
| 249 | NULL, | ||
| 250 | }; | ||
| 251 | |||
| 252 | AVCodec ff_libutvideo_encoder = { | ||
| 253 | "libutvideo", | ||
| 254 | NULL_IF_CONFIG_SMALL("Ut Video"), | ||
| 255 | AVMEDIA_TYPE_VIDEO, | ||
| 256 | AV_CODEC_ID_UTVIDEO, | ||
| 257 | AV_CODEC_CAP_AUTO_THREADS | (int)AV_CODEC_CAP_LOSSLESS | AV_CODEC_CAP_INTRA_ONLY, | ||
| 258 | NULL, /* supported_framerates */ | ||
| 259 | (const enum AVPixelFormat[]) { | ||
| 260 | AV_PIX_FMT_YUV420P, AV_PIX_FMT_YUYV422, AV_PIX_FMT_BGR24, | ||
| 261 | AV_PIX_FMT_RGB32, AV_PIX_FMT_NONE | ||
| 262 | }, | ||
| 263 | NULL, /* supported_samplerates */ | ||
| 264 | NULL, /* sample_fmts */ | ||
| 265 | NULL, /* channel_layouts */ | ||
| 266 | 0, /* max_lowres */ | ||
| 267 | &utvideo_class, /* priv_class */ | ||
| 268 | NULL, /* profiles */ | ||
| 269 | sizeof(UtVideoContext), | ||
| 270 | NULL, /* next */ | ||
| 271 | NULL, /* init_thread_copy */ | ||
| 272 | NULL, /* update_thread_context */ | ||
| 273 | NULL, /* defaults */ | ||
| 274 | NULL, /* init_static_data */ | ||
| 275 | utvideo_encode_init, | ||
| 276 | NULL, /* encode */ | ||
| 277 | utvideo_encode_frame, | ||
| 278 | NULL, /* decode */ | ||
| 279 | utvideo_encode_close, | ||
| 280 | NULL, /* flush */ | ||
| 281 | }; | ||