aboutsummaryrefslogtreecommitdiffstats
path: root/libavcodec/videotoolboxenc.c
Commit message (Collapse)AuthorAgeFilesLines
* videotoolboxenc: Add an iOS version condition for ↵Martin Storsjö2025-04-011-1/+1
| | | | | | | | VTCopySupportedPropertyDictionaryForEncoder This fixes building for iOS versions older than 11.0. Signed-off-by: Martin Storsjö <martin@martin.st>
* avcodec/videotoolboxenc: Add AYUV as a candidate pix_fmt for HEVC alphaZhao Zhili2025-03-171-2/+5
| | | | Signed-off-by: Zhao Zhili <zhilizhao@tencent.com>
* lavc/videotoolboxenc: add hevc main42210 and p210wang-bin2025-03-131-0/+10
| | | | Signed-off-by: Zhao Zhili <zhilizhao@tencent.com>
* avcodec/codec_internal, all: Use macros to set deprecated AVCodec fieldsAndreas Rheinhardt2025-03-101-3/+3
| | | | | | | | | | | | | | The aim of this is twofold: a) Clang warns when setting a deprecated field in a definition and because several of the widely set AVCodec fields are deprecated, one gets several hundred warnings from Clang for an ordinary build. Yet fortunately Clang (unlike GCC) allows to disable deprecation warnings inside a definition, so that one can create simple macros to set these fields that also suppress deprecation warnings for Clang. This has already been done in fdff1b9cbfd8cf5a9810c29efa4baf13a4786742 for AVCodec.channel_layouts. b) Using macros will allow to easily migrate these fields to internal ones. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* lavc/videotoolboxenc: Add spatial_aq optionDennis Sädtler2025-02-111-0/+17
| | | | | | | Added in macOS 15 "Sequoia". Signed-off-by: Dennis Sädtler <dennis@obsproject.com> Signed-off-by: Martin Storsjö <martin@martin.st>
* avcodec/internal: add FFCodec.color_rangesNiklas Haas2024-09-081-0/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | I went through all codecs and put them into five basic categories: 1. JPEG range only 2. MPEG range only 3. Explicitly tagged 4. Broken (codec supports both but encoder ignores tags) 5. N/A (headerless or pseudo-formats) Filters in category 5 remain untouched. The rest gain an explicit assignment of their supported color ranges, with codecs in category 4 being set to MPEG-only for safety. It might be considered redundant to distinguish between 0 (category 5) and MPEG+JPEG (category 3), but in doing so we effectively communicate that we can guarantee that these tags will be encoded, which is distinct from the situation where there are some codecs that simply don't have tagging or implied semantics (e.g. rawvideo). A full list of codecs follows: JPEG range only: - amv - roqvideo MPEG range only: - asv1, asv2 - avui - cfhd - cljr - dnxhd - dvvideo - ffv1 - flv - h261, h263, h263p - {h263,vp8}_v4l2m2m - huffyuv, ffvhuff - jpeg2000 - libopenjpeg - libtheora - libwebp, libwebp_anim - libx262 - libxavs, libxavs2 - libxvid - mpeg1video, mpeg2video - mpeg2_qsv - mpeg2_vaapi - mpeg4, msmpeg4, msmpeg4v2, wmv1, wmv2 - mpeg4_omx - prores, prores_aw, prores_ks - rv10, rv20 - snow - speedhq - svq1 - tiff - utvideo Explicitly tagged (MPEG/JPEG): - {av1,h264,hevc}_nvenc - {av1,h264,hevc}_vaapi - {av1,h264,hevc,vp8,vp9,mpeg4}_mediacodec - {av1,h264,hevc,vp9}_qsv - h264_amf - {h264,hevc,prores}_videotoolbox - libaom-av1 - libkvazaar - libopenh264 - librav1e - libsvtav1 - libvpx, libvpx-vp9 - libx264 - libx265 - ljpeg - mjpeg - vc2 Broken (encoder ignores tags): - {av1,hevc}_amf - {h264,hevc,mpeg4}_v4l2m2m - h264_omx - libxeve - magicyuv - {vp8,vp9,mjpeg}_vaapi N/A: - ayuv, yuv4, y41p, v308, v210, v410, v408 (headerless) - pgmyuv (headerless) - rawvideo, bitpacked (headerless) - vnull, wrapped_avframe (pseudocodecs)
* avcodec/videotoolboxenc: Fix leaking of supported_propsZhao Zhili2024-08-261-0/+4
| | | | | | | | There are two VTCompressionSessionRef been created, one for generating extradata, and another for normal encoding. supported_props was been overwritten without release. Signed-off-by: Zhao Zhili <zhilizhao@tencent.com>
* avcodec/videotoolboxenc: Fix variable type of AV_OPT_TYPE_BOOLZhao Zhili2024-07-261-1/+1
| | | | Signed-off-by: Zhao Zhili <zhilizhao@tencent.com>
* avcodec/videotoolboxenc: Set default bitrate to zeroZhao Zhili2024-07-261-0/+1
| | | | | | | | | | | | Zero is auto mode. From the doc of videotoolbox: The default bit rate is zero, which indicates that the video encoder should determine the size of compressed data. Before the patch, the default bitrate is 200000 setting by avcodec/options_table, which doesn't work for most of cases. Signed-off-by: Zhao Zhili <zhilizhao@tencent.com>
* avcodec/videotoolboxenc: Fix bitrate doesn't work as expectedZhao Zhili2024-07-261-0/+9
| | | | | | | | Commit 4ef5e7d4722 add qmin/qmax support to videotoolbox encoder. The default value of (qmin, qmax) is (2, 31), which makes bitrate control doesn't work as users' expectations. Signed-off-by: Zhao Zhili <zhilizhao@tencent.com>
* avcodec/videotoolboxenc: Put ExtraSEI inside BufNode directlyZhao Zhili2024-07-161-39/+21
| | | | | | Reduce error path and simplify the code. Signed-off-by: Zhao Zhili <zhilizhao@tencent.com>
* avcodec/videotoolboxenc: Fix concurrent access to CVPixelBufferRefZhao Zhili2024-07-161-2/+12
| | | | | | | | | | | | | | | | | | | | | | | | | | | For a frame comes from AV_HWDEVICE_TYPE_VIDEOTOOLBOX, it's CVPixelBufferRef is maintained by a pool. CVPixelBufferRef returned to the pool when frame buffer reference reached to zero. However, VTCompressionSessionEncodeFrame also hold a reference to the CVPixelBufferRef. So a new frame get from av_hwframe_get_buffer may access a CVPixelBufferRef which still used by the encoder. It's only after vtenc_output_callback that we can make sure CVPixelBufferRef has been released by the encoder. The issue can be tested with sample from trac #10884. ffmpeg -hwaccel videotoolbox \ -hwaccel_output_format videotoolbox_vld \ -i input.mp4 \ -c:v hevc_videotoolbox \ -profile:v main \ -b:v 3M \ -vf scale_vt=w=iw/2:h=ih/2:color_matrix=bt709:color_primaries=bt709:color_transfer=bt709 \ -c:a copy \ -tag:v hvc1 \ output.mp4 Withtout the patch, there are some out of order images in output.mp4. Signed-off-by: Zhao Zhili <zhilizhao@tencent.com>
* avcodec/videotoolboxenc: Use BufNode as sourceFrameRefconZhao Zhili2024-07-161-26/+51
| | | | | | | | | | | ExtraSEI is used as the sourceFrameRefcon of VTCompressionSessionEncodeFrame. It cannot hold other information which is necessary to fix another issue in the following patch. This patch also fixed leak of ExtraSEI on the error path of vtenc_output_callback. Signed-off-by: Zhao Zhili <zhilizhao@tencent.com>
* avcodec/videotoolboxenc: Remove unused variableZhao Zhili2024-07-161-1/+0
| | | | Signed-off-by: Zhao Zhili <zhilizhao@tencent.com>
* avcodec/videotoolboxenc: Don't ignore ENOMEMZhao Zhili2024-07-161-13/+16
| | | | Signed-off-by: Zhao Zhili <zhilizhao@tencent.com>
* avcodec/videotoolboxenc: fix vtctx reset conditionHao Guan2024-07-071-1/+8
| | | | | | | | | | | In vtenc_populate_extradata, the cleanup function vtenc_reset should not be used when no error occurs, otherwise some color information is lost (#11036). This patch checks the status code and conducts the correct cleanup. Signed-off-by: Hao Guan <hguandl@gmail.com> Signed-off-by: Zhao Zhili <zhilizhao@tencent.com>
* avutil/common: Don't auto-include mem.hAndreas Rheinhardt2024-03-311-0/+1
| | | | | | | | | | | There are lots of files that don't need it: The number of object files that actually need it went down from 2011 to 884 here. Keep it for external users in order to not cause breakages. Also improve the other headers a bit while just at it. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* all: use designated initializers for AVOption.unitAnton Khirnov2024-02-141-36/+36
| | | | | | | | | | | | | | | | | | | | | | | | Makes it robust against adding fields before it, which will be useful in following commits. Majority of the patch generated by the following Coccinelle script: @@ typedef AVOption; identifier arr_name; initializer list il; initializer list[8] il1; expression tail; @@ AVOption arr_name[] = { il, { il1, - tail + .unit = tail }, ... }; with some manual changes, as the script: * has trouble with options defined inside macros * sometimes does not handle options under an #else branch * sometimes swallows whitespace
* Revert "all: Don't set AVClass.item_name to its default value"Anton Khirnov2024-01-201-0/+3
| | | | | | | Some callers assume that item_name is always set, so this may be considered an API break. This reverts commit 0c6203c97a99f69dbaa6e4011d48c331e1111f5e.
* avcodec/videotoolboxenc: fix setting avctx color_range doesn't workZhao Zhili2024-01-121-1/+1
| | | | Signed-off-by: Zhao Zhili <zhilizhao@tencent.com>
* avcodec/proresenc: make transparency honored in mov/QTClément Bœsch2024-01-061-0/+2
| | | | | | | | | In the mov muxer (in mov_write_video_tag()), bits_per_coded_sample will be written under certain conditions and is required to be 32 for the transparency to be honored in QuickTime. prores_kostya already has this setting but prores_anatoliy and prores_videotoolbox didn't.
* all: Don't set AVClass.item_name to its default valueAndreas Rheinhardt2023-12-221-3/+0
| | | | | | | | Unnecessary since acf63d5350adeae551d412db699f8ca03f7e76b9; also avoids relocations. Reviewed-by: Anton Khirnov <anton@khirnov.net> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/videotoolboxenc: refactor dump encoder nameZhao Zhili2023-11-271-27/+38
| | | | Signed-off-by: Zhao Zhili <zhilizhao@tencent.com>
* avcodec/videotoolboxenc: Fix build failure due to PropertyKey_EncoderIDZhao Zhili2023-11-271-1/+3
| | | | Signed-off-by: Zhao Zhili <zhilizhao@tencent.com>
* avcodec/videotoolboxenc: Check and set hevc profileZhao Zhili2023-10-181-0/+18
| | | | | | | | | | | 1. If user don't specify the profile, set it to main10 when pixel format is 10 bits. Before the patch, videotoolbox output main profile bitstream with 10 bit input, which can be confusing. 2. Warning when user set profile to main explicitly with 10 bit input. It works, but not the best choice. 3. Reject main 10 profile with 8 bit input, it doesn't work. Signed-off-by: Zhao Zhili <zhilizhao@tencent.com>
* avcodec/videotoolboxenc: add hw_configsZhao Zhili2023-10-181-0/+9
| | | | | | | | | Will be used in the following patch. With hw_config we can get avctx->hw_frames_ctx, and with avctx->hw_frames_ctx we get sw_pix_fmt. Otherwise sw_pix_fmt is none. I need sw_pix_fmt before get the first frame to set hevc encoder profile. Signed-off-by: Zhao Zhili <zhilizhao@tencent.com>
* lavc/videotoolboxenc: Get the encoder supported propertiesJun Zhao2023-09-151-23/+49
| | | | | | | Get the encoder supported properties list, it will be used for feature support checks. Signed-off-by: Jun Zhao <barryjzhao@tencent.com>
* lavc/videotoolboxenc: Dump the encoderJun Zhao2023-09-151-0/+28
| | | | | | Dump the encoder, it's will help debug some case Signed-off-by: Jun Zhao <barryjzhao@tencent.com>
* avcodec/defs: Add AV_PROFILE_* defines, deprecate FF_PROFILE_* definesAndreas Rheinhardt2023-09-071-39/+39
| | | | | | | | | These defines are also used in other contexts than just AVCodecContext ones, e.g. in libavformat. Furthermore, given that these defines are public, the AV-prefix is the right one, so deprecate (and not just move) the FF-macros. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/videotoolboxenc: use color parameters conversion from avutilZhao Zhili2023-07-231-124/+13
| | | | Signed-off-by: Zhao Zhili <zhilizhao@tencent.com>
* lavc/videotoolboxenc: fix enabling low-latency encodexufuji4562023-07-021-11/+7
| | | | | | | | | Use CFDictionarySetValue to enable low-latency encoding mode. Since the key is a type of "EncoderSpecification", instead of "CompressionProperty". Signed-off-by: xufuji456 <839789740@qq.com> Signed-off-by: Rick Kern <kernrj@gmail.com>
* avcodec/videotoolboxenc: inherit profile from AVCodecContextZhao Zhili2023-06-191-0/+3
| | | | | | | This can happen when user set the avctx->profile field directly instead of specify profile via option. Signed-off-by: Zhao Zhili <zhilizhao@tencent.com>
* avcodec/videotoolboxenc: remove AUTO_PROFILE defineZhao Zhili2023-06-191-6/+5
| | | | | | Use FF_PROFILE_UNKNOWN as auto mode. Signed-off-by: Zhao Zhili <zhilizhao@tencent.com>
* avcodec/videotoolboxenc: use int as the type of profileZhao Zhili2023-06-191-8/+8
| | | | | | | | | | | Other than save a few bytes, it also has the benefit to show the AV_OPT_TYPE_CONST value in help, e.g., -profile <int> E..V....... Profile (from 0 to INT_MAX) (default 0) baseline 66 E..V....... Baseline Profile ... Signed-off-by: Zhao Zhili <zhilizhao@tencent.com>
* lavc/videotoolboxenc: support additional optionsRick Kern2023-06-031-1/+121
| | | | | | | | | | | Added support for more VideoToolbox encoder options: - qmin and qmax options are now used - max_slice_bytes: Max number of bytes per H.264 slice - max_ref_frames: Limit the number of reference frames - Disable open GOP when the cgop flag is set - power_efficient: Enable power-efficient mode Signed-off-by: Rick Kern <kernrj@gmail.com>
* avcodec/videotoolboxenc: add CBP/CHP profilexufuji4562023-06-031-4/+34
| | | | | | | The CBP/CHP profile has available with H264 in iOS 15.0. Official Doc: https://developer.apple.com/documentation/videotoolbox/kvtprofilelevel_h264_constrainedbaseline_autolevel Signed-off-by: Rick Kern <kernrj@gmail.com>
* lavc/videotoolboxenc: use ffmpeg profile constantsRick Kern2023-06-031-35/+22
| | | | Signed-off-by: Rick Kern <kernrj@gmail.com>
* lavc/videotoolboxenc: warn when alpha quality not setRick Kern2023-05-201-0/+7
| | | | | | Added a warn log when alpha quality cannot be set, but continue encoding. Signed-off-by: Rick Kern <kernrj@gmail.com>
* lavc/videotoolboxenc: better compat_keys docsRick Kern2023-05-201-3/+13
| | | | | | | Added more specific docs about when to use compat_keys, and how to add new constants. Signed-off-by: Rick Kern <kernrj@gmail.com>
* lavc/videotoolboxenc: better compat_keys documentationRick Kern2023-05-191-1/+5
| | | | | | | Added documentation that describes when compat_keys should be used, and why it exists. Signed-off-by: Rick Kern <kernrj@gmail.com>
* avcodec/videotoolboxenc: add low-latency encodingxufuji4562023-05-191-0/+14
| | | | | | | | When using low-latency mode, it eliminates frame reordering and follows a one-in-one-out encoding mode Signed-off-by: xufuji456 <839789740@qq.com> Signed-off-by: Rick Kern <kernrj@gmail.com>
* lavc/videotoolboxenc: fix warningsJun Zhao2023-04-091-3/+3
| | | | | | | fix mixing declarations and code and function declaration without a prototype warnings Signed-off-by: Jun Zhao <barryjzhao@tencent.com>
* avcodec/videotoolboxenc: fix error codeZhao Zhili2023-01-111-2/+6
| | | | | | | 1. Fix return 0 on error. 2. Fix return OS error code passthrough. Signed-off-by: Zhao Zhili <zhilizhao@tencent.com>
* avcodec/videotoolboxenc: pass error code throughZhao Zhili2023-01-111-2/+2
| | | | Signed-off-by: Zhao Zhili <zhilizhao@tencent.com>
* avcodec/videotoolboxenc: log when get_cv_pixel_format failedZhao Zhili2023-01-111-12/+11
| | | | Signed-off-by: Zhao Zhili <zhilizhao@tencent.com>
* lavc/videotoolboxenc: fix warningsRick Kern2022-12-031-2/+4
| | | | | | This handles an unhandled error, and removes an unnecessary variable. Signed-off-by: Rick Kern <kernrj@gmail.com>
* lavc/videotoolboxenc: Fix crash by uninitialized valueThilo Borgmann2022-09-211-3/+1
| | | | If create_cv_pixel_buffer() fails, pixel_buffer_info might get into CFRelease() containing an arbitrary value.
* avcodec/codec_internal: Add macro to set AVCodec.long_nameAndreas Rheinhardt2022-09-031-3/+3
| | | | | | | | It reduces typing: Before this patch, there were 105 codecs whose long_name-definition exceeded the 80 char line length limit. Now there are only nine of them. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/videotoolboxenc: Add CBR option to H264 and HEVC encoderSebastian Beckmann2022-08-291-3/+24
| | | | | | | | | Adds an option to use constant bitrate instead of average bitrate to the videotoolbox encoders. This is enabled via -constant_bit_rate true. macOS 13 is required for this option to work. Signed-off-by: Sebastian Beckmann <beckmann.sebastian@outlook.de> Signed-off-by: Rick Kern <kernrj@gmail.com>
* avcodec: Make init-threadsafety the defaultAndreas Rheinhardt2022-07-181-6/+3
| | | | | | | | | | | and remove FF_CODEC_CAP_INIT_THREADSAFE All our native codecs are already init-threadsafe (only wrappers for external libraries and hwaccels are typically not marked as init-threadsafe yet), so it is only natural for this to also be the default state. Reviewed-by: Anton Khirnov <anton@khirnov.net> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>