[FFmpeg-devel] [PATCH 0/5] Bitstream filter support for A/53 Closed Captions

2023-02-03 Thread ffmpegagent
cc: Aman Karmani a...@tmm1.net cc: Eric Lindvall e...@5stops.com cc: Mark
Thompson s...@jkqxz.net cc: David Engel da...@istwok.net cc: Scott Theisen
scott.the@gmail.com cc: Miguel Borges de Freitas 92e...@gmail.com

/cc https://github.com/MythTV/mythtv/issues/364 /cc
https://github.com/xbmc/xbmc/pull/22605 /cc
https://github.com/xbmc/xbmc/pull/22603 /cc
https://github.com/xbmc/xbmc/pull/22333

Aman Karmani (3):
  avcodec/mpeg2_metadata_bsf: add support for a/53 closed captions
  avcodec/h264_metadata_bsf: add support for a/53 closed captions
  avcodec/h265_metadata_bsf: add support for a/53 closed captions

Eric Lindvall (1):
  cbs_sei: add ff_cbs_sei_delete_message helper

Mark Thompson (1):
  cbs: Add some common code for read/write of miscellaneous user data

 doc/bitstream_filters.texi|  33 
 libavcodec/Makefile   |   6 +-
 libavcodec/cbs_misc.c | 217 ++
 libavcodec/cbs_misc.h | 109 +
 libavcodec/cbs_misc_syntax_template.c | 150 ++
 libavcodec/cbs_sei.c  |  25 +++
 libavcodec/cbs_sei.h  |   7 +
 libavcodec/h264_metadata_bsf.c| 144 +
 libavcodec/h265_metadata_bsf.c| 144 +
 libavcodec/mpeg2_metadata_bsf.c   |  80 ++
 10 files changed, 912 insertions(+), 3 deletions(-)
 create mode 100644 libavcodec/cbs_misc.c
 create mode 100644 libavcodec/cbs_misc.h
 create mode 100644 libavcodec/cbs_misc_syntax_template.c


base-commit: 9a820ec8b1e2323b70a1cebd204bf459bf7daa1a
Published-As: 
https://github.com/ffstaging/FFmpeg/releases/tag/pr-ffstaging-50%2Ftmm1%2Fcbs-misc-a53-v3-v1
Fetch-It-Via: git fetch https://github.com/ffstaging/FFmpeg 
pr-ffstaging-50/tmm1/cbs-misc-a53-v3-v1
Pull-Request: https://github.com/ffstaging/FFmpeg/pull/50
-- 
ffmpeg-codebot
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH 0/2] libavformat/matroskadec: set fixed duration for subtitles

2023-01-10 Thread ffmpegagent
The matroska specification states the start time and duration of subtitle
entries are encoded in the block TimeStamp and BlockDuration. Furthermore,
for all subtitle formats except S_HDMV/PGS the BlockDuration must always be
defined and have an absolute value even if it is simply 0. ffmpeg assumes
that a duration of 0 means the duration is still unknown and tries to adjust
based on the next packet pts. This is wrong for all formats except
S_HDMV/PGS. Since changing the semantics of duration 0 is not an option
(touches too many parts of the code) this change introduces
AV_PKT_FLAG_FIXED_DURATION flag which decoders might use to flag the
duration of a given packet should not be changed.

Signed-off-by: Miguel Borges de Freitas ene...@kodi.tv



This is my attempt at fixing https://trac.ffmpeg.org/ticket/10135 Initially
reported to Kodi in https://github.com/xbmc/xbmc/issues/21625

Miguel Borges de Freitas (2):
  libavformat/matroskadec: set fixed duration for subtitles
  fate: update test reference data to include AV_PKT_FLAG_FIXED_DURATION

 libavcodec/packet.h|  5 ++
 libavformat/demux.c|  3 +-
 libavformat/matroskadec.c  |  4 +
 tests/ref/fate/matroska-dvbsub-remux   | 84 ++--
 tests/ref/fate/matroska-zero-length-block  |  4 +-
 tests/ref/fate/matroska-zlib-decompression |  2 +-
 tests/ref/fate/shortest-sub| 92 +++---
 7 files changed, 102 insertions(+), 92 deletions(-)


base-commit: 94aa70d757af6b0e0919250f9def2a819aa00358
Published-As: 
https://github.com/ffstaging/FFmpeg/releases/tag/pr-ffstaging-48%2Fenen92%2Fass_mkv_fixed_subs-v1
Fetch-It-Via: git fetch https://github.com/ffstaging/FFmpeg 
pr-ffstaging-48/enen92/ass_mkv_fixed_subs-v1
Pull-Request: https://github.com/ffstaging/FFmpeg/pull/48
-- 
ffmpeg-codebot
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH v2 0/2] QSV Overlay Filter: Copy side data from input to output frame

2022-11-03 Thread ffmpegagent
This is split out from my earlier patchset "SEI parsing for QSV decoders"
(https://github.com/ffstaging/FFmpeg/pull/31) as it is only logically
related but not technically.

The first patch had been reviewed and partially authored by Anton (I have
indicated this with a signed-off line, please advise in case this wouldn't
be right)

The second patch performs the copying of side data from input to output
frames.

softworkz

v2:

 * Fix commit message (avcodec > avfilter)
 * Bump version in version.h
 * Resolve rebase conflicts

softworkz (2):
  avutil/frame: Add av_frame_copy_side_data() and
av_frame_remove_all_side_data()
  avfilter/vpp_qsv: Copy side-data from input to output frame

 doc/APIchanges   |  4 +++
 libavfilter/qsvvpp.c |  6 
 libavfilter/vf_overlay_qsv.c | 19 +++---
 libavutil/frame.c| 67 ++--
 libavutil/frame.h| 32 +
 libavutil/version.h  |  2 +-
 6 files changed, 99 insertions(+), 31 deletions(-)


base-commit: 5661c8715ce4f752e676bda75b332efc669694ed
Published-As: 
https://github.com/ffstaging/FFmpeg/releases/tag/pr-ffstaging-44%2Fsoftworkz%2Fsubmit_copy_sidedata-v2
Fetch-It-Via: git fetch https://github.com/ffstaging/FFmpeg 
pr-ffstaging-44/softworkz/submit_copy_sidedata-v2
Pull-Request: https://github.com/ffstaging/FFmpeg/pull/44

Range-diff vs v1:

 1:  28c4b9e324 ! 1:  d8cdd25105 avutil/frame: Add av_frame_copy_side_data() 
and av_frame_remove_all_side_data()
 @@ doc/APIchanges: libavutil: 2021-04-27
   
   API changes, most recent first:
   
 -+2022-05-26 - x - lavu 57.40.100 - frame.h
 ++2022-05-26 - x - lavu 57.41.100 - frame.h
  +  Add av_frame_remove_all_side_data(), av_frame_copy_side_data(),
  +  AV_FRAME_TRANSFER_SD_COPY, and AV_FRAME_TRANSFER_SD_FILTER.
 -+
 - 2022-10-11 - xx - lavu 57.39.101 - pixfmt.h
 -   Add AV_PIX_FMT_RGBF32 and AV_PIX_FMT_RGBAF32.
 ++  
 + 2022-10-30 - xx - lavu 57.40.100 - channel_layout.h
 +   Add AV_CH_LAYOUT_CUBE and AV_CHANNEL_LAYOUT_CUBE.
   
  
   ## libavutil/frame.c ##
 @@ libavutil/version.h
*/
   
   #define LIBAVUTIL_VERSION_MAJOR  57
 --#define LIBAVUTIL_VERSION_MINOR  39
 --#define LIBAVUTIL_VERSION_MICRO 101
 -+#define LIBAVUTIL_VERSION_MINOR  40
 -+#define LIBAVUTIL_VERSION_MICRO 100
 +-#define LIBAVUTIL_VERSION_MINOR  40
 ++#define LIBAVUTIL_VERSION_MINOR  41
 + #define LIBAVUTIL_VERSION_MICRO 100
   
   #define LIBAVUTIL_VERSION_INT   AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \
 -LIBAVUTIL_VERSION_MINOR, \
 2:  43eb3257af ! 2:  0e71469a87 avcodec/vpp_qsv: Copy side data from input to 
output frame
 @@ Metadata
  Author: softworkz 
  
   ## Commit message ##
 -avcodec/vpp_qsv: Copy side data from input to output frame
 +avfilter/vpp_qsv: Copy side-data from input to output frame
  
  Signed-off-by: softworkz 
  

-- 
ffmpeg-codebot
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH v2 00/11] Fixes and Enhancements for VAAPI Overlay

2022-10-30 Thread ffmpegagent
This patchset resolves a number of issues in the current code:

 * Bogus doubles framesync initialization
 * Executing build_parameters on each input frame
 * Segfault when there's no secondary input (yet)

and adds a number of enhancements to bring this on-par with the other
overlay filters:

 * Enable pixel alpha blending
 * Expose framesync parameters
 * Add support for expressions in overlay parameters (x, y, w, h)

v2 Changes:

 * Changed var names to all-caps
 * Added note about defaults for w/h to filters.texi

softworkz (11):
  avfilter/overlay_vaapi: use FILTER_SINGLE_PIXFMT
  avfilter/overlay_vaapi: build filter params just once
  avfilter/overlay_vaapi: remove double framesync init
  avfilter/overlay_vaapi: handle secondary null input
  avfilter/overlay_vaapi: reformat options
  avfilter/overlay_vaapi: remove redundant .get_buffer assignments
  avfilter/overlay_vaapi: add framesync options
  avfilter/overlay_vaapi: precalculate blend_state, enable pixel alpha
  avfilter/overlay_vaapi: enable expressions for overlay parameters
  doc/filters.texi: remove incorrect statement
  doc/filters.texi: update overlay_vaapi documentation

 doc/filters.texi   |  52 --
 libavfilter/vf_overlay_vaapi.c | 328 ++---
 2 files changed, 259 insertions(+), 121 deletions(-)


base-commit: f3b5277057ad84071721f01419fe4badeceaff08
Published-As: 
https://github.com/ffstaging/FFmpeg/releases/tag/pr-ffstaging-42%2Fsoftworkz%2Fsubmit_vaapi_overlay-v2
Fetch-It-Via: git fetch https://github.com/ffstaging/FFmpeg 
pr-ffstaging-42/softworkz/submit_vaapi_overlay-v2
Pull-Request: https://github.com/ffstaging/FFmpeg/pull/42

Range-diff vs v1:

  1:  6ec5e9960b =  1:  6ec5e9960b avfilter/overlay_vaapi: use 
FILTER_SINGLE_PIXFMT
  2:  3c1629de97 =  2:  3c1629de97 avfilter/overlay_vaapi: build filter params 
just once
  3:  2bd535abb5 =  3:  2bd535abb5 avfilter/overlay_vaapi: remove double 
framesync init
  4:  fb365de036 =  4:  fb365de036 avfilter/overlay_vaapi: handle secondary 
null input
  5:  6624c66688 =  5:  6624c66688 avfilter/overlay_vaapi: reformat options
  6:  989f16597e =  6:  989f16597e avfilter/overlay_vaapi: remove redundant 
.get_buffer assignments
  7:  5ff8f82002 =  7:  5ff8f82002 avfilter/overlay_vaapi: add framesync options
  8:  4fba07d9f9 =  8:  4fba07d9f9 avfilter/overlay_vaapi: precalculate 
blend_state, enable pixel alpha
  9:  36ed7b96eb !  9:  20b9e9c992 avfilter/overlay_vaapi: enable expressions 
for overlay parameters
 @@ libavfilter/vf_overlay_vaapi.c
  +#include "libavutil/eval.h"
  +
  +enum var_name {
 -+VAR_MAIN_iW, VAR_MW,
 -+VAR_MAIN_iH, VAR_MH,
 -+VAR_OVERLAY_iW,
 -+VAR_OVERLAY_iH,
 ++VAR_MAIN_IW, VAR_MW,
 ++VAR_MAIN_IH, VAR_MH,
 ++VAR_OVERLAY_IW,
 ++VAR_OVERLAY_IH,
  +VAR_OVERLAY_X,  VAR_OX,
  +VAR_OVERLAY_Y,  VAR_OY,
  +VAR_OVERLAY_W,  VAR_OW,
 @@ libavfilter/vf_overlay_vaapi.c: static int 
have_alpha_planar(AVFilterLink *link)
  +AVFilterContext  *avctx  = inlink->dst;
  +OverlayVAAPIContext *ctx = avctx->priv;
  +
 -+ctx->var_values[VAR_MAIN_iW] =
 ++ctx->var_values[VAR_MAIN_IW] =
  +ctx->var_values[VAR_MW]  = inlink->w;
 -+ctx->var_values[VAR_MAIN_iH] =
 ++ctx->var_values[VAR_MAIN_IH] =
  +ctx->var_values[VAR_MH]  = inlink->h;
  +
  +return ff_vaapi_vpp_config_input(inlink);
 @@ libavfilter/vf_overlay_vaapi.c: static int 
have_alpha_planar(AVFilterLink *link)
   OverlayVAAPIContext *ctx = avctx->priv;
  +int ret;
  +
 -+ctx->var_values[VAR_OVERLAY_iW] = inlink->w;
 -+ctx->var_values[VAR_OVERLAY_iH] = inlink->h;
 ++ctx->var_values[VAR_OVERLAY_IW] = inlink->w;
 ++ctx->var_values[VAR_OVERLAY_IH] = inlink->h;
  +
  +ret = eval_expr(avctx);
  +if (ret < 0)
 10:  3618b3e941 = 10:  be57f70a9d doc/filters.texi: remove incorrect statement
 11:  675b5279c3 ! 11:  b3ea03e037 doc/filters.texi: update overlay_vaapi 
documentation
 @@ doc/filters.texi: It takes two inputs and has one output. The first 
input is the
  +Set expressions for the width and height the overlaid video
  +on the main video.
  +
 ++Default values are 'overlay_iw' for 'w' and 'overlay_ih*w/overlay_iw' 
for 'h'.
 ++
  +The expressions can contain the following parameters:
  +
  +@table @option

-- 
ffmpeg-codebot
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH v9 00/25] Subtitle Filtering 2022

2022-10-25 Thread ffmpegagent

Subtitle Filtering 2022
===

This is a substantial update to the earlier subtitle filtering patch series.
A primary goal has been to address others' concerns as much as possible on
one side and to provide more clarity and control over the way things are
working. Clarity is is specifically important to allow for a better
understanding of the need for a subtitle start pts value that can be
different from the frame's pts value. This is done by refactoring the
subtitle timing fields in AVFrame, adding a frame field to indicate repeated
subtitle frames, and finally the full removal of the heartbeat
functionality, replaced by a new 'subfeed' filter that provides different
modes for arbitrating subtitle frames in a filter graph. Finally, each
subtitle filter's documentation has been amended by a section describing the
filter's timeline behavior (in v3 update).


Subtitle Filtering Demos


I published a demonstration of subtitle filtering capabilities with OCR,
text and bitmap subtitle manipulation involved: Demo 1: Text-Manipulation
with Bitmap Subtitles
[https://github.com/softworkz/SubtitleFilteringDemos/tree/master/Demo1]


v9
==

 * Cleared the cc recipient list
 * Resending after e-mail error


v8
==

 * Rebased and adapted to upstream changes


v7
==

 * Revert loglevel change
 * snull: propagate format
 * fftools/ffmpeg: ensure monotonic (frame-)pts values for subtitles


v6 - Fix assertion errors
=

 * text2graphicsub: fix null point on uninit after error
 * strim: propagate width and height
 * avfilter: add default propagation time_base from inlink to outlink


v5 - Conversion to Graphic Subtitles, and other enhancements


 * I'm glad to announce that Traian (@tcoza) has joined the project and
   contributed a new 'text2graphicsub' filter to convert text subtitles to
   graphic subtitles, which can in turn be encoded as dvd, dvb or x-subs
   (and any other encoder for graphic subs that might be added in the
   future). This filter closes the last open "gap" in subtitle processing.
 * stripstyles filter: now allows very fine-grained control over which ASS
   style codes should be preserved or stripped
 * stripstyles: do not drop dialog margin values
 * subfeed filter: eliminates duplicate frames with duplicate start times
   when 'fix_overlap' is specified
 * textmod: do not drop effect values
 * graphicsub2text: reduce font size jitter
 * ass_split: add function to selectively preserve elements when splitting
 * add strim, snull and ssink and further unify subtitle frame handling with
   audio and video
 * ffmpeg_filter: get simple filter notation working for subtitles


v4 - Quality Improvements
=

 * finally an updated version
 * includes many improvements from internal testing
 * all FATE tests passed
 * all example commands from the docs verified to work
 * can't list all the detail changes..
 * I have left out the extra commits which can be handled separately, just
   in case somebody wonders why these are missing:
   * avcodec/webvttenc: Don't encode drawing codes and empty lines
   * avcodec/webvttenc: convert hard-space tags to  
   * avutil/ass_split: Add parsing of hard-space tags (\h)
   * avutil/ass_split: Treat all content in curly braces as hidden
   * avutil/ass_split: Fix ass parsing of style codes with comments


v3 - Rebase
===

due to merge conflicts - apologies.


Changes in v2
=

 * added .gitattributes file to enforce binary diffs for the test refs that
   cannot be applied when being sent via e-mail
 * perform filter graph re-init due to subtitle "frame size" change only
   when the size was unknown before and not set via -canvas_size
 * overlaytextsubs: Make sure to request frames on the subtitle input
 * avfilter/splitcc: Start parsing cc data on key frames only
 * avcodec/webvttenc: Don't encode ass drawing codes and empty lines
 * stripstyles: fix mem leak
 * gs2t: improve color detection
 * gs2t: empty frames must not be skipped
 * subfeed: fix name
 * textmod: preserve margins
 * added .gitattributes file to enforce binary diffs for the test refs that
   cannot be applied when being sent via e-mail
 * perform filter graph re-init due to subtitle "frame size" change only
   when the size was unknown before and not set via -canvas_size
 * avcodec/dvbsubdec: Fix conditions for fallback to default resolution
 * Made changes suggested by Andreas
 * Fixed failing command line reported by Michael

Changes from previous version v24:


AVFrame
===

 * Removed sub_start_time The start time is now added to the subtitle
   start_pts during decoding The sub_end_time field is adjusted accordingly
 * Renamed sub_end_time to duration which it is effectively after removing
   the start_time
 * Added a sub-struct 'subtitle_timing' to av frame Contains subtitle_pts
   renamed to 'subtitle_timing.start_pts' and 'subtitle_

[FFmpeg-devel] [PATCH v6 0/3] Implement SEI parsing for QSV decoders

2022-10-24 Thread ffmpegagent
Missing SEI information has always been a major drawback when using the QSV
decoders. It turned out that there's a hardly known api method that provides
access to all SEI (h264/hevc) or user data (mpeg2video).

This allows to get things like closed captions, frame packing, display
orientation, HDR data (mastering display, content light level, etc.) without
having to rely on those data being provided by the MSDK as extended buffers.

The commit "Implement SEI parsing for QSV decoders" includes some hard-coded
workarounds for MSDK bugs which I reported:
https://github.com/Intel-Media-SDK/MediaSDK/issues/2597#issuecomment-1072795311
If someone is interested in the details please contact me directly.

v5

 * Split out the first two commits as a separate patchset
   https://github.com/ffstaging/FFmpeg/pull/44
 * For mpeg12, parse A53 data in qsvdec directly
 * For h264 and hevc, factor out ff_hxxx_set_sei_to_frame functions to avoid
   being dependent on the full decoder contexts
 * Ensure sufficient padding for get_bits API
 * Addresses all points (1, 2, 3, 4) made by Andreas
   
https://patchwork.ffmpeg.org/project/ffmpeg/cover/pull.31.v5.ffstaging.ffmpeg.1656708534.ffmpegag...@gmail.com/

v4

 * add new dependencies in makefile Now, build still works when someone uses
   configure --disable-decoder=h264 --disable-decoder=hevc
   --disable-decoder=mpegvideo --disable-decoder=mpeg1video
   --disable-decoder=mpeg2video --enable-libmfx

v3

 * frame.h: clarify doc text for av_frame_copy_side_data()

v2

 * qsvdec: make error handling consistent and clear
 * qsvdec: remove AV_CODEC_ID_MPEG1VIDEO constants
 * hevcdec: rename function to ff_hevc_set_side_data(), add doc text

v3

 * qsvdec: fix c/p error

softworkz (3):
  avcodec/hevcdec: factor out ff_hevc_set_set_to_frame
  avcodec/h264dec: make h264_export_frame_props() accessible
  avcodec/qsvdec: Implement SEI parsing for QSV decoders

 libavcodec/Makefile |   2 +-
 libavcodec/h264_sei.c   | 197 
 libavcodec/h264_sei.h   |   2 +
 libavcodec/h264_slice.c | 190 +---
 libavcodec/hevc_sei.c   | 252 +++
 libavcodec/hevc_sei.h   |   3 +
 libavcodec/hevcdec.c| 249 +--
 libavcodec/qsvdec.c | 321 
 8 files changed, 782 insertions(+), 434 deletions(-)


base-commit: 882a17068fd8e62c7d38c14e6fb160d7c9fc446a
Published-As: 
https://github.com/ffstaging/FFmpeg/releases/tag/pr-ffstaging-31%2Fsoftworkz%2Fsubmit_qsv_sei-v6
Fetch-It-Via: git fetch https://github.com/ffstaging/FFmpeg 
pr-ffstaging-31/softworkz/submit_qsv_sei-v6
Pull-Request: https://github.com/ffstaging/FFmpeg/pull/31

Range-diff vs v5:

 1:  7656477360 < -:  -- avutil/frame: Add av_frame_copy_side_data() 
and av_frame_remove_all_side_data()
 2:  06976606c5 < -:  -- avcodec/vpp_qsv: Copy side data from input to 
output frame
 3:  320a8a535c < -:  -- avcodec/mpeg12dec: make 
mpeg_decode_user_data() accessible
 4:  e58ad6564f ! 1:  4e9adcd90a avcodec/hevcdec: make set_side_data() 
accessible
 @@ Metadata
  Author: softworkz 
  
   ## Commit message ##
 -avcodec/hevcdec: make set_side_data() accessible
 +avcodec/hevcdec: factor out ff_hevc_set_set_to_frame
  
  Signed-off-by: softworkz 
  
 - ## libavcodec/hevcdec.c ##
 -@@ libavcodec/hevcdec.c: error:
 - return res;
 - }
 + ## libavcodec/hevc_sei.c ##
 +@@
 + #include "hevc_ps.h"
 + #include "hevc_sei.h"
   
 --static int set_side_data(HEVCContext *s)
 -+int ff_hevc_set_side_data(AVCodecContext *logctx, HEVCSEI *sei, 
HEVCContext *s, AVFrame *out)
 ++#include "libavutil/display.h"
 ++#include "libavutil/film_grain_params.h"
 ++#include "libavutil/mastering_display_metadata.h"
 ++#include "libavutil/stereo3d.h"
 ++#include "libavutil/timecode.h"
 ++
 + static int decode_nal_sei_decoded_picture_hash(HEVCSEIPictureHash *s,
 +GetByteContext *gb)
   {
 --AVFrame *out = s->ref->frame;
 --int ret;
 -+int ret = 0;
 - 
 --if (s->sei.frame_packing.present &&
 --s->sei.frame_packing.arrangement_type >= 3 &&
 --s->sei.frame_packing.arrangement_type <= 5 &&
 --s->sei.frame_packing.content_interpretation_type > 0 &&
 --s->sei.frame_packing.content_interpretation_type < 3) {
 +@@ libavcodec/hevc_sei.c: void ff_hevc_reset_sei(HEVCSEI *s)
 + av_buffer_unref(&s->dynamic_hdr_plus.info);
 + av_buffer_unref(&s->dynamic_hdr_vivid.info);
 + }
 ++
 ++int ff_hevc_set_sei_to_frame(AVCodecContext *logctx, HEVCSEI *sei, 
AVFrame *out, AVRational framerate, uint64_t seed, const VUI *vui, int 
bit_depth_luma, int bit_depth_chroma)
 ++{
  +if (sei->frame_packing.present &&
  +sei->frame_packing.arrangement_t

[FFmpeg-devel] [PATCH 0/2] QSV Overlay Filter: Copy side data from input to output frame

2022-10-24 Thread ffmpegagent
This is split out from my earlier patchset "SEI parsing for QSV decoders"
(https://github.com/ffstaging/FFmpeg/pull/31) as it is only logically
related but not technically.

The first patch had been reviewed and partially authored by Anton (I have
indicated this with a signed-off line, please advise in case this wouldn't
be right)

The second patch performs the copying of side data from input to output
frames.

softworkz

softworkz (2):
  avutil/frame: Add av_frame_copy_side_data() and
av_frame_remove_all_side_data()
  avcodec/vpp_qsv: Copy side data from input to output frame

 doc/APIchanges   |  4 +++
 libavfilter/qsvvpp.c |  6 
 libavfilter/vf_overlay_qsv.c | 19 +++---
 libavutil/frame.c| 67 ++--
 libavutil/frame.h| 32 +
 libavutil/version.h  |  4 +--
 6 files changed, 100 insertions(+), 32 deletions(-)


base-commit: 882a17068fd8e62c7d38c14e6fb160d7c9fc446a
Published-As: 
https://github.com/ffstaging/FFmpeg/releases/tag/pr-ffstaging-44%2Fsoftworkz%2Fsubmit_copy_sidedata-v1
Fetch-It-Via: git fetch https://github.com/ffstaging/FFmpeg 
pr-ffstaging-44/softworkz/submit_copy_sidedata-v1
Pull-Request: https://github.com/ffstaging/FFmpeg/pull/44
-- 
ffmpeg-codebot
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH v2 0/2] Print filter input/output formats in help output

2022-10-11 Thread ffmpegagent
Example output for command: ffmpeg -h filters=overlay

Filter overlay
  Overlay a video source on top of the input.
slice threading supported
Inputs:
   #0: main (video), Formats: Dynamic, Default: [yuv420p, yuvj420p, 
yuva420p, nv12, nv21]
   #1: overlay (video), Formats: Dynamic, Default: [yuva420p]
Outputs:
   #0: default (video), Formats: Dynamic, Default: [yuv420p, yuvj420p, 
yuva420p, nv12, nv21]

overlay AVOptions:
[...]



Examples for what it prints in various cases


For pass-through filter links

"All (passthrough)"


For filters using query_formats

"Dynamic"


For filters using query_formats where a call to query_formats succeeds

"Dynamic, Default: [yuv420p, yuvj420p, yuva420p, nv12, nv21]"


For all other cases

"[s16p, s32p, fltp, dblp]"


Except when all formats are supported (number of formats equals number of
available formats)

"All"




v2: rebase and fix compiler warnings

softworkz (2):
  avfilter/avfilter: add avfilter_print_config_formats()
  ftools/opt_common: Print filter input/output formats in help output

 doc/APIchanges  |   3 ++
 fftools/opt_common.c|  37 +
 libavfilter/avfilter.c  | 102 +++-
 libavfilter/avfilter.h  |  12 +
 libavfilter/avfiltergraph.c |  15 --
 libavfilter/internal.h  |   9 
 libavfilter/version.h   |   4 +-
 7 files changed, 163 insertions(+), 19 deletions(-)


base-commit: 479747645f795b6f4f376578ea1556409f943c31
Published-As: 
https://github.com/ffstaging/FFmpeg/releases/tag/pr-ffstaging-43%2Fsoftworkz%2Fsubmit_print_formats-v2
Fetch-It-Via: git fetch https://github.com/ffstaging/FFmpeg 
pr-ffstaging-43/softworkz/submit_print_formats-v2
Pull-Request: https://github.com/ffstaging/FFmpeg/pull/43

Range-diff vs v1:

 1:  c9496ca671 ! 1:  5ae347e40c avfilter/avfilter: add 
avfilter_print_config_formats()
 @@ doc/APIchanges: libavutil: 2021-04-27
   
  +2022-10-11 - xx - lavf 59.50.100 - avfilter.h
  +  Add add avfilter_print_config_formats().
 -+
 - 2022-10-05 - 37d5ddc317 - lavu 57.39.100 - cpu.h
 -   Add AV_CPU_FLAG_RVB_BASIC.
 ++  
 + 2022-10-11 - xx - lavu 57.39.101 - pixfmt.h
 +   Add AV_PIX_FMT_RGBF32 and AV_PIX_FMT_RGBAF32.
   
  
   ## libavfilter/avfilter.c ##
 @@ libavfilter/avfilter.c: void avfilter_link_free(AVFilterLink **link)
   av_freep(link);
   }
   
 -+static unsigned get_nb_pix_fmts()
 ++static unsigned get_nb_pix_fmts(void)
  +{
  +unsigned i = 0;
  +while (av_pix_fmt_desc_get(i++)) {}
  +return i - 1;
  +}
  +
 -+static unsigned get_nb_sample_fmts()
 ++static unsigned get_nb_sample_fmts(void)
  +{
  +unsigned i = 0;
  +while (av_get_sample_fmt_name(i++)) {}
 @@ libavfilter/avfiltergraph.c: static int query_formats(AVFilterGraph 
*graph, void
  -ret = filter_query_formats(f);
  -else
  -ret = ff_default_query_formats(f);
 ++
  +ret = ff_filter_query_formats(f);
   if (ret < 0 && ret != AVERROR(EAGAIN))
   return ret;
 2:  c99d278881 ! 2:  29389422a9 ftools/opt_common: Print filter input/output 
formats in help output
 @@ fftools/opt_common.c: static void show_help_filter(const char *name)
   {
   #if CONFIG_AVFILTER
   const AVFilter *f = avfilter_get_by_name(name);
 --int i, count;
  +AVBPrint bp;
 -+int i, count, ret;
 + int i, count;
   
   if (!name) {
 - av_log(NULL, AV_LOG_ERROR, "No filter name specified.\n");
  @@ fftools/opt_common.c: static void show_help_filter(const char *name)
   return;
   }

-- 
ffmpeg-codebot
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH 0/2] Print filter input/output formats in help output

2022-10-11 Thread ffmpegagent
Example out put for command: ffmpeg -h filters=overlay

Filter overlay
  Overlay a video source on top of the input.
slice threading supported
Inputs:
   #0: main (video), Formats: Dynamic, Default: [yuv420p, yuvj420p, 
yuva420p, nv12, nv21]
   #1: overlay (video), Formats: Dynamic, Default: [yuva420p]
Outputs:
   #0: default (video), Formats: Dynamic, Default: [yuv420p, yuvj420p, 
yuva420p, nv12, nv21]

overlay AVOptions:
[...]



Examples for what it prints in various cases



For pass-through filter links
=

"All (passthrough)"



For filters using query_formats
===

"Dynamic"



For filters using query_formats where a call to query_formats succeeds
==

"Dynamic, Default: [yuv420p, yuvj420p, yuva420p, nv12, nv21]"



For all other cases
===

"[s16p, s32p, fltp, dblp]"



Except in case when all formats are supported
=

(when the number of formats equals the number of available formats)

"All"


softworkz (2):
  avfilter/avfilter: add avfilter_print_config_formats()
  ftools/opt_common: Print filter input/output formats in help output

 doc/APIchanges  |   3 ++
 fftools/opt_common.c|  39 +-
 libavfilter/avfilter.c  | 102 +++-
 libavfilter/avfilter.h  |  12 +
 libavfilter/avfiltergraph.c |  14 +++--
 libavfilter/internal.h  |   9 
 libavfilter/version.h   |   4 +-
 7 files changed, 163 insertions(+), 20 deletions(-)


base-commit: e10e27a2ead8848648b29a1b397cc240206e9c3d
Published-As: 
https://github.com/ffstaging/FFmpeg/releases/tag/pr-ffstaging-43%2Fsoftworkz%2Fsubmit_print_formats-v1
Fetch-It-Via: git fetch https://github.com/ffstaging/FFmpeg 
pr-ffstaging-43/softworkz/submit_print_formats-v1
Pull-Request: https://github.com/ffstaging/FFmpeg/pull/43
-- 
ffmpeg-codebot
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH 00/11] Fixes and Enhancements for VAAPI Overlay

2022-10-10 Thread ffmpegagent
This patchset resolves a number of issues in the current code:

 * Bogus doubles framesync initialization
 * Executing build_parameters on each input frame
 * Segfault when there's no secondary input (yet)

and adds a number of enhancements to bring this on-par with the other
overlay filters:

 * Enable pixel alpha blending
 * Expose framesync parameters
 * Add support for expressions in overlay parameters (x, y, w, h)

softworkz (11):
  avfilter/overlay_vaapi: use FILTER_SINGLE_PIXFMT
  avfilter/overlay_vaapi: build filter params just once
  avfilter/overlay_vaapi: remove double framesync init
  avfilter/overlay_vaapi: handle secondary null input
  avfilter/overlay_vaapi: reformat options
  avfilter/overlay_vaapi: remove redundant .get_buffer assignments
  avfilter/overlay_vaapi: add framesync options
  avfilter/overlay_vaapi: precalculate blend_state, enable pixel alpha
  avfilter/overlay_vaapi: enable expressions for overlay parameters
  doc/filters.texi: remove incorrect statement
  doc/filters.texi: update overlay_vaapi documentation

 doc/filters.texi   |  50 +++--
 libavfilter/vf_overlay_vaapi.c | 328 ++---
 2 files changed, 257 insertions(+), 121 deletions(-)


base-commit: f3b5277057ad84071721f01419fe4badeceaff08
Published-As: 
https://github.com/ffstaging/FFmpeg/releases/tag/pr-ffstaging-42%2Fsoftworkz%2Fsubmit_vaapi_overlay-v1
Fetch-It-Via: git fetch https://github.com/ffstaging/FFmpeg 
pr-ffstaging-42/softworkz/submit_vaapi_overlay-v1
Pull-Request: https://github.com/ffstaging/FFmpeg/pull/42
-- 
ffmpeg-codebot
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH v2 0/2] libavformat/mov: Add support for exporting poster time.

2022-10-05 Thread ffmpegagent
Export the poster_time_location if available. The poster_time_location is
calculated using the poster_time / time_scale = X seconds. The value of
poster_time_location indicates where in the video the poster frame is.

Addresses feedback from
https://www.mail-archive.com/ffmpeg-devel@ffmpeg.org/msg138122.html.

Signed-off-by: Bryce Chester Newman bryce.new...@gettyimages.com

Bryce Chester Newman (2):
  libavformat/mov: Add support for exporting poster time.
  ibavformat/mov: Add support for exporting poster time.

 doc/demuxers.texi  |  6 ++
 libavformat/isom.h |  1 +
 libavformat/mov.c  | 13 +++--
 3 files changed, 18 insertions(+), 2 deletions(-)


base-commit: 5f02a261a2ddca7c79198869b45d35019baac819
Published-As: 
https://github.com/ffstaging/FFmpeg/releases/tag/pr-ffstaging-41%2Fbrycechesternewman%2Fadd_poster_time_location_mov-v2
Fetch-It-Via: git fetch https://github.com/ffstaging/FFmpeg 
pr-ffstaging-41/brycechesternewman/add_poster_time_location_mov-v2
Pull-Request: https://github.com/ffstaging/FFmpeg/pull/41

Range-diff vs v1:

 1:  c10a75a9ed = 1:  c10a75a9ed libavformat/mov: Add support for exporting 
poster time.
 -:  -- > 2:  c8f54a5d86 ibavformat/mov: Add support for exporting 
poster time.

-- 
ffmpeg-codebot
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH 0/3] Add option to log timing

2022-08-24 Thread ffmpegagent
This pathcset adds two logging flags: 'timing' and 'datetiming'.

Usage:

ffmpeg -loglevel +timing

or

ffmpeg -loglevel +datetiming

softworkz (3):
  avutil/log: support logging of date and timing information
  fftools/opt_common: add timing and datetiming log flags
  doc/fftools-common-opts: document log timing flags

 doc/APIchanges   |  3 +++
 doc/fftools-common-opts.texi |  4 
 fftools/opt_common.c | 12 
 libavutil/log.c  | 32 +---
 libavutil/log.h  | 10 ++
 libavutil/version.h  |  4 ++--
 6 files changed, 60 insertions(+), 5 deletions(-)


base-commit: 48cb2c7a8a2deca40dd2f143848dd5addc25465c
Published-As: 
https://github.com/ffstaging/FFmpeg/releases/tag/pr-ffstaging-37%2Fsoftworkz%2Fsubmit_logtiming-v1
Fetch-It-Via: git fetch https://github.com/ffstaging/FFmpeg 
pr-ffstaging-37/softworkz/submit_logtiming-v1
Pull-Request: https://github.com/ffstaging/FFmpeg/pull/37
-- 
ffmpeg-codebot
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH v3 0/4] Add derive-device function which searches for existing devices in both directions

2022-07-21 Thread ffmpegagent
This is an updated version of: [PATCH v4 1/1] avutils/hwcontext: When
deriving a hwdevice, search for existing device in both directions

There has been an objection that the earlier patchset would change API
behavior, and that this change should be limited to ffmpeg cli.

To achieve this, the API behavior is left unchanged now and a new function
av_hwdevice_ctx_get_or_create_derived() is added and used by the hwupload
and hwmap filters.

v2: Implemented concept for "weak references" to avoid circular reference
lockup.

v3: rebased due to conflicts

softworkz (4):
  avutil/buffer: add av_ref_from_buffer() function
  avutils/hwcontext: add derive-device function which searches for
existing devices in both directions
  lavu: bump minor version and add doc/APIchanges entry for
av_hwdevice_ctx_get_or_create_derived()
  avfilter/hwmap,hwupload: use new av_hwdevice_ctx_get_or_create_derived
method

 doc/APIchanges |   6 ++
 libavfilter/vf_hwmap.c |   4 +-
 libavfilter/vf_hwupload.c  |   2 +-
 libavutil/buffer.c |  16 
 libavutil/buffer.h |   8 ++
 libavutil/hwcontext.c  | 167 +++--
 libavutil/hwcontext.h  |  20 
 libavutil/hwcontext_internal.h |  11 +++
 libavutil/hwcontext_qsv.c  |  11 ++-
 libavutil/version.h|   2 +-
 10 files changed, 233 insertions(+), 14 deletions(-)


base-commit: f7d510b33ff33d2f5cb096017ee1c00f624cc138
Published-As: 
https://github.com/ffstaging/FFmpeg/releases/tag/pr-ffstaging-25%2Fsoftworkz%2Fderive_devices-v3
Fetch-It-Via: git fetch https://github.com/ffstaging/FFmpeg 
pr-ffstaging-25/softworkz/derive_devices-v3
Pull-Request: https://github.com/ffstaging/FFmpeg/pull/25

Range-diff vs v2:

 1:  e9c920c237 = 1:  b17a72426c avutil/buffer: add av_ref_from_buffer() 
function
 2:  bec8ccfcc2 = 2:  5cd017dfa7 avutils/hwcontext: add derive-device function 
which searches for existing devices in both directions
 3:  a2c8e79e8a ! 3:  03528fce43 lavu: bump minor version and add 
doc/APIchanges entry for av_hwdevice_ctx_get_or_create_derived()
 @@ doc/APIchanges: libavutil: 2021-04-27
   
   API changes, most recent first:
   
 -+2022-05-21 - xx - lavu 57.25.100 - hwcontext.h
 ++2022-07-01 - xx - lavu 57.31.100 - hwcontext.h
  +  Add av_hwdevice_ctx_get_or_create_derived().
  +
 -+2022-04-30 - xx - lavu 57.25.100 - buffer.h
 ++2022-07-01 - xx - lavu 57.31.100 - buffer.h
  +  Add av_ref_from_buffer().
  +
 - 2022-03-16 - xx - all libraries - version_major.h
 -   Add lib/version_major.h as new installed headers, which only
 -   contain the major version number (and corresponding API deprecation
 + 2022-07-xx - xx - lavu 57.30.100 - frame.h
 +   Add AVFrame.duration, deprecate AVFrame.pkt_duration.
 + 
  
   ## libavutil/version.h ##
  @@
*/
   
   #define LIBAVUTIL_VERSION_MAJOR  57
 --#define LIBAVUTIL_VERSION_MINOR  24
 --#define LIBAVUTIL_VERSION_MICRO 101
 -+#define LIBAVUTIL_VERSION_MINOR  25
 -+#define LIBAVUTIL_VERSION_MICRO 100
 +-#define LIBAVUTIL_VERSION_MINOR  30
 ++#define LIBAVUTIL_VERSION_MINOR  31
 + #define LIBAVUTIL_VERSION_MICRO 100
   
   #define LIBAVUTIL_VERSION_INT   AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \
 -LIBAVUTIL_VERSION_MINOR, \
 4:  d0957afde6 = 4:  7ee28b7c25 avfilter/hwmap,hwupload: use new 
av_hwdevice_ctx_get_or_create_derived method

-- 
ffmpeg-codebot
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH v5 0/6] Implement SEI parsing for QSV decoders

2022-07-01 Thread ffmpegagent
Missing SEI information has always been a major drawback when using the QSV
decoders. I used to think that there's no chance to get at the data without
explicit implementation from the MSDK side (or doing something weird like
parsing in parallel). It turned out that there's a hardly known api method
that provides access to all SEI (h264/hevc) or user data (mpeg2video).

This allows to get things like closed captions, frame packing, display
orientation, HDR data (mastering display, content light level, etc.) without
having to rely on those data being provided by the MSDK as extended buffers.

The commit "Implement SEI parsing for QSV decoders" includes some hard-coded
workarounds for MSDK bugs which I reported:
https://github.com/Intel-Media-SDK/MediaSDK/issues/2597#issuecomment-1072795311

But that doesn't help. Those bugs exist and I'm sharing my workarounds,
which are empirically determined by testing a range of files. If someone is
interested, I can provide private access to a repository where we have been
testing this. Alternatively, I could also leave those workarounds out, and
just skip those SEI types.

In a previous version of this patchset, there was a concern that payload
data might need to be re-ordered. Meanwhile I have researched this carefully
and the conclusion is that this is not required.

My detailed analysis can be found here:
https://gist.github.com/softworkz/36c49586a8610813a32270ee3947a932

v4

 * add new dependencies in makefile Now, build still works when someone uses
   configure --disable-decoder=h264 --disable-decoder=hevc
   --disable-decoder=mpegvideo --disable-decoder=mpeg1video
   --disable-decoder=mpeg2video --enable-libmfx

v3

 * frame.h: clarify doc text for av_frame_copy_side_data()

v2

 * qsvdec: make error handling consistent and clear
 * qsvdec: remove AV_CODEC_ID_MPEG1VIDEO constants
 * hevcdec: rename function to ff_hevc_set_side_data(), add doc text

v3

 * qsvdec: fix c/p error

softworkz (6):
  avutil/frame: Add av_frame_copy_side_data() and
av_frame_remove_all_side_data()
  avcodec/vpp_qsv: Copy side data from input to output frame
  avcodec/mpeg12dec: make mpeg_decode_user_data() accessible
  avcodec/hevcdec: make set_side_data() accessible
  avcodec/h264dec: make h264_export_frame_props() accessible
  avcodec/qsvdec: Implement SEI parsing for QSV decoders

 doc/APIchanges   |   4 +
 libavcodec/Makefile  |   6 +-
 libavcodec/h264_slice.c  |  98 ---
 libavcodec/h264dec.h |   2 +
 libavcodec/hevcdec.c | 117 +-
 libavcodec/hevcdec.h |   9 ++
 libavcodec/hevcdsp.c |   4 +
 libavcodec/mpeg12.h  |  28 +
 libavcodec/mpeg12dec.c   |  40 +-
 libavcodec/qsvdec.c  | 234 +++
 libavfilter/qsvvpp.c |   6 +
 libavfilter/vf_overlay_qsv.c |  19 ++-
 libavutil/frame.c|  67 ++
 libavutil/frame.h|  32 +
 libavutil/version.h  |   2 +-
 15 files changed, 494 insertions(+), 174 deletions(-)


base-commit: 6a82412bf33108111eb3f63076fd5a51349ae114
Published-As: 
https://github.com/ffstaging/FFmpeg/releases/tag/pr-ffstaging-31%2Fsoftworkz%2Fsubmit_qsv_sei-v5
Fetch-It-Via: git fetch https://github.com/ffstaging/FFmpeg 
pr-ffstaging-31/softworkz/submit_qsv_sei-v5
Pull-Request: https://github.com/ffstaging/FFmpeg/pull/31

Range-diff vs v4:

 1:  7656477360 = 1:  7656477360 avutil/frame: Add av_frame_copy_side_data() 
and av_frame_remove_all_side_data()
 2:  06976606c5 = 2:  06976606c5 avcodec/vpp_qsv: Copy side data from input to 
output frame
 3:  320a8a535c = 3:  320a8a535c avcodec/mpeg12dec: make 
mpeg_decode_user_data() accessible
 4:  e58ad6564f = 4:  e58ad6564f avcodec/hevcdec: make set_side_data() 
accessible
 5:  a57bfaebb9 = 5:  4c0b6eb4cb avcodec/h264dec: make 
h264_export_frame_props() accessible
 6:  3f2588563e ! 6:  19bc00be4d avcodec/qsvdec: Implement SEI parsing for QSV 
decoders
 @@ Commit message
  
  Signed-off-by: softworkz 
  
 + ## libavcodec/Makefile ##
 +@@ libavcodec/Makefile: OBJS-$(CONFIG_MSS34DSP)+= 
mss34dsp.o
 + OBJS-$(CONFIG_PIXBLOCKDSP) += pixblockdsp.o
 + OBJS-$(CONFIG_QPELDSP) += qpeldsp.o
 + OBJS-$(CONFIG_QSV) += qsv.o
 +-OBJS-$(CONFIG_QSVDEC)  += qsvdec.o
 ++OBJS-$(CONFIG_QSVDEC)  += qsvdec.o h264_slice.o 
h264_cabac.o h264_cavlc.o \
 ++  h264_direct.o h264_mb.o 
h264_picture.o h264_loopfilter.o \
 ++  h264dec.o h264_refs.o cabac.o 
hevcdec.o hevc_refs.o \
 ++ 
  hevc_filter.o hevc_cabac.o hevc_mvs.o hevcpred.o hevcdsp.o \
 ++ 
  h274.o dovi_rpu.o mpeg12dec.o
 + OBJS-$(CONFIG_Q

[FFmpeg-devel] [PATCH v4 0/6] Implement SEI parsing for QSV decoders

2022-06-26 Thread ffmpegagent
Missing SEI information has always been a major drawback when using the QSV
decoders. I used to think that there's no chance to get at the data without
explicit implementation from the MSDK side (or doing something weird like
parsing in parallel). It turned out that there's a hardly known api method
that provides access to all SEI (h264/hevc) or user data (mpeg2video).

This allows to get things like closed captions, frame packing, display
orientation, HDR data (mastering display, content light level, etc.) without
having to rely on those data being provided by the MSDK as extended buffers.

The commit "Implement SEI parsing for QSV decoders" includes some hard-coded
workarounds for MSDK bugs which I reported:
https://github.com/Intel-Media-SDK/MediaSDK/issues/2597#issuecomment-1072795311

But that doesn't help. Those bugs exist and I'm sharing my workarounds,
which are empirically determined by testing a range of files. If someone is
interested, I can provide private access to a repository where we have been
testing this. Alternatively, I could also leave those workarounds out, and
just skip those SEI types.

In a previous version of this patchset, there was a concern that payload
data might need to be re-ordered. Meanwhile I have researched this carefully
and the conclusion is that this is not required.

My detailed analysis can be found here:
https://gist.github.com/softworkz/36c49586a8610813a32270ee3947a932

v3

 * frame.h: clarify doc text for av_frame_copy_side_data()

v2

 * qsvdec: make error handling consistent and clear
 * qsvdec: remove AV_CODEC_ID_MPEG1VIDEO constants
 * hevcdec: rename function to ff_hevc_set_side_data(), add doc text

v3

 * qsvdec: fix c/p error

softworkz (6):
  avutil/frame: Add av_frame_copy_side_data() and
av_frame_remove_all_side_data()
  avcodec/vpp_qsv: Copy side data from input to output frame
  avcodec/mpeg12dec: make mpeg_decode_user_data() accessible
  avcodec/hevcdec: make set_side_data() accessible
  avcodec/h264dec: make h264_export_frame_props() accessible
  avcodec/qsvdec: Implement SEI parsing for QSV decoders

 doc/APIchanges   |   4 +
 libavcodec/h264_slice.c  |  98 ---
 libavcodec/h264dec.h |   2 +
 libavcodec/hevcdec.c | 117 +-
 libavcodec/hevcdec.h |   9 ++
 libavcodec/mpeg12.h  |  28 +
 libavcodec/mpeg12dec.c   |  40 +-
 libavcodec/qsvdec.c  | 234 +++
 libavfilter/qsvvpp.c |   6 +
 libavfilter/vf_overlay_qsv.c |  19 ++-
 libavutil/frame.c|  67 ++
 libavutil/frame.h|  32 +
 libavutil/version.h  |   2 +-
 13 files changed, 485 insertions(+), 173 deletions(-)


base-commit: 6a82412bf33108111eb3f63076fd5a51349ae114
Published-As: 
https://github.com/ffstaging/FFmpeg/releases/tag/pr-ffstaging-31%2Fsoftworkz%2Fsubmit_qsv_sei-v4
Fetch-It-Via: git fetch https://github.com/ffstaging/FFmpeg 
pr-ffstaging-31/softworkz/submit_qsv_sei-v4
Pull-Request: https://github.com/ffstaging/FFmpeg/pull/31

Range-diff vs v3:

 1:  c442597a35 ! 1:  7656477360 avutil/frame: Add av_frame_copy_side_data() 
and av_frame_remove_all_side_data()
 @@ doc/APIchanges: libavutil: 2021-04-27
   
   API changes, most recent first:
   
 -+2022-05-26 - x - lavu 57.26.100 - frame.h
 ++2022-05-26 - x - lavu 57.28.100 - frame.h
  +  Add av_frame_remove_all_side_data(), av_frame_copy_side_data(),
  +  AV_FRAME_TRANSFER_SD_COPY, and AV_FRAME_TRANSFER_SD_FILTER.
  +
 - 2022-05-23 - x - lavu 57.25.100 - avutil.h
 -   Deprecate av_fopen_utf8() without replacement.
 - 
 + 2022-06-12 - xx - lavf 59.25.100 - avio.h
 +   Add avio_vprintf(), similar to avio_printf() but allow to use it
 +   from within a function taking a variable argument list as input.
  
   ## libavutil/frame.c ##
  @@ libavutil/frame.c: FF_ENABLE_DEPRECATION_WARNINGS
 @@ libavutil/frame.h: int av_frame_copy(AVFrame *dst, const AVFrame *src);
  + * @param src a frame from which to copy the side data.
  + * @param flags a combination of AV_FRAME_TRANSFER_SD_*
  + *
 -+ * @return >= 0 on success, a negative AVERROR on error.
 ++ * @return 0 on success, a negative AVERROR on error.
  + *
  + * @note This function will create new references to side data buffers 
in src,
  + * unless the AV_FRAME_TRANSFER_SD_COPY flag is passed.
 @@ libavutil/version.h
*/
   
   #define LIBAVUTIL_VERSION_MAJOR  57
 --#define LIBAVUTIL_VERSION_MINOR  25
 -+#define LIBAVUTIL_VERSION_MINOR  26
 +-#define LIBAVUTIL_VERSION_MINOR  27
 ++#define LIBAVUTIL_VERSION_MINOR  28
   #define LIBAVUTIL_VERSION_MICRO 100
   
   #define LIBAVUTIL_VERSION_INT   AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \
 2:  6f50d0bd57 = 2:  06976606c5 avcodec/vpp_qsv: Copy side data from input to 
output frame
 3:  f682b1d6

[FFmpeg-devel] [PATCH v6 00/25] Subtitle Filtering 2022

2022-06-26 Thread ffmpegagent

Subtitle Filtering 2022
===

This is a substantial update to the earlier subtitle filtering patch series.
A primary goal has been to address others' concerns as much as possible on
one side and to provide more clarity and control over the way things are
working. Clarity is is specifically important to allow for a better
understanding of the need for a subtitle start pts value that can be
different from the frame's pts value. This is done by refactoring the
subtitle timing fields in AVFrame, adding a frame field to indicate repeated
subtitle frames, and finally the full removal of the heartbeat
functionality, replaced by a new 'subfeed' filter that provides different
modes for arbitrating subtitle frames in a filter graph. Finally, each
subtitle filter's documentation has been amended by a section describing the
filter's timeline behavior (in v3 update).


Subtitle Filtering Demos


I published a demonstration of subtitle filtering capabilities with OCR,
text and bitmap subtitle manipulation involved: Demo 1: Text-Manipulation
with Bitmap Subtitles
[https://github.com/softworkz/SubtitleFilteringDemos/tree/master/Demo1]


v6 - Fix assertion errors
=

 * text2graphicsub: fix null point on uninit after error
 * strim: propagate width and height
 * avfilter: add default propagation time_base from inlink to outlink


v5 - Conversion to Graphic Subtitles, and other enhancements


 * I'm glad to announce that Traian (@tcoza) has joined the project and
   contributed a new 'text2graphicsub' filter to convert text subtitles to
   graphic subtitles, which can in turn be encoded as dvd, dvb or x-subs
   (and any other encoder for graphic subs that might be added in the
   future). This filter closes the last open "gap" in subtitle processing.
 * stripstyles filter: now allows very fine-grained control over which ASS
   style codes should be preserved or stripped
 * stripstyles: do not drop dialog margin values
 * subfeed filter: eliminates duplicate frames with duplicate start times
   when 'fix_overlap' is specified
 * textmod: do not drop effect values
 * graphicsub2text: reduce font size jitter
 * ass_split: add function to selectively preserve elements when splitting
 * add strim, snull and ssink and further unify subtitle frame handling with
   audio and video
 * ffmpeg_filter: get simple filter notation working for subtitles


v4 - Quality Improvements
=

 * finally an updated version
 * includes many improvements from internal testing
 * all FATE tests passed
 * all example commands from the docs verified to work
 * can't list all the detail changes..
 * I have left out the extra commits which can be handled separately, just
   in case somebody wonders why these are missing:
   * avcodec/webvttenc: Don't encode drawing codes and empty lines
   * avcodec/webvttenc: convert hard-space tags to  
   * avutil/ass_split: Add parsing of hard-space tags (\h)
   * avutil/ass_split: Treat all content in curly braces as hidden
   * avutil/ass_split: Fix ass parsing of style codes with comments


v3 - Rebase
===

due to merge conflicts - apologies.


Changes in v2
=

 * added .gitattributes file to enforce binary diffs for the test refs that
   cannot be applied when being sent via e-mail
 * perform filter graph re-init due to subtitle "frame size" change only
   when the size was unknown before and not set via -canvas_size
 * overlaytextsubs: Make sure to request frames on the subtitle input
 * avfilter/splitcc: Start parsing cc data on key frames only
 * avcodec/webvttenc: Don't encode ass drawing codes and empty lines
 * stripstyles: fix mem leak
 * gs2t: improve color detection
 * gs2t: empty frames must not be skipped
 * subfeed: fix name
 * textmod: preserve margins
 * added .gitattributes file to enforce binary diffs for the test refs that
   cannot be applied when being sent via e-mail
 * perform filter graph re-init due to subtitle "frame size" change only
   when the size was unknown before and not set via -canvas_size
 * avcodec/dvbsubdec: Fix conditions for fallback to default resolution
 * Made changes suggested by Andreas
 * Fixed failing command line reported by Michael

Changes from previous version v24:


AVFrame
===

 * Removed sub_start_time The start time is now added to the subtitle
   start_pts during decoding The sub_end_time field is adjusted accordingly
 * Renamed sub_end_time to duration which it is effectively after removing
   the start_time
 * Added a sub-struct 'subtitle_timing' to av frame Contains subtitle_pts
   renamed to 'subtitle_timing.start_pts' and 'subtitle_timing.duration'
 * Change both fields to (fixed) time_base AV_TIMEBASE
 * add repeat_sub field provides a clear indication whether a subtitle frame
   is an actual subtitle event or a repeated subtitle frame in a filter
   graph


Heartbeat Removal
===

[FFmpeg-devel] [PATCH v5 00/25] Subtitle Filtering 2022

2022-06-25 Thread ffmpegagent

Subtitle Filtering 2022
===

This is a substantial update to the earlier subtitle filtering patch series.
A primary goal has been to address others' concerns as much as possible on
one side and to provide more clarity and control over the way things are
working. Clarity is is specifically important to allow for a better
understanding of the need for a subtitle start pts value that can be
different from the frame's pts value. This is done by refactoring the
subtitle timing fields in AVFrame, adding a frame field to indicate repeated
subtitle frames, and finally the full removal of the heartbeat
functionality, replaced by a new 'subfeed' filter that provides different
modes for arbitrating subtitle frames in a filter graph. Finally, each
subtitle filter's documentation has been amended by a section describing the
filter's timeline behavior (in v3 update).


Subtitle Filtering Demos


I published a demonstration of subtitle filtering capabilities with OCR,
text and bitmap subtitle manipulation involved: Demo 1: Text-Manipulation
with Bitmap Subtitles
[https://github.com/softworkz/SubtitleFilteringDemos/tree/master/Demo1]


v5 - Conversion to Graphic Subtitles, and other enhancements


 * I'm glad to announce that Traian (@tcoza) has joined the project and
   contributed a new 'text2graphicsub' filter to convert text subtitles to
   graphic subtitles, which can in turn be encoded as dvd, dvb or x-subs
   (and any other encoder for graphic subs that might be added in the
   future). This filter closes the last open "gap" in subtitle processing.
 * stripstyles filter: now allows very fine-grained control over which ASS
   style codes should be preserved or stripped
 * stripstyles: do not drop dialog margin values
 * subfeed filter: eliminates duplicate frames with duplicate start times
   when 'fix_overlap' is specified
 * textmod: do not drop effect values
 * graphicsub2text: reduce font size jitter
 * ass_split: add function to selectively preserve elements when splitting
 * add strim, snull and ssink and further unify subtitle frame handling with
   audio and video
 * ffmpeg_filter: get simple filter notation working for subtitles


v4 - Quality Improvements
=

 * finally an updated version
 * includes many improvements from internal testing
 * all FATE tests passed
 * all example commands from the docs verified to work
 * can't list all the detail changes..
 * I have left out the extra commits which can be handled separately, just
   in case somebody wonders why these are missing:
   * avcodec/webvttenc: Don't encode drawing codes and empty lines
   * avcodec/webvttenc: convert hard-space tags to  
   * avutil/ass_split: Add parsing of hard-space tags (\h)
   * avutil/ass_split: Treat all content in curly braces as hidden
   * avutil/ass_split: Fix ass parsing of style codes with comments


v3 - Rebase
===

due to merge conflicts - apologies.


Changes in v2
=

 * added .gitattributes file to enforce binary diffs for the test refs that
   cannot be applied when being sent via e-mail
 * perform filter graph re-init due to subtitle "frame size" change only
   when the size was unknown before and not set via -canvas_size
 * overlaytextsubs: Make sure to request frames on the subtitle input
 * avfilter/splitcc: Start parsing cc data on key frames only
 * avcodec/webvttenc: Don't encode ass drawing codes and empty lines
 * stripstyles: fix mem leak
 * gs2t: improve color detection
 * gs2t: empty frames must not be skipped
 * subfeed: fix name
 * textmod: preserve margins
 * added .gitattributes file to enforce binary diffs for the test refs that
   cannot be applied when being sent via e-mail
 * perform filter graph re-init due to subtitle "frame size" change only
   when the size was unknown before and not set via -canvas_size
 * avcodec/dvbsubdec: Fix conditions for fallback to default resolution
 * Made changes suggested by Andreas
 * Fixed failing command line reported by Michael

Changes from previous version v24:


AVFrame
===

 * Removed sub_start_time The start time is now added to the subtitle
   start_pts during decoding The sub_end_time field is adjusted accordingly
 * Renamed sub_end_time to duration which it is effectively after removing
   the start_time
 * Added a sub-struct 'subtitle_timing' to av frame Contains subtitle_pts
   renamed to 'subtitle_timing.start_pts' and 'subtitle_timing.duration'
 * Change both fields to (fixed) time_base AV_TIMEBASE
 * add repeat_sub field provides a clear indication whether a subtitle frame
   is an actual subtitle event or a repeated subtitle frame in a filter
   graph


Heartbeat Removal
=

 * completely removed the earlier heartbeat implementation
 * filtering arbitration is now implemented in a new filter: 'subfeed'
 * subfeed will be auto-inserted for compatiblity with sub2video command
   l

[FFmpeg-devel] [PATCH 0/2] lavfi/drawutils: improve colorspace support

2022-06-02 Thread ffmpegagent
This introduces ff_draw_init2, adding support for colorspaces other than
BT601 and explicit full/limited range configuration.

rcombs (2):
  lavfi/colorspace: add ff_matrix_mul_3x3_vec
  lavfi/drawutils: improve colorspace support

 libavfilter/colorspace.c  |  11 +
 libavfilter/colorspace.h  |   1 +
 libavfilter/drawutils.c   |  84 +--
 libavfilter/drawutils.h   |  26 +-
 tests/ref/fate/filter-chromashift-smear   |  10 +-
 tests/ref/fate/filter-chromashift-wrap|  10 +-
 tests/ref/fate/filter-decimate| 480 +-
 tests/ref/fate/filter-fps-down|  22 +-
 tests/ref/fate/filter-fps-down-eof-pass   |  22 +-
 tests/ref/fate/filter-fps-down-round-down |  20 +-
 tests/ref/fate/filter-fps-down-round-up   |  22 +-
 tests/ref/fate/filter-fps-start-drop  |  12 +-
 tests/ref/fate/filter-fps-start-fill  |  12 +-
 tests/ref/fate/filter-fps-up  |  28 +-
 tests/ref/fate/filter-fps-up-round-down   |  28 +-
 tests/ref/fate/filter-fps-up-round-up |  28 +-
 tests/ref/fate/filter-framerate-12bit-down| 100 ++--
 tests/ref/fate/filter-framerate-12bit-up  | 120 ++---
 tests/ref/fate/filter-framerate-down  |   2 +-
 tests/ref/fate/filter-framerate-up|  20 +-
 .../filter-metadata-signalstats-yuv420p10 |   2 +-
 tests/ref/fate/filter-minterpolate-down   |   2 +-
 tests/ref/fate/filter-minterpolate-up |  20 +-
 tests/ref/fate/filter-mpdecimate  |  40 +-
 tests/ref/fate/filter-overlay_yuv420p10   |   6 +-
 tests/ref/fate/filter-overlay_yuv422p10   |   6 +-
 tests/ref/fate/filter-pixfmts-pad |  84 +--
 tests/ref/fate/filter-pixfmts-tinterlace_pad  |  22 +-
 tests/ref/fate/filter-testsrc2-yuv420p| 140 ++---
 tests/ref/fate/filter-testsrc2-yuv444p| 140 ++---
 tests/ref/fate/filter-tpad-add|   4 +-
 tests/ref/fate/filter-tpad-clone  |   8 +-
 tests/ref/fate/filter-unsharp-yuv420p10   |  40 +-
 tests/ref/fate/filter-untile  |  16 +-
 34 files changed, 819 insertions(+), 769 deletions(-)


base-commit: c6364b711bad1fe2fbd90e5b2798f87080ddf5ea
Published-As: 
https://github.com/ffstaging/FFmpeg/releases/tag/pr-ffstaging-33%2Frcombs%2Fdrawutils-v1
Fetch-It-Via: git fetch https://github.com/ffstaging/FFmpeg 
pr-ffstaging-33/rcombs/drawutils-v1
Pull-Request: https://github.com/ffstaging/FFmpeg/pull/33
-- 
ffmpeg-codebot
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH v3 0/6] Implement SEI parsing for QSV decoders

2022-06-01 Thread ffmpegagent
Missing SEI information has always been a major drawback when using the QSV
decoders. I used to think that there's no chance to get at the data without
explicit implementation from the MSDK side (or doing something weird like
parsing in parallel). It turned out that there's a hardly known api method
that provides access to all SEI (h264/hevc) or user data (mpeg2video).

This allows to get things like closed captions, frame packing, display
orientation, HDR data (mastering display, content light level, etc.) without
having to rely on those data being provided by the MSDK as extended buffers.

The commit "Implement SEI parsing for QSV decoders" includes some hard-coded
workarounds for MSDK bugs which I reported:
https://github.com/Intel-Media-SDK/MediaSDK/issues/2597#issuecomment-1072795311

But that doesn't help. Those bugs exist and I'm sharing my workarounds,
which are empirically determined by testing a range of files. If someone is
interested, I can provide private access to a repository where we have been
testing this. Alternatively, I could also leave those workarounds out, and
just skip those SEI types.

In a previous version of this patchset, there was a concern that payload
data might need to be re-ordered. Meanwhile I have researched this carefully
and the conclusion is that this is not required.

My detailed analysis can be found here:
https://gist.github.com/softworkz/36c49586a8610813a32270ee3947a932

v2

 * qsvdec: make error handling consistent and clear
 * qsvdec: remove AV_CODEC_ID_MPEG1VIDEO constants
 * hevcdec: rename function to ff_hevc_set_side_data(), add doc text

v3

 * qsvdec: fix c/p error

softworkz (6):
  avutil/frame: Add av_frame_copy_side_data() and
av_frame_remove_all_side_data()
  avcodec/vpp_qsv: Copy side data from input to output frame
  avcodec/mpeg12dec: make mpeg_decode_user_data() accessible
  avcodec/hevcdec: make set_side_data() accessible
  avcodec/h264dec: make h264_export_frame_props() accessible
  avcodec/qsvdec: Implement SEI parsing for QSV decoders

 doc/APIchanges   |   4 +
 libavcodec/h264_slice.c  |  98 ---
 libavcodec/h264dec.h |   2 +
 libavcodec/hevcdec.c | 117 +-
 libavcodec/hevcdec.h |   9 ++
 libavcodec/mpeg12.h  |  28 +
 libavcodec/mpeg12dec.c   |  40 +-
 libavcodec/qsvdec.c  | 234 +++
 libavfilter/qsvvpp.c |   6 +
 libavfilter/vf_overlay_qsv.c |  19 ++-
 libavutil/frame.c|  67 ++
 libavutil/frame.h|  32 +
 libavutil/version.h  |   2 +-
 13 files changed, 485 insertions(+), 173 deletions(-)


base-commit: 77b529fbd228fe30a870e3157f051885b436ad92
Published-As: 
https://github.com/ffstaging/FFmpeg/releases/tag/pr-ffstaging-31%2Fsoftworkz%2Fsubmit_qsv_sei-v3
Fetch-It-Via: git fetch https://github.com/ffstaging/FFmpeg 
pr-ffstaging-31/softworkz/submit_qsv_sei-v3
Pull-Request: https://github.com/ffstaging/FFmpeg/pull/31

Range-diff vs v2:

 1:  4ee6cb47db = 1:  c442597a35 avutil/frame: Add av_frame_copy_side_data() 
and av_frame_remove_all_side_data()
 2:  3152156c97 = 2:  6f50d0bd57 avcodec/vpp_qsv: Copy side data from input to 
output frame
 3:  8082c3ab84 = 3:  f682b1d695 avcodec/mpeg12dec: make 
mpeg_decode_user_data() accessible
 4:  306bdaa39c = 4:  995d835233 avcodec/hevcdec: make set_side_data() 
accessible
 5:  16f5dfbfd1 = 5:  ac8dc06395 avcodec/h264dec: make 
h264_export_frame_props() accessible
 6:  23de6d2774 ! 6:  27c3dded4d avcodec/qsvdec: Implement SEI parsing for QSV 
decoders
 @@ libavcodec/qsvdec.c: static int qsv_export_film_grain(AVCodecContext 
*avctx, mfx
  +if (init_get_bits(&gb, &payload.Data[start], payload.NumBit - 
start * 8) < 0)
  +av_log(avctx, AV_LOG_ERROR, "Error initializing bitstream 
reader SEI type: %d  Numbits %d error: %d\n", payload.Type, payload.NumBit, 
ret);
  +else {
 -+ret = ff_h264_sei_decode(&sei, &gb, NULL, avctx);
 ++ret = ff_hevc_decode_nal_sei(&gb, avctx, &sei, &ps, 
HEVC_NAL_SEI_PREFIX);
  +
  +if (ret < 0)
  +av_log(avctx, AV_LOG_WARNING, "Failed to parse SEI type: 
%d  Numbits %d error: %d\n", payload.Type, payload.NumBit, ret);

-- 
ffmpeg-codebot
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH v2 0/6] Implement SEI parsing for QSV decoders

2022-06-01 Thread ffmpegagent
Missing SEI information has always been a major drawback when using the QSV
decoders. I used to think that there's no chance to get at the data without
explicit implementation from the MSDK side (or doing something weird like
parsing in parallel). It turned out that there's a hardly known api method
that provides access to all SEI (h264/hevc) or user data (mpeg2video).

This allows to get things like closed captions, frame packing, display
orientation, HDR data (mastering display, content light level, etc.) without
having to rely on those data being provided by the MSDK as extended buffers.

The commit "Implement SEI parsing for QSV decoders" includes some hard-coded
workarounds for MSDK bugs which I reported:
https://github.com/Intel-Media-SDK/MediaSDK/issues/2597#issuecomment-1072795311

But that doesn't help. Those bugs exist and I'm sharing my workarounds,
which are empirically determined by testing a range of files. If someone is
interested, I can provide private access to a repository where we have been
testing this. Alternatively, I could also leave those workarounds out, and
just skip those SEI types.

In a previous version of this patchset, there was a concern that payload
data might need to be re-ordered. Meanwhile I have researched this carefully
and the conclusion is that this is not required.

My detailed analysis can be found here:
https://gist.github.com/softworkz/36c49586a8610813a32270ee3947a932

v2

 * qsvdec: make error handling consistent and clear
 * qsvdec: remove AV_CODEC_ID_MPEG1VIDEO constants
 * hevcdec: rename function to ff_hevc_set_side_data(), add doc text

softworkz (6):
  avutil/frame: Add av_frame_copy_side_data() and
av_frame_remove_all_side_data()
  avcodec/vpp_qsv: Copy side data from input to output frame
  avcodec/mpeg12dec: make mpeg_decode_user_data() accessible
  avcodec/hevcdec: make set_side_data() accessible
  avcodec/h264dec: make h264_export_frame_props() accessible
  avcodec/qsvdec: Implement SEI parsing for QSV decoders

 doc/APIchanges   |   4 +
 libavcodec/h264_slice.c  |  98 ---
 libavcodec/h264dec.h |   2 +
 libavcodec/hevcdec.c | 117 +-
 libavcodec/hevcdec.h |   9 ++
 libavcodec/mpeg12.h  |  28 +
 libavcodec/mpeg12dec.c   |  40 +-
 libavcodec/qsvdec.c  | 234 +++
 libavfilter/qsvvpp.c |   6 +
 libavfilter/vf_overlay_qsv.c |  19 ++-
 libavutil/frame.c|  67 ++
 libavutil/frame.h|  32 +
 libavutil/version.h  |   2 +-
 13 files changed, 485 insertions(+), 173 deletions(-)


base-commit: b033913d1c5998a29dfd13e9906dd707ff6eff12
Published-As: 
https://github.com/ffstaging/FFmpeg/releases/tag/pr-ffstaging-31%2Fsoftworkz%2Fsubmit_qsv_sei-v2
Fetch-It-Via: git fetch https://github.com/ffstaging/FFmpeg 
pr-ffstaging-31/softworkz/submit_qsv_sei-v2
Pull-Request: https://github.com/ffstaging/FFmpeg/pull/31

Range-diff vs v1:

 1:  4ee6cb47db = 1:  4ee6cb47db avutil/frame: Add av_frame_copy_side_data() 
and av_frame_remove_all_side_data()
 2:  3152156c97 = 2:  3152156c97 avcodec/vpp_qsv: Copy side data from input to 
output frame
 3:  8082c3ab84 = 3:  8082c3ab84 avcodec/mpeg12dec: make 
mpeg_decode_user_data() accessible
 4:  485d7f913d ! 4:  306bdaa39c avcodec/hevcdec: make set_side_data() 
accessible
 @@ libavcodec/hevcdec.c: error:
   }
   
  -static int set_side_data(HEVCContext *s)
 -+int ff_set_side_data(AVCodecContext *logctx, HEVCSEI *sei, HEVCContext 
*s, AVFrame *out)
 ++int ff_hevc_set_side_data(AVCodecContext *logctx, HEVCSEI *sei, 
HEVCContext *s, AVFrame *out)
   {
  -AVFrame *out = s->ref->frame;
  -int ret;
 @@ libavcodec/hevcdec.c: static int hevc_frame_start(HEVCContext *s)
   }
   
  -ret = set_side_data(s);
 -+ret = ff_set_side_data(s->avctx, &s->sei, s, s->ref->frame);
 ++ret = ff_hevc_set_side_data(s->avctx, &s->sei, s, s->ref->frame);
   if (ret < 0)
   goto fail;
   
 @@ libavcodec/hevcdec.h: void ff_hevc_hls_residual_coding(HEVCContext *s, 
int x0, i
   
   void ff_hevc_hls_mvd_coding(HEVCContext *s, int x0, int y0, int 
log2_cb_size);
   
 -+int ff_set_side_data(AVCodecContext *logctx, HEVCSEI *sei, HEVCContext 
*s, AVFrame *out);
 ++/**
 ++ * Set the decodec side data to an AVFrame.
 ++ * @logctx context for logging.
 ++ * @sei HEVCSEI decoding context, must not be NULL.
 ++ * @s HEVCContext, can be NULL.
 ++ * @return < 0 on error, 0 otherwise.
 ++ */
 ++int ff_hevc_set_side_data(AVCodecContext *logctx, HEVCSEI *sei, 
HEVCContext *s, AVFrame *out);
  +
   extern const uint8_t ff_hevc_qpel_extra_before[4];
   extern const uint8_t ff_hevc_qpel_extra_after[4];
 5:  fb5c3df8e5 = 5:  16f5dfbfd1 avcodec/h264dec: make 
h264_export_frame_props() accessible
 6:  dcf08cd7b7 ! 6:  23de6d2774 avcodec/qsvde

[FFmpeg-devel] [PATCH v8 0/3] Support long file names on Windows

2022-05-26 Thread ffmpegagent
This patchset adds support for long file and directory paths on Windows. The
implementation follows the same logic that .NET is using internally, with
the only exception that it doesn't expand short path components in 8.3
format. .NET does this as the same function is also used for other purposes,
but in our case, that's not required. Short (8.3) paths are working as well
with the extended path prefix, even when longer than 260.

Successfully tested:

 * Regular paths wth drive letter
 * Regular UNC paths
 * Long paths wth drive letter
 * Long paths wth drive letter and forward slashes
 * Long UNC paths
 * Prefixed paths wth drive letter
 * Prefixed UNC paths

I have kept the individual functions separate on purpose, to make it easy to
compare with the .NET impl. (compilers should inlinie those anyway)

v2

 * wchar_filename: Improve comments and function documentation
 * os_support: adjust defines to use win32_stat

v3

 * removed length check in path_is_extended()
 * added path_is_device_path() check in add_extended_prefix()
 * add_extended_prefix(): clarified doc and add checks
 * clarified string allocation length calculation
 * replaced 260 with MAX_PATH
 * removed redundant checks after normalization

v4

 * rebased. no changes

v5

 * resolved the ugly struct duplication
 * compatible with _USE_32BIT_TIME_T

v6

 * wchar_filename.h: added links to .NET source code
 * wchar_filename.h: free allocations on error
 * os_support.hs: use clean and safe way to redirect stat() calls

v7

 * os_support.h: remapped fstat with win32_stat structure
 * os_support.h: use int64_t for some members
 * avformat/file: remove _WIN32 condition

v8

 * os_support.h: documented win32_stat structure
 * os_support.h: renamed function parameters

softworkz (3):
  avutil/wchar_filename,file_open: Support long file names on Windows
  avformat/os_support: Support long file names on Windows
  avformat/file: remove _WIN32 condition

 libavformat/file.c |   4 -
 libavformat/os_support.h   | 116 ++--
 libavutil/file_open.c  |   2 +-
 libavutil/wchar_filename.h | 180 +
 4 files changed, 272 insertions(+), 30 deletions(-)


base-commit: 6076dbcb55d0c9b6693d1acad12a63f7268301aa
Published-As: 
https://github.com/ffstaging/FFmpeg/releases/tag/pr-ffstaging-28%2Fsoftworkz%2Fsubmit_long_filenames-v8
Fetch-It-Via: git fetch https://github.com/ffstaging/FFmpeg 
pr-ffstaging-28/softworkz/submit_long_filenames-v8
Pull-Request: https://github.com/ffstaging/FFmpeg/pull/28

Range-diff vs v7:

 1:  960aa795ff = 1:  960aa795ff avutil/wchar_filename,file_open: Support long 
file names on Windows
 2:  7751335906 ! 2:  d0cc40a0d4 avformat/os_support: Support long file names 
on Windows
 @@ libavformat/os_support.h
  +
  +#  define stat win32_stat
  +
 ++/*
 ++ * The POSIX definition for the stat() function uses a struct of the
 ++ * same name (struct stat), that why it takes this extra effort  for
 ++ * redirecting/replacing the stat() function with our own one which
 ++ * is capable to handle long path names on Windows.
 ++ * The struct below roughly follows the POSIX definition. Time values
 ++ * are 64bit, but in cases when _USE_32BIT_TIME_T is defined, they
 ++ * will be set to values no larger than INT32_MAX which corresponds
 ++ * to file times up to the year 2038.
 ++ */
  +struct win32_stat
  +{
  +_dev_t st_dev; /* ID of device containing file */
 @@ libavformat/os_support.h: DEF_FS_FUNCTION(unlink, _wunlink, _unlink)
  -fallback: \
  -/* filename may be be in CP_ACP */\
  -return afunc(filename_utf8, par); \
 -+static inline int win32_access(const char *filename_utf8, int par)
 ++static inline int win32_access(const char *filename_utf8, int mode)
  +{
  +wchar_t *filename_w;
  +int ret;
 @@ libavformat/os_support.h: DEF_FS_FUNCTION(unlink, _wunlink, _unlink)
  +return -1;
  +if (!filename_w)
  +goto fallback;
 -+ret = _waccess(filename_w, par);
 ++ret = _waccess(filename_w, mode);
  +av_free(filename_w);
  +return ret;
  +fallback:
 -+return _access(filename_utf8, par);
 ++return _access(filename_utf8, mode);
  +}
  +
 -+static inline void copy_stat(struct _stati64 *winstat, struct win32_stat 
*par)
 ++static inline void copy_stat(struct _stati64 *crtstat, struct win32_stat 
*buf)
  +{
 -+par->st_dev   = winstat->st_dev;
 -+par->st_ino   = winstat->st_ino;
 -+par->st_mode  = winstat->st_mode;
 -+par->st_nlink = winstat->st_nlink;
 -+par->st_uid   = winstat->st_uid;
 -+par->st_gid   = winstat->st_gid;
 -+par->st_rdev  = winstat->st_rdev;
 -

[FFmpeg-devel] [PATCH 0/6] Implement SEI parsing for QSV decoders

2022-05-26 Thread ffmpegagent
Missing SEI information has always been a major drawback when using the QSV
decoders. I used to think that there's no chance to get at the data without
explicit implementation from the MSDK side (or doing something weird like
parsing in parallel). It turned out that there's a hardly known api method
that provides access to all SEI (h264/hevc) or user data (mpeg2video).

This allows to get things like closed captions, frame packing, display
orientation, HDR data (mastering display, content light level, etc.) without
having to rely on those data being provided by the MSDK as extended buffers.

The commit "Implement SEI parsing for QSV decoders" includes some hard-coded
workarounds for MSDK bugs which I reported:
https://github.com/Intel-Media-SDK/MediaSDK/issues/2597#issuecomment-1072795311

But that doesn't help. Those bugs exist and I'm sharing my workarounds,
which are empirically determined by testing a range of files. If someone is
interested, I can provide private access to a repository where we have been
testing this. Alternatively, I could also leave those workarounds out, and
just skip those SEI types.

In a previous version of this patchset, there was a concern that payload
data might need to be re-ordered. Meanwhile I have researched this carefully
and the conclusion is that this is not required.

My detailed analysis can be found here:
https://gist.github.com/softworkz/36c49586a8610813a32270ee3947a932

softworkz (6):
  avutil/frame: Add av_frame_copy_side_data() and
av_frame_remove_all_side_data()
  avcodec/vpp_qsv: Copy side data from input to output frame
  avcodec/mpeg12dec: make mpeg_decode_user_data() accessible
  avcodec/hevcdec: make set_side_data() accessible
  avcodec/h264dec: make h264_export_frame_props() accessible
  avcodec/qsvdec: Implement SEI parsing for QSV decoders

 doc/APIchanges   |   4 +
 libavcodec/h264_slice.c  |  98 +++
 libavcodec/h264dec.h |   2 +
 libavcodec/hevcdec.c | 117 +-
 libavcodec/hevcdec.h |   2 +
 libavcodec/mpeg12.h  |  28 +
 libavcodec/mpeg12dec.c   |  40 +-
 libavcodec/qsvdec.c  | 233 +++
 libavfilter/qsvvpp.c |   6 +
 libavfilter/vf_overlay_qsv.c |  19 ++-
 libavutil/frame.c|  67 ++
 libavutil/frame.h|  32 +
 libavutil/version.h  |   2 +-
 13 files changed, 477 insertions(+), 173 deletions(-)


base-commit: b033913d1c5998a29dfd13e9906dd707ff6eff12
Published-As: 
https://github.com/ffstaging/FFmpeg/releases/tag/pr-ffstaging-31%2Fsoftworkz%2Fsubmit_qsv_sei-v1
Fetch-It-Via: git fetch https://github.com/ffstaging/FFmpeg 
pr-ffstaging-31/softworkz/submit_qsv_sei-v1
Pull-Request: https://github.com/ffstaging/FFmpeg/pull/31
-- 
ffmpeg-codebot
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH v7 0/3] Support long file names on Windows

2022-05-24 Thread ffmpegagent
This patchset adds support for long file and directory paths on Windows. The
implementation follows the same logic that .NET is using internally, with
the only exception that it doesn't expand short path components in 8.3
format. .NET does this as the same function is also used for other purposes,
but in our case, that's not required. Short (8.3) paths are working as well
with the extended path prefix, even when longer than 260.

Successfully tested:

 * Regular paths wth drive letter
 * Regular UNC paths
 * Long paths wth drive letter
 * Long paths wth drive letter and forward slashes
 * Long UNC paths
 * Prefixed paths wth drive letter
 * Prefixed UNC paths

I have kept the individual functions separate on purpose, to make it easy to
compare with the .NET impl. (compilers should inlinie those anyway)

v2

 * wchar_filename: Improve comments and function documentation
 * os_support: adjust defines to use win32_stat

v3

 * removed length check in path_is_extended()
 * added path_is_device_path() check in add_extended_prefix()
 * add_extended_prefix(): clarified doc and add checks
 * clarified string allocation length calculation
 * replaced 260 with MAX_PATH
 * removed redundant checks after normalization

v4

 * rebased. no changes

v5

 * resolved the ugly struct duplication
 * compatible with _USE_32BIT_TIME_T

v6

 * wchar_filename.h: added links to .NET source code
 * wchar_filename.h: free allocations on error
 * os_support.hs: use clean and safe way to redirect stat() calls

v7

 * os_support.h: remapped fstat with win32_stat structure
 * os_support.h: use int64_t for some members
 * avformat/file: remove _WIN32 condition

softworkz (3):
  avutil/wchar_filename,file_open: Support long file names on Windows
  avformat/os_support: Support long file names on Windows
  avformat/file: remove _WIN32 condition

 libavformat/file.c |   4 -
 libavformat/os_support.h   | 106 --
 libavutil/file_open.c  |   2 +-
 libavutil/wchar_filename.h | 180 +
 4 files changed, 262 insertions(+), 30 deletions(-)


base-commit: 6076dbcb55d0c9b6693d1acad12a63f7268301aa
Published-As: 
https://github.com/ffstaging/FFmpeg/releases/tag/pr-ffstaging-28%2Fsoftworkz%2Fsubmit_long_filenames-v7
Fetch-It-Via: git fetch https://github.com/ffstaging/FFmpeg 
pr-ffstaging-28/softworkz/submit_long_filenames-v7
Pull-Request: https://github.com/ffstaging/FFmpeg/pull/28

Range-diff vs v6:

 1:  960aa795ff = 1:  960aa795ff avutil/wchar_filename,file_open: Support long 
file names on Windows
 2:  6f8d400db7 ! 2:  7751335906 avformat/os_support: Support long file names 
on Windows
 @@ libavformat/os_support.h
  +short  st_uid; /* user ID of owner */
  +short  st_gid; /* group ID of owner */
  +_dev_t st_rdev;/* device ID (if special file) */
 -+long   st_size;/* total size, in bytes */
 -+time_t st_atime;   /* time of last access */
 -+time_t st_mtime;   /* time of last modification */
 -+time_t st_ctime;   /* time of last status change */
 ++int64_tst_size;/* total size, in bytes */
 ++int64_tst_atime;   /* time of last access */
 ++int64_tst_mtime;   /* time of last modification */
 ++int64_tst_ctime;   /* time of last status change */
  +};
  +
   #  ifdef fstat
   #   undef fstat
   #  endif
 +-#  define fstat(f,s) _fstati64((f), (s))
 ++#  define fstat win32_fstat
 + #endif /* defined(_WIN32) */
 + 
 + 
  @@ libavformat/os_support.h: static inline int win32_##name(const char 
*filename_utf8) \
   wchar_t *filename_w;  \
   int ret;  \
 @@ libavformat/os_support.h: DEF_FS_FUNCTION(unlink, _wunlink, _unlink)
  +return ret;
  +fallback:
  +return _access(filename_utf8, par);
 ++}
 ++
 ++static inline void copy_stat(struct _stati64 *winstat, struct win32_stat 
*par)
 ++{
 ++par->st_dev   = winstat->st_dev;
 ++par->st_ino   = winstat->st_ino;
 ++par->st_mode  = winstat->st_mode;
 ++par->st_nlink = winstat->st_nlink;
 ++par->st_uid   = winstat->st_uid;
 ++par->st_gid   = winstat->st_gid;
 ++par->st_rdev  = winstat->st_rdev;
 ++par->st_size  = winstat->st_size;
 ++par->st_atime = winstat->st_atime;
 ++par->st_mtime = winstat->st_mtime;
 ++par->st_ctime = winstat->st_ctime;
   }
   
  -DEF_FS_FUNCTION2(access, _waccess, _access, int)
  -DEF_FS_FUNCTION2(stat, _wstati64, _stati64, struct stat*)
 -+static inline int win32_stat(const char *filename_utf8, struct stat *par)
 ++static inline int win32_stat(const char *filename_utf8, struct 
win32_stat *par)

[FFmpeg-devel] [PATCH v6 0/2] Support long file names on Windows

2022-05-24 Thread ffmpegagent
This patchset adds support for long file and directory paths on Windows. The
implementation follows the same logic that .NET is using internally, with
the only exception that it doesn't expand short path components in 8.3
format. .NET does this as the same function is also used for other purposes,
but in our case, that's not required. Short (8.3) paths are working as well
with the extended path prefix, even when longer than 260.

Successfully tested:

 * Regular paths wth drive letter
 * Regular UNC paths
 * Long paths wth drive letter
 * Long paths wth drive letter and forward slashes
 * Long UNC paths
 * Prefixed paths wth drive letter
 * Prefixed UNC paths

I have kept the individual functions separate on purpose, to make it easy to
compare with the .NET impl. (compilers should inlinie those anyway)

v2

 * wchar_filename: Improve comments and function documentation
 * os_support: adjust defines to use win32_stat

v3

 * removed length check in path_is_extended()
 * added path_is_device_path() check in add_extended_prefix()
 * add_extended_prefix(): clarified doc and add checks
 * clarified string allocation length calculation
 * replaced 260 with MAX_PATH
 * removed redundant checks after normalization

v4

 * rebased. no changes

v5

 * resolved the ugly struct duplication
 * compatible with _USE_32BIT_TIME_T

v6

 * wchar_filename.h: added links to .NET source code
 * wchar_filename.h: free allocations on error
 * os_support.hs: use clean and safe way to redirect stat() calls

softworkz (2):
  avutil/wchar_filename,file_open: Support long file names on Windows
  avformat/os_support: Support long file names on Windows

 libavformat/os_support.h   |  87 +-
 libavutil/file_open.c  |   2 +-
 libavutil/wchar_filename.h | 180 +
 3 files changed, 244 insertions(+), 25 deletions(-)


base-commit: 6076dbcb55d0c9b6693d1acad12a63f7268301aa
Published-As: 
https://github.com/ffstaging/FFmpeg/releases/tag/pr-ffstaging-28%2Fsoftworkz%2Fsubmit_long_filenames-v6
Fetch-It-Via: git fetch https://github.com/ffstaging/FFmpeg 
pr-ffstaging-28/softworkz/submit_long_filenames-v6
Pull-Request: https://github.com/ffstaging/FFmpeg/pull/28

Range-diff vs v5:

 1:  13118dc1fa ! 1:  960aa795ff avutil/wchar_filename,file_open: Support long 
file names on Windows
 @@ libavutil/wchar_filename.h: static inline int utf8towchar(const char 
*filename_u
  +/**
  + * Checks for extended path prefixes for which normalization needs to be 
skipped.
  + * see .NET6: PathInternal.IsExtended()
 ++ * 
https://github.com/dotnet/runtime/blob/9260c249140ef90b4299d0fe1aa3037e25228518/src/libraries/Common/src/System/IO/PathInternal.Windows.cs#L165
  + */
  +static inline int path_is_extended(const wchar_t *path)
  +{
 @@ libavutil/wchar_filename.h: static inline int utf8towchar(const char 
*filename_u
  +
  +/**
  + * Checks for a device path prefix.
 -+ * see .NET6: PathInternal.IsDevicePath()
 ++ * see .NET6: PathInternal.IsDevice()
 ++ * we don't check forward slashes and extended paths (as already done)
 ++ * 
https://github.com/dotnet/runtime/blob/9260c249140ef90b4299d0fe1aa3037e25228518/src/libraries/Common/src/System/IO/PathInternal.Windows.cs#L132
  + */
  +static inline int path_is_device_path(const wchar_t *path)
  +{
 @@ libavutil/wchar_filename.h: static inline int utf8towchar(const char 
*filename_u
  +/**
  + * Performs path normalization by calling GetFullPathNameW().
  + * see .NET6: PathHelper.GetFullPathName()
 ++ * 
https://github.com/dotnet/runtime/blob/2a99e18eedabcf1add064c099da59d9301ce45e0/src/libraries/System.Private.CoreLib/src/System/IO/PathHelper.Windows.cs#L70
  + */
  +static inline int get_full_path_name(wchar_t **ppath_w)
  +{
 @@ libavutil/wchar_filename.h: static inline int utf8towchar(const char 
*filename_u
  +
  +num_chars = GetFullPathNameW(*ppath_w, num_chars, temp_w, NULL);
  +if (num_chars <= 0) {
 ++av_free(temp_w);
  +errno = EINVAL;
  +return -1;
  +}
 @@ libavutil/wchar_filename.h: static inline int utf8towchar(const char 
*filename_u
  + * Normalizes a Windows file or folder path.
  + * Expansion of short paths (with 8.3 path components) is currently 
omitted
  + * as it is not required for accessing long paths.
 -+ * see .NET6: PathHelper.Normalize().
 ++ * see .NET6: PathHelper.Normalize()
 ++ * 
https://github.com/dotnet/runtime/blob/2a99e18eedabcf1add064c099da59d9301ce45e0/src/libraries/System.Private.CoreLib/src/System/IO/PathHelper.Windows.cs#L25
  + */
  +static inline int path_normalize(wchar_t **ppath_w)
  +{
 @@ libavutil/wchar_filename.h: static inline int utf8towchar(const char 
*filename_u
  + * This function expects that the path has been normalized before by
  + * calling path_normalize() and it doesn't check wh

[FFmpeg-devel] [PATCH v5 0/2] Support long file names on Windows

2022-05-24 Thread ffmpegagent
This patchset adds support for long file and directory paths on Windows. The
implementation follows the same logic that .NET is using internally, with
the only exception that it doesn't expand short path components in 8.3
format. .NET does this as the same function is also used for other purposes,
but in our case, that's not required. Short (8.3) paths are working as well
with the extended path prefix, even when longer than 260.

Successfully tested:

 * Regular paths wth drive letter
 * Regular UNC paths
 * Long paths wth drive letter
 * Long paths wth drive letter and forward slashes
 * Long UNC paths
 * Prefixed paths wth drive letter
 * Prefixed UNC paths

I have kept the individual functions separate on purpose, to make it easy to
compare with the .NET impl. (compilers should inlinie those anyway)

v2

 * wchar_filename: Improve comments and function documentation
 * os_support: adjust defines to use win32_stat

v3

 * removed length check in path_is_extended()
 * added path_is_device_path() check in add_extended_prefix()
 * add_extended_prefix(): clarified doc and add checks
 * clarified string allocation length calculation
 * replaced 260 with MAX_PATH
 * removed redundant checks after normalization

v4

 * rebased. no changes

v5

 * resolved the ugly struct duplication
 * compatible with _USE_32BIT_TIME_T

softworkz (2):
  avutil/wchar_filename,file_open: Support long file names on Windows
  avformat/os_support: Support long file names on Windows

 libavformat/os_support.h   |  16 ++--
 libavutil/file_open.c  |   2 +-
 libavutil/wchar_filename.h | 166 +
 3 files changed, 178 insertions(+), 6 deletions(-)


base-commit: 6076dbcb55d0c9b6693d1acad12a63f7268301aa
Published-As: 
https://github.com/ffstaging/FFmpeg/releases/tag/pr-ffstaging-28%2Fsoftworkz%2Fsubmit_long_filenames-v5
Fetch-It-Via: git fetch https://github.com/ffstaging/FFmpeg 
pr-ffstaging-28/softworkz/submit_long_filenames-v5
Pull-Request: https://github.com/ffstaging/FFmpeg/pull/28

Range-diff vs v4:

 1:  13118dc1fa = 1:  13118dc1fa avutil/wchar_filename,file_open: Support long 
file names on Windows
 2:  252ed89499 ! 2:  5313aeec0e avformat/os_support: Support long file names 
on Windows
 @@ libavformat/os_support.h
  +
  +struct win32_stat
  +{
 -+_dev_t st_dev;
 -+_ino_t st_ino;
 -+unsigned short st_mode;
 -+short  st_nlink;
 -+short  st_uid;
 -+short  st_gid;
 -+_dev_t st_rdev;
 -+__int64st_size;
 -+__time64_t st_atime;
 -+__time64_t st_mtime;
 -+__time64_t st_ctime;
 ++struct _stati64;
  +};
  +
   #  ifdef fstat

-- 
ffmpeg-codebot
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH v4 0/2] Support long file names on Windows

2022-05-23 Thread ffmpegagent
This patchset adds support for long file and directory paths on Windows. The
implementation follows the same logic that .NET is using internally, with
the only exception that it doesn't expand short path components in 8.3
format. .NET does this as the same function is also used for other purposes,
but in our case, that's not required. Short (8.3) paths are working as well
with the extended path prefix, even when longer than 260.

Successfully tested:

 * Regular paths wth drive letter
 * Regular UNC paths
 * Long paths wth drive letter
 * Long paths wth drive letter and forward slashes
 * Long UNC paths
 * Prefixed paths wth drive letter
 * Prefixed UNC paths

I have kept the individual functions separate on purpose, to make it easy to
compare with the .NET impl. (compilers should inlinie those anyway)

v2

 * wchar_filename: Improve comments and function documentation
 * os_support: adjust defines to use win32_stat

v3

 * removed length check in path_is_extended()
 * added path_is_device_path() check in add_extended_prefix()
 * add_extended_prefix(): clarified doc and add checks
 * clarified string allocation length calculation
 * replaced 260 with MAX_PATH
 * removed redundant checks after normalization

v4

 * rebased. no changes

softworkz (2):
  avutil/wchar_filename,file_open: Support long file names on Windows
  avformat/os_support: Support long file names on Windows

 libavformat/os_support.h   |  26 --
 libavutil/file_open.c  |   2 +-
 libavutil/wchar_filename.h | 166 +
 3 files changed, 188 insertions(+), 6 deletions(-)


base-commit: 6076dbcb55d0c9b6693d1acad12a63f7268301aa
Published-As: 
https://github.com/ffstaging/FFmpeg/releases/tag/pr-ffstaging-28%2Fsoftworkz%2Fsubmit_long_filenames-v4
Fetch-It-Via: git fetch https://github.com/ffstaging/FFmpeg 
pr-ffstaging-28/softworkz/submit_long_filenames-v4
Pull-Request: https://github.com/ffstaging/FFmpeg/pull/28

Range-diff vs v3:

 1:  ce70f7b021 = 1:  13118dc1fa avutil/wchar_filename,file_open: Support long 
file names on Windows
 2:  a5268800a4 = 2:  252ed89499 avformat/os_support: Support long file names 
on Windows

-- 
ffmpeg-codebot
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH v7 0/2] use av_fopen_utf8() instead of plain fopen()

2022-05-23 Thread ffmpegagent
Unify file access operations by replacing usages of direct calls to posix
fopen()

v2: Remove changes to fftools for now
v3: Add some additional replacements
v4: Fix and improve commit messages
v5: Add patch to remap ff_open in libavfilter for MSVC on Windows
v6: Add avfilter/file_open.c to "Files without standard license headers"
list
v7: Rebase and use the new avpriv_fopen_utf8() instead

softworkz (2):
  avfilter: use av_fopen_utf8() instead of plain fopen()
  avcodec/dvdsubdec: use av_fopen_utf8() instead of plain fopen()

 libavcodec/dvdsubdec.c| 2 +-
 libavfilter/af_firequalizer.c | 2 +-
 libavfilter/vf_deshake.c  | 2 +-
 libavfilter/vf_psnr.c | 2 +-
 libavfilter/vf_signature.c| 4 ++--
 libavfilter/vf_ssim.c | 2 +-
 libavfilter/vf_vidstabdetect.c| 2 +-
 libavfilter/vf_vidstabtransform.c | 2 +-
 libavfilter/vf_vmafmotion.c   | 2 +-
 9 files changed, 10 insertions(+), 10 deletions(-)


base-commit: 6076dbcb55d0c9b6693d1acad12a63f7268301aa
Published-As: 
https://github.com/ffstaging/FFmpeg/releases/tag/pr-ffstaging-26%2Fsoftworkz%2Fsubmit_replace_fopen-v7
Fetch-It-Via: git fetch https://github.com/ffstaging/FFmpeg 
pr-ffstaging-26/softworkz/submit_replace_fopen-v7
Pull-Request: https://github.com/ffstaging/FFmpeg/pull/26

Range-diff vs v6:

 1:  bcafcfacea ! 1:  aabfa10d44 avfilter: use av_fopen_utf8() instead of plain 
fopen()
 @@ libavfilter/af_firequalizer.c: static int 
generate_kernel(AVFilterContext *ctx,
   return ret;
   
  -if (s->dumpfile && (!s->dump_buf || !s->analysis_rdft || !(dump_fp = 
fopen(s->dumpfile, "w"
 -+if (s->dumpfile && (!s->dump_buf || !s->analysis_rdft || !(dump_fp = 
av_fopen_utf8(s->dumpfile, "w"
 ++if (s->dumpfile && (!s->dump_buf || !s->analysis_rdft || !(dump_fp = 
avpriv_fopen_utf8(s->dumpfile, "w"
   av_log(ctx, AV_LOG_WARNING, "dumping failed.\n");
   
   vars[VAR_CHS] = inlink->ch_layout.nb_channels;
 @@ libavfilter/vf_deshake.c: static av_cold int init(AVFilterContext *ctx)
   
   if (deshake->filename)
  -deshake->fp = fopen(deshake->filename, "w");
 -+deshake->fp = av_fopen_utf8(deshake->filename, "w");
 ++deshake->fp = avpriv_fopen_utf8(deshake->filename, "w");
   if (deshake->fp)
   fwrite("Ori x, Avg x, Fin x, Ori y, Avg y, Fin y, Ori angle, Avg 
angle, Fin angle, Ori zoom, Avg zoom, Fin zoom\n", 1, 104, deshake->fp);
   
 @@ libavfilter/vf_psnr.c: static av_cold int init(AVFilterContext *ctx)
   s->stats_file = stdout;
   } else {
  -s->stats_file = fopen(s->stats_file_str, "w");
 -+s->stats_file = av_fopen_utf8(s->stats_file_str, "w");
 ++s->stats_file = avpriv_fopen_utf8(s->stats_file_str, "w");
   if (!s->stats_file) {
   int err = AVERROR(errno);
   char buf[128];
 @@ libavfilter/vf_signature.c: static int xml_export(AVFilterContext *ctx, 
StreamCo
   unsigned int pot3[5] = { 3*3*3*3, 3*3*3, 3*3, 3, 1 };
   
  -f = fopen(filename, "w");
 -+f = av_fopen_utf8(filename, "w");
 ++f = avpriv_fopen_utf8(filename, "w");
   if (!f) {
   int err = AVERROR(EINVAL);
   char buf[128];
 @@ libavfilter/vf_signature.c: static int binary_export(AVFilterContext 
*ctx, Strea
   return AVERROR(ENOMEM);
   
  -f = fopen(filename, "wb");
 -+f = av_fopen_utf8(filename, "wb");
 ++f = avpriv_fopen_utf8(filename, "wb");
   if (!f) {
   int err = AVERROR(EINVAL);
   char buf[128];
 @@ libavfilter/vf_ssim.c: static av_cold int init(AVFilterContext *ctx)
   s->stats_file = stdout;
   } else {
  -s->stats_file = fopen(s->stats_file_str, "w");
 -+s->stats_file = av_fopen_utf8(s->stats_file_str, "w");
 ++s->stats_file = avpriv_fopen_utf8(s->stats_file_str, "w");
   if (!s->stats_file) {
   int err = AVERROR(errno);
   char buf[128];
 @@ libavfilter/vf_vidstabdetect.c: static int config_input(AVFilterLink 
*inlink)
   av_log(ctx, AV_LOG_INFO, "result = %s\n", s->result);
   
  -s->f = fopen(s->result, "w");
 -+s->f = av_fopen_utf8(s->result, "w");
 ++s->f = avpriv_fopen_utf8(s->result, "w");
   if (s->f == NULL) {
   av_log(ctx, AV_LOG_ERROR, "cannot open transform file %s\n", 
s->result);
   return AVERROR(EINVAL);
 @@ libavfilter/vf_vidstabtransform.c: static int config_input(AVFilterLink 
*inlink)
   av_log(ctx, AV_LOG_INFO, "interpol  = %s\n", 
getInterpolationTypeName(tc->conf.interpolType));
   
  -f = fopen(tc->input, "r");
 -+f = av_fopen

[FFmpeg-devel] [PATCH v2 0/4] Add derive-device function which searches for existing devices in both directions

2022-05-21 Thread ffmpegagent
This is an updated version of: [PATCH v4 1/1] avutils/hwcontext: When
deriving a hwdevice, search for existing device in both directions

There has been an objection that the earlier patchset would change API
behavior, and that this change should be limited to ffmpeg cli.

To achieve this, the API behavior is left unchanged now and a new function
av_hwdevice_ctx_get_or_create_derived() is added and used by the hwupload
and hwmap filters.

v2: Implemented concept for "weak references" to avoid circular reference
lockup.

softworkz (4):
  avutil/buffer: add av_ref_from_buffer() function
  avutils/hwcontext: add derive-device function which searches for
existing devices in both directions
  lavu: bump minor version and add doc/APIchanges entry for
av_hwdevice_ctx_get_or_create_derived()
  avfilter/hwmap,hwupload: use new av_hwdevice_ctx_get_or_create_derived
method

 doc/APIchanges |   6 ++
 libavfilter/vf_hwmap.c |   4 +-
 libavfilter/vf_hwupload.c  |   2 +-
 libavutil/buffer.c |  16 
 libavutil/buffer.h |   8 ++
 libavutil/hwcontext.c  | 167 +++--
 libavutil/hwcontext.h  |  20 
 libavutil/hwcontext_internal.h |  11 +++
 libavutil/hwcontext_qsv.c  |  11 ++-
 libavutil/version.h|   4 +-
 10 files changed, 234 insertions(+), 15 deletions(-)


base-commit: 9ab20b1614194280b862d98dfcdb7b1bcff03329
Published-As: 
https://github.com/ffstaging/FFmpeg/releases/tag/pr-ffstaging-25%2Fsoftworkz%2Fderive_devices-v2
Fetch-It-Via: git fetch https://github.com/ffstaging/FFmpeg 
pr-ffstaging-25/softworkz/derive_devices-v2
Pull-Request: https://github.com/ffstaging/FFmpeg/pull/25

Range-diff vs v1:

 -:  -- > 1:  e9c920c237 avutil/buffer: add av_ref_from_buffer() 
function
 1:  85ff784b6f ! 2:  bec8ccfcc2 avutils/hwcontext: add derive-device function 
which searches for existing devices in both directions
 @@ Commit message
  Signed-off-by: softworkz 
  
   ## libavutil/hwcontext.c ##
 -@@ libavutil/hwcontext.c: static const AVClass hwdevice_ctx_class = {
 - static void hwdevice_ctx_free(void *opaque, uint8_t *data)
 +@@
 + #include "buffer.h"
 + #include "common.h"
 + #include "hwcontext.h"
 ++
 ++#include 
 ++
 ++#include "buffer_internal.h"
 + #include "hwcontext_internal.h"
 + #include "imgutils.h"
 + #include "log.h"
 + #include "mem.h"
 + #include "pixdesc.h"
 + #include "pixfmt.h"
 ++#include "thread.h"
 + 
 + static const HWContextType * const hw_table[] = {
 + #if CONFIG_CUDA
 +@@ libavutil/hwcontext.c: static const char *const hw_type_names[] = {
 + [AV_HWDEVICE_TYPE_VULKAN] = "vulkan",
 + };
 + 
 ++#define DEVICE_REGISTRY_SIZE 1024
 ++
 ++static AVMutex mutex;
 ++static int is_mutex_initialized = 0;
 ++static int max_device_reg_id = 1;
 ++static AVBuffer *hw_device_registry[DEVICE_REGISTRY_SIZE];
 ++
 ++static int register_hw_device(const AVBufferRef *ref)
 ++{
 ++AVHWDeviceContext *ctx = (AVHWDeviceContext*)ref->data;
 ++const int reg_id = max_device_reg_id;
 ++
 ++if (ctx == NULL)
 ++return AVERROR(EINVAL);
 ++
 ++if (!is_mutex_initialized) {
 ++int ret;
 ++ret = ff_mutex_init(&mutex, NULL);
 ++if (ret) {
 ++av_log(ctx, AV_LOG_ERROR, "hwcontext: mutex initialization 
failed! Error code: %d\n", ret);
 ++return AVERROR(EINVAL);
 ++}
 ++
 ++is_mutex_initialized = 1;
 ++}
 ++
 ++ff_mutex_lock(&mutex);
 ++
 ++for (int i = 0; i < max_device_reg_id; ++i) {
 ++if (hw_device_registry[i] != NULL && hw_device_registry[i] == 
ref->buffer) {
 ++ff_mutex_unlock(&mutex);
 ++return i;
 ++}
 ++}
 ++
 ++if (max_device_reg_id >= DEVICE_REGISTRY_SIZE) {
 ++ff_mutex_unlock(&mutex);
 ++av_log(ctx, AV_LOG_ERROR, "Device registry limit (%d) reached. 
Please check for excessive device creation.", DEVICE_REGISTRY_SIZE);
 ++return AVERROR(ENOMEM);
 ++}
 ++
 ++hw_device_registry[reg_id] = ref->buffer;
 ++max_device_reg_id++;
 ++
 ++ff_mutex_unlock(&mutex);
 ++
 ++return reg_id;
 ++}
 ++
 ++static void unregister_hw_device(const AVHWDeviceContext *ctx)
 ++{
 ++if (ctx == NULL || !is_mutex_initialized)
 ++return;
 ++
 ++ff_mutex_lock(&mutex);
 ++
 ++hw_device_registry[ctx->internal->registered_device_id] = NULL;
 ++
 ++ff_mutex_unlock(&mutex);
 ++}
 ++
 ++static AVBufferRef *get_registered_hw_device(int registered_id)
 ++{
 ++if (registered_id <= 0 || registered_id >= max_device_reg_id)
 ++return NULL;
 

[FFmpeg-devel] [PATCH v5 00/10] libavformat/asf: fix handling of byte array length values

2022-05-20 Thread ffmpegagent
The spec allows attachment sizes of up to UINT32_MAX while we can handle
only sizes up to INT32_MAX (in downstream code)

The debug.assert in get_tag didn't really address this, and truncating the
value_len in calling methods cannot be used because the length value is
required in order to continue parsing. This adds a check with log message in
ff_asf_handle_byte_array to handle those (rare) cases.

v2: Rebased & PING
v3: Adjustments suggested by Michael
v4: 1 of 11 merged, 10 to go..
v5: adjusted commit message of 4/10 as requested

softworkz (10):
  libavformat/asf: fix handling of byte array length values
  libavformat/asfdec: fix get_value return type and add checks for
  libavformat/asfdec: fix type of value_len
  libavformat/asfdec: fixing get_tag
  libavformat/asfdec: implement parsing of GUID values
  libavformat/asfdec: avoid clang warnings
  libavformat/asfdec: remove variable redefinition in inner scope
  libavformat/asfdec: ensure variables are initialized
  libavformat/asfdec: fix parameter type in asf_read_stream_propertie()
  libavformat/asfdec: fix variable types and add checks for unsupported
values

 libavformat/asf.c  |   8 +-
 libavformat/asf.h  |   2 +-
 libavformat/asfdec_f.c | 338 +++--
 3 files changed, 229 insertions(+), 119 deletions(-)


base-commit: 9ab20b1614194280b862d98dfcdb7b1bcff03329
Published-As: 
https://github.com/ffstaging/FFmpeg/releases/tag/pr-ffstaging-12%2Fsoftworkz%2Fmaster-upstream_asf_4-v5
Fetch-It-Via: git fetch https://github.com/ffstaging/FFmpeg 
pr-ffstaging-12/softworkz/master-upstream_asf_4-v5
Pull-Request: https://github.com/ffstaging/FFmpeg/pull/12

Range-diff vs v4:

  1:  60966b7907 =  1:  7505ffa3c5 libavformat/asf: fix handling of byte array 
length values
  2:  5acab7b52b =  2:  f2d0b72bf0 libavformat/asfdec: fix get_value return 
type and add checks for
  3:  97e0d765c9 =  3:  99660db6ef libavformat/asfdec: fix type of value_len
  4:  025123f72d =  4:  8aaab15e8b libavformat/asfdec: fixing get_tag
  5:  2d01e4dff5 =  5:  ba31d01715 libavformat/asfdec: implement parsing of 
GUID values
  6:  33b3d163df !  6:  d171cd5184 libavformat/asfdec: fix macro definition and 
use
 @@ Metadata
  Author: softworkz 
  
   ## Commit message ##
 -libavformat/asfdec: fix macro definition and use
 +libavformat/asfdec: avoid clang warnings
 +
 +such as:
 +- bugprone-macro-parentheses
 +- wextra-semi-stmt
  
  Signed-off-by: softworkz 
  
  7:  1509b83f47 =  7:  0d032d9d4c libavformat/asfdec: remove variable 
redefinition in inner scope
  8:  fd31b0be2e =  8:  6bdb2d8bec libavformat/asfdec: ensure variables are 
initialized
  9:  f8728b1c51 =  9:  d510093ed6 libavformat/asfdec: fix parameter type in 
asf_read_stream_propertie()
 10:  78ed5aeb38 = 10:  a05986d76b libavformat/asfdec: fix variable types and 
add checks for unsupported values

-- 
ffmpeg-codebot
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH v6 0/3] use av_fopen_utf8() instead of plain fopen()

2022-05-19 Thread ffmpegagent
Unify file access operations by replacing usages of direct calls to posix
fopen()

v2: Remove changes to fftools for now
v3: Add some additional replacements
v4: Fix and improve commit messages
v5: Add patch to remap ff_open in libavfilter for MSVC on Windows
v6: Add avfilter/file_open.c to "Files without standard license headers"
list

softworkz (3):
  avfilter: use av_fopen_utf8() instead of plain fopen()
  avcodec/dvdsubdec: use av_fopen_utf8() instead of plain fopen()
  avfilter: Make avpriv_open a library-internal function on msvcrt

 libavcodec/dvdsubdec.c| 2 +-
 libavfilter/Makefile  | 1 +
 libavfilter/af_firequalizer.c | 2 +-
 libavfilter/file_open.c   | 1 +
 libavfilter/vf_deshake.c  | 2 +-
 libavfilter/vf_psnr.c | 2 +-
 libavfilter/vf_signature.c| 4 ++--
 libavfilter/vf_ssim.c | 2 +-
 libavfilter/vf_vidstabdetect.c| 2 +-
 libavfilter/vf_vidstabtransform.c | 2 +-
 libavfilter/vf_vmafmotion.c   | 2 +-
 tests/ref/fate/source | 1 +
 12 files changed, 13 insertions(+), 10 deletions(-)
 create mode 100644 libavfilter/file_open.c


base-commit: 41a558fea06cc0a23b8d2d0dfb03ef6a25cf5100
Published-As: 
https://github.com/ffstaging/FFmpeg/releases/tag/pr-ffstaging-26%2Fsoftworkz%2Fsubmit_replace_fopen-v6
Fetch-It-Via: git fetch https://github.com/ffstaging/FFmpeg 
pr-ffstaging-26/softworkz/submit_replace_fopen-v6
Pull-Request: https://github.com/ffstaging/FFmpeg/pull/26

Range-diff vs v5:

 1:  bcafcfacea = 1:  bcafcfacea avfilter: use av_fopen_utf8() instead of plain 
fopen()
 2:  94d023ece3 = 2:  94d023ece3 avcodec/dvdsubdec: use av_fopen_utf8() instead 
of plain fopen()
 3:  5e50103af3 ! 3:  4035d5dd7b avfilter: Make avpriv_open a library-internal 
function on msvcrt
 @@ libavfilter/Makefile: OBJS = allfilters.o
   ## libavfilter/file_open.c (new) ##
  @@
  +#include "libavutil/file_open.c"
 +
 + ## tests/ref/fate/source ##
 +@@ tests/ref/fate/source: libavcodec/reverse.c
 + libavdevice/file_open.c
 + libavdevice/reverse.c
 + libavfilter/af_arnndn.c
 ++libavfilter/file_open.c
 + libavfilter/log2_tab.c
 + libavformat/file_open.c
 + libavformat/golomb_tab.c

-- 
ffmpeg-codebot
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH v5 0/3] use av_fopen_utf8() instead of plain fopen()

2022-05-19 Thread ffmpegagent
Unify file access operations by replacing usages of direct calls to posix
fopen()

v2: Remove changes to fftools for now
v3: Add some additional replacements
v4: Fix and improve commit messages
v5: Add patch to remap ff_open in libavfilter for MSVC on Windows

softworkz (3):
  avfilter: use av_fopen_utf8() instead of plain fopen()
  avcodec/dvdsubdec: use av_fopen_utf8() instead of plain fopen()
  avfilter: Make avpriv_open a library-internal function on msvcrt

 libavcodec/dvdsubdec.c| 2 +-
 libavfilter/Makefile  | 1 +
 libavfilter/af_firequalizer.c | 2 +-
 libavfilter/file_open.c   | 1 +
 libavfilter/vf_deshake.c  | 2 +-
 libavfilter/vf_psnr.c | 2 +-
 libavfilter/vf_signature.c| 4 ++--
 libavfilter/vf_ssim.c | 2 +-
 libavfilter/vf_vidstabdetect.c| 2 +-
 libavfilter/vf_vidstabtransform.c | 2 +-
 libavfilter/vf_vmafmotion.c   | 2 +-
 11 files changed, 12 insertions(+), 10 deletions(-)
 create mode 100644 libavfilter/file_open.c


base-commit: 41a558fea06cc0a23b8d2d0dfb03ef6a25cf5100
Published-As: 
https://github.com/ffstaging/FFmpeg/releases/tag/pr-ffstaging-26%2Fsoftworkz%2Fsubmit_replace_fopen-v5
Fetch-It-Via: git fetch https://github.com/ffstaging/FFmpeg 
pr-ffstaging-26/softworkz/submit_replace_fopen-v5
Pull-Request: https://github.com/ffstaging/FFmpeg/pull/26

Range-diff vs v4:

 1:  7c455d7fa0 = 1:  bcafcfacea avfilter: use av_fopen_utf8() instead of plain 
fopen()
 2:  68192b1a1e = 2:  94d023ece3 avcodec/dvdsubdec: use av_fopen_utf8() instead 
of plain fopen()
 -:  -- > 3:  5e50103af3 avfilter: Make avpriv_open a library-internal 
function on msvcrt

-- 
ffmpeg-codebot
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH v4 0/2] use av_fopen_utf8() instead of plain fopen()

2022-05-17 Thread ffmpegagent
Unify file access operations by replacing usages of direct calls to posix
fopen()

v2: Remove changes to fftools for now
v3: Add some additional replacements
v4: Fix and improve commit messages

softworkz (2):
  avfilter: use av_fopen_utf8() instead of plain fopen()
  avcodec/dvdsubdec: use av_fopen_utf8() instead of plain fopen()

 libavcodec/dvdsubdec.c| 2 +-
 libavfilter/af_firequalizer.c | 2 +-
 libavfilter/vf_deshake.c  | 2 +-
 libavfilter/vf_psnr.c | 2 +-
 libavfilter/vf_signature.c| 4 ++--
 libavfilter/vf_ssim.c | 2 +-
 libavfilter/vf_vidstabdetect.c| 2 +-
 libavfilter/vf_vidstabtransform.c | 2 +-
 libavfilter/vf_vmafmotion.c   | 2 +-
 9 files changed, 10 insertions(+), 10 deletions(-)


base-commit: e3580f60775c897c3b13b178c57ab191ecc4a031
Published-As: 
https://github.com/ffstaging/FFmpeg/releases/tag/pr-ffstaging-26%2Fsoftworkz%2Fsubmit_replace_fopen-v4
Fetch-It-Via: git fetch https://github.com/ffstaging/FFmpeg 
pr-ffstaging-26/softworkz/submit_replace_fopen-v4
Pull-Request: https://github.com/ffstaging/FFmpeg/pull/26

Range-diff vs v3:

 1:  d81855ba42 ! 1:  7c455d7fa0 avfilter: use av_fopen_utf8() instead of plain 
fopen()
 @@ Metadata
   ## Commit message ##
  avfilter: use av_fopen_utf8() instead of plain fopen()
  
 +Unify file access operations by replacing usages of direct calls
 +to posix fopen() to prepare for long filename support on Windows.
 +
  Signed-off-by: softworkz 
  
   ## libavfilter/af_firequalizer.c ##
 2:  1be02d9e04 ! 2:  68192b1a1e avfilter/dvdsubdec: use av_fopen_utf8() 
instead of plain fopen()
 @@ Metadata
  Author: softworkz 
  
   ## Commit message ##
 -avfilter/dvdsubdec: use av_fopen_utf8() instead of plain fopen()
 +avcodec/dvdsubdec: use av_fopen_utf8() instead of plain fopen()
 +
 +Unify file access operations by replacing usages of direct calls
 +to posix fopen() to prepare for long filename support on Windows.
  
  Signed-off-by: softworkz 
  

-- 
ffmpeg-codebot
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH v3 0/2] use av_fopen_utf8() instead of plain fopen()

2022-05-16 Thread ffmpegagent
Unify file access operations by replacing usages of direct calls to posix
fopen()

v2: Remove changes to fftools for now
v3: Add some additional replacements

softworkz (2):
  avfilter: use av_fopen_utf8() instead of plain fopen()
  avfilter/dvdsubdec: use av_fopen_utf8() instead of plain fopen()

 libavcodec/dvdsubdec.c| 2 +-
 libavfilter/af_firequalizer.c | 2 +-
 libavfilter/vf_deshake.c  | 2 +-
 libavfilter/vf_psnr.c | 2 +-
 libavfilter/vf_signature.c| 4 ++--
 libavfilter/vf_ssim.c | 2 +-
 libavfilter/vf_vidstabdetect.c| 2 +-
 libavfilter/vf_vidstabtransform.c | 2 +-
 libavfilter/vf_vmafmotion.c   | 2 +-
 9 files changed, 10 insertions(+), 10 deletions(-)


base-commit: e3580f60775c897c3b13b178c57ab191ecc4a031
Published-As: 
https://github.com/ffstaging/FFmpeg/releases/tag/pr-ffstaging-26%2Fsoftworkz%2Fsubmit_replace_fopen-v3
Fetch-It-Via: git fetch https://github.com/ffstaging/FFmpeg 
pr-ffstaging-26/softworkz/submit_replace_fopen-v3
Pull-Request: https://github.com/ffstaging/FFmpeg/pull/26

Range-diff vs v2:

 1:  e47287be64 ! 1:  d81855ba42 avfilter: use av_fopen_utf8() instead of plain 
fopen()
 @@ libavfilter/vf_deshake.c: static av_cold int init(AVFilterContext *ctx)
   fwrite("Ori x, Avg x, Fin x, Ori y, Avg y, Fin y, Ori angle, Avg 
angle, Fin angle, Ori zoom, Avg zoom, Fin zoom\n", 1, 104, deshake->fp);
   
  
 + ## libavfilter/vf_psnr.c ##
 +@@ libavfilter/vf_psnr.c: static av_cold int init(AVFilterContext *ctx)
 + if (!strcmp(s->stats_file_str, "-")) {
 + s->stats_file = stdout;
 + } else {
 +-s->stats_file = fopen(s->stats_file_str, "w");
 ++s->stats_file = av_fopen_utf8(s->stats_file_str, "w");
 + if (!s->stats_file) {
 + int err = AVERROR(errno);
 + char buf[128];
 +
   ## libavfilter/vf_signature.c ##
  @@ libavfilter/vf_signature.c: static int xml_export(AVFilterContext 
*ctx, StreamContext *sc, const char* filen
   FILE* f;
 @@ libavfilter/vf_ssim.c: static av_cold int init(AVFilterContext *ctx)
   int err = AVERROR(errno);
   char buf[128];
  
 + ## libavfilter/vf_vidstabdetect.c ##
 +@@ libavfilter/vf_vidstabdetect.c: static int config_input(AVFilterLink 
*inlink)
 + av_log(ctx, AV_LOG_INFO, "  show = %d\n", s->conf.show);
 + av_log(ctx, AV_LOG_INFO, "result = %s\n", s->result);
 + 
 +-s->f = fopen(s->result, "w");
 ++s->f = av_fopen_utf8(s->result, "w");
 + if (s->f == NULL) {
 + av_log(ctx, AV_LOG_ERROR, "cannot open transform file %s\n", 
s->result);
 + return AVERROR(EINVAL);
 +
 + ## libavfilter/vf_vidstabtransform.c ##
 +@@ libavfilter/vf_vidstabtransform.c: static int 
config_input(AVFilterLink *inlink)
 + av_log(ctx, AV_LOG_INFO, "zoomspeed = %g\n", 
tc->conf.zoomSpeed);
 + av_log(ctx, AV_LOG_INFO, "interpol  = %s\n", 
getInterpolationTypeName(tc->conf.interpolType));
 + 
 +-f = fopen(tc->input, "r");
 ++f = av_fopen_utf8(tc->input, "r");
 + if (!f) {
 + int ret = AVERROR(errno);
 + av_log(ctx, AV_LOG_ERROR, "cannot open input file %s\n", 
tc->input);
 +
   ## libavfilter/vf_vmafmotion.c ##
  @@ libavfilter/vf_vmafmotion.c: static av_cold int init(AVFilterContext 
*ctx)
   if (!strcmp(s->stats_file_str, "-")) {
 -:  -- > 2:  1be02d9e04 avfilter/dvdsubdec: use av_fopen_utf8() 
instead of plain fopen()

-- 
ffmpeg-codebot
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH v3 0/2] Support long file names on Windows

2022-05-16 Thread ffmpegagent
This patchset adds support for long file and directory paths on Windows. The
implementation follows the same logic that .NET is using internally, with
the only exception that it doesn't expand short path components in 8.3
format. .NET does this as the same function is also used for other purposes,
but in our case, that's not required. Short (8.3) paths are working as well
with the extended path prefix, even when longer than 260.

Successfully tested:

 * Regular paths wth drive letter
 * Regular UNC paths
 * Long paths wth drive letter
 * Long paths wth drive letter and forward slashes
 * Long UNC paths
 * Prefixed paths wth drive letter
 * Prefixed UNC paths

I have kept the individual functions separate on purpose, to make it easy to
compare with the .NET impl. (compilers should inlinie those anyway)

v2

 * wchar_filename: Improve comments and function documentation
 * os_support: adjust defines to use win32_stat

v3

 * removed length check in path_is_extended()
 * added path_is_device_path() check in add_extended_prefix()
 * add_extended_prefix(): clarified doc and add checks
 * clarified string allocation length calculation
 * replaced 260 with MAX_PATH
 * removed redundant checks after normalization

softworkz (2):
  avutil/wchar_filename,file_open: Support long file names on Windows
  avformat/os_support: Support long file names on Windows

 libavformat/os_support.h   |  26 --
 libavutil/file_open.c  |   2 +-
 libavutil/wchar_filename.h | 166 +
 3 files changed, 188 insertions(+), 6 deletions(-)


base-commit: e3580f60775c897c3b13b178c57ab191ecc4a031
Published-As: 
https://github.com/ffstaging/FFmpeg/releases/tag/pr-ffstaging-28%2Fsoftworkz%2Fsubmit_long_filenames-v3
Fetch-It-Via: git fetch https://github.com/ffstaging/FFmpeg 
pr-ffstaging-28/softworkz/submit_long_filenames-v3
Pull-Request: https://github.com/ffstaging/FFmpeg/pull/28

Range-diff vs v2:

 1:  b66dbdf40c ! 1:  ce70f7b021 avutil/wchar_filename,file_open: Support long 
file names on Windows
 @@ libavutil/wchar_filename.h: static inline int utf8towchar(const char 
*filename_u
  + */
  +static inline int path_is_extended(const wchar_t *path)
  +{
 -+size_t len = wcslen(path);
 -+if (len >= 4  && path[0] == L'\\' && (path[1] == L'\\' || path[1] == 
L'?') && path[2] == L'?' && path[3] == L'\\')
 ++if (path[0] == L'\\' && (path[1] == L'\\' || path[1] == L'?') && 
path[2] == L'?' && path[3] == L'\\')
 ++return 1;
 ++
 ++return 0;
 ++}
 ++
 ++/**
 ++ * Checks for a device path prefix.
 ++ * see .NET6: PathInternal.IsDevicePath()
 ++ */
 ++static inline int path_is_device_path(const wchar_t *path)
 ++{
 ++if (path[0] == L'\\' && path[1] == L'\\' && path[2] == L'.' && 
path[3] == L'\\')
  +return 1;
  +
  +return 0;
 @@ libavutil/wchar_filename.h: static inline int utf8towchar(const char 
*filename_u
  + * Adds an extended path or UNC prefix to longs paths or paths ending
  + * with a space or a dot. (' ' or '.').
  + * This function expects that the path has been normalized before by
 -+ * calling path_normalize().
 ++ * calling path_normalize() and it doesn't check whether the path is
 ++ * actually long (> MAX_PATH).
  + * see .NET6: PathInternal.EnsureExtendedPrefix() *
  + */
  +static inline int add_extended_prefix(wchar_t **ppath_w)
 @@ libavutil/wchar_filename.h: static inline int utf8towchar(const char 
*filename_u
  +const size_t len= wcslen(path_w);
  +wchar_t *temp_w;
  +
 -+if (len < 2)
 ++/* We're skipping the check IsPartiallyQualified() because
 ++ * we expect to have called GetFullPathNameW() already. */
 ++if (len < 2 || path_is_extended(*ppath_w) || 
path_is_device_path(*ppath_w)) {
  +return 0;
 ++}
  +
 -+/* We're skipping the check IsPartiallyQualified() because
 -+ * we know we have called GetFullPathNameW() already, also
 -+ * we don't check IsDevice() because device paths are not
 -+ * allowed to be long paths and we're calling this only
 -+ * for long paths.
 -+ */
  +if (path_w[0] == L'\\' && path_w[1] == L'\\') {
 -+// The length of unc_prefix is 6 plus 1 for terminating zeros
 -+temp_w = (wchar_t *)av_calloc(len + 6 + 1, sizeof(wchar_t));
 ++/* unc_prefix length is 8 plus 1 for terminating zeros,
 ++ * we subtract 2 for the leading '\\' of the original path */
 ++temp_w = (wchar_t *)av_calloc(len - 2 + 8 + 1, sizeof(wchar_t));
  +if (!temp_w) {
  +errno = ENOMEM;
  +return -1;
 @@ libavutil/wchar_filename.h: static inline int utf8towchar(const char 
*filename_u
  + * APIs. Paths with extended path prefix (either '\\?\' or \??\') are
  + * le

[FFmpeg-devel] [PATCH v2 0/2] Support long file names on Windows

2022-05-15 Thread ffmpegagent
This patchset adds support for long file and directory paths on Windows. The
implementation follows the same logic that .NET is using internally, with
the only exception that it doesn't expand short path components in 8.3
format. .NET does this as the same function is also used for other purposes,
but in our case, that's not required. Short (8.3) paths are working as well
with the extended path prefix, even when longer than 260.

Successfully tested:

 * Regular paths wth drive letter
 * Regular UNC paths
 * Long paths wth drive letter
 * Long paths wth drive letter and forward slashes
 * Long UNC paths
 * Prefixed paths wth drive letter
 * Prefixed UNC paths

I have kept the individual functions separate on purpose, to make it easy to
compare with the .NET impl. (compilers should inlinie those anyway)

v2

 * wchar_filename: Improve comments and function documentation
 * os_support: adjust defines to use win32_stat

softworkz (2):
  avutil/wchar_filename,file_open: Support long file names on Windows
  avformat/os_support: Support long file names on Windows

 libavformat/os_support.h   |  26 +--
 libavutil/file_open.c  |   2 +-
 libavutil/wchar_filename.h | 156 +
 3 files changed, 178 insertions(+), 6 deletions(-)


base-commit: d2d8b9b972ba2df6b2a2ebe29f5307cbb7a69c33
Published-As: 
https://github.com/ffstaging/FFmpeg/releases/tag/pr-ffstaging-28%2Fsoftworkz%2Fsubmit_long_filenames-v2
Fetch-It-Via: git fetch https://github.com/ffstaging/FFmpeg 
pr-ffstaging-28/softworkz/submit_long_filenames-v2
Pull-Request: https://github.com/ffstaging/FFmpeg/pull/28

Range-diff vs v1:

 1:  26c579e4ee ! 1:  b66dbdf40c avutil/wchar_filename,file_open: Support long 
file names on Windows
 @@ libavutil/wchar_filename.h: static inline int utf8towchar(const char 
*filename_u
   return 0;
   }
  +
 ++/**
 ++ * Checks for extended path prefixes for which normalization needs to be 
skipped.
 ++ * see .NET6: PathInternal.IsExtended()
 ++ */
  +static inline int path_is_extended(const wchar_t *path)
  +{
 -+// see .NET6: PathInternal.IsExtended()
  +size_t len = wcslen(path);
  +if (len >= 4  && path[0] == L'\\' && (path[1] == L'\\' || path[1] == 
L'?') && path[2] == L'?' && path[3] == L'\\')
  +return 1;
 @@ libavutil/wchar_filename.h: static inline int utf8towchar(const char 
*filename_u
  +return 0;
  +}
  +
 ++/**
 ++ * Performs path normalization by calling GetFullPathNameW().
 ++ * see .NET6: PathHelper.GetFullPathName()
 ++ */
  +static inline int get_full_path_name(wchar_t **ppath_w)
  +{
  +int num_chars;
  +wchar_t *temp_w;
  +
 -+// see .NET6: PathHelper.GetFullPathName()
  +num_chars = GetFullPathNameW(*ppath_w, 0, NULL, NULL);
  +if (num_chars <= 0) {
  +errno = EINVAL;
 @@ libavutil/wchar_filename.h: static inline int utf8towchar(const char 
*filename_u
  +return 0;
  +}
  +
 ++/**
 ++ * Normalizes a Windows file or folder path.
 ++ * Expansion of short paths (with 8.3 path components) is currently 
omitted
 ++ * as it is not required for accessing long paths.
 ++ * see .NET6: PathHelper.Normalize().
 ++ */
  +static inline int path_normalize(wchar_t **ppath_w)
  +{
  +int ret;
  +
 -+// see .NET6: PathHelper.Normalize()
  +if ((ret = get_full_path_name(ppath_w)) < 0)
  +return ret;
  +
  +/* What .NET does at this point is to call 
PathHelper.TryExpandShortFileName()
 -+   in case the path contains a '~' character.
 -+   We don't need to do this as we don't need to normalize the file 
name
 -+   for presentation, and the extended path prefix works with 8.3 path
 -+   components as well */
 ++ * in case the path contains a '~' character.
 ++ * We don't need to do this as we don't need to normalize the file 
name
 ++ * for presentation, and the extended path prefix works with 8.3 path
 ++ * components as well
 ++ */
  +return 0;
  +}
  +
 ++/**
 ++ * Adds an extended path or UNC prefix to longs paths or paths ending
 ++ * with a space or a dot. (' ' or '.').
 ++ * This function expects that the path has been normalized before by
 ++ * calling path_normalize().
 ++ * see .NET6: PathInternal.EnsureExtendedPrefix() *
 ++ */
  +static inline int add_extended_prefix(wchar_t **ppath_w)
  +{
  +const wchar_t *unc_prefix   = L"?\\UNC\\";
 @@ libavutil/wchar_filename.h: static inline int utf8towchar(const char 
*filename_u
  +if (len < 2)
  +return 0;
  +
 -+// see .NET6: PathInternal.EnsureExtendedPrefix()
 ++/* We're skipping the check IsPartiallyQualified() because
 ++ * we know we have called GetFullPathName

[FFmpeg-devel] [PATCH v4 00/10] libavformat/asf: fix handling of byte array length values

2022-05-14 Thread ffmpegagent
The spec allows attachment sizes of up to UINT32_MAX while we can handle
only sizes up to INT32_MAX (in downstream code)

The debug.assert in get_tag didn't really address this, and truncating the
value_len in calling methods cannot be used because the length value is
required in order to continue parsing. This adds a check with log message in
ff_asf_handle_byte_array to handle those (rare) cases.

v2: Rebased & PING v3: Adjustments suggested by Michael v4: 1 of 11 merged,
10 to go..

softworkz (10):
  libavformat/asf: fix handling of byte array length values
  libavformat/asfdec: fix get_value return type and add checks for
  libavformat/asfdec: fix type of value_len
  libavformat/asfdec: fixing get_tag
  libavformat/asfdec: implement parsing of GUID values
  libavformat/asfdec: fix macro definition and use
  libavformat/asfdec: remove variable redefinition in inner scope
  libavformat/asfdec: ensure variables are initialized
  libavformat/asfdec: fix parameter type in asf_read_stream_propertie()
  libavformat/asfdec: fix variable types and add checks for unsupported
values

 libavformat/asf.c  |   8 +-
 libavformat/asf.h  |   2 +-
 libavformat/asfdec_f.c | 338 +++--
 3 files changed, 229 insertions(+), 119 deletions(-)


base-commit: e6f0cec88041449475f37b82b76699d2f7b5b124
Published-As: 
https://github.com/ffstaging/FFmpeg/releases/tag/pr-ffstaging-12%2Fsoftworkz%2Fmaster-upstream_asf_4-v4
Fetch-It-Via: git fetch https://github.com/ffstaging/FFmpeg 
pr-ffstaging-12/softworkz/master-upstream_asf_4-v4
Pull-Request: https://github.com/ffstaging/FFmpeg/pull/12

Range-diff vs v3:

  1:  b5c56bf5d0 =  1:  60966b7907 libavformat/asf: fix handling of byte array 
length values
  2:  e6aa0fb7f3 !  2:  5acab7b52b libavformat/asfdec: fix get_value return 
type and add checks for
 @@ libavformat/asfdec_f.c: static int asf_probe(const AVProbeData *pd)
   {
   switch (type) {
   case ASF_BOOL:
 -@@ libavformat/asfdec_f.c: static int 
asf_read_ext_content_desc(AVFormatContext *s, int64_t size)
 +@@ libavformat/asfdec_f.c: static int 
asf_read_ext_content_desc(AVFormatContext *s)
   {
   AVIOContext *pb = s->pb;
   ASFContext *asf = s->priv_data;
 @@ libavformat/asfdec_f.c: static int 
asf_read_ext_content_desc(AVFormatContext *s,
   int desc_count, i, ret;
   
   desc_count = avio_rl16(pb);
 -@@ libavformat/asfdec_f.c: static int 
asf_read_ext_content_desc(AVFormatContext *s, int64_t size)
 +@@ libavformat/asfdec_f.c: static int 
asf_read_ext_content_desc(AVFormatContext *s)
   /* My sample has that stream set to 0 maybe that mean the 
container.
* ASF stream count starts at 1. I am using 0 to the container 
value
* since it's unused. */
 @@ libavformat/asfdec_f.c: static int 
asf_read_ext_content_desc(AVFormatContext *s,
   return 0;
   }
   
 -@@ libavformat/asfdec_f.c: static int asf_read_metadata(AVFormatContext 
*s, int64_t size)
 +@@ libavformat/asfdec_f.c: static int asf_read_metadata(AVFormatContext 
*s)
   {
   AVIOContext *pb = s->pb;
   ASFContext *asf = s->priv_data;
 @@ libavformat/asfdec_f.c: static int asf_read_metadata(AVFormatContext 
*s, int64_t
   int n, stream_num, name_len_utf16, name_len_utf8, value_len;
   int ret, i;
   n = avio_rl16(pb);
 -@@ libavformat/asfdec_f.c: static int asf_read_metadata(AVFormatContext 
*s, int64_t size)
 +@@ libavformat/asfdec_f.c: static int asf_read_metadata(AVFormatContext 
*s)
   av_log(s, AV_LOG_TRACE, "%d stream %d name_len %2d type %d len 
%4d <%s>\n",
   i, stream_num, name_len_utf16, value_type, value_len, 
name);
   
  3:  b84474d729 !  3:  97e0d765c9 libavformat/asfdec: fix type of value_len
 @@ libavformat/asfdec_f.c: static uint64_t get_value(AVIOContext *pb, int 
type, int
   {
   ASFContext *asf = s->priv_data;
   char *value = NULL;
 -@@ libavformat/asfdec_f.c: static int 
asf_read_ext_stream_properties(AVFormatContext *s, int64_t size)
 - static int asf_read_content_desc(AVFormatContext *s, int64_t size)
 +@@ libavformat/asfdec_f.c: static int 
asf_read_ext_stream_properties(AVFormatContext *s)
 + static int asf_read_content_desc(AVFormatContext *s)
   {
   AVIOContext *pb = s->pb;
  -int len1, len2, len3, len4, len5;
 @@ libavformat/asfdec_f.c: static int 
asf_read_ext_stream_properties(AVFormatContex
   
   len1 = avio_rl16(pb);
   len2 = avio_rl16(pb);
 -@@ libavformat/asfdec_f.c: static int asf_read_metadata(AVFormatContext 
*s, int64_t size)
 +@@ libavformat/asfdec_f.c: static int asf_read_metadata(AVFormatContext 
*s)
   ASFContext *asf = s->priv_data;
   uint64_t dar_num[128] = {0};
   uint64_t dar_den[128] = {0};
  4:  a54feb51a1 =  4:  025

[FFmpeg-devel] [PATCH 0/2] Support long file names on Windows

2022-05-13 Thread ffmpegagent
This patchset adds support for long file and directory paths on Windows. The
implementation follows the same logic that .NET is using internally, with
the only exception that it doesn't expand short path components in 8.3
format. .NET does this as the same function is also used for other purposes,
but in our case, that's not required. Short (8.3) paths are working as well
with the extended path prefix, even when longer than 260.

Successfully tested:

 * Regular paths wth drive letter
 * Regular UNC paths
 * Long paths wth drive letter
 * Long paths wth drive letter and forward slashes
 * Long UNC paths
 * Prefixed paths wth drive letter
 * Prefixed UNC paths

I have kept the individual functions separate on purpose, to make it easy to
compare with the .NET impl. (compilers should inlinie those anyway)

softworkz (2):
  avutil/wchar_filename,file_open: Support long file names on Windows
  avformat/os_support: Support long file names on Windows

 libavformat/os_support.h   |   8 +--
 libavutil/file_open.c  |   2 +-
 libavutil/wchar_filename.h | 123 +
 3 files changed, 128 insertions(+), 5 deletions(-)


base-commit: d2d8b9b972ba2df6b2a2ebe29f5307cbb7a69c33
Published-As: 
https://github.com/ffstaging/FFmpeg/releases/tag/pr-ffstaging-28%2Fsoftworkz%2Fsubmit_long_filenames-v1
Fetch-It-Via: git fetch https://github.com/ffstaging/FFmpeg 
pr-ffstaging-28/softworkz/submit_long_filenames-v1
Pull-Request: https://github.com/ffstaging/FFmpeg/pull/28
-- 
ffmpeg-codebot
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH 0/6] lavc/videotoolboxdec: improve HEVC stream compatibility

2022-05-09 Thread ffmpegagent
 * Improve logging in error conditions
 * Improve NAL-escape function behavior
 * Fix some syntax issues in hvcc
 * Correctly escape NALs in hvcc
 * Make sure we expose the stop bits in H264 PS NALs

These changes fix support for several samples I've found or generated
locally.

rcombs (6):
  lavc/videotoolboxdec: warn on nonzero status in the callback
  lavc/videotoolboxdec: fix escaping sequential zero sequences
  lavc/videotoolboxdec: fix generating HEVC
general_profile_compatibility_flags
  lavc/videotoolboxdec: fix writing too many 1 bits for the reserved
fields
  lavc/videotoolboxdec: insert emu-prevention bytes for HEVC as well
  lavc/h264_ps: always include the stop bit in [s|p]ps->data

 libavcodec/h264_ps.c  |  8 
 libavcodec/videotoolbox.c | 32 
 2 files changed, 28 insertions(+), 12 deletions(-)


base-commit: f77ac5131cd1c623aa54ec432cba0d922e9aa470
Published-As: 
https://github.com/ffstaging/FFmpeg/releases/tag/pr-ffstaging-23%2Frcombs%2Fvtdec-hevc-3byte-v1
Fetch-It-Via: git fetch https://github.com/ffstaging/FFmpeg 
pr-ffstaging-23/rcombs/vtdec-hevc-3byte-v1
Pull-Request: https://github.com/ffstaging/FFmpeg/pull/23
-- 
ffmpeg-codebot
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH v3 00/11] libavformat/asf: fix handling of byte array length values

2022-05-07 Thread ffmpegagent
The spec allows attachment sizes of up to UINT32_MAX while we can handle
only sizes up to INT32_MAX (in downstream code)

The debug.assert in get_tag didn't really address this, and truncating the
value_len in calling methods cannot be used because the length value is
required in order to continue parsing. This adds a check with log message in
ff_asf_handle_byte_array to handle those (rare) cases.

v2: Rebased & PING v3: Adjustments suggested by Michael

softworkz (11):
  libavformat/asf: fix handling of byte array length values
  libavformat/asfdec: fix get_value return type and add checks for
  libavformat/asfdec: fix type of value_len
  libavformat/asfdec: fixing get_tag
  libavformat/asfdec: implement parsing of GUID values
  libavformat/asfdec: remove unused parameters
  libavformat/asfdec: fix macro definition and use
  libavformat/asfdec: remove variable redefinition in inner scope
  libavformat/asfdec: ensure variables are initialized
  libavformat/asfdec: fix parameter type in asf_read_stream_propertie()
  libavformat/asfdec: fix variable types and add checks for unsupported
values

 libavformat/asf.c  |   8 +-
 libavformat/asf.h  |   2 +-
 libavformat/asfdec_f.c | 368 ++---
 3 files changed, 244 insertions(+), 134 deletions(-)


base-commit: f1c19867d72a14699277175101b2bcf1e333af88
Published-As: 
https://github.com/ffstaging/FFmpeg/releases/tag/pr-ffstaging-12%2Fsoftworkz%2Fmaster-upstream_asf_4-v3
Fetch-It-Via: git fetch https://github.com/ffstaging/FFmpeg 
pr-ffstaging-12/softworkz/master-upstream_asf_4-v3
Pull-Request: https://github.com/ffstaging/FFmpeg/pull/12

Range-diff vs v2:

  1:  0056a93a34 !  1:  b5c56bf5d0 libavformat/asf: fix handling of byte array 
length values
 @@ libavformat/asf.c: static int get_id3_tag(AVFormatContext *s, int len)
  +}
  +
   if (!strcmp(name, "WM/Picture")) // handle cover art
 --return asf_read_picture(s, val_len);
 -+return asf_read_picture(s, (int)val_len);
 + return asf_read_picture(s, val_len);
   else if (!strcmp(name, "ID3")) // handle ID3 tag
 --return get_id3_tag(s, val_len);
 -+return get_id3_tag(s, (int)val_len);
 + return get_id3_tag(s, val_len);
   
 -+av_log(s, AV_LOG_VERBOSE, "Unsupported byte array in tag %s.\n", 
name);
 ++av_log(s, AV_LOG_DEBUG, "Unsupported byte array in tag %s.\n", name);
   return 1;
   }
  
  2:  a35b7c87d4 !  2:  e6aa0fb7f3 libavformat/asfdec: fix get_value return 
type and add checks for
 @@ libavformat/asfdec_f.c: static int asf_probe(const AVProbeData *pd)
   {
   switch (type) {
   case ASF_BOOL:
 +@@ libavformat/asfdec_f.c: static int 
asf_read_ext_content_desc(AVFormatContext *s, int64_t size)
 + {
 + AVIOContext *pb = s->pb;
 + ASFContext *asf = s->priv_data;
 ++uint64_t dar_num = 0;
 ++uint64_t dar_den = 0;
 + int desc_count, i, ret;
 + 
 + desc_count = avio_rl16(pb);
  @@ libavformat/asfdec_f.c: static int 
asf_read_ext_content_desc(AVFormatContext *s, int64_t size)
   /* My sample has that stream set to 0 maybe that mean the 
container.
* ASF stream count starts at 1. I am using 0 to the container 
value
 @@ libavformat/asfdec_f.c: static int 
asf_read_ext_content_desc(AVFormatContext *s,
  -else if (!strcmp(name, "AspectRatioY"))
  -asf->dar[0].den = get_value(s->pb, value_type, 32);
  +if (!strcmp(name, "AspectRatioX")) {
 -+const uint64_t value = get_value(s->pb, value_type, 32);
 -+if (value > INT32_MAX) {
 -+av_log(s, AV_LOG_DEBUG, "Unsupported AspectRatioX value: 
%"PRIu64"\n", value);
 ++dar_num = get_value(s->pb, value_type, 32);
 ++if (dar_num > INT64_MAX) {
 ++av_log(s, AV_LOG_DEBUG, "Unsupported AspectRatioX value: 
%"PRIu64"\n", dar_num);
  +return AVERROR(ENOTSUP);
  +}
 -+asf->dar[0].num = (int)value;
  +}
  +else if (!strcmp(name, "AspectRatioY")) {
 -+const uint64_t value = get_value(s->pb, value_type, 32);
 -+if (value > INT32_MAX) {
 -+av_log(s, AV_LOG_DEBUG, "Unsupported AspectRatioY value: 
%"PRIu64"\n", value);
 ++dar_den = get_value(s->pb, value_type, 32);
 ++if (dar_den > INT64_MAX) {
 ++av_log(s, AV_LOG_DEBUG, "Unsupported AspectRatioY value: 
%"PRIu64"\n", dar_den);
  +return AVERROR(ENOTSUP);
  +}
 -+asf->dar[0].den = (int)value;
  +}
   else
   get_tag(s, name, value_type, value_len, 32);
   }
 + 
 ++if (dar_num && dar_den)
 ++av_reduce(&asf-

[FFmpeg-devel] [PATCH 0/2] use av_fopen_utf8() instead of plain fopen()

2022-05-07 Thread ffmpegagent
Unify file access operations by replacing usages of direct calls to posix
fopen()

softworkz (2):
  fftools: use av_fopen_utf8() instead of plain fopen()
  avfilter: use av_fopen_utf8() instead of plain fopen()

 fftools/cmdutils.c| 6 +++---
 fftools/ffmpeg.c  | 4 ++--
 fftools/opt_common.c  | 2 +-
 libavfilter/af_firequalizer.c | 2 +-
 libavfilter/vf_deshake.c  | 2 +-
 libavfilter/vf_signature.c| 4 ++--
 libavfilter/vf_ssim.c | 2 +-
 libavfilter/vf_vmafmotion.c   | 2 +-
 8 files changed, 12 insertions(+), 12 deletions(-)


base-commit: f3b7ba21ba49b32b4476a8c7c5a9bcdad15e3943
Published-As: 
https://github.com/ffstaging/FFmpeg/releases/tag/pr-ffstaging-26%2Fsoftworkz%2Fsubmit_replace_fopen-v1
Fetch-It-Via: git fetch https://github.com/ffstaging/FFmpeg 
pr-ffstaging-26/softworkz/submit_replace_fopen-v1
Pull-Request: https://github.com/ffstaging/FFmpeg/pull/26
-- 
ffmpeg-codebot
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH v2 00/11] libavformat/asf: fix handling of byte array length values

2022-05-07 Thread ffmpegagent
The spec allows attachment sizes of up to UINT32_MAX while we can handle
only sizes up to INT32_MAX (in downstream code)

The debug.assert in get_tag didn't really address this, and truncating the
value_len in calling methods cannot be used because the length value is
required in order to continue parsing. This adds a check with log message in
ff_asf_handle_byte_array to handle those (rare) cases.

v2: Rebased & PING

softworkz (11):
  libavformat/asf: fix handling of byte array length values
  libavformat/asfdec: fix get_value return type and add checks for
  libavformat/asfdec: fix type of value_len
  libavformat/asfdec: fixing get_tag
  libavformat/asfdec: implement parsing of GUID values
  libavformat/asfdec: remove unused parameters
  libavformat/asfdec: fix macro definition and use
  libavformat/asfdec: remove variable redefinition in inner scope
  libavformat/asfdec: ensure variables are initialized
  libavformat/asfdec: fix parameter type in asf_read_stream_propertie()
  libavformat/asfdec: fix variable types and add checks for unsupported
values

 libavformat/asf.c  |  12 +-
 libavformat/asf.h  |   2 +-
 libavformat/asfdec_f.c | 349 ++---
 3 files changed, 232 insertions(+), 131 deletions(-)


base-commit: f3b7ba21ba49b32b4476a8c7c5a9bcdad15e3943
Published-As: 
https://github.com/ffstaging/FFmpeg/releases/tag/pr-ffstaging-12%2Fsoftworkz%2Fmaster-upstream_asf_4-v2
Fetch-It-Via: git fetch https://github.com/ffstaging/FFmpeg 
pr-ffstaging-12/softworkz/master-upstream_asf_4-v2
Pull-Request: https://github.com/ffstaging/FFmpeg/pull/12

Range-diff vs v1:

  1:  1e8c0fa058 =  1:  0056a93a34 libavformat/asf: fix handling of byte array 
length values
  2:  b5be0046e9 =  2:  a35b7c87d4 libavformat/asfdec: fix get_value return 
type and add checks for
  3:  c8119dad11 =  3:  b8039dc4cf libavformat/asfdec: fix type of value_len
  4:  3528d46886 =  4:  6e19df6e89 libavformat/asfdec: fixing get_tag
  5:  dc5a56662c =  5:  0f3c417efe libavformat/asfdec: implement parsing of 
GUID values
  6:  9988ecc6d2 =  6:  3bee11e40f libavformat/asfdec: remove unused parameters
  7:  3b5695c25b =  7:  ca9bbc79de libavformat/asfdec: fix macro definition and 
use
  8:  f1af8c82fc =  8:  238290bbce libavformat/asfdec: remove variable 
redefinition in inner scope
  9:  2214e02e7e =  9:  654e44d526 libavformat/asfdec: ensure variables are 
initialized
 10:  b60e0bcc29 = 10:  d461f039d2 libavformat/asfdec: fix parameter type in 
asf_read_stream_propertie()
 11:  da268b909b = 11:  f606f322bb libavformat/asfdec: fix variable types and 
add checks for unsupported values

-- 
ffmpeg-codebot
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH 0/3] Add derive-device function which searches for existing devices in both directions

2022-04-30 Thread ffmpegagent
This is an updated version of: [PATCH v4 1/1] avutils/hwcontext: When
deriving a hwdevice, search for existing device in both directions

There has been an objection that the earlier patchset would change API
behavior, and that this change should be limited to ffmpeg cli.

To achieve this, the API behavior is left unchanged now and a new function
av_hwdevice_ctx_get_or_create_derived() is added and used by the hwupload
and hwmap filters.

softworkz (3):
  avutils/hwcontext: add derive-device function which searches for
existing devices in both directions
  lavu: bump minor version and add doc/APIchanges entry for
av_hwdevice_ctx_get_or_create_derived()
  avfilter/hwmap,hwupload: use new av_hwdevice_ctx_get_or_create_derived
method

 doc/APIchanges |  3 ++
 libavfilter/vf_hwmap.c |  4 +-
 libavfilter/vf_hwupload.c  |  2 +-
 libavutil/hwcontext.c  | 72 +++---
 libavutil/hwcontext.h  | 20 ++
 libavutil/hwcontext_internal.h |  6 +++
 libavutil/hwcontext_qsv.c  | 13 --
 libavutil/version.h|  4 +-
 8 files changed, 110 insertions(+), 14 deletions(-)


base-commit: eef652ca9c893a84c6430fcdd53eed186c299d82
Published-As: 
https://github.com/ffstaging/FFmpeg/releases/tag/pr-ffstaging-25%2Fsoftworkz%2Fderive_devices-v1
Fetch-It-Via: git fetch https://github.com/ffstaging/FFmpeg 
pr-ffstaging-25/softworkz/derive_devices-v1
Pull-Request: https://github.com/ffstaging/FFmpeg/pull/25
-- 
ffmpeg-codebot
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH v3 26/26] avcodec/dvbsubdec: Fix conditions for fallback to default resolution

2022-01-19 Thread ffmpegagent
From: softworkz 

The previous code expected a segment of type CLUT definition to exist
in order to accept a set of segments to be complete.
This was an incorrect assumption as the presence of a CLUT segment
is not mandatory.
(version 1.6.1 of the spec is probably a bit more clear about this
than earlier versions: https://www.etsi.org/deliver/etsi_en/
300700_300799/300743/01.06.01_20/en_300743v010601a.pdf)

The flawed condition prevented proper fallback to using the default
resolution for the decoding context.

Signed-off-by: softworkz 
---
 libavcodec/dvbsubdec.c | 51 +-
 1 file changed, 30 insertions(+), 21 deletions(-)

diff --git a/libavcodec/dvbsubdec.c b/libavcodec/dvbsubdec.c
index 0d64c6e71c..3a6259101c 100644
--- a/libavcodec/dvbsubdec.c
+++ b/libavcodec/dvbsubdec.c
@@ -33,7 +33,7 @@
 #define DVBSUB_CLUT_SEGMENT 0x12
 #define DVBSUB_OBJECT_SEGMENT   0x13
 #define DVBSUB_DISPLAYDEFINITION_SEGMENT 0x14
-#define DVBSUB_DISPLAY_SEGMENT  0x80
+#define DVBSUB_END_DISPLAY_SEGMENT  0x80
 
 #define cm (ff_crop_tab + MAX_NEG_CROP)
 
@@ -1620,8 +1620,12 @@ static int dvbsub_decode(AVCodecContext *avctx,
 int segment_length;
 int i;
 int ret = 0;
-int got_segment = 0;
-int got_dds = 0;
+//int got_segment = 0;
+int got_page = 0;
+int got_region = 0;
+int got_object = 0;
+int got_end_display = 0;
+int got_displaydef = 0;
 
 ff_dlog(avctx, "DVB sub packet:\n");
 
@@ -1666,34 +1670,28 @@ static int dvbsub_decode(AVCodecContext *avctx,
 switch (segment_type) {
 case DVBSUB_PAGE_SEGMENT:
 ret = dvbsub_parse_page_segment(avctx, p, segment_length, sub, 
got_sub_ptr);
-got_segment |= 1;
+got_page = 1;
 break;
 case DVBSUB_REGION_SEGMENT:
 ret = dvbsub_parse_region_segment(avctx, p, segment_length);
-got_segment |= 2;
+got_region = 1;
 break;
 case DVBSUB_CLUT_SEGMENT:
 ret = dvbsub_parse_clut_segment(avctx, p, segment_length);
 if (ret < 0) goto end;
-got_segment |= 4;
 break;
 case DVBSUB_OBJECT_SEGMENT:
 ret = dvbsub_parse_object_segment(avctx, p, segment_length);
-got_segment |= 8;
+got_object = 1;
 break;
 case DVBSUB_DISPLAYDEFINITION_SEGMENT:
 ret = dvbsub_parse_display_definition_segment(avctx, p,
   segment_length);
-got_dds = 1;
+got_displaydef = 1;
 break;
-case DVBSUB_DISPLAY_SEGMENT:
+case DVBSUB_END_DISPLAY_SEGMENT:
 ret = dvbsub_display_end_segment(avctx, p, segment_length, 
sub, got_sub_ptr);
-if (got_segment == 15 && !got_dds && !avctx->width && 
!avctx->height) {
-// Default from ETSI EN 300 743 V1.3.1 (7.2.1)
-avctx->width  = 720;
-avctx->height = 576;
-}
-got_segment |= 16;
+got_end_display = 1;
 break;
 default:
 ff_dlog(avctx, "Subtitling segment type 0x%x, page id %d, 
length %d\n",
@@ -1706,13 +1704,24 @@ static int dvbsub_decode(AVCodecContext *avctx,
 
 p += segment_length;
 }
-// Some streams do not send a display segment but if we have all the other
-// segments then we need no further data.
-if (got_segment == 15) {
-av_log(avctx, AV_LOG_DEBUG, "Missing display_end_segment, 
emulating\n");
-dvbsub_display_end_segment(avctx, p, 0, sub, got_sub_ptr);
-}
 
+// Even though not mandated by the spec, we're imposing a minimum 
requirement
+// for a useful packet to have at least one page, region and object 
segment.
+if (got_page && got_region && got_object && got_end_display) {
+
+if (!got_displaydef && !avctx->width && !avctx->height) {
+// Default from ETSI EN 300 743 V1.3.1 (7.2.1)
+avctx->width  = 720;
+avctx->height = 576;
+}
+
+// Some streams do not send an end-of-display segment but if we have 
all the other
+// segments then we need no further data.
+if (!got_end_display) {
+av_log(avctx, AV_LOG_DEBUG, "Missing display_end_segment, 
emulating\n");
+dvbsub_display_end_segment(avctx, p, 0, sub, got_sub_ptr);
+}
+}
 end:
 if (ret < 0) {
 return ret;
-- 
ffmpeg-codebot
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH v3 25/26] avcodec/webvttenc: Don't encode drawing codes and empty lines

2022-01-19 Thread ffmpegagent
From: softworkz 

Signed-off-by: softworkz 
---
 libavcodec/webvttenc.c | 31 +++
 1 file changed, 27 insertions(+), 4 deletions(-)

diff --git a/libavcodec/webvttenc.c b/libavcodec/webvttenc.c
index 48945dcb8e..62c4aa7ffd 100644
--- a/libavcodec/webvttenc.c
+++ b/libavcodec/webvttenc.c
@@ -39,6 +39,8 @@ typedef struct {
 int count;
 char stack[WEBVTT_STACK_SIZE];
 int stack_ptr;
+int has_text;
+int drawing_scale;
 } WebVTTContext;
 
 #ifdef __GNUC__
@@ -115,17 +117,24 @@ static void webvtt_style_apply(WebVTTContext *s, const 
char *style)
 static void webvtt_text_cb(void *priv, const char *text, int len)
 {
 WebVTTContext *s = priv;
-av_bprint_append_data(&s->buffer, text, len);
+if (!s->drawing_scale) {
+av_bprint_append_data(&s->buffer, text, len);
+s->has_text = 1;
+}
 }
 
 static void webvtt_new_line_cb(void *priv, int forced)
 {
-webvtt_print(priv, "\n");
+WebVTTContext *s = priv;
+if (!s->drawing_scale)
+webvtt_print(priv, "\n");
 }
 
 static void webvtt_hard_space_cb(void *priv)
 {
-webvtt_print(priv, " ");
+WebVTTContext *s = priv;
+if (!s->drawing_scale)
+webvtt_print(priv, " ");
 }
 
 static void webvtt_style_cb(void *priv, char style, int close)
@@ -149,6 +158,12 @@ static void webvtt_end_cb(void *priv)
 webvtt_stack_push_pop(priv, 0, 1);
 }
 
+static void dialog_drawing_mode_cb(void *priv, int scale)
+{
+WebVTTContext *s = priv;
+s->drawing_scale = scale;
+}
+
 static const ASSCodesCallbacks webvtt_callbacks = {
 .text = webvtt_text_cb,
 .new_line = webvtt_new_line_cb,
@@ -161,6 +176,7 @@ static const ASSCodesCallbacks webvtt_callbacks = {
 .cancel_overrides = webvtt_cancel_overrides_cb,
 .move = NULL,
 .end  = webvtt_end_cb,
+.drawing_mode = dialog_drawing_mode_cb,
 };
 
 static void ensure_ass_context(WebVTTContext* s, const AVFrame* frame)
@@ -211,16 +227,23 @@ static int webvtt_encode_frame(AVCodecContext* avctx, 
AVPacket* avpkt,
 }
 
 if (ass) {
+const unsigned saved_len = s->buffer.len;
 
-if (i > 0)
+if (i > 0 && s->buffer.len > 0)
 webvtt_new_line_cb(s, 0);
 
+s->drawing_scale = 0;
+s->has_text = 0;
+
 dialog = avpriv_ass_split_dialog(s->ass_ctx, ass);
 if (!dialog)
 return AVERROR(ENOMEM);
 webvtt_style_apply(s, dialog->style);
 avpriv_ass_split_override_codes(&webvtt_callbacks, s, 
dialog->text);
 avpriv_ass_free_dialog(&dialog);
+
+if (!s->has_text)
+s->buffer.len = saved_len;
 }
 }
 
-- 
ffmpeg-codebot

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH v3 24/26] doc/APIchanges: update for subtitle filtering changes

2022-01-19 Thread ffmpegagent
From: softworkz 

Signed-off-by: softworkz 
---
 doc/APIchanges   | 24 
 libavcodec/version.h |  2 +-
 libavutil/version.h  |  2 +-
 3 files changed, 26 insertions(+), 2 deletions(-)

diff --git a/doc/APIchanges b/doc/APIchanges
index 8df0364e4c..c8238fb008 100644
--- a/doc/APIchanges
+++ b/doc/APIchanges
@@ -14,6 +14,30 @@ libavutil: 2021-04-27
 
 API changes, most recent first:
 
+2021-12-05 - xx - lavc 59.15.100 - avcodec.h
+  Deprecate avcodec_encode_subtitle(), use regular encode api now
+
+2021-12-05 - xx - lavc 59.15.100 - codec_desc.h
+  Add avcodec_descriptor_get_subtitle_format()
+
+2021-12-05 - xx - lavc 59.15.100 - avcodec.h
+  Deprecate avsubtitle_free()
+  Deprecate avcodec_decode_subtitle2(), use regular decode api now
+
+2021-12-05 - xx - lavu 57.11.100 - frame.h
+  Add AVMediaType field to AVFrame
+  Add Fields for carrying subtitle data to AVFrame
+  (subtitle_areas, subtitle_header, subtitle_pts, start/end time, etc.)
+  Add av_frame_get_buffer2() and deprecate av_frame_get_buffer()
+
+2021-12-05 - xx - lavu 57.11.100 - subfmt.h
+  Add struct AVSubtitleArea (replaces AVSubtitle)
+  Add av_get_subtitle_fmt_name() and av_get_subtitle_fmt()
+
+2021-12-05 - xx - lavu 57.11.100 - subfmt.h
+  Add enum AVSubtitleType (moved from lavc), add new values, deprecate existing
+
+2021-11-xx - xx - lavfi 8.19.100 - avfilter.h
 2022-01-04 - 78dc21b123e - lavu 57.16.100 - frame.h
   Add AV_FRAME_DATA_DOVI_METADATA.
 
diff --git a/libavcodec/version.h b/libavcodec/version.h
index a46fb05f1a..b5867ad041 100644
--- a/libavcodec/version.h
+++ b/libavcodec/version.h
@@ -28,7 +28,7 @@
 #include "libavutil/version.h"
 
 #define LIBAVCODEC_VERSION_MAJOR  59
-#define LIBAVCODEC_VERSION_MINOR  20
+#define LIBAVCODEC_VERSION_MINOR  21
 #define LIBAVCODEC_VERSION_MICRO 100
 
 #define LIBAVCODEC_VERSION_INT  AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \
diff --git a/libavutil/version.h b/libavutil/version.h
index 5bf48f6304..168e24f410 100644
--- a/libavutil/version.h
+++ b/libavutil/version.h
@@ -79,7 +79,7 @@
  */
 
 #define LIBAVUTIL_VERSION_MAJOR  57
-#define LIBAVUTIL_VERSION_MINOR  18
+#define LIBAVUTIL_VERSION_MINOR  19
 #define LIBAVUTIL_VERSION_MICRO 100
 
 #define LIBAVUTIL_VERSION_INT   AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \
-- 
ffmpeg-codebot

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH v3 23/26] avcodec/webvttenc: convert hard-space tags to  

2022-01-19 Thread ffmpegagent
From: softworkz 

Signed-off-by: softworkz 
---
 libavcodec/webvttenc.c   |  6 ++
 tests/ref/fate/sub-webvttenc | 10 +-
 2 files changed, 11 insertions(+), 5 deletions(-)

diff --git a/libavcodec/webvttenc.c b/libavcodec/webvttenc.c
index c0436f5739..48945dcb8e 100644
--- a/libavcodec/webvttenc.c
+++ b/libavcodec/webvttenc.c
@@ -123,6 +123,11 @@ static void webvtt_new_line_cb(void *priv, int forced)
 webvtt_print(priv, "\n");
 }
 
+static void webvtt_hard_space_cb(void *priv)
+{
+webvtt_print(priv, " ");
+}
+
 static void webvtt_style_cb(void *priv, char style, int close)
 {
 if (style == 's') // strikethrough unsupported
@@ -147,6 +152,7 @@ static void webvtt_end_cb(void *priv)
 static const ASSCodesCallbacks webvtt_callbacks = {
 .text = webvtt_text_cb,
 .new_line = webvtt_new_line_cb,
+.hard_space   = webvtt_hard_space_cb,
 .style= webvtt_style_cb,
 .color= NULL,
 .font_name= NULL,
diff --git a/tests/ref/fate/sub-webvttenc b/tests/ref/fate/sub-webvttenc
index f4172dcc84..ee9de2859e 100644
--- a/tests/ref/fate/sub-webvttenc
+++ b/tests/ref/fate/sub-webvttenc
@@ -132,26 +132,26 @@ but show this: {normal text}
 \ N is a forced line break
 \ h is a hard space
 Normal spaces at the start and at the end of the line are trimmed while hard 
spaces are not trimmed.
-The line will never break automatically right before or after a hard space. :-D
+The line will never break automatically right before or after a hard space. :-D
 
 00:54.501 --> 00:56.500
 
- A (05 hard spaces followed by a letter)
+ A (05 hard spaces followed by a letter)
 A (Normal  spaces followed by a letter)
 A (No hard spaces followed by a letter)
 
 00:56.501 --> 00:58.500
- A (05 hard spaces followed by a letter)
+ A (05 hard spaces followed by a letter)
 A (Normal  spaces followed by a letter)
 A (No hard spaces followed by a letter)
 Show this: \TEST and this: \-)
 
 00:58.501 --> 01:00.500
 
-A letter followed by 05 hard spaces: A 
+A letter followed by 05 hard spaces: A 
 A letter followed by normal  spaces: A
 A letter followed by no hard spaces: A
-05 hard  spaces between letters: A A
+05 hard  spaces between letters: A A
 5 normal spaces between letters: A A
 
 ^--Forced line break
-- 
ffmpeg-codebot

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH v3 22/26] avutil/ass_split: Add parsing of hard-space tags (\h)

2022-01-19 Thread ffmpegagent
From: softworkz 

The \h tag in ASS/SSA is indicating a non-breaking space. See
https://github.com/Aegisub/aegisite/blob/master/source/docs/3.2/
ASS_Tags.html.md

The ass_split implementation is used by almost all text subtitle
encoders and it didn't handle this tag. Interestingly, several
tests are testing for \h parsing and had incorrect reference data
for those tests.

The \h tag is specific to ASS and doesn't have any meaning outside
of ASS.
Still, the reference data for ttmlenc, textenc and webvttenc were
full of \h tags even though this tag doesn't have a meaning there.

Signed-off-by: softworkz 
---
 libavutil/ass_split.c|  7 +++
 tests/ref/fate/.gitattributes|  3 +++
 tests/ref/fate/mov-mp4-ttml-dfxp |  8 
 tests/ref/fate/mov-mp4-ttml-stpp |  8 
 tests/ref/fate/sub-textenc   | 10 +-
 tests/ref/fate/sub-ttmlenc   |  8 
 tests/ref/fate/sub-webvttenc | 10 +-
 7 files changed, 32 insertions(+), 22 deletions(-)
 create mode 100644 tests/ref/fate/.gitattributes

diff --git a/libavutil/ass_split.c b/libavutil/ass_split.c
index c5963351fc..30512dfc74 100644
--- a/libavutil/ass_split.c
+++ b/libavutil/ass_split.c
@@ -484,6 +484,7 @@ int avpriv_ass_split_override_codes(const ASSCodesCallbacks 
*callbacks, void *pr
 while (buf && *buf) {
 if (text && callbacks->text &&
 (sscanf(buf, "\\%1[nN]", new_line) == 1 ||
+ sscanf(buf, "\\%1[hH]", new_line) == 1 ||
  !strncmp(buf, "{\\", 2))) {
 callbacks->text(priv, text, text_len);
 text = NULL;
@@ -492,6 +493,12 @@ int avpriv_ass_split_override_codes(const 
ASSCodesCallbacks *callbacks, void *pr
 if (callbacks->new_line)
 callbacks->new_line(priv, new_line[0] == 'N');
 buf += 2;
+} else if (sscanf(buf, "\\%1[hH]", new_line) == 1) {
+if (callbacks->hard_space)
+callbacks->hard_space(priv);
+else if (callbacks->text)
+callbacks->text(priv, " ", 1);
+buf += 2;
 } else if (!strncmp(buf, "{\\", 2)) {
 buf++;
 while (*buf == '\\') {
diff --git a/tests/ref/fate/.gitattributes b/tests/ref/fate/.gitattributes
new file mode 100644
index 00..19be64d085
--- /dev/null
+++ b/tests/ref/fate/.gitattributes
@@ -0,0 +1,3 @@
+sub-textenc -diff
+sub-ttmlenc -diff
+sub-webvttenc -diff
diff --git a/tests/ref/fate/mov-mp4-ttml-dfxp b/tests/ref/fate/mov-mp4-ttml-dfxp
index e24b5d618b..e565ffa1f6 100644
--- a/tests/ref/fate/mov-mp4-ttml-dfxp
+++ b/tests/ref/fate/mov-mp4-ttml-dfxp
@@ -1,9 +1,9 @@
-2e7e01c821c111466e7a2844826b7f6d *tests/data/fate/mov-mp4-ttml-dfxp.mp4
-8519 tests/data/fate/mov-mp4-ttml-dfxp.mp4
+658884e1b789e75c454b25bdf71283c9 *tests/data/fate/mov-mp4-ttml-dfxp.mp4
+8486 tests/data/fate/mov-mp4-ttml-dfxp.mp4
 #tb 0: 1/1000
 #media_type 0: data
 #codec_id 0: none
-0,  0,  0,68500, 7866, 0x456c36b7
+0,  0,  0,68500, 7833, 0x31b22193
 {
 "packets": [
 {
@@ -15,7 +15,7 @@
 "dts_time": "0.00",
 "duration": 68500,
 "duration_time": "68.50",
-"size": "7866",
+"size": "7833",
 "pos": "44",
 "flags": "K_"
 }
diff --git a/tests/ref/fate/mov-mp4-ttml-stpp b/tests/ref/fate/mov-mp4-ttml-stpp
index 77bd23b7bf..f25b5b2d28 100644
--- a/tests/ref/fate/mov-mp4-ttml-stpp
+++ b/tests/ref/fate/mov-mp4-ttml-stpp
@@ -1,9 +1,9 @@
-cbd2c7ff864a663b0d893deac5a0caec *tests/data/fate/mov-mp4-ttml-stpp.mp4
-8547 tests/data/fate/mov-mp4-ttml-stpp.mp4
+c9570de0ccebc858b0c662a7e449582c *tests/data/fate/mov-mp4-ttml-stpp.mp4
+8514 tests/data/fate/mov-mp4-ttml-stpp.mp4
 #tb 0: 1/1000
 #media_type 0: data
 #codec_id 0: none
-0,  0,  0,68500, 7866, 0x456c36b7
+0,  0,  0,68500, 7833, 0x31b22193
 {
 "packets": [
 {
@@ -15,7 +15,7 @@ cbd2c7ff864a663b0d893deac5a0caec 
*tests/data/fate/mov-mp4-ttml-stpp.mp4
 "dts_time": "0.00",
 "duration": 68500,
 "duration_time": "68.50",
-"size": "7866",
+"size": "7833",
 "pos": "44",
 "flags": "K_"
 }
diff --git a/tests/ref/fate/sub-textenc b/tests/ref/fate/sub-textenc
index 3ea56b38f0..910ca3d6e3 100644
--- a/tests/ref/fate/sub-textenc
+++ b/tests/ref/fate/sub-textenc
@@ -160,18 +160,18 @@ but show this: {normal text}
 \ N is a forced line break
 \ h is a hard space
 Normal spaces at the start and at the end of the line are trimmed while hard 
spaces are not trimmed.
-The\hline\hwill\hnever\hbreak\hautomatically\hright\hbefore\hor\hafter\ha\hhard\hspace.\h:-D
+The line will never break automatically right before or after a hard space. :-D
 
 31
 00:00:54,501 --> 00:00:56,500
 
-\h\h\h\h\hA (05 hard spaces followed by a letter)
+ A (05 hard spaces followed by a let

[FFmpeg-devel] [PATCH v3 20/26] avcodec/subtitles: Migrate subtitle encoders to frame-based API

2022-01-19 Thread ffmpegagent
From: softworkz 

and provide a compatibility shim for the legacy api

Signed-off-by: softworkz 
---
 libavcodec/assenc.c| 189 ++---
 libavcodec/avcodec.h   |   5 +-
 libavcodec/dvbsubenc.c |  96 ++-
 libavcodec/dvdsubenc.c | 102 
 libavcodec/encode.c|  61 +++-
 libavcodec/movtextenc.c| 114 --
 libavcodec/srtenc.c| 108 ++---
 libavcodec/tests/avcodec.c |   2 -
 libavcodec/ttmlenc.c   | 101 +++-
 libavcodec/webvttenc.c |  86 -
 libavcodec/xsubenc.c   |  88 ++---
 11 files changed, 687 insertions(+), 265 deletions(-)

diff --git a/libavcodec/assenc.c b/libavcodec/assenc.c
index b0e475834b..e1401b1ac5 100644
--- a/libavcodec/assenc.c
+++ b/libavcodec/assenc.c
@@ -22,70 +22,195 @@
 #include 
 
 #include "avcodec.h"
+#include "encode.h"
 #include "libavutil/ass_internal.h"
 #include "internal.h"
 #include "libavutil/avstring.h"
 #include "libavutil/internal.h"
 #include "libavutil/mem.h"
 
+typedef struct {
+AVCodecContext *avctx;
+AVFrame* current_frame;
+int have_frame;
+int current_area;
+} AssEncContext;
+
+static void check_write_header(AVCodecContext* avctx, const AVFrame* frame)
+{
+if (avctx->extradata_size)
+return;
+
+if (frame->subtitle_header && frame->subtitle_header->size > 0) {
+const char* subtitle_header = (char*)frame->subtitle_header->data;
+avctx->extradata_size = strlen(subtitle_header);
+avctx->extradata = av_mallocz(frame->subtitle_header->size + 1);
+memcpy(avctx->extradata, subtitle_header, avctx->extradata_size);
+avctx->extradata[avctx->extradata_size] = 0;
+}
+
+if (!avctx->extradata_size) {
+const char* subtitle_header = 
avpriv_ass_get_subtitle_header_default(0);
+if (!subtitle_header)
+return;
+
+avctx->extradata_size = strlen(subtitle_header);
+avctx->extradata = av_mallocz(avctx->extradata_size + 1);
+memcpy(avctx->extradata, subtitle_header, avctx->extradata_size);
+avctx->extradata[avctx->extradata_size] = 0;
+av_freep(&subtitle_header);
+}
+}
+
 static av_cold int ass_encode_init(AVCodecContext *avctx)
 {
-avctx->extradata = av_malloc(avctx->subtitle_header_size + 1);
-if (!avctx->extradata)
-return AVERROR(ENOMEM);
-memcpy(avctx->extradata, avctx->subtitle_header, 
avctx->subtitle_header_size);
-avctx->extradata_size = avctx->subtitle_header_size;
-avctx->extradata[avctx->extradata_size] = 0;
+AssEncContext *s = avctx->priv_data;
+
+if (avctx->subtitle_header_size) {
+avctx->extradata = av_malloc(avctx->subtitle_header_size + 1);
+if (!avctx->extradata)
+return AVERROR(ENOMEM);
+memcpy(avctx->extradata, avctx->subtitle_header, 
avctx->subtitle_header_size);
+avctx->extradata_size   = avctx->subtitle_header_size;
+avctx->extradata[avctx->extradata_size] = 0;
+}
+
+s->current_frame = av_frame_alloc();
+return 0;
+}
+
+static av_cold int ass_encode_close(AVCodecContext *avctx)
+{
+AssEncContext *s = avctx->priv_data;
+av_frame_free(&s->current_frame);
 return 0;
 }
 
-static int ass_encode_frame(AVCodecContext *avctx,
-unsigned char *buf, int bufsize,
-const AVSubtitle *sub)
+static int ass_encode_frame(AVCodecContext* avctx, AVPacket* avpkt,
+const AVFrame* frame, int* got_packet)
+{
+int ret;
+size_t req_len = 0, total_len = 0;
+
+check_write_header(avctx, frame);
+
+for (unsigned i = 0; i < frame->num_subtitle_areas; i++) {
+const char *ass = frame->subtitle_areas[i]->ass;
+
+if (frame->subtitle_areas[i]->type != AV_SUBTITLE_FMT_ASS) {
+av_log(avctx, AV_LOG_ERROR, "Only AV_SUBTITLE_FMT_ASS type 
supported.\n");
+return AVERROR(EINVAL);
+}
+
+if (ass)
+req_len += strlen(ass);
+}
+
+ret = ff_get_encode_buffer(avctx, avpkt, req_len + 1, 0);
+if (ret < 0) {
+av_log(avctx, AV_LOG_ERROR, "Error getting output packet.\n");
+return ret;
+}
+
+for (unsigned i = 0; i < frame->num_subtitle_areas; i++) {
+const char *ass = frame->subtitle_areas[i]->ass;
+
+if (ass) {
+size_t len = av_strlcpy((char *)avpkt->data + total_len, ass, 
avpkt->size - total_len);
+total_len += len;
+}
+}
+
+avpkt->size = total_len;
+*got_packet = total_len > 0;
+
+return 0;
+}
+
+static int ass_receive_packet(AVCodecContext *avctx, AVPacket *avpkt)
 {
-int i, len, total_len = 0;
+AssEncContext *s = avctx-

[FFmpeg-devel] [PATCH v3 19/26] avfilter/subfeed: add subtitle feed filter

2022-01-19 Thread ffmpegagent
From: softworkz 

Signed-off-by: softworkz 
---
 libavfilter/Makefile |   1 +
 libavfilter/allfilters.c |   1 +
 libavfilter/sf_subfeed.c | 366 +++
 3 files changed, 368 insertions(+)
 create mode 100644 libavfilter/sf_subfeed.c

diff --git a/libavfilter/Makefile b/libavfilter/Makefile
index 94160d1429..ad8a5a9d18 100644
--- a/libavfilter/Makefile
+++ b/libavfilter/Makefile
@@ -571,6 +571,7 @@ OBJS-$(CONFIG_TEXTMOD_FILTER)+= sf_textmod.o
 OBJS-$(CONFIG_SPLITCC_FILTER)+= sf_splitcc.o
 OBJS-$(CONFIG_STRIPSTYLES_FILTER)+= sf_stripstyles.o
 OBJS-$(CONFIG_SUBSCALE_FILTER)   += sf_subscale.o
+OBJS-$(CONFIG_SUBFEED_FILTER)+= sf_subfeed.o
 
 # multimedia filters
 OBJS-$(CONFIG_ABITSCOPE_FILTER)  += avf_abitscope.o
diff --git a/libavfilter/allfilters.c b/libavfilter/allfilters.c
index 487e2bd6a8..fe1aec093b 100644
--- a/libavfilter/allfilters.c
+++ b/libavfilter/allfilters.c
@@ -554,6 +554,7 @@ extern const AVFilter ff_sf_showspeaker;
 extern const AVFilter ff_sf_splitcc;
 extern const AVFilter ff_sf_stripstyles;
 extern const AVFilter ff_sf_subscale;
+extern const AVFilter ff_sf_subfeed;
 extern const AVFilter ff_sf_textmod;
 extern const AVFilter ff_svf_graphicsub2video;
 extern const AVFilter ff_svf_textsub2video;
diff --git a/libavfilter/sf_subfeed.c b/libavfilter/sf_subfeed.c
new file mode 100644
index 00..7df6641f6a
--- /dev/null
+++ b/libavfilter/sf_subfeed.c
@@ -0,0 +1,366 @@
+/*
+ * Copyright (c) 2021 softworkz
+ *
+ * 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
+ * subtitle filter for feeding subtitle frames into a filtergraph in a 
contiguous way
+ *
+ *
+ * also supports
+ *   - duration fixup
+ * delaying a subtitle event with unknown duration and infer duration from 
the
+ * start time of the subsequent subtitle
+ *   - scattering
+ * splitting a subtitle event with unknown duration into multiple ones with
+ * a short and fixed duration
+ *
+ */
+
+#include "filters.h"
+#include "libavutil/opt.h"
+#include "subtitles.h"
+#include "libavutil/avassert.h"
+
+enum SubFeedMode {
+FM_REPEAT,
+FM_SCATTER,
+FM_FORWARD,
+};
+
+typedef struct SubFeedContext {
+const AVClass *class;
+enum AVSubtitleType format;
+enum SubFeedMode mode;
+
+AVRational frame_rate;
+int fix_durations;
+int fix_overlap;
+
+int current_frame_isnew;
+int eof;
+int got_first_input;
+int need_frame;
+int64_t next_pts_offset;
+int64_t recent_subtitle_pts;
+
+int64_t counter;
+
+/**
+ * Queue of frames waiting to be filtered.
+ */
+FFFrameQueue fifo;
+
+} SubFeedContext;
+
+static int64_t ms_to_avtb(int64_t ms)
+{
+return av_rescale_q(ms, (AVRational){ 1, 1000 }, AV_TIME_BASE_Q);
+}
+
+static int64_t avtb_to_ms(int64_t avtb)
+{
+return av_rescale_q(avtb, AV_TIME_BASE_Q, (AVRational){ 1, 1000 });
+}
+
+static int init(AVFilterContext *ctx)
+{
+SubFeedContext *s = ctx->priv;
+
+ff_framequeue_init(&s->fifo, NULL);
+
+return 0;
+}
+
+static void uninit(AVFilterContext *ctx)
+{
+SubFeedContext *s = ctx->priv;
+ff_framequeue_free(&s->fifo);
+}
+
+static int config_input(AVFilterLink *link)
+{
+const subfeedContext *context = link->dst->priv;
+
+return 0;
+}
+
+static int query_formats(AVFilterContext *ctx)
+{
+AVFilterFormats *formats;
+AVFilterLink *inlink0 = ctx->inputs[0];
+AVFilterLink *outlink0 = ctx->outputs[0];
+static const enum AVSubtitleType subtitle_fmts[] = { 
AV_SUBTITLE_FMT_BITMAP, AV_SUBTITLE_FMT_ASS, AV_SUBTITLE_FMT_NB };
+int ret;
+
+formats = ff_make_format_list(subtitle_fmts);
+
+if ((ret = ff_formats_ref(formats, &inlink0->outcfg.formats)) < 0)
+return ret;
+
+if ((ret = ff_formats_ref(formats, &outlink0->incfg.formats)) < 0)
+return ret;
+
+return 0;
+}
+
+static int config_output(AVFilterLink *outlink)
+{
+SubFeedContext *s = outlink->src->priv;
+const AVFilterLink *inlink = outlink->src->inputs[0];
+
+outlink->time_base = AV_TIME_BASE_Q;
+outlink->format = inlink->format;
+outlink->w = inlink->w;
+outlink->h = inlink->h;
+
+if (s->mode == FM_FORWARD)
+

[FFmpeg-devel] [PATCH v3 18/26] avfilter/subscale: Add filter for scaling and/or re-arranging graphical subtitles

2022-01-19 Thread ffmpegagent
From: softworkz 

Signed-off-by: softworkz 
---
 configure |   1 +
 doc/filters.texi  | 164 +++
 libavfilter/Makefile  |   1 +
 libavfilter/allfilters.c  |   1 +
 libavfilter/sf_subscale.c | 884 ++
 5 files changed, 1051 insertions(+)
 create mode 100644 libavfilter/sf_subscale.c

diff --git a/configure b/configure
index 59d3bb86f0..acb788edfc 100755
--- a/configure
+++ b/configure
@@ -3732,6 +3732,7 @@ sr_filter_deps="avformat swscale"
 sr_filter_select="dnn"
 stereo3d_filter_deps="gpl"
 splitcc_filter_deps="avcodec"
+subscale_filter_deps="swscale avcodec"
 subtitles_filter_deps="avformat avcodec libass"
 super2xsai_filter_deps="gpl"
 pixfmts_super2xsai_test_deps="super2xsai_filter"
diff --git a/doc/filters.texi b/doc/filters.texi
index 1c0a00c7ae..c9a1616d84 100644
--- a/doc/filters.texi
+++ b/doc/filters.texi
@@ -26354,6 +26354,170 @@ Set the rendering margin in pixels.
 For rendering, alway use the latest event only, which is covering the given 
point in time.
 @end table
 
+@section subscale
+
+Provides high-quality scaling and rearranging functionality for graphical 
subtitles.
+
+The subscale filter provides multiple approaches for manipulating
+the size and position of graphical subtitle rectangles wich can
+be combined or used separately.
+Scaling is performed by converting the palettized subtitle bitmaps
+to RGBA and re-quantization to palette colors afterwards via elbg algorithm.
+
+The two major operations are 'scale' and 're-arrange' with the
+latter being separated as 'arrange_h' and 'arrange_v'.
+
+
+Inputs:
+- 0: Subtitles [bitmap]
+
+Outputs:
+- 0: Subtitles [bitmap]
+
+It accepts the following parameters:
+
+@table @option
+
+@item w, width
+Set the width of the output.
+Width and height in case of graphical subtitles are just indicating
+a virtual size for which the output (consisting of 0-n bitmap rectangles)
+is intended to be displayed on.
+
+@item h, height
+Set the height of the output.
+
+@item margin_h
+Sets a horizontal margin to be preserverved when using any
+of the arrange modes.
+
+@item margin_v
+Sets a vertical margin to be preserverved when using any
+of the arrange modes.
+
+@item force_original_aspect_ratio
+Enable decreasing or increasing output video width or height if necessary to
+keep the original aspect ratio. Possible values:
+
+@table @samp
+@item disable
+Scale the video as specified and disable this feature.
+
+@item decrease
+The output video dimensions will automatically be decreased if needed.
+
+@item increase
+The output video dimensions will automatically be increased if needed.
+
+@end table
+
+
+@item scale_mode
+Specifies how subtitle bitmaps should be scaled.
+The scale factor is determined by the the factor between input
+and output size.
+
+@table @samp
+@item none
+Do not apply any common scaling.
+
+@item uniform
+Uniformly scale all subtitle bitmaps including their positions.
+
+@item uniform_no_reposition
+Uniformly scale all subtitle bitmaps without changing positions.
+
+@end table
+
+
+@item arrange_h
+Specifies how subtitle bitmaps should be arranged horizontally.
+
+@item arrange_v
+Specifies how subtitle bitmaps should be arranged vertically.
+
+
+@table @samp
+@item none
+Do not rearrange subtitle bitmaps.
+
+@item margin_no_scale
+Move subtitle bitmaps to be positioned inside the specified
+margin (margin_h or margin_v) when possible and without scaling.
+
+@item margin_and_scale
+Move subtitle bitmaps to be positioned inside the specified
+margin (margin_h or margin_v) and scale in case it doesn't fit.
+
+@item snapalign_no_scale
+Categorize subtitle bitmap positions as one of left/center/right
+or top/bottom/middle based on original positioning and apply
+these alignments for the target positioning.
+No scaling will be applied.
+
+@item snapalign_and_scale
+Categorize subtitle bitmap positions as one of left/center/right
+or top/bottom/middle based on original positioning and apply
+these alignments for the target positioning.
+Bitmaps that do not fit inside the margins borders are
+scaled to fit.
+@end table
+
+@item eval
+Set evaluation mode for the expressions (@option{width}, @option{height}).
+
+It accepts the following values:
+@table @samp
+@item init
+Evaluate expressions only once during the filter initialization.
+
+@item frame
+Evaluate expressions for each incoming frame. This is way slower than the
+@samp{init} mode since it requires all the scalers to be re-computed, but it
+allows advanced dynamic expressions.
+@end table
+
+Default value is @samp{init}.
+
+
+@item num_colors
+Set the number of palette colors for output images.
+Choose the maximum (256) when further processing is done (e.g.
+overlaying on a video).
+When subtitles will be encoded as bitmap subtitles (e.g. dvbsub),
+a smaller number of palette colors (e.g. 4-16) might need to be used, depending
+on the target format and codec.
+
+@item bitmap_width_align
+@item bitmap_height_align
+Make s

[FFmpeg-devel] [PATCH v3 17/26] avfilter/graphicsub2text: Add new graphicsub2text filter (OCR)

2022-01-19 Thread ffmpegagent
From: softworkz 

Signed-off-by: softworkz 
---
 configure|1 +
 doc/filters.texi |   55 ++
 libavfilter/Makefile |2 +
 libavfilter/allfilters.c |1 +
 libavfilter/sf_graphicsub2text.c | 1132 ++
 5 files changed, 1191 insertions(+)
 create mode 100644 libavfilter/sf_graphicsub2text.c

diff --git a/configure b/configure
index 2a561b6f75..59d3bb86f0 100755
--- a/configure
+++ b/configure
@@ -3665,6 +3665,7 @@ frei0r_filter_deps="frei0r"
 frei0r_src_filter_deps="frei0r"
 fspp_filter_deps="gpl"
 gblur_vulkan_filter_deps="vulkan spirv_compiler"
+graphicsub2text_filter_deps="libtesseract"
 hflip_vulkan_filter_deps="vulkan spirv_compiler"
 histeq_filter_deps="gpl"
 hqdn3d_filter_deps="gpl"
diff --git a/doc/filters.texi b/doc/filters.texi
index c7a11a0896..1c0a00c7ae 100644
--- a/doc/filters.texi
+++ b/doc/filters.texi
@@ -25948,6 +25948,61 @@ ffmpeg -i 
"https://streams.videolan.org/ffmpeg/mkv_subtitles.mkv"; -filter_comple
 @end example
 @end itemize
 
+@section graphicsub2text
+
+Converts graphic subtitles to text subtitles by performing OCR.
+
+For this filter to be available, ffmpeg needs to be compiled with libtesseract 
(see https://github.com/tesseract-ocr/tesseract).
+Language models need to be downloaded from 
https://github.com/tesseract-ocr/tessdata and put into as subfolder named 
'tessdata' or into a folder specified via the environment variable 
'TESSDATA_PREFIX'.
+The path can also be specified via filter option (see below).
+
+Note: These models are including the data for both OCR modes.
+
+Inputs:
+- 0: Subtitles [bitmap]
+
+Outputs:
+- 0: Subtitles [text]
+
+It accepts the following parameters:
+
+@table @option
+@item ocr_mode
+The character recognition mode to use.
+
+Supported OCR modes are:
+
+@table @var
+@item 0, tesseract
+This is the classic libtesseract operation mode. It is fast but less accurate 
than LSTM.
+@item 1, lstm
+Newer OCR implementation based on ML models. Provides usually better results, 
requires more processing resources.
+@item 2, both
+Use a combination of both modes.
+@end table
+
+@item tessdata_path
+The path to a folder containing the language models to be used.
+
+@item language
+The recognition language. It needs to match the first three characters of a  
language model file in the tessdata path.
+
+@end table
+
+
+@subsection Examples
+
+@itemize
+@item
+Convert DVB graphic subtitles to ASS (text) subtitles
+
+Note: For this to work, you need to have the data file 'eng.traineddata' in a 
'tessdata' subfolder (see above).
+@example
+ffmpeg -loglevel verbose -i 
"https://streams.videolan.org/streams/ts/video_subs_ttxt%2Bdvbsub.ts"; 
-filter_complex "[0:13]graphicsub2text=delay_when_no_duration=1" -c:s ass -y 
output.mkv
+@end example
+@end itemize
+
+
 @section graphicsub2video
 
 Renders graphic subtitles as video frames.
diff --git a/libavfilter/Makefile b/libavfilter/Makefile
index b2e715cf8a..1397351373 100644
--- a/libavfilter/Makefile
+++ b/libavfilter/Makefile
@@ -299,6 +299,8 @@ OBJS-$(CONFIG_GBLUR_VULKAN_FILTER)   += 
vf_gblur_vulkan.o vulkan.o vulka
 OBJS-$(CONFIG_GEQ_FILTER)+= vf_geq.o
 OBJS-$(CONFIG_GRADFUN_FILTER)+= vf_gradfun.o
 OBJS-$(CONFIG_GRAPHICSUB2VIDEO_FILTER)   += vf_overlaygraphicsubs.o 
framesync.o
+OBJS-$(CONFIG_GRAPHICSUB2TEXT_FILTER)+= sf_graphicsub2text.o
+OBJS-$(CONFIG_GRAPHICSUB2VIDEO_FILTER)   += vf_overlaygraphicsubs.o 
framesync.o
 OBJS-$(CONFIG_GRAPHMONITOR_FILTER)   += f_graphmonitor.o
 OBJS-$(CONFIG_GRAYWORLD_FILTER)  += vf_grayworld.o
 OBJS-$(CONFIG_GREYEDGE_FILTER)   += vf_colorconstancy.o
diff --git a/libavfilter/allfilters.c b/libavfilter/allfilters.c
index 4996d3d27a..544eca616a 100644
--- a/libavfilter/allfilters.c
+++ b/libavfilter/allfilters.c
@@ -549,6 +549,7 @@ extern const AVFilter ff_avf_showwaves;
 extern const AVFilter ff_avf_showwavespic;
 extern const AVFilter ff_vaf_spectrumsynth;
 extern const AVFilter ff_sf_censor;
+extern const AVFilter ff_sf_graphicsub2text;
 extern const AVFilter ff_sf_showspeaker;
 extern const AVFilter ff_sf_splitcc;
 extern const AVFilter ff_sf_stripstyles;
diff --git a/libavfilter/sf_graphicsub2text.c b/libavfilter/sf_graphicsub2text.c
new file mode 100644
index 00..9b413d314e
--- /dev/null
+++ b/libavfilter/sf_graphicsub2text.c
@@ -0,0 +1,1132 @@
+/*
+ * Copyright (c) 2021 softworkz
+ *
+ * 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 Gene

[FFmpeg-devel] [PATCH v3 16/26] avfilter/splitcc: Add splitcc filter for closed caption handling

2022-01-19 Thread ffmpegagent
From: softworkz 

- splitcc {V -> VS)
  Extract closed-caption (A53) data from video
  frames as subtitle Frames

ffmpeg -y -loglevel verbose -i "https://streams.videolan.org/streams
/ts/CC/NewsStream-608-ac3.ts" -filter_complex "[0:v]splitcc[vid1],
textmod=mode=remove_chars:find='@',[vid1]overlay_textsubs" output.mkv

Signed-off-by: softworkz 
---
 configure|   1 +
 doc/filters.texi |  63 +++
 libavfilter/Makefile |   1 +
 libavfilter/allfilters.c |   1 +
 libavfilter/sf_splitcc.c | 395 +++
 5 files changed, 461 insertions(+)
 create mode 100644 libavfilter/sf_splitcc.c

diff --git a/configure b/configure
index 7b66e315f2..2a561b6f75 100755
--- a/configure
+++ b/configure
@@ -3730,6 +3730,7 @@ spp_filter_select="fft idctdsp fdctdsp me_cmp pixblockdsp"
 sr_filter_deps="avformat swscale"
 sr_filter_select="dnn"
 stereo3d_filter_deps="gpl"
+splitcc_filter_deps="avcodec"
 subtitles_filter_deps="avformat avcodec libass"
 super2xsai_filter_deps="gpl"
 pixfmts_super2xsai_test_deps="super2xsai_filter"
diff --git a/doc/filters.texi b/doc/filters.texi
index 2f0e560ca0..c7a11a0896 100644
--- a/doc/filters.texi
+++ b/doc/filters.texi
@@ -26182,6 +26182,69 @@ ffmpeg -i INPUT -filter_complex 
"showspeaker=format=colon:style='@{\\c&HDD&\
 @end example
 @end itemize
 
+
+@section splitcc
+
+Split-out closed-caption/A53 subtitles from video frame side data.
+
+This filter provides an input and an output for video frames, which are just 
passed through without modification.
+The second out provides subtitle frames which are extracted from video frame 
side data.
+
+Inputs:
+@itemize
+@item 0: Video [ALL]
+@end itemize
+
+Outputs:
+@itemize
+@item 0: Video (same as input)
+@item 1: Subtitles [TEXT]
+@end itemize
+
+It accepts the following parameters:
+
+@table @option
+
+@item use_cc_styles
+Emit closed caption style header.
+This will make closed captions appear in white font with a black rectangle 
background.
+
+@item real_time
+Emit subtitle events as they are decoded for real-time display.
+
+@item real_time_latency_msec
+Minimum elapsed time between emitting real-time subtitle events.
+Only applies to real_time mode.
+
+@item data_field
+Select data field. Possible values:
+
+@table @samp
+@item auto
+Pick first one that appears.
+@item first
+@item second
+@end table
+
+@end table
+
+@subsection Examples
+
+@itemize
+@item
+Extract closed captions as text subtitle stream and overlay it onto the video 
in cc style (black bar background):
+@example
+ffmpeg -i "https://streams.videolan.org/streams/ts/CC/NewsStream-608-ac3.ts"; 
-filter_complex  
"[0:v:0]splitcc=use_cc_styles=1[vid1][sub1];[vid1][sub1]overlaytextsubs" 
output.mkv
+@end example
+
+@item
+A nicer variant, using realtime output from cc_dec and rendering it with the 
render_latest_only parameter from overlaytextsubs to avoid ghosting by timely 
overlap.
+@example
+ffmpeg -i "https://streams.videolan.org/streams/ts/CC/NewsStream-608-ac3.ts"; 
-filter_complex  
"[0:v:0]splitcc=real_time=1:real_time_latency_msec=200[vid1][sub1];[vid1][sub1]overlaytextsubs=render_latest_only=1"
 output.mkv
+@end example
+@end itemize
+
+
 @section textsub2video
 
 Converts text subtitles to video frames.
diff --git a/libavfilter/Makefile b/libavfilter/Makefile
index 9c512e3527..b2e715cf8a 100644
--- a/libavfilter/Makefile
+++ b/libavfilter/Makefile
@@ -566,6 +566,7 @@ OBJS-$(CONFIG_NULLSINK_FILTER)   += 
vsink_nullsink.o
 OBJS-$(CONFIG_CENSOR_FILTER) += sf_textmod.o
 OBJS-$(CONFIG_SHOW_SPEAKER_FILTER)   += sf_textmod.o
 OBJS-$(CONFIG_TEXTMOD_FILTER)+= sf_textmod.o
+OBJS-$(CONFIG_SPLITCC_FILTER)+= sf_splitcc.o
 OBJS-$(CONFIG_STRIPSTYLES_FILTER)+= sf_stripstyles.o
 
 # multimedia filters
diff --git a/libavfilter/allfilters.c b/libavfilter/allfilters.c
index 23f65533a1..4996d3d27a 100644
--- a/libavfilter/allfilters.c
+++ b/libavfilter/allfilters.c
@@ -550,6 +550,7 @@ extern const AVFilter ff_avf_showwavespic;
 extern const AVFilter ff_vaf_spectrumsynth;
 extern const AVFilter ff_sf_censor;
 extern const AVFilter ff_sf_showspeaker;
+extern const AVFilter ff_sf_splitcc;
 extern const AVFilter ff_sf_stripstyles;
 extern const AVFilter ff_sf_textmod;
 extern const AVFilter ff_svf_graphicsub2video;
diff --git a/libavfilter/sf_splitcc.c b/libavfilter/sf_splitcc.c
new file mode 100644
index 00..14235e822c
--- /dev/null
+++ b/libavfilter/sf_splitcc.c
@@ -0,0 +1,395 @@
+/*
+ * Copyright (c) 2021 softworkz
+ *
+ * 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
+

[FFmpeg-devel] [PATCH v3 15/26] avfilter/stripstyles: Add stripstyles filter

2022-01-19 Thread ffmpegagent
From: softworkz 

- stripstyles {S -> S)
  Remove all inline styles from subtitle events

Signed-off-by: softworkz 
---
 doc/filters.texi |  37 ++
 libavfilter/Makefile |   1 +
 libavfilter/allfilters.c |   1 +
 libavfilter/sf_stripstyles.c | 211 +++
 4 files changed, 250 insertions(+)
 create mode 100644 libavfilter/sf_stripstyles.c

diff --git a/doc/filters.texi b/doc/filters.texi
index 6559f9d101..2f0e560ca0 100644
--- a/doc/filters.texi
+++ b/doc/filters.texi
@@ -25832,6 +25832,43 @@ ffmpeg -i 
"http://streams.videolan.org/samples/sub/SSA/subtitle_testing_complex.
 @end example
 @end itemize
 
+@section stripstyles
+
+Remove all inline styles from subtitle events.
+
+Inputs:
+@itemize
+@item 0: Subtitles[TEXT]
+@end itemize
+
+Outputs:
+@itemize
+@item 0: Subtitles[TEXT]
+@end itemize
+
+It accepts the following parameters:
+
+@table @option
+@item remove_animated
+Also remove text which is subject to animation (default: true)
+Usually, animated text elements are used used in addition to static subtitle 
lines for creating effects, so in most cases it is safe to remove the animation 
content.
+If subtitle text is missing, try setting this to false.
+
+@item select_layer
+Process only ASS subtitle events from a specific layer. This allows to filter 
out certain effects where an ASS author duplicates the text onto multiple 
layers.
+
+@end table
+
+@subsection Examples
+
+@itemize
+@item
+Remove styles and animations from ASS subtitles and output events from ass 
layer 0 only. Then convert asn save as SRT stream:
+@example
+ffmpeg -i 
"https://streams.videolan.org/samples/sub/SSA/subtitle_testing_complex.mkv"; 
-filter_complex "[0:1]stripstyles=select_layer=0" -map 0 -c:s srt output.mkv
+@end example
+@end itemize
+
 
 @section textmod
 
diff --git a/libavfilter/Makefile b/libavfilter/Makefile
index 4579b7c8c0..9c512e3527 100644
--- a/libavfilter/Makefile
+++ b/libavfilter/Makefile
@@ -566,6 +566,7 @@ OBJS-$(CONFIG_NULLSINK_FILTER)   += 
vsink_nullsink.o
 OBJS-$(CONFIG_CENSOR_FILTER) += sf_textmod.o
 OBJS-$(CONFIG_SHOW_SPEAKER_FILTER)   += sf_textmod.o
 OBJS-$(CONFIG_TEXTMOD_FILTER)+= sf_textmod.o
+OBJS-$(CONFIG_STRIPSTYLES_FILTER)+= sf_stripstyles.o
 
 # multimedia filters
 OBJS-$(CONFIG_ABITSCOPE_FILTER)  += avf_abitscope.o
diff --git a/libavfilter/allfilters.c b/libavfilter/allfilters.c
index 9c489fdc66..23f65533a1 100644
--- a/libavfilter/allfilters.c
+++ b/libavfilter/allfilters.c
@@ -550,6 +550,7 @@ extern const AVFilter ff_avf_showwavespic;
 extern const AVFilter ff_vaf_spectrumsynth;
 extern const AVFilter ff_sf_censor;
 extern const AVFilter ff_sf_showspeaker;
+extern const AVFilter ff_sf_stripstyles;
 extern const AVFilter ff_sf_textmod;
 extern const AVFilter ff_svf_graphicsub2video;
 extern const AVFilter ff_svf_textsub2video;
diff --git a/libavfilter/sf_stripstyles.c b/libavfilter/sf_stripstyles.c
new file mode 100644
index 00..bc3c5d1441
--- /dev/null
+++ b/libavfilter/sf_stripstyles.c
@@ -0,0 +1,211 @@
+/*
+ * Copyright (c) 2021 softworkz
+ *
+ * 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
+ * text subtitle filter which removes inline-styles from subtitles
+ */
+
+#include "libavutil/opt.h"
+#include "internal.h"
+#include "libavutil/ass_split_internal.h"
+#include "libavutil/bprint.h"
+
+typedef struct StripStylesContext {
+const AVClass *class;
+enum AVSubtitleType format;
+int remove_animated;
+int select_layer;
+} StripStylesContext;
+
+typedef struct DialogContext {
+StripStylesContext* ss_ctx;
+AVBPrint buffer;
+int drawing_scale;
+int is_animated;
+} DialogContext;
+
+static void dialog_text_cb(void *priv, const char *text, int len)
+{
+DialogContext *s = priv;
+
+av_log(s->ss_ctx, AV_LOG_DEBUG, "dialog_text_cb: %s\n", text);
+
+if (!s->drawing_scale && (!s->is_animated || !s->ss_ctx->remove_animated))
+av_bprint_append_data(&s->buffer, text, len);
+}
+
+static void dialog_new_line_cb(void *priv, int forced)
+{
+DialogContext *s = priv;
+if (!s->drawing_scale && !s->is_animated)
+av_bprint_append_data(&s->buffer, forced ? "\\N" : "\\n", 2);
+}

[FFmpeg-devel] [PATCH v3 14/26] avfilter/textmod: Add textmod, censor and show_speaker filters

2022-01-19 Thread ffmpegagent
From: softworkz 

- textmod {S -> S)
  Modify subtitle text in a number of ways

- censor {S -> S)
  Censor subtitles using a word list

- show_speaker {S -> S)
  Prepend speaker names from ASS subtitles to the visible text lines

Signed-off-by: softworkz 
---
 doc/filters.texi | 206 
 libavfilter/Makefile |   5 +
 libavfilter/allfilters.c |   3 +
 libavfilter/sf_textmod.c | 710 +++
 4 files changed, 924 insertions(+)
 create mode 100644 libavfilter/sf_textmod.c

diff --git a/doc/filters.texi b/doc/filters.texi
index 02a854851c..6559f9d101 100644
--- a/doc/filters.texi
+++ b/doc/filters.texi
@@ -25772,6 +25772,145 @@ existing filters using @code{--disable-filters}.
 
 Below is a description of the currently available subtitle filters.
 
+
+@section censor
+
+Censor selected words in text subtitles.
+
+Inputs:
+@itemize
+@item 0: Subtitles[TEXT]
+@end itemize
+
+Outputs:
+@itemize
+@item 0: Subtitles[TEXT]
+@end itemize
+
+It accepts the following parameters:
+
+@table @option
+@item mode
+The censoring mode to apply.
+
+Supported censoring modes are:
+
+@table @var
+@item 0, keep_first_last
+Replace all characters with the 'censor_char' except the first and the last 
character of a word.
+For words with less than 4 characters, the last character will be replaced as 
well.
+For words with less than 3 characters, the first character will be replaced as 
well.
+@item 1, keep_first
+Replace all characters with the 'censor_char' except the first character of a 
word.
+For words with less than 3 characters, the first character will be replaced as 
well.
+@item 2, all
+Replace all characters with the 'censor_char'.
+@end table
+
+@item words
+A list of words to censor, separated by 'separator'.
+
+@item words_file
+Specify a file from which to load the contents for the 'words' parameter.
+
+@item censor_char
+Single character used as replacement for censoring.
+
+@item separator
+Delimiter character for words. Used with replace_words and remove_words- Must 
be a single character.
+The default is '.'.
+
+@end table
+
+@subsection Examples
+
+@itemize
+@item
+Censor a few given words with a pound character.
+@example
+ffmpeg -i 
"http://streams.videolan.org/samples/sub/SSA/subtitle_testing_complex.mkv"; 
-filter_complex 
"[0:1]censor=words='diss,louder,hope,beam,word':censor_char='#'" -map 0 -y 
output.mkv
+@end example
+@end itemize
+
+
+@section textmod
+
+Modify subtitle text in a number of ways.
+
+Inputs:
+@itemize
+@item 0: Subtitles[TEXT]
+@end itemize
+
+Outputs:
+@itemize
+@item 0: Subtitles[TEXT]
+@end itemize
+
+It accepts the following parameters:
+
+@table @option
+@item mode
+The kind of text modification to apply
+
+Supported operation modes are:
+
+@table @var
+@item 0, leet
+Convert subtitle text to 'leet speak'. It's primarily useful for testing as 
the modification will be visible with almost all text lines.
+@item 1, to_upper
+Change all text to upper case. Might improve readability.
+@item 2, to_lower
+Change all text to lower case.
+@item 3, replace_chars
+Replace one or more characters. Requires the find and replace parameters to be 
specified.
+Both need to be equal in length.
+The first char in find is replaced by the first char in replace, same for all 
subsequent chars.
+@item 4, remove_chars
+Remove certain characters. Requires the find parameter to be specified.
+All chars in the find parameter string will be removed from all subtitle text.
+@item 5, replace_words
+Replace one or more words. Requires the find and replace parameters to be 
specified. Multiple words must be separated by the delimiter char specified vie 
the separator parameter (default: ',').
+The number of words in the find and replace parameters needs to be equal.
+The first word in find is replaced by the first word in replace, same for all 
subsequent words
+@item 6, remove_words
+Remove certain words. Requires the find parameter to be specified. Multiple 
words must be separated by the delimiter char specified vie the separator 
parameter (default: ',').
+All words in the find parameter string will be removed from all subtitle text.
+@end table
+
+@item find
+Required for replace_chars, remove_chars, replace_words and remove_words.
+
+@item find_file
+Specify a file from which to load the contents for the 'find' parameter.
+
+@item replace
+Required for replace_chars and replace_words.
+
+@item replace_file
+Specify a file from which to load the contents for the 'replace' parameter.
+
+@item separator
+Delimiter character for words. Used with replace_words and remove_words- Must 
be a single character.
+The default is '.'.
+
+@end table
+
+@subsection Examples
+
+@itemize
+@item
+Change all characters to upper case while keeping all styles and animations:
+@example
+ffmpeg -i "https://streams.videolan.org/ffmpeg/mkv_subtitles.mkv"; 
-filter_complex "[0:s]textmod=mode=to_upper" -map 0 -y out.mkv
+@end example
+@item
+Remove a set of symbol characters for am i

[FFmpeg-devel] [PATCH v3 13/26] avfilter/overlaytextsubs: Add overlaytextsubs and textsubs2video filters

2022-01-19 Thread ffmpegagent
From: softworkz 

- overlaytextsubs {VS -> V)
  Overlay text subtitles onto a video stream.

- textsubs2video {S -> V)
  Converts text subtitles to video frames

Signed-off-by: softworkz 
---
 configure|   2 +
 doc/filters.texi | 113 ++
 libavfilter/Makefile |   2 +
 libavfilter/allfilters.c |   6 +-
 libavfilter/vf_overlaytextsubs.c | 678 +++
 5 files changed, 799 insertions(+), 2 deletions(-)
 create mode 100644 libavfilter/vf_overlaytextsubs.c

diff --git a/configure b/configure
index 1928a77344..7b66e315f2 100755
--- a/configure
+++ b/configure
@@ -3692,6 +3692,7 @@ overlay_qsv_filter_deps="libmfx"
 overlay_qsv_filter_select="qsvvpp"
 overlay_vaapi_filter_deps="vaapi VAProcPipelineCaps_blend_flags"
 overlay_vulkan_filter_deps="vulkan spirv_compiler"
+overlaytextsubs_filter_deps="avcodec libass"
 owdenoise_filter_deps="gpl"
 pad_opencl_filter_deps="opencl"
 pan_filter_deps="swresample"
@@ -3736,6 +3737,7 @@ superequalizer_filter_deps="avcodec"
 superequalizer_filter_select="rdft"
 surround_filter_deps="avcodec"
 surround_filter_select="rdft"
+textsub2video_filter_deps="avcodec libass"
 tinterlace_filter_deps="gpl"
 tinterlace_merge_test_deps="tinterlace_filter"
 tinterlace_pad_test_deps="tinterlace_filter"
diff --git a/doc/filters.texi b/doc/filters.texi
index 2bd3737cf5..02a854851c 100644
--- a/doc/filters.texi
+++ b/doc/filters.texi
@@ -25880,6 +25880,119 @@ Overlay PGS subtitles
 ffmpeg -i 
"https://streams.videolan.org/samples/sub/PGS/Girl_With_The_Dragon_Tattoo_2%3A23%3A56.mkv";
 -filter_complex "[0:0][0:1]overlaygraphicsubs" output.mp4
 @end example
 @end itemize
+
+@section overlaytextsubs
+
+Overlay text subtitles onto a video stream.
+
+This filter supersedes the classic @ref{subtitles} filter opposed to which it 
does no longer require to open and access the source stream separately, which 
is often causing problems or doesn't even work for non-local or slow sources.
+
+Inputs:
+@itemize
+@item 0: Video [YUV420P, YUV422P, YUV444P, ARGB, RGBA, ABGR, BGRA, RGB24, 
BGR24]
+@item 1: Subtitles [TEXT]
+@end itemize
+
+Outputs:
+@itemize
+@item 0: Video (same as input)
+@end itemize
+
+It accepts the following parameters:
+
+@table @option
+
+@item alpha
+Process alpha channel, by default alpha channel is untouched.
+
+@item fonts_dir
+Set a directory path containing fonts that can be used by the filter.
+These fonts will be used in addition to whatever the font provider uses.
+
+@item default_font_path
+Path to a font file to be used as the default font.
+
+@item font_size
+Set the default font size.
+
+@item fontconfig_file
+Path to ASS fontconfig configuration file.
+
+@item force_style
+Override default style or script info parameters of the subtitles. It accepts a
+string containing ASS style format @code{KEY=VALUE} couples separated by ",".
+
+@item margin
+Set the rendering margin in pixels.
+
+@item render_latest_only
+For rendering, alway use the latest event only, which is covering the given 
point in time
+@end table
+
+@subsection Examples
+
+@itemize
+@item
+Overlay ASS subtitles with animations:
+@example
+ffmpeg -i 
"http://streams.videolan.org/samples/sub/SSA/subtitle_testing_complex.mkv"; 
-filter_complex "[0:v]overlaytextsubs" -map 0 -y out.mkv
+@end example
+@end itemize
+
+@section textsub2video
+
+Converts text subtitles to video frames.
+
+For overlaying text subtitles onto video frames it is recommended to use the 
overlay_textsubs filter.
+The textsub2video is useful for for creating transparent text-frames when 
overlay is done via hw acceleration
+
+Inputs:
+@itemize
+@item 0: Subtitles [TEXT]
+@end itemize
+
+Outputs:
+@itemize
+@item 0: Video [RGB32]
+@end itemize
+
+It accepts the following parameters:
+
+@table @option
+
+@item rate, r
+Set the framerate for updating overlay frames.
+Normally, overlay frames will only be updated each time when the subtitles to 
display are changing.
+In cases where subtitles include advanced features (like animation), this 
parameter determines the frequency by which the overlay frames should be 
updated.
+
+@item size, s
+Set the output frame size.
+Allows to override the size of output video frames.
+
+@item fonts_dir
+Set a directory path containing fonts that can be used by the filter.
+These fonts will be used in addition to whatever the font provider uses.
+
+@item default_font_path
+Path to a font file to be used as the default font.
+
+@item font_size
+Set the default font size.
+
+@item fontconfig_file
+Path to ASS fontconfig configuration file.
+
+@item force_style
+Override default style or script info parameters of the subtitles. It accepts a
+string containing ASS style format @code{KEY=VALUE} couples separated by ",".
+
+@item margin
+Set the rendering margin in pixels.
+
+@item render_latest_only
+For rendering, alway use the latest event only, which is covering the given 
point in time.
+@end table
+
 @c man end SUBTITLE FILTERS
 

[FFmpeg-devel] [PATCH v3 08/26] avfilter/subtitles: Add subtitles.c for subtitle frame allocation

2022-01-19 Thread ffmpegagent
From: softworkz 

Analog to avfilter/video.c and avfilter/audio.c

Signed-off-by: softworkz 
---
 libavfilter/Makefile|  1 +
 libavfilter/avfilter.c  |  4 +++
 libavfilter/internal.h  |  1 +
 libavfilter/subtitles.c | 63 +
 libavfilter/subtitles.h | 44 
 5 files changed, 113 insertions(+)
 create mode 100644 libavfilter/subtitles.c
 create mode 100644 libavfilter/subtitles.h

diff --git a/libavfilter/Makefile b/libavfilter/Makefile
index 282967144b..f1176644c9 100644
--- a/libavfilter/Makefile
+++ b/libavfilter/Makefile
@@ -19,6 +19,7 @@ OBJS = allfilters.o   
  \
framequeue.o \
graphdump.o  \
graphparser.o\
+   subtitles.o  \
video.o  \
 
 OBJS-$(HAVE_THREADS) += pthread.o
diff --git a/libavfilter/avfilter.c b/libavfilter/avfilter.c
index 7362bcdab5..df5b8f483c 100644
--- a/libavfilter/avfilter.c
+++ b/libavfilter/avfilter.c
@@ -43,6 +43,7 @@
 #include "formats.h"
 #include "framepool.h"
 #include "internal.h"
+#include "subtitles.h"
 
 #include "libavutil/ffversion.h"
 const char av_filter_ffversion[] = "FFmpeg version " FFMPEG_VERSION;
@@ -1475,6 +1476,9 @@ int ff_inlink_make_frame_writable(AVFilterLink *link, 
AVFrame **rframe)
 case AVMEDIA_TYPE_AUDIO:
 out = ff_get_audio_buffer(link, frame->nb_samples);
 break;
+case AVMEDIA_TYPE_SUBTITLE:
+out = ff_get_subtitles_buffer(link, link->format);
+break;
 default:
 return AVERROR(EINVAL);
 }
diff --git a/libavfilter/internal.h b/libavfilter/internal.h
index 1099b82b4b..fc09ef574c 100644
--- a/libavfilter/internal.h
+++ b/libavfilter/internal.h
@@ -90,6 +90,7 @@ struct AVFilterPad {
 union {
 AVFrame *(*video)(AVFilterLink *link, int w, int h);
 AVFrame *(*audio)(AVFilterLink *link, int nb_samples);
+AVFrame *(*subtitle)(AVFilterLink *link, int format);
 } get_buffer;
 
 /**
diff --git a/libavfilter/subtitles.c b/libavfilter/subtitles.c
new file mode 100644
index 00..951bfd612c
--- /dev/null
+++ b/libavfilter/subtitles.c
@@ -0,0 +1,63 @@
+/*
+ * Copyright (c) 2021 softworkz
+ *
+ * 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
+ */
+
+#include "libavutil/common.h"
+
+#include "subtitles.h"
+#include "avfilter.h"
+#include "internal.h"
+
+
+AVFrame *ff_null_get_subtitles_buffer(AVFilterLink *link, int format)
+{
+return ff_get_subtitles_buffer(link->dst->outputs[0], format);
+}
+
+AVFrame *ff_default_get_subtitles_buffer(AVFilterLink *link, int format)
+{
+AVFrame *frame;
+
+frame = av_frame_alloc();
+if (!frame)
+return NULL;
+
+frame->format = format;
+frame->type = AVMEDIA_TYPE_SUBTITLE;
+
+if (av_frame_get_buffer2(frame, 0) < 0) {
+av_frame_free(&frame);
+return NULL;
+}
+
+return frame;
+}
+
+AVFrame *ff_get_subtitles_buffer(AVFilterLink *link, int format)
+{
+AVFrame *ret = NULL;
+
+if (link->dstpad->get_buffer.subtitle)
+ret = link->dstpad->get_buffer.subtitle(link, format);
+
+if (!ret)
+ret = ff_default_get_subtitles_buffer(link, format);
+
+return ret;
+}
diff --git a/libavfilter/subtitles.h b/libavfilter/subtitles.h
new file mode 100644
index 00..4a9115126e
--- /dev/null
+++ b/libavfilter/subtitles.h
@@ -0,0 +1,44 @@
+/*
+ * Copyright (c) 2021 softworkz
+ *
+ * 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

[FFmpeg-devel] [PATCH v3 12/26] avfilter/overlaygraphicsubs: Add overlaygraphicsubs and graphicsub2video filters

2022-01-19 Thread ffmpegagent
From: softworkz 

- overlaygraphicsubs (VS -> V)
  Overlay graphic subtitles onto a video stream

- graphicsub2video {S -> V)
  Converts graphic subtitles to video frames (with alpha)
  Gets auto-inserted for retaining compatibility with
  sub2video command lines

Signed-off-by: softworkz 
---
 doc/filters.texi| 118 +
 libavfilter/Makefile|   2 +
 libavfilter/allfilters.c|   2 +
 libavfilter/vf_overlaygraphicsubs.c | 765 
 4 files changed, 887 insertions(+)
 create mode 100644 libavfilter/vf_overlaygraphicsubs.c

diff --git a/doc/filters.texi b/doc/filters.texi
index 248c09caf8..2bd3737cf5 100644
--- a/doc/filters.texi
+++ b/doc/filters.texi
@@ -25764,6 +25764,124 @@ tools.
 
 @c man end VIDEO SINKS
 
+@chapter Subtitle Filters
+@c man begin SUBTITLE FILTERS
+
+When you configure your FFmpeg build, you can disable any of the
+existing filters using @code{--disable-filters}.
+
+Below is a description of the currently available subtitle filters.
+
+@section graphicsub2video
+
+Renders graphic subtitles as video frames.
+
+This filter replaces the previous "sub2video" hack which did the conversion 
implicitly and up-front as subtitle filtering wasn't possible at that time.
+To retain compatibility with earlier sub2video command lines, this filter is 
being auto-inserted in those cases.
+
+For overlaying graphicsal subtitles it is recommended to use the 
'overlay_graphicsubs' filter which is more efficient and takes less processing 
resources.
+
+This filter is still useful in cases where the overlay is done with hardware 
acceleration (e.g. overlay_qsv, overlay_vaapi, overlay_cuda) for preparing the 
overlay frames.
+
+Inputs:
+@itemize
+@item 0: Subtitles [BITMAP]
+@end itemize
+
+Outputs:
+@itemize
+@item 0: Video [RGB32]
+@end itemize
+
+
+It accepts the following parameters:
+
+@table @option
+@item size, s
+Set the size of the output video frame.
+
+@end table
+
+@subsection Examples
+
+@itemize
+@item
+Overlay PGS subtitles
+(not recommended - better use overlay_graphicsubs)
+@example
+ffmpeg -i 
"https://streams.videolan.org/samples/sub/PGS/Girl_With_The_Dragon_Tattoo_2%3A23%3A56.mkv";
 -filter_complex "[0:1]graphicsub2video[subs];[0:0][subs]overlay" output.mp4
+@end example
+
+@item
+Overlay PGS subtitles implicitly
+The graphicsub2video is inserted automatically for compatibility with legacy 
command lines.
+@example
+ffmpeg -i 
"https://streams.videolan.org/samples/sub/PGS/Girl_With_The_Dragon_Tattoo_2%3A23%3A56.mkv";
 -filter_complex "[0:0][0:1]overlay" output.mp4
+@end example
+@end itemize
+
+@section overlaygraphicsubs
+
+Overlay graphic subtitles onto a video stream.
+
+This filter can blend graphical subtitles on a video stream directly, i.e. 
without creating full-size alpha images first.
+The blending operation is limited to the area of the subtitle rectangles, 
which also means that no processing is done at times where no subtitles are to 
be displayed.
+
+Inputs:
+@itemize
+@item 0: Video [YUV420P, YUV422P, YUV444P, ARGB, RGBA, ABGR, BGRA, RGB24, 
BGR24]
+@item 1: Subtitles [BITMAP]
+@end itemize
+
+Outputs:
+@itemize
+@item 0: Video (same as input)
+@end itemize
+
+It accepts the following parameters:
+
+@table @option
+@item x
+@item y
+Set the expression for the x and y coordinates of the overlaid video
+on the main video. Default value is "0" for both expressions. In case
+the expression is invalid, it is set to a huge value (meaning that the
+overlay will not be displayed within the output visible area).
+
+@item eof_action
+See @ref{framesync}.
+
+@item eval
+Set when the expressions for @option{x}, and @option{y} are evaluated.
+
+It accepts the following values:
+@table @samp
+@item init
+only evaluate expressions once during the filter initialization or
+when a command is processed
+
+@item frame
+evaluate expressions for each incoming frame
+@end table
+
+Default value is @samp{frame}.
+
+@item shortest
+See @ref{framesync}.
+
+@end table
+
+@subsection Examples
+
+@itemize
+@item
+Overlay PGS subtitles
+@example
+ffmpeg -i 
"https://streams.videolan.org/samples/sub/PGS/Girl_With_The_Dragon_Tattoo_2%3A23%3A56.mkv";
 -filter_complex "[0:0][0:1]overlaygraphicsubs" output.mp4
+@end example
+@end itemize
+@c man end SUBTITLE FILTERS
+
 @chapter Multimedia Filters
 @c man begin MULTIMEDIA FILTERS
 
diff --git a/libavfilter/Makefile b/libavfilter/Makefile
index f1176644c9..c326b8d32b 100644
--- a/libavfilter/Makefile
+++ b/libavfilter/Makefile
@@ -298,6 +298,7 @@ OBJS-$(CONFIG_GBLUR_FILTER)  += vf_gblur.o
 OBJS-$(CONFIG_GBLUR_VULKAN_FILTER)   += vf_gblur_vulkan.o vulkan.o 
vulkan_filter.o
 OBJS-$(CONFIG_GEQ_FILTER)+= vf_geq.o
 OBJS-$(CONFIG_GRADFUN_FILTER)+= vf_gradfun.o
+OBJS-$(CONFIG_GRAPHICSUB2VIDEO_FILTER)   += vf_overlaygraphicsubs.o 
framesync.o
 OBJS-$(CONFIG_GRAPHMONITOR_FILTER)   += f_graphmonitor.o
 OBJS-$(CONFIG_GRAYWORLD_FIL

[FFmpeg-devel] [PATCH v3 07/26] fftools/play, probe: Adjust for subtitle changes

2022-01-19 Thread ffmpegagent
From: softworkz 

Signed-off-by: softworkz 
---
 fftools/ffplay.c  | 102 +-
 fftools/ffprobe.c |  47 +
 2 files changed, 77 insertions(+), 72 deletions(-)

diff --git a/fftools/ffplay.c b/fftools/ffplay.c
index e7b20be76b..94286eb678 100644
--- a/fftools/ffplay.c
+++ b/fftools/ffplay.c
@@ -152,7 +152,6 @@ typedef struct Clock {
 /* Common struct for handling all types of decoded data and allocated render 
buffers. */
 typedef struct Frame {
 AVFrame *frame;
-AVSubtitle sub;
 int serial;
 double pts;   /* presentation timestamp for the frame */
 double duration;  /* estimated duration of the frame */
@@ -586,7 +585,7 @@ static int decoder_init(Decoder *d, AVCodecContext *avctx, 
PacketQueue *queue, S
 return 0;
 }
 
-static int decoder_decode_frame(Decoder *d, AVFrame *frame, AVSubtitle *sub) {
+static int decoder_decode_frame(Decoder *d, AVFrame *frame) {
 int ret = AVERROR(EAGAIN);
 
 for (;;) {
@@ -620,6 +619,9 @@ static int decoder_decode_frame(Decoder *d, AVFrame *frame, 
AVSubtitle *sub) {
 }
 }
 break;
+case AVMEDIA_TYPE_SUBTITLE:
+ret = avcodec_receive_frame(d->avctx, frame);
+break;
 }
 if (ret == AVERROR_EOF) {
 d->finished = d->pkt_serial;
@@ -652,25 +654,11 @@ static int decoder_decode_frame(Decoder *d, AVFrame 
*frame, AVSubtitle *sub) {
 av_packet_unref(d->pkt);
 } while (1);
 
-if (d->avctx->codec_type == AVMEDIA_TYPE_SUBTITLE) {
-int got_frame = 0;
-ret = avcodec_decode_subtitle2(d->avctx, sub, &got_frame, d->pkt);
-if (ret < 0) {
-ret = AVERROR(EAGAIN);
-} else {
-if (got_frame && !d->pkt->data) {
-d->packet_pending = 1;
-}
-ret = got_frame ? 0 : (d->pkt->data ? AVERROR(EAGAIN) : 
AVERROR_EOF);
-}
-av_packet_unref(d->pkt);
+if (avcodec_send_packet(d->avctx, d->pkt) == AVERROR(EAGAIN)) {
+av_log(d->avctx, AV_LOG_ERROR, "Receive_frame and send_packet both 
returned EAGAIN, which is an API violation.\n");
+d->packet_pending = 1;
 } else {
-if (avcodec_send_packet(d->avctx, d->pkt) == AVERROR(EAGAIN)) {
-av_log(d->avctx, AV_LOG_ERROR, "Receive_frame and send_packet 
both returned EAGAIN, which is an API violation.\n");
-d->packet_pending = 1;
-} else {
-av_packet_unref(d->pkt);
-}
+av_packet_unref(d->pkt);
 }
 }
 }
@@ -683,7 +671,6 @@ static void decoder_destroy(Decoder *d) {
 static void frame_queue_unref_item(Frame *vp)
 {
 av_frame_unref(vp->frame);
-avsubtitle_free(&vp->sub);
 }
 
 static int frame_queue_init(FrameQueue *f, PacketQueue *pktq, int max_size, 
int keep_last)
@@ -981,7 +968,7 @@ static void video_image_display(VideoState *is)
 if (frame_queue_nb_remaining(&is->subpq) > 0) {
 sp = frame_queue_peek(&is->subpq);
 
-if (vp->pts >= sp->pts + ((float) sp->sub.start_display_time / 
1000)) {
+if (vp->pts >= sp->pts) {
 if (!sp->uploaded) {
 uint8_t* pixels[4];
 int pitch[4];
@@ -993,25 +980,27 @@ static void video_image_display(VideoState *is)
 if (realloc_texture(&is->sub_texture, 
SDL_PIXELFORMAT_ARGB, sp->width, sp->height, SDL_BLENDMODE_BLEND, 1) < 0)
 return;
 
-for (i = 0; i < sp->sub.num_rects; i++) {
-AVSubtitleRect *sub_rect = sp->sub.rects[i];
+for (i = 0; i < sp->frame->num_subtitle_areas; i++) {
+AVSubtitleArea *area = sp->frame->subtitle_areas[i];
+SDL_Rect sdl_rect = { .x = area->x, .y = area->y, .w = 
area->w, .h = area->h };
 
-sub_rect->x = av_clip(sub_rect->x, 0, sp->width );
-sub_rect->y = av_clip(sub_rect->y, 0, sp->height);
-sub_rect->w = av_clip(sub_rect->w, 0, sp->width  - 
sub_rect->x);
-sub_rect->h = av_clip(sub_rect->h, 0, sp->height - 
sub_rect->y);
+area->x = av_clip(area->x, 0, sp->width );
+area->y = av_clip(area->y, 0, sp->height);
+area->w = av_clip(area->w, 0, sp->width  - area->x);
+area->h = av_clip(area->h, 0, sp->height - area->y);
 
 is->sub_convert_ctx = 
sws_getCachedContext(is->sub_convert_ctx,
-sub_rect->w, sub_rect->h, AV_PIX_FMT_PAL8,
-sub_rect->w, sub_rect->h, AV_PIX_FMT_BGRA,
+  

[FFmpeg-devel] [PATCH v3 11/26] avfilter/sbuffer: Add sbuffersrc and sbuffersink filters

2022-01-19 Thread ffmpegagent
From: softworkz 

Signed-off-by: softworkz 
---
 configure|  2 +-
 libavfilter/allfilters.c |  2 ++
 libavfilter/buffersink.c | 54 ++
 libavfilter/buffersink.h |  7 
 libavfilter/buffersrc.c  | 72 
 libavfilter/buffersrc.h  |  1 +
 6 files changed, 137 insertions(+), 1 deletion(-)

diff --git a/configure b/configure
index 52ef214b73..1928a77344 100755
--- a/configure
+++ b/configure
@@ -7856,7 +7856,7 @@ print_enabled_components(){
 fi
 done
 if [ "$name" = "filter_list" ]; then
-for c in asrc_abuffer vsrc_buffer asink_abuffer vsink_buffer; do
+for c in asrc_abuffer vsrc_buffer ssrc_sbuffer asink_abuffer 
vsink_buffer ssink_sbuffer; do
 printf "&ff_%s,\n" $c >> $TMPH
 done
 fi
diff --git a/libavfilter/allfilters.c b/libavfilter/allfilters.c
index 714468afce..ebb2e374bd 100644
--- a/libavfilter/allfilters.c
+++ b/libavfilter/allfilters.c
@@ -557,8 +557,10 @@ extern const AVFilter ff_avsrc_movie;
  * being the same while having different 'types'). */
 extern  const AVFilter ff_asrc_abuffer;
 extern  const AVFilter ff_vsrc_buffer;
+extern  const AVFilter ff_ssrc_sbuffer;
 extern  const AVFilter ff_asink_abuffer;
 extern  const AVFilter ff_vsink_buffer;
+extern  const AVFilter ff_ssink_sbuffer;
 extern const AVFilter ff_af_afifo;
 extern const AVFilter ff_vf_fifo;
 
diff --git a/libavfilter/buffersink.c b/libavfilter/buffersink.c
index c0215669e7..0b268c2fa4 100644
--- a/libavfilter/buffersink.c
+++ b/libavfilter/buffersink.c
@@ -29,6 +29,8 @@
 #include "libavutil/internal.h"
 #include "libavutil/opt.h"
 
+#include "libavcodec/avcodec.h"
+
 #define FF_INTERNAL_FIELDS 1
 #include "framequeue.h"
 
@@ -57,6 +59,10 @@ typedef struct BufferSinkContext {
 int *sample_rates;  ///< list of accepted sample rates
 int sample_rates_size;
 
+/* only used for subtitles */
+enum AVSubtitleType *subtitle_types; ///< list of accepted subtitle 
types, must be terminated with -1
+int subtitle_types_size;
+
 AVFrame *peeked_frame;
 } BufferSinkContext;
 
@@ -305,6 +311,28 @@ static int asink_query_formats(AVFilterContext *ctx)
 return 0;
 }
 
+static int ssink_query_formats(AVFilterContext *ctx)
+{
+BufferSinkContext *buf = ctx->priv;
+AVFilterFormats *formats = NULL;
+unsigned i;
+int ret;
+
+CHECK_LIST_SIZE(subtitle_types)
+if (buf->subtitle_types_size) {
+for (i = 0; i < NB_ITEMS(buf->subtitle_types); i++)
+if ((ret = ff_add_subtitle_type(&formats, buf->subtitle_types[i])) 
< 0)
+return ret;
+if ((ret = ff_set_common_formats(ctx, formats)) < 0)
+return ret;
+} else {
+if ((ret = ff_default_query_formats(ctx)) < 0)
+return ret;
+}
+
+return 0;
+}
+
 #define OFFSET(x) offsetof(BufferSinkContext, x)
 #define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM
 static const AVOption buffersink_options[] = {
@@ -322,9 +350,16 @@ static const AVOption abuffersink_options[] = {
 { NULL },
 };
 #undef FLAGS
+#define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_SUBTITLE_PARAM
+static const AVOption sbuffersink_options[] = {
+{ "subtitle_types", "set the supported subtitle formats", 
OFFSET(subtitle_types), AV_OPT_TYPE_BINARY, .flags = FLAGS },
+{ NULL },
+};
+#undef FLAGS
 
 AVFILTER_DEFINE_CLASS(buffersink);
 AVFILTER_DEFINE_CLASS(abuffersink);
+AVFILTER_DEFINE_CLASS(sbuffersink);
 
 static const AVFilterPad avfilter_vsink_buffer_inputs[] = {
 {
@@ -363,3 +398,22 @@ const AVFilter ff_asink_abuffer = {
 .outputs   = NULL,
 FILTER_QUERY_FUNC(asink_query_formats),
 };
+
+static const AVFilterPad avfilter_ssink_sbuffer_inputs[] = {
+{
+.name = "default",
+.type = AVMEDIA_TYPE_SUBTITLE,
+},
+};
+
+const AVFilter ff_ssink_sbuffer = {
+.name  = "sbuffersink",
+.description   = NULL_IF_CONFIG_SMALL("Buffer subtitle frames, and make 
them available to the end of the filter graph."),
+.priv_class= &sbuffersink_class,
+.priv_size = sizeof(BufferSinkContext),
+.init  = common_init,
+.activate  = activate,
+FILTER_INPUTS(avfilter_ssink_sbuffer_inputs),
+.outputs   = NULL,
+FILTER_QUERY_FUNC(ssink_query_formats),
+};
diff --git a/libavfilter/buffersink.h b/libavfilter/buffersink.h
index 69ed0f29a8..11905abdc5 100644
--- a/libavfilter/buffersink.h
+++ b/libavfilter/buffersink.h
@@ -129,6 +129,13 @@ typedef struct AVABufferSinkParams {
  */
 attribute_deprecated
 AVABufferSinkParams *av_abuffersink_params_alloc(void);
+
+/**
+ * Deprecated and unused struct to use for initializing an sbuffersink context.
+ */
+typedef struct AVSBufferSinkParams {
+const int *subtitle_type;
+} AVSBufferSinkParams;
 #endif
 
 /**
diff --git a/libavfilter/buffersrc.c b/libavfilter/buffersrc.c
index b0611872f1..d2362999a2 100644
--- a/liba

[FFmpeg-devel] [PATCH v3 06/26] avcodec/subtitles: Replace deprecated enum values

2022-01-19 Thread ffmpegagent
From: softworkz 

Signed-off-by: softworkz 
---
 libavcodec/ass.h   | 2 +-
 libavcodec/assdec.c| 2 +-
 libavcodec/dvbsubdec.c | 2 +-
 libavcodec/dvdsubdec.c | 2 +-
 libavcodec/dvdsubenc.c | 2 +-
 libavcodec/pgssubdec.c | 2 +-
 libavcodec/xsubdec.c   | 2 +-
 7 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/libavcodec/ass.h b/libavcodec/ass.h
index 8bc13d7ab8..43c5ad651a 100644
--- a/libavcodec/ass.h
+++ b/libavcodec/ass.h
@@ -83,7 +83,7 @@ static inline int avpriv_ass_add_rect(AVSubtitle *sub, const 
char *dialog,
 rects[sub->num_rects]   = av_mallocz(sizeof(*rects[0]));
 if (!rects[sub->num_rects])
 return AVERROR(ENOMEM);
-rects[sub->num_rects]->type = SUBTITLE_ASS;
+rects[sub->num_rects]->type = AV_SUBTITLE_FMT_ASS;
 ass_str = avpriv_ass_get_dialog(readorder, layer, style, speaker, dialog);
 if (!ass_str)
 return AVERROR(ENOMEM);
diff --git a/libavcodec/assdec.c b/libavcodec/assdec.c
index 7802a44e71..fd321e7004 100644
--- a/libavcodec/assdec.c
+++ b/libavcodec/assdec.c
@@ -54,7 +54,7 @@ static int ass_decode_frame(AVCodecContext *avctx, void 
*data, int *got_sub_ptr,
 if (!sub->rects[0])
 return AVERROR(ENOMEM);
 sub->num_rects = 1;
-sub->rects[0]->type = SUBTITLE_ASS;
+sub->rects[0]->type = AV_SUBTITLE_FMT_ASS;
 sub->rects[0]->ass  = av_strdup(avpkt->data);
 if (!sub->rects[0]->ass)
 return AVERROR(ENOMEM);
diff --git a/libavcodec/dvbsubdec.c b/libavcodec/dvbsubdec.c
index bc741a1de6..0d64c6e71c 100644
--- a/libavcodec/dvbsubdec.c
+++ b/libavcodec/dvbsubdec.c
@@ -795,7 +795,7 @@ static int save_subtitle_set(AVCodecContext *avctx, 
AVSubtitle *sub, int *got_ou
 rect->w = region->width;
 rect->h = region->height;
 rect->nb_colors = (1 << region->depth);
-rect->type  = SUBTITLE_BITMAP;
+rect->type  = AV_SUBTITLE_FMT_BITMAP;
 rect->linesize[0] = region->width;
 
 clut = get_clut(ctx, region->clut);
diff --git a/libavcodec/dvdsubdec.c b/libavcodec/dvdsubdec.c
index 52259f0730..b39b3d1838 100644
--- a/libavcodec/dvdsubdec.c
+++ b/libavcodec/dvdsubdec.c
@@ -406,7 +406,7 @@ static int decode_dvd_subtitles(DVDSubContext *ctx, 
AVSubtitle *sub_header,
 sub_header->rects[0]->y = y1;
 sub_header->rects[0]->w = w;
 sub_header->rects[0]->h = h;
-sub_header->rects[0]->type = SUBTITLE_BITMAP;
+sub_header->rects[0]->type = AV_SUBTITLE_FMT_BITMAP;
 sub_header->rects[0]->linesize[0] = w;
 sub_header->rects[0]->flags = is_menu ? 
AV_SUBTITLE_FLAG_FORCED : 0;
 }
diff --git a/libavcodec/dvdsubenc.c b/libavcodec/dvdsubenc.c
index ff4fbed39d..943a7466d9 100644
--- a/libavcodec/dvdsubenc.c
+++ b/libavcodec/dvdsubenc.c
@@ -268,7 +268,7 @@ static int encode_dvd_subtitles(AVCodecContext *avctx,
 if (rects == 0 || !h->rects)
 return AVERROR(EINVAL);
 for (i = 0; i < rects; i++)
-if (h->rects[i]->type != SUBTITLE_BITMAP) {
+if (h->rects[i]->type != AV_SUBTITLE_FMT_BITMAP) {
 av_log(avctx, AV_LOG_ERROR, "Bitmap subtitle required\n");
 return AVERROR(EINVAL);
 }
diff --git a/libavcodec/pgssubdec.c b/libavcodec/pgssubdec.c
index bdd20c914b..22b6616f9b 100644
--- a/libavcodec/pgssubdec.c
+++ b/libavcodec/pgssubdec.c
@@ -535,7 +535,7 @@ static int display_end_segment(AVCodecContext *avctx, void 
*data,
 if (!rect)
 return AVERROR(ENOMEM);
 sub->rects[sub->num_rects++] = rect;
-rect->type = SUBTITLE_BITMAP;
+rect->type = AV_SUBTITLE_FMT_BITMAP;
 
 /* Process bitmap */
 object = find_object(ctx->presentation.objects[i].id, &ctx->objects);
diff --git a/libavcodec/xsubdec.c b/libavcodec/xsubdec.c
index 85cd7d1c20..a4be18a1d8 100644
--- a/libavcodec/xsubdec.c
+++ b/libavcodec/xsubdec.c
@@ -107,7 +107,7 @@ static int decode_frame(AVCodecContext *avctx, void *data, 
int *got_sub_ptr,
 sub->num_rects = 1;
 rect->x = x; rect->y = y;
 rect->w = w; rect->h = h;
-rect->type = SUBTITLE_BITMAP;
+rect->type = AV_SUBTITLE_FMT_BITMAP;
 rect->linesize[0] = w;
 rect->data[0] = av_malloc(w * h);
 rect->nb_colors = 4;
-- 
ffmpeg-codebot

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH v3 05/26] avcodec, avutil: Move ass helper functions to avutil as avpriv_ and extend ass dialog parsing

2022-01-19 Thread ffmpegagent
From: softworkz 

Also add

- hard_space callback (for upcoming fix)
- extensible callback (for future extension)

Signed-off-by: softworkz 
---
 libavcodec/Makefile   |  56 +++
 libavcodec/ass.h  | 144 ++
 libavcodec/assdec.c   |   2 +-
 libavcodec/assenc.c   |   2 +-
 libavcodec/ccaption_dec.c |  19 +--
 libavcodec/jacosubdec.c   |   2 +-
 libavcodec/libaribb24.c   |   2 +-
 libavcodec/libzvbi-teletextdec.c  |  14 +-
 libavcodec/microdvddec.c  |   7 +-
 libavcodec/movtextdec.c   |   3 +-
 libavcodec/movtextenc.c   |  20 +--
 libavcodec/mpl2dec.c  |   2 +-
 libavcodec/realtextdec.c  |   2 +-
 libavcodec/samidec.c  |   2 +-
 libavcodec/srtdec.c   |   2 +-
 libavcodec/srtenc.c   |  16 +-
 libavcodec/subviewerdec.c |   2 +-
 libavcodec/textdec.c  |   4 +-
 libavcodec/ttmlenc.c  |  15 +-
 libavcodec/webvttdec.c|   2 +-
 libavcodec/webvttenc.c|  16 +-
 libavutil/Makefile|   2 +
 {libavcodec => libavutil}/ass.c   |  91 +--
 libavutil/ass_internal.h  | 135 
 {libavcodec => libavutil}/ass_split.c |  30 ++--
 .../ass_split_internal.h  |  32 ++--
 26 files changed, 355 insertions(+), 269 deletions(-)
 rename {libavcodec => libavutil}/ass.c (65%)
 create mode 100644 libavutil/ass_internal.h
 rename {libavcodec => libavutil}/ass_split.c (94%)
 rename libavcodec/ass_split.h => libavutil/ass_split_internal.h (86%)

diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index cfc70a3eaf..80bf8ff2d2 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -215,10 +215,10 @@ OBJS-$(CONFIG_APNG_DECODER)+= png.o pngdec.o 
pngdsp.o
 OBJS-$(CONFIG_APNG_ENCODER)+= png.o pngenc.o
 OBJS-$(CONFIG_ARBC_DECODER)+= arbc.o
 OBJS-$(CONFIG_ARGO_DECODER)+= argo.o
-OBJS-$(CONFIG_SSA_DECODER) += assdec.o ass.o
-OBJS-$(CONFIG_SSA_ENCODER) += assenc.o ass.o
-OBJS-$(CONFIG_ASS_DECODER) += assdec.o ass.o
-OBJS-$(CONFIG_ASS_ENCODER) += assenc.o ass.o
+OBJS-$(CONFIG_SSA_DECODER) += assdec.o
+OBJS-$(CONFIG_SSA_ENCODER) += assenc.o
+OBJS-$(CONFIG_ASS_DECODER) += assdec.o
+OBJS-$(CONFIG_ASS_ENCODER) += assenc.o
 OBJS-$(CONFIG_ASV1_DECODER)+= asvdec.o asv.o mpeg12data.o
 OBJS-$(CONFIG_ASV1_ENCODER)+= asvenc.o asv.o mpeg12data.o
 OBJS-$(CONFIG_ASV2_DECODER)+= asvdec.o asv.o mpeg12data.o
@@ -259,7 +259,7 @@ OBJS-$(CONFIG_BRENDER_PIX_DECODER) += brenderpix.o
 OBJS-$(CONFIG_C93_DECODER) += c93.o
 OBJS-$(CONFIG_CAVS_DECODER)+= cavs.o cavsdec.o cavsdsp.o \
   cavsdata.o
-OBJS-$(CONFIG_CCAPTION_DECODER)+= ccaption_dec.o ass.o
+OBJS-$(CONFIG_CCAPTION_DECODER)+= ccaption_dec.o
 OBJS-$(CONFIG_CDGRAPHICS_DECODER)  += cdgraphics.o
 OBJS-$(CONFIG_CDTOONS_DECODER) += cdtoons.o
 OBJS-$(CONFIG_CDXL_DECODER)+= cdxl.o
@@ -434,7 +434,7 @@ OBJS-$(CONFIG_INTERPLAY_ACM_DECODER)   += interplayacm.o
 OBJS-$(CONFIG_INTERPLAY_DPCM_DECODER)  += dpcm.o
 OBJS-$(CONFIG_INTERPLAY_VIDEO_DECODER) += interplayvideo.o
 OBJS-$(CONFIG_IPU_DECODER) += mpeg12dec.o mpeg12.o mpeg12data.o
-OBJS-$(CONFIG_JACOSUB_DECODER) += jacosubdec.o ass.o
+OBJS-$(CONFIG_JACOSUB_DECODER) += jacosubdec.o
 OBJS-$(CONFIG_JPEG2000_ENCODER)+= j2kenc.o mqcenc.o mqc.o jpeg2000.o \
   jpeg2000dwt.o
 OBJS-$(CONFIG_JPEG2000_DECODER)+= jpeg2000dec.o jpeg2000.o 
jpeg2000dsp.o \
@@ -456,7 +456,7 @@ OBJS-$(CONFIG_MAGICYUV_ENCODER)+= magicyuvenc.o
 OBJS-$(CONFIG_MDEC_DECODER)+= mdec.o mpeg12.o mpeg12data.o
 OBJS-$(CONFIG_METASOUND_DECODER)   += metasound.o metasound_data.o \
   twinvq.o
-OBJS-$(CONFIG_MICRODVD_DECODER)+= microdvddec.o ass.o
+OBJS-$(CONFIG_MICRODVD_DECODER)+= microdvddec.o
 OBJS-$(CONFIG_MIMIC_DECODER)   += mimic.o
 OBJS-$(CONFIG_MJPEG_DECODER)   += mjpegdec.o mjpegdec_common.o
 OBJS-$(CONFIG_MJPEG_QSV_DECODER)   += qsvdec.o
@@ -471,8 +471,8 @@ OBJS-$(CONFIG_MLP_ENCODER) += mlpenc.o mlp.o
 OBJS-$(CONFIG_MMVIDEO_DECODER) += mmvideo.o
 OBJS-$(CONFIG_MOBICLIP_DECODER)+= mobiclip.o
 OBJS-$(CONFIG_MOTIONPIXELS_DECODER)+= motionpixels.o
-OBJS-$(CONFIG_MOVTEXT_DECODER) += movtextdec.o ass.o
-OBJS-$(CONFIG_MOVTEXT_ENCOD

[FFmpeg-devel] [PATCH v3 10/26] avfilter/avfilter: Fix hardcoded input index

2022-01-19 Thread ffmpegagent
From: softworkz 

This fix targets (rare) cases where multiple input pads have a
.filter_frame function. ff_request_frame_to_filter needs
to call ff_request_frame with the correct input pad
instead of the hardcoded first one.

Signed-off-by: softworkz 
---
 libavfilter/avfilter.c | 18 +-
 1 file changed, 13 insertions(+), 5 deletions(-)

diff --git a/libavfilter/avfilter.c b/libavfilter/avfilter.c
index 75d5e86539..aa9aa71f53 100644
--- a/libavfilter/avfilter.c
+++ b/libavfilter/avfilter.c
@@ -463,7 +463,7 @@ static int64_t guess_status_pts(AVFilterContext *ctx, int 
status, AVRational lin
 return AV_NOPTS_VALUE;
 }
 
-static int ff_request_frame_to_filter(AVFilterLink *link)
+static int ff_request_frame_to_filter(AVFilterLink *link, int input_index)
 {
 int ret = -1;
 
@@ -472,8 +472,8 @@ static int ff_request_frame_to_filter(AVFilterLink *link)
 link->frame_blocked_in = 1;
 if (link->srcpad->request_frame)
 ret = link->srcpad->request_frame(link);
-else if (link->src->inputs[0])
-ret = ff_request_frame(link->src->inputs[0]);
+else if (link->src->inputs[input_index])
+ret = ff_request_frame(link->src->inputs[input_index]);
 if (ret < 0) {
 if (ret != AVERROR(EAGAIN) && ret != link->status_in)
 ff_avfilter_link_set_in_status(link, ret, 
guess_status_pts(link->src, ret, link->time_base));
@@ -1172,6 +1172,14 @@ static int forward_status_change(AVFilterContext 
*filter, AVFilterLink *in)
 {
 unsigned out = 0, progress = 0;
 int ret;
+int input_index = 0;
+
+for (int i = 0; i < in->dst->nb_inputs; i++) {
+if (&in->dst->input_pads[i] == in->dstpad) {
+input_index = i;
+break;
+}
+}
 
 av_assert0(!in->status_out);
 if (!filter->nb_outputs) {
@@ -1181,7 +1189,7 @@ static int forward_status_change(AVFilterContext *filter, 
AVFilterLink *in)
 while (!in->status_out) {
 if (!filter->outputs[out]->status_in) {
 progress++;
-ret = ff_request_frame_to_filter(filter->outputs[out]);
+ret = ff_request_frame_to_filter(filter->outputs[out], 
input_index);
 if (ret < 0)
 return ret;
 }
@@ -1218,7 +1226,7 @@ static int ff_filter_activate_default(AVFilterContext 
*filter)
 for (i = 0; i < filter->nb_outputs; i++) {
 if (filter->outputs[i]->frame_wanted_out &&
 !filter->outputs[i]->frame_blocked_in) {
-return ff_request_frame_to_filter(filter->outputs[i]);
+return ff_request_frame_to_filter(filter->outputs[i], 0);
 }
 }
 return FFERROR_NOT_READY;
-- 
ffmpeg-codebot

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH v3 04/26] avfilter/subtitles: Update vf_subtitles to use new decoding api

2022-01-19 Thread ffmpegagent
From: softworkz 

Signed-off-by: softworkz 
---
 libavfilter/vf_subtitles.c | 56 +-
 1 file changed, 43 insertions(+), 13 deletions(-)

diff --git a/libavfilter/vf_subtitles.c b/libavfilter/vf_subtitles.c
index 3fc4eeb63d..25e217e845 100644
--- a/libavfilter/vf_subtitles.c
+++ b/libavfilter/vf_subtitles.c
@@ -35,14 +35,12 @@
 # include "libavformat/avformat.h"
 #endif
 #include "libavutil/avstring.h"
-#include "libavutil/imgutils.h"
 #include "libavutil/opt.h"
 #include "libavutil/parseutils.h"
 #include "drawutils.h"
 #include "avfilter.h"
 #include "internal.h"
 #include "formats.h"
-#include "video.h"
 
 typedef struct AssContext {
 const AVClass *class;
@@ -292,6 +290,29 @@ static int attachment_is_font(AVStream * st)
 return 0;
 }
 
+static int decode(AVCodecContext *avctx, AVFrame *frame, int *got_frame, 
AVPacket *pkt)
+{
+int ret;
+
+*got_frame = 0;
+
+if (pkt) {
+ret = avcodec_send_packet(avctx, pkt);
+// In particular, we don't expect AVERROR(EAGAIN), because we read all
+// decoded frames with avcodec_receive_frame() until done.
+if (ret < 0 && ret != AVERROR_EOF)
+return ret;
+}
+
+ret = avcodec_receive_frame(avctx, frame);
+if (ret < 0 && ret != AVERROR(EAGAIN))
+return ret;
+if (ret >= 0)
+*got_frame = 1;
+
+return 0;
+}
+
 AVFILTER_DEFINE_CLASS(subtitles);
 
 static av_cold int init_subtitles(AVFilterContext *ctx)
@@ -306,6 +327,7 @@ static av_cold int init_subtitles(AVFilterContext *ctx)
 AVStream *st;
 AVPacket pkt;
 AssContext *ass = ctx->priv;
+enum AVSubtitleType subtitle_format;
 
 /* Init libass */
 ret = init(ctx);
@@ -386,13 +408,17 @@ static av_cold int init_subtitles(AVFilterContext *ctx)
 ret = AVERROR_DECODER_NOT_FOUND;
 goto end;
 }
+
 dec_desc = avcodec_descriptor_get(st->codecpar->codec_id);
-if (dec_desc && !(dec_desc->props & AV_CODEC_PROP_TEXT_SUB)) {
+subtitle_format = avcodec_descriptor_get_subtitle_format(dec_desc);
+
+if (subtitle_format != AV_SUBTITLE_FMT_ASS) {
 av_log(ctx, AV_LOG_ERROR,
-   "Only text based subtitles are currently supported\n");
-ret = AVERROR_PATCHWELCOME;
+   "Only text based subtitles are supported by this filter\n");
+ret = AVERROR_INVALIDDATA;
 goto end;
 }
+
 if (ass->charenc)
 av_dict_set(&codec_opts, "sub_charenc", ass->charenc, 0);
 
@@ -448,27 +474,31 @@ static av_cold int init_subtitles(AVFilterContext *ctx)
   dec_ctx->subtitle_header_size);
 while (av_read_frame(fmt, &pkt) >= 0) {
 int i, got_subtitle;
-AVSubtitle sub = {0};
+AVFrame *sub = av_frame_alloc();
+if (!sub) {
+ret = AVERROR(ENOMEM);
+goto end;
+}
 
 if (pkt.stream_index == sid) {
-ret = avcodec_decode_subtitle2(dec_ctx, &sub, &got_subtitle, &pkt);
+ret = decode(dec_ctx, sub, &got_subtitle, &pkt);
 if (ret < 0) {
 av_log(ctx, AV_LOG_WARNING, "Error decoding: %s (ignored)\n",
av_err2str(ret));
 } else if (got_subtitle) {
-const int64_t start_time = av_rescale_q(sub.pts, 
AV_TIME_BASE_Q, av_make_q(1, 1000));
-const int64_t duration   = sub.end_display_time;
-for (i = 0; i < sub.num_rects; i++) {
-char *ass_line = sub.rects[i]->ass;
+const int64_t start_time = 
av_rescale_q(sub->subtitle_timing.start_pts, AV_TIME_BASE_Q, av_make_q(1, 
1000));
+const int64_t duration   = 
av_rescale_q(sub->subtitle_timing.duration, AV_TIME_BASE_Q, av_make_q(1, 1000));
+for (i = 0; i < sub->num_subtitle_areas; i++) {
+char *ass_line = sub->subtitle_areas[i]->ass;
 if (!ass_line)
-break;
+continue;
 ass_process_chunk(ass->track, ass_line, strlen(ass_line),
   start_time, duration);
 }
 }
 }
 av_packet_unref(&pkt);
-avsubtitle_free(&sub);
+av_frame_free(&sub);
 }
 
 end:
-- 
ffmpeg-codebot

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH v3 09/26] avfilter/avfilter: Handle subtitle frames

2022-01-19 Thread ffmpegagent
From: softworkz 

Signed-off-by: softworkz 
---
 libavfilter/avfilter.c  |  8 +---
 libavfilter/avfilter.h  | 11 +++
 libavfilter/avfiltergraph.c |  5 +
 libavfilter/formats.c   | 22 ++
 libavfilter/formats.h   |  3 +++
 libavfilter/internal.h  | 18 +++---
 6 files changed, 61 insertions(+), 6 deletions(-)

diff --git a/libavfilter/avfilter.c b/libavfilter/avfilter.c
index df5b8f483c..75d5e86539 100644
--- a/libavfilter/avfilter.c
+++ b/libavfilter/avfilter.c
@@ -56,7 +56,8 @@ static void tlog_ref(void *ctx, AVFrame *ref, int end)
 ref->linesize[0], ref->linesize[1], ref->linesize[2], 
ref->linesize[3],
 ref->pts, ref->pkt_pos);
 
-if (ref->width) {
+switch(ref->type) {
+case AVMEDIA_TYPE_VIDEO:
 ff_tlog(ctx, " a:%d/%d s:%dx%d i:%c iskey:%d type:%c",
 ref->sample_aspect_ratio.num, ref->sample_aspect_ratio.den,
 ref->width, ref->height,
@@ -64,12 +65,13 @@ static void tlog_ref(void *ctx, AVFrame *ref, int end)
 ref->top_field_first ? 'T' : 'B',/* Top / Bottom */
 ref->key_frame,
 av_get_picture_type_char(ref->pict_type));
-}
-if (ref->nb_samples) {
+break;
+case AVMEDIA_TYPE_AUDIO:
 ff_tlog(ctx, " cl:%"PRId64"d n:%d r:%d",
 ref->channel_layout,
 ref->nb_samples,
 ref->sample_rate);
+break;
 }
 
 ff_tlog(ctx, "]%s", end ? "\n" : "");
diff --git a/libavfilter/avfilter.h b/libavfilter/avfilter.h
index b105dc3159..9f917deb41 100644
--- a/libavfilter/avfilter.h
+++ b/libavfilter/avfilter.h
@@ -45,6 +45,7 @@
 #include "libavutil/log.h"
 #include "libavutil/samplefmt.h"
 #include "libavutil/pixfmt.h"
+#include "libavutil/subfmt.h"
 #include "libavutil/rational.h"
 
 #include "libavfilter/version.h"
@@ -343,6 +344,12 @@ typedef struct AVFilter {
  * and outputs use the same sample rate and channel count/layout.
  */
 const enum AVSampleFormat *samples_list;
+/**
+ * Analogous to pixels, but delimited by AV_SUBTITLE_FMT_NONE
+ * and restricted to filters that only have AVMEDIA_TYPE_SUBTITLE
+ * inputs and outputs.
+ */
+const enum AVSubtitleType *subs_list;
 /**
  * Equivalent to { pix_fmt, AV_PIX_FMT_NONE } as pixels_list.
  */
@@ -351,6 +358,10 @@ typedef struct AVFilter {
  * Equivalent to { sample_fmt, AV_SAMPLE_FMT_NONE } as samples_list.
  */
 enum AVSampleFormat sample_fmt;
+/**
+ * Equivalent to { sub_fmt, AV_SUBTITLE_FMT_NONE } as subs_list.
+ */
+enum AVSubtitleType sub_fmt;
 } formats;
 
 int priv_size;  ///< size of private data to allocate for the filter
diff --git a/libavfilter/avfiltergraph.c b/libavfilter/avfiltergraph.c
index b8b432e98b..f4987654af 100644
--- a/libavfilter/avfiltergraph.c
+++ b/libavfilter/avfiltergraph.c
@@ -311,6 +311,8 @@ static int filter_link_check_formats(void *log, 
AVFilterLink *link, AVFilterForm
 return ret;
 break;
 
+case AVMEDIA_TYPE_SUBTITLE:
+return 0;
 default:
 av_assert0(!"reached");
 }
@@ -441,6 +443,9 @@ static int query_formats(AVFilterGraph *graph, void 
*log_ctx)
 if (!link)
 continue;
 
+if (link->type == AVMEDIA_TYPE_SUBTITLE)
+continue;
+
 neg = ff_filter_get_negotiation(link);
 av_assert0(neg);
 for (neg_step = 1; neg_step < neg->nb_mergers; neg_step++) {
diff --git a/libavfilter/formats.c b/libavfilter/formats.c
index ba62f73248..5c972bb183 100644
--- a/libavfilter/formats.c
+++ b/libavfilter/formats.c
@@ -19,6 +19,7 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
+#include "libavutil/subfmt.h"
 #include "libavutil/avassert.h"
 #include "libavutil/channel_layout.h"
 #include "libavutil/common.h"
@@ -431,6 +432,12 @@ int ff_add_channel_layout(AVFilterChannelLayouts **l, 
uint64_t channel_layout)
 return 0;
 }
 
+int ff_add_subtitle_type(AVFilterFormats **avff, int64_t fmt)
+{
+ADD_FORMAT(avff, fmt, ff_formats_unref, int, formats, nb_formats);
+return 0;
+}
+
 AVFilterFormats *ff_make_formats_list_singleton(int fmt)
 {
 int fmts[2] = { fmt, -1 };
@@ -450,6 +457,13 @@ AVFilterFormats *ff_all_formats(enum AVMediaType type)
 return NULL;
 fmt++;
 }
+} else if (type == AVMEDIA_TYPE_SUBTITLE) {
+if (ff_add_subtitle_type(&ret, AV_SUBTITLE_FMT_BITMAP) < 0)
+return NULL;
+if (ff_add_subtitle_type(&ret, AV_SUBTITLE_FMT_ASS) < 0)
+return NULL;
+if (ff_add_subtitle_type(&ret, AV_SUBTITLE_FMT_TEXT) < 0)
+return NULL;
 }
 
 return ret;
@@ -724,6 +738,10 @@ int ff_default_query_formats(AVFilterContext *ctx)
 type= 

[FFmpeg-devel] [PATCH v3 03/26] avcodec/subtitles: Introduce new frame-based subtitle decoding API

2022-01-19 Thread ffmpegagent
From: softworkz 

- Modify avcodec_send_packet() to support subtitles via the regular
  frame based decoding API
- Add decode_subtitle_shim() which takes subtitle frames,
  and serves as a compatibility shim to the legacy subtitle decoding
  API until all subtitle decoders are migrated to the frame-based API
- Add additional methods for conversion between old and new API

Signed-off-by: softworkz 
---
 libavcodec/avcodec.h|   8 +-
 libavcodec/codec_desc.c |  11 +++
 libavcodec/codec_desc.h |   8 ++
 libavcodec/decode.c |  60 +++--
 libavcodec/internal.h   |  16 
 libavcodec/utils.c  | 184 
 6 files changed, 278 insertions(+), 9 deletions(-)

diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h
index fe5a83cf85..9d59f6e840 100644
--- a/libavcodec/avcodec.h
+++ b/libavcodec/avcodec.h
@@ -1675,7 +1675,7 @@ typedef struct AVCodecContext {
 
 /**
  * Header containing style information for text subtitles.
- * For SUBTITLE_ASS subtitle type, it should contain the whole ASS
+ * For AV_SUBTITLE_FMT_ASS subtitle type, it should contain the whole ASS
  * [Script Info] and [V4+ Styles] section, plus the [Events] line and
  * the Format line following. It shouldn't include any Dialogue line.
  * - encoding: Set/allocated/freed by user (before avcodec_open2())
@@ -2415,7 +2415,10 @@ int avcodec_close(AVCodecContext *avctx);
  * Free all allocated data in the given subtitle struct.
  *
  * @param sub AVSubtitle to free.
+ *
+ * @deprecated Use the regular frame based encode and decode APIs instead.
  */
+attribute_deprecated
 void avsubtitle_free(AVSubtitle *sub);
 
 /**
@@ -2508,7 +2511,10 @@ enum AVChromaLocation avcodec_chroma_pos_to_enum(int 
xpos, int ypos);
  * must be freed with avsubtitle_free if *got_sub_ptr is set.
  * @param[in,out] got_sub_ptr Zero if no subtitle could be decompressed, 
otherwise, it is nonzero.
  * @param[in] avpkt The input AVPacket containing the input buffer.
+ *
+ * @deprecated Use the new decode API (avcodec_send_packet, 
avcodec_receive_frame) instead.
  */
+attribute_deprecated
 int avcodec_decode_subtitle2(AVCodecContext *avctx, AVSubtitle *sub,
 int *got_sub_ptr,
 AVPacket *avpkt);
diff --git a/libavcodec/codec_desc.c b/libavcodec/codec_desc.c
index 0974ee03de..e48e4532ba 100644
--- a/libavcodec/codec_desc.c
+++ b/libavcodec/codec_desc.c
@@ -3548,3 +3548,14 @@ enum AVMediaType avcodec_get_type(enum AVCodecID 
codec_id)
 const AVCodecDescriptor *desc = avcodec_descriptor_get(codec_id);
 return desc ? desc->type : AVMEDIA_TYPE_UNKNOWN;
 }
+
+enum AVSubtitleType avcodec_descriptor_get_subtitle_format(const 
AVCodecDescriptor *codec_descriptor)
+{
+if(codec_descriptor->props & AV_CODEC_PROP_BITMAP_SUB)
+return AV_SUBTITLE_FMT_BITMAP;
+
+if(codec_descriptor->props & AV_CODEC_PROP_TEXT_SUB)
+return AV_SUBTITLE_FMT_ASS;
+
+return AV_SUBTITLE_FMT_UNKNOWN;
+}
diff --git a/libavcodec/codec_desc.h b/libavcodec/codec_desc.h
index 126b52df47..ba68d24e0e 100644
--- a/libavcodec/codec_desc.h
+++ b/libavcodec/codec_desc.h
@@ -121,6 +121,14 @@ const AVCodecDescriptor *avcodec_descriptor_next(const 
AVCodecDescriptor *prev);
  */
 const AVCodecDescriptor *avcodec_descriptor_get_by_name(const char *name);
 
+/**
+ * Return subtitle format from a codec descriptor
+ *
+ * @param codec_descriptor codec descriptor
+ * @return the subtitle type (e.g. bitmap, text)
+ */
+enum AVSubtitleType avcodec_descriptor_get_subtitle_format(const 
AVCodecDescriptor *codec_descriptor);
+
 /**
  * @}
  */
diff --git a/libavcodec/decode.c b/libavcodec/decode.c
index 0912f86a14..e3cf1cfa3d 100644
--- a/libavcodec/decode.c
+++ b/libavcodec/decode.c
@@ -576,6 +576,39 @@ static int decode_receive_frame_internal(AVCodecContext 
*avctx, AVFrame *frame)
 return ret;
 }
 
+static int decode_subtitle2_priv(AVCodecContext *avctx, AVSubtitle *sub,
+ int *got_sub_ptr, AVPacket *avpkt);
+
+static int decode_subtitle_shim(AVCodecContext *avctx, AVFrame *frame, 
AVPacket *avpkt)
+{
+int ret, got_sub_ptr = 0;
+AVSubtitle subtitle = { 0 };
+
+if (frame->buf[0])
+return AVERROR(EAGAIN);
+
+av_frame_unref(frame);
+
+ret = decode_subtitle2_priv(avctx, &subtitle, &got_sub_ptr, avpkt);
+
+if (ret >= 0 && got_sub_ptr) {
+frame->type = AVMEDIA_TYPE_SUBTITLE;
+frame->format = subtitle.format;
+ret = av_frame_get_buffer2(frame, 0);
+
+if (ret >= 0)
+ret = ff_frame_put_subtitle(frame, &subtitle);
+
+frame->width = avctx->width;
+frame->height = avctx->height;
+frame->pkt_dts = avpkt->dts;
+}
+
+avsubtitle_free(&subtitle);
+
+return ret;
+}
+
 int attribute_align_arg avcodec_send_packet(AVCodecContext *avctx, const 
AVPacket *avpkt)
 {
 AVCodecInternal *avci = avctx->internal;
@@ -59

[FFmpeg-devel] [PATCH v3 02/26] avutil/frame: Prepare AVFrame for subtitle handling

2022-01-19 Thread ffmpegagent
From: softworkz 

Root commit for adding subtitle filtering capabilities.
In detail:

- Add type (AVMediaType) field to AVFrame
  Replaces previous way of distinction which was based on checking
  width and height to determine whether a frame is audio or video
- Add subtitle fields to AVFrame
- Add new struct AVSubtitleArea, similar to AVSubtitleRect, but
  different allocation logic. Cannot and must not be used
  interchangeably, hence the new struct

Signed-off-by: softworkz 
---
 libavutil/Makefile |   1 +
 libavutil/frame.c  | 211 -
 libavutil/frame.h  |  85 +-
 libavutil/subfmt.c |  45 ++
 libavutil/subfmt.h |  47 ++
 5 files changed, 364 insertions(+), 25 deletions(-)
 create mode 100644 libavutil/subfmt.c

diff --git a/libavutil/Makefile b/libavutil/Makefile
index ce644f4d48..8bc0a14942 100644
--- a/libavutil/Makefile
+++ b/libavutil/Makefile
@@ -160,6 +160,7 @@ OBJS = adler32.o
\
slicethread.o\
spherical.o  \
stereo3d.o   \
+   subfmt.o \
threadmessage.o  \
time.o   \
timecode.o   \
diff --git a/libavutil/frame.c b/libavutil/frame.c
index 8997c85e35..2b95830b6f 100644
--- a/libavutil/frame.c
+++ b/libavutil/frame.c
@@ -26,6 +26,7 @@
 #include "imgutils.h"
 #include "mem.h"
 #include "samplefmt.h"
+#include "subfmt.h"
 #include "hwcontext.h"
 
 #define CHECK_CHANNELS_CONSISTENCY(frame) \
@@ -50,6 +51,9 @@ const char *av_get_colorspace_name(enum AVColorSpace val)
 return name[val];
 }
 #endif
+
+static int frame_copy_subtitles(AVFrame *dst, const AVFrame *src, int 
copy_data);
+
 static void get_frame_defaults(AVFrame *frame)
 {
 memset(frame, 0, sizeof(*frame));
@@ -70,7 +74,12 @@ static void get_frame_defaults(AVFrame *frame)
 frame->colorspace  = AVCOL_SPC_UNSPECIFIED;
 frame->color_range = AVCOL_RANGE_UNSPECIFIED;
 frame->chroma_location = AVCHROMA_LOC_UNSPECIFIED;
-frame->flags   = 0;
+frame->num_subtitle_areas  = 0;
+frame->subtitle_areas  = NULL;
+frame->subtitle_header = NULL;
+frame->repeat_sub  = 0;
+frame->subtitle_timing.start_pts = 0;
+frame->subtitle_timing.duration  = 0;
 }
 
 static void free_side_data(AVFrameSideData **ptr_sd)
@@ -240,23 +249,55 @@ static int get_audio_buffer(AVFrame *frame, int align)
 
 }
 
+static int get_subtitle_buffer(AVFrame *frame)
+{
+// Buffers in AVFrame->buf[] are not used in case of subtitle frames.
+// To accomodate with existing code, checking ->buf[0] to determine
+// whether a frame is ref-counted or has data, we're adding a 1-byte
+// buffer here, which marks the subtitle frame to contain data.
+frame->buf[0] = av_buffer_alloc(1);
+if (!frame->buf[0]) {
+av_frame_unref(frame);
+return AVERROR(ENOMEM);
+}
+
+frame->extended_data = frame->data;
+
+return 0;
+}
+
 int av_frame_get_buffer(AVFrame *frame, int align)
+{
+if (frame->width > 0 && frame->height > 0)
+frame->type = AVMEDIA_TYPE_VIDEO;
+else if (frame->nb_samples > 0 && (frame->channel_layout || 
frame->channels > 0))
+frame->type = AVMEDIA_TYPE_AUDIO;
+
+return av_frame_get_buffer2(frame, align);
+}
+
+int av_frame_get_buffer2(AVFrame *frame, int align)
 {
 if (frame->format < 0)
 return AVERROR(EINVAL);
 
-if (frame->width > 0 && frame->height > 0)
+switch(frame->type) {
+case AVMEDIA_TYPE_VIDEO:
 return get_video_buffer(frame, align);
-else if (frame->nb_samples > 0 && (frame->channel_layout || 
frame->channels > 0))
+case AVMEDIA_TYPE_AUDIO:
 return get_audio_buffer(frame, align);
-
-return AVERROR(EINVAL);
+case AVMEDIA_TYPE_SUBTITLE:
+return get_subtitle_buffer(frame);
+default:
+return AVERROR(EINVAL);
+}
 }
 
 static int frame_copy_props(AVFrame *dst, const AVFrame *src, int force_copy)
 {
 int ret, i;
 
+dst->type   = src->type;
 dst->key_frame  = src->key_frame;
 dst->pict_type  = src->pict_type;
 dst->sample_aspect_ratio= src->sample_aspect_ratio;
@@ -288,6 +329,12 @@ static int frame_copy_props(AVFrame *dst, const AVFrame 
*src, int force_copy)
 dst->colorspace = src->colorspace;
 dst->color_range= src->color_range;
 dst->chroma_location= src->chroma_location;
+dst->repeat_sub = src->repeat_sub;
+dst->subtitle_timing.start_pts = src->subtitle_timing.start_pts;
+  

[FFmpeg-devel] [PATCH v3 01/26] avcodec, avutil: Move enum AVSubtitleType to avutil, add new and deprecate old values

2022-01-19 Thread ffmpegagent
From: softworkz 

Signed-off-by: softworkz 
---
 libavcodec/avcodec.h | 19 +
 libavutil/Makefile   |  1 +
 libavutil/subfmt.h   | 68 
 libavutil/version.h  |  1 +
 4 files changed, 71 insertions(+), 18 deletions(-)
 create mode 100644 libavutil/subfmt.h

diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h
index ec1a0566a4..fe5a83cf85 100644
--- a/libavcodec/avcodec.h
+++ b/libavcodec/avcodec.h
@@ -35,6 +35,7 @@
 #include "libavutil/frame.h"
 #include "libavutil/log.h"
 #include "libavutil/pixfmt.h"
+#include "libavutil/subfmt.h"
 #include "libavutil/rational.h"
 
 #include "codec.h"
@@ -2238,24 +2239,6 @@ typedef struct AVHWAccel {
  * @}
  */
 
-enum AVSubtitleType {
-SUBTITLE_NONE,
-
-SUBTITLE_BITMAP,///< A bitmap, pict will be set
-
-/**
- * Plain text, the text field must be set by the decoder and is
- * authoritative. ass and pict fields may contain approximations.
- */
-SUBTITLE_TEXT,
-
-/**
- * Formatted text, the ass field must be set by the decoder and is
- * authoritative. pict and text fields may contain approximations.
- */
-SUBTITLE_ASS,
-};
-
 #define AV_SUBTITLE_FLAG_FORCED 0x0001
 
 typedef struct AVSubtitleRect {
diff --git a/libavutil/Makefile b/libavutil/Makefile
index d17876df1a..ce644f4d48 100644
--- a/libavutil/Makefile
+++ b/libavutil/Makefile
@@ -74,6 +74,7 @@ HEADERS = adler32.h   
  \
   sha512.h  \
   spherical.h   \
   stereo3d.h\
+  subfmt.h  \
   threadmessage.h   \
   time.h\
   timecode.h\
diff --git a/libavutil/subfmt.h b/libavutil/subfmt.h
new file mode 100644
index 00..791b45519f
--- /dev/null
+++ b/libavutil/subfmt.h
@@ -0,0 +1,68 @@
+/*
+ * Copyright (c) 2021 softworkz
+ *
+ * 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
+ */
+
+#ifndef AVUTIL_SUBFMT_H
+#define AVUTIL_SUBFMT_H
+
+#include "version.h"
+
+enum AVSubtitleType {
+
+/**
+ * Subtitle format unknown.
+ */
+AV_SUBTITLE_FMT_NONE = -1,
+
+/**
+ * Subtitle format unknown.
+ */
+AV_SUBTITLE_FMT_UNKNOWN = 0,
+#if FF_API_OLD_SUBTITLES
+SUBTITLE_NONE = 0,  ///< Deprecated, use AV_SUBTITLE_FMT_NONE 
instead.
+#endif
+
+/**
+ * Bitmap area in AVSubtitleRect.data, pixfmt AV_PIX_FMT_PAL8.
+ */
+AV_SUBTITLE_FMT_BITMAP = 1,
+#if FF_API_OLD_SUBTITLES
+SUBTITLE_BITMAP = 1,///< Deprecated, use AV_SUBTITLE_FMT_BITMAP 
instead.
+#endif
+
+/**
+ * Plain text in AVSubtitleRect.text.
+ */
+AV_SUBTITLE_FMT_TEXT = 2,
+#if FF_API_OLD_SUBTITLES
+SUBTITLE_TEXT = 2,  ///< Deprecated, use AV_SUBTITLE_FMT_TEXT 
instead.
+#endif
+
+/**
+ * Text Formatted as per ASS specification, contained AVSubtitleRect.ass.
+ */
+AV_SUBTITLE_FMT_ASS = 3,
+#if FF_API_OLD_SUBTITLES
+SUBTITLE_ASS = 3,   ///< Deprecated, use AV_SUBTITLE_FMT_ASS 
instead.
+#endif
+
+AV_SUBTITLE_FMT_NB, ///< number of subtitle formats, DO NOT USE 
THIS if you want to link with shared libav* because the number of formats might 
differ between versions.
+};
+
+#endif /* AVUTIL_SUBFMT_H */
diff --git a/libavutil/version.h b/libavutil/version.h
index 953aac9d94..5bf48f6304 100644
--- a/libavutil/version.h
+++ b/libavutil/version.h
@@ -110,6 +110,7 @@
 #define FF_API_COLORSPACE_NAME  (LIBAVUTIL_VERSION_MAJOR < 58)
 #define FF_API_AV_MALLOCZ_ARRAY (LIBAVUTIL_VERSION_MAJOR < 58)
 #define FF_API_FIFO_PEEK2   (LIBAVUTIL_VERSION_MAJOR < 58)
+#define FF_API_OLD_SUBTITLES(LIBAVUTIL_VERSION_MAJOR < 58)
 
 /**
  * @}
-- 
ffmpeg-codebot

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or ema

[FFmpeg-devel] [PATCH v3 00/26] Subtitle Filtering 2022

2022-01-19 Thread ffmpegagent


Subtitle Filtering 2022
===

This is a substantial update to the earlier subtitle filtering patch series.
A primary goal has been to address others' concerns as much as possible on
one side and to provide more clarity and control over the way things are
working. Clarity is is specifically important to allow for a better
understanding of the need for a subtitle start pts value that can be
different from the frame's pts value. This is done by refactoring the
subtitle timing fields in AVFrame, adding a frame field to indicate repeated
subtitle frames, and finally the full removal of the heartbeat
functionality, replaced by a new 'subfeed' filter that provides different
modes for arbitrating subtitle frames in a filter graph. Finally, each
subtitle filter's documentation has been amended by a section describing the
filter's timeline behavior (in v3 update).

The update also includes major improvements to graphicsub2text and lots of
other details.

Versioning is restarting at v1 due to the new submission procedure.


v3 - Rebase
===

due to merge conflicts - apologies.


Changes in v2
=

 * added .gitattributes file to enforce binary diffs for the test refs that
   cannot be applied when being sent via e-mail
 * perform filter graph re-init due to subtitle "frame size" change only
   when the size was unknown before and not set via -canvas_size
 * overlaytextsubs: Make sure to request frames on the subtitle input
 * avfilter/splitcc: Start parsing cc data on key frames only
 * avcodec/webvttenc: Don't encode ass drawing codes and empty lines
 * stripstyles: fix mem leak
 * gs2t: improve color detection
 * gs2t: empty frames must not be skipped
 * subfeed: fix name
 * textmod: preserve margins
 * added .gitattributes file to enforce binary diffs for the test refs that
   cannot be applied when being sent via e-mail
 * perform filter graph re-init due to subtitle "frame size" change only
   when the size was unknown before and not set via -canvas_size
 * avcodec/dvbsubdec: Fix conditions for fallback to default resolution
 * Made changes suggested by Andreas
 * Fixed failing command line reported by Michael

Changes from previous version v24:


AVFrame
===

 * Removed sub_start_time The start time is now added to the subtitle
   start_pts during decoding The sub_end_time field is adjusted accordingly
 * Renamed sub_end_time to duration which it is effectively after removing
   the start_time
 * Added a sub-struct 'subtitle_timing' to av frame Contains subtitle_pts
   renamed to 'subtitle_timing.start_pts' and 'subtitle_timing.duration'
 * Change both fields to (fixed) time_base AV_TIMEBASE
 * add repeat_sub field provides a clear indication whether a subtitle frame
   is an actual subtitle event or a repeated subtitle frame in a filter
   graph


Heartbeat Removal
=

 * completely removed the earlier heartbeat implementation
 * filtering arbitration is now implemented in a new filter: 'subfeed'
 * subfeed will be auto-inserted for compatiblity with sub2video command
   lines
 * the new behavior is not exactly identical to the earlier behavior, but it
   basically allows to achieve the same results


New 'subfeed' Filter


 * a versatile filter for solving all kinds of problems with subtile frame
   flow in filter graphs
 * Can be inserted at any position in a graph
 * Auto-inserted for sub2video command lines (in repeat-mode)
 * Allows duration fixup delay input frames with unknown duration and infer
   duration from start of subsequent frame
 * Provides multiple modes of operation:
   * repeat mode (default) Queues input frames Outputs frames at a fixed
 (configurable) rate Either sends a matching input frame (repeatedly) or
 empty frames otherwise
   * scatter mode similar to repeat mode, but splits input frames by
 duration into small segments with same content
   * forward mode No fixed output rate Useful in combination with duration
 fixup or overlap fixup


ffmpeg Tool Changes
===

 * delay subtitle output stream initialization (like for audio and video)
   This is needed for example when a format header depends on having
   received an initial frame to derive certain header values from
 * decoding: set subtitle frame size from decoding context
 * re-init graph when subtitle size changes
 * always insert subscale filter for sub2video command lines (to ensure
   correct scaling)


Subtitle Encoding
=

 * ignore repeated frames for encoding based on repeat_sub field in AVFrame
 * support multi-area encoding for text subtitles Subtitle OCR can create
   multiple areas at different positions. Previously, the texts were always
   squashed into a single area ('subtitle rect'), which was not ideal.
   Multiple text areas are now generally supported:
   * ASS Encoder Changed to use the 'receive_packet' encoding API A single
 frame with multiple text areas will create multiple packets

[FFmpeg-devel] [PATCH v2 26/26] avcodec/dvbsubdec: Fix conditions for fallback to default resolution

2022-01-19 Thread ffmpegagent
From: softworkz 

The previous code expected a segment of type CLUT definition to exist
in order to accept a set of segments to be complete.
This was an incorrect assumption as the presence of a CLUT segment
is not mandatory.
(version 1.6.1 of the spec is probably a bit more clear about this
than earlier versions: https://www.etsi.org/deliver/etsi_en/
300700_300799/300743/01.06.01_20/en_300743v010601a.pdf)

The flawed condition prevented proper fallback to using the default
resolution for the decoding context.

Signed-off-by: softworkz 
---
 libavcodec/dvbsubdec.c | 51 +-
 1 file changed, 30 insertions(+), 21 deletions(-)

diff --git a/libavcodec/dvbsubdec.c b/libavcodec/dvbsubdec.c
index 0d64c6e71c..3a6259101c 100644
--- a/libavcodec/dvbsubdec.c
+++ b/libavcodec/dvbsubdec.c
@@ -33,7 +33,7 @@
 #define DVBSUB_CLUT_SEGMENT 0x12
 #define DVBSUB_OBJECT_SEGMENT   0x13
 #define DVBSUB_DISPLAYDEFINITION_SEGMENT 0x14
-#define DVBSUB_DISPLAY_SEGMENT  0x80
+#define DVBSUB_END_DISPLAY_SEGMENT  0x80
 
 #define cm (ff_crop_tab + MAX_NEG_CROP)
 
@@ -1620,8 +1620,12 @@ static int dvbsub_decode(AVCodecContext *avctx,
 int segment_length;
 int i;
 int ret = 0;
-int got_segment = 0;
-int got_dds = 0;
+//int got_segment = 0;
+int got_page = 0;
+int got_region = 0;
+int got_object = 0;
+int got_end_display = 0;
+int got_displaydef = 0;
 
 ff_dlog(avctx, "DVB sub packet:\n");
 
@@ -1666,34 +1670,28 @@ static int dvbsub_decode(AVCodecContext *avctx,
 switch (segment_type) {
 case DVBSUB_PAGE_SEGMENT:
 ret = dvbsub_parse_page_segment(avctx, p, segment_length, sub, 
got_sub_ptr);
-got_segment |= 1;
+got_page = 1;
 break;
 case DVBSUB_REGION_SEGMENT:
 ret = dvbsub_parse_region_segment(avctx, p, segment_length);
-got_segment |= 2;
+got_region = 1;
 break;
 case DVBSUB_CLUT_SEGMENT:
 ret = dvbsub_parse_clut_segment(avctx, p, segment_length);
 if (ret < 0) goto end;
-got_segment |= 4;
 break;
 case DVBSUB_OBJECT_SEGMENT:
 ret = dvbsub_parse_object_segment(avctx, p, segment_length);
-got_segment |= 8;
+got_object = 1;
 break;
 case DVBSUB_DISPLAYDEFINITION_SEGMENT:
 ret = dvbsub_parse_display_definition_segment(avctx, p,
   segment_length);
-got_dds = 1;
+got_displaydef = 1;
 break;
-case DVBSUB_DISPLAY_SEGMENT:
+case DVBSUB_END_DISPLAY_SEGMENT:
 ret = dvbsub_display_end_segment(avctx, p, segment_length, 
sub, got_sub_ptr);
-if (got_segment == 15 && !got_dds && !avctx->width && 
!avctx->height) {
-// Default from ETSI EN 300 743 V1.3.1 (7.2.1)
-avctx->width  = 720;
-avctx->height = 576;
-}
-got_segment |= 16;
+got_end_display = 1;
 break;
 default:
 ff_dlog(avctx, "Subtitling segment type 0x%x, page id %d, 
length %d\n",
@@ -1706,13 +1704,24 @@ static int dvbsub_decode(AVCodecContext *avctx,
 
 p += segment_length;
 }
-// Some streams do not send a display segment but if we have all the other
-// segments then we need no further data.
-if (got_segment == 15) {
-av_log(avctx, AV_LOG_DEBUG, "Missing display_end_segment, 
emulating\n");
-dvbsub_display_end_segment(avctx, p, 0, sub, got_sub_ptr);
-}
 
+// Even though not mandated by the spec, we're imposing a minimum 
requirement
+// for a useful packet to have at least one page, region and object 
segment.
+if (got_page && got_region && got_object && got_end_display) {
+
+if (!got_displaydef && !avctx->width && !avctx->height) {
+// Default from ETSI EN 300 743 V1.3.1 (7.2.1)
+avctx->width  = 720;
+avctx->height = 576;
+}
+
+// Some streams do not send an end-of-display segment but if we have 
all the other
+// segments then we need no further data.
+if (!got_end_display) {
+av_log(avctx, AV_LOG_DEBUG, "Missing display_end_segment, 
emulating\n");
+dvbsub_display_end_segment(avctx, p, 0, sub, got_sub_ptr);
+}
+}
 end:
 if (ret < 0) {
 return ret;
-- 
ffmpeg-codebot
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH v2 25/26] avcodec/webvttenc: Don't encode drawing codes and empty lines

2022-01-19 Thread ffmpegagent
From: softworkz 

Signed-off-by: softworkz 
---
 libavcodec/webvttenc.c | 31 +++
 1 file changed, 27 insertions(+), 4 deletions(-)

diff --git a/libavcodec/webvttenc.c b/libavcodec/webvttenc.c
index 48945dcb8e..62c4aa7ffd 100644
--- a/libavcodec/webvttenc.c
+++ b/libavcodec/webvttenc.c
@@ -39,6 +39,8 @@ typedef struct {
 int count;
 char stack[WEBVTT_STACK_SIZE];
 int stack_ptr;
+int has_text;
+int drawing_scale;
 } WebVTTContext;
 
 #ifdef __GNUC__
@@ -115,17 +117,24 @@ static void webvtt_style_apply(WebVTTContext *s, const 
char *style)
 static void webvtt_text_cb(void *priv, const char *text, int len)
 {
 WebVTTContext *s = priv;
-av_bprint_append_data(&s->buffer, text, len);
+if (!s->drawing_scale) {
+av_bprint_append_data(&s->buffer, text, len);
+s->has_text = 1;
+}
 }
 
 static void webvtt_new_line_cb(void *priv, int forced)
 {
-webvtt_print(priv, "\n");
+WebVTTContext *s = priv;
+if (!s->drawing_scale)
+webvtt_print(priv, "\n");
 }
 
 static void webvtt_hard_space_cb(void *priv)
 {
-webvtt_print(priv, " ");
+WebVTTContext *s = priv;
+if (!s->drawing_scale)
+webvtt_print(priv, " ");
 }
 
 static void webvtt_style_cb(void *priv, char style, int close)
@@ -149,6 +158,12 @@ static void webvtt_end_cb(void *priv)
 webvtt_stack_push_pop(priv, 0, 1);
 }
 
+static void dialog_drawing_mode_cb(void *priv, int scale)
+{
+WebVTTContext *s = priv;
+s->drawing_scale = scale;
+}
+
 static const ASSCodesCallbacks webvtt_callbacks = {
 .text = webvtt_text_cb,
 .new_line = webvtt_new_line_cb,
@@ -161,6 +176,7 @@ static const ASSCodesCallbacks webvtt_callbacks = {
 .cancel_overrides = webvtt_cancel_overrides_cb,
 .move = NULL,
 .end  = webvtt_end_cb,
+.drawing_mode = dialog_drawing_mode_cb,
 };
 
 static void ensure_ass_context(WebVTTContext* s, const AVFrame* frame)
@@ -211,16 +227,23 @@ static int webvtt_encode_frame(AVCodecContext* avctx, 
AVPacket* avpkt,
 }
 
 if (ass) {
+const unsigned saved_len = s->buffer.len;
 
-if (i > 0)
+if (i > 0 && s->buffer.len > 0)
 webvtt_new_line_cb(s, 0);
 
+s->drawing_scale = 0;
+s->has_text = 0;
+
 dialog = avpriv_ass_split_dialog(s->ass_ctx, ass);
 if (!dialog)
 return AVERROR(ENOMEM);
 webvtt_style_apply(s, dialog->style);
 avpriv_ass_split_override_codes(&webvtt_callbacks, s, 
dialog->text);
 avpriv_ass_free_dialog(&dialog);
+
+if (!s->has_text)
+s->buffer.len = saved_len;
 }
 }
 
-- 
ffmpeg-codebot

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH v2 24/26] doc/APIchanges: update for subtitle filtering changes

2022-01-19 Thread ffmpegagent
From: softworkz 

Signed-off-by: softworkz 
---
 doc/APIchanges   | 24 
 libavcodec/version.h |  2 +-
 libavutil/version.h  |  2 +-
 3 files changed, 26 insertions(+), 2 deletions(-)

diff --git a/doc/APIchanges b/doc/APIchanges
index 8df0364e4c..c8238fb008 100644
--- a/doc/APIchanges
+++ b/doc/APIchanges
@@ -14,6 +14,30 @@ libavutil: 2021-04-27
 
 API changes, most recent first:
 
+2021-12-05 - xx - lavc 59.15.100 - avcodec.h
+  Deprecate avcodec_encode_subtitle(), use regular encode api now
+
+2021-12-05 - xx - lavc 59.15.100 - codec_desc.h
+  Add avcodec_descriptor_get_subtitle_format()
+
+2021-12-05 - xx - lavc 59.15.100 - avcodec.h
+  Deprecate avsubtitle_free()
+  Deprecate avcodec_decode_subtitle2(), use regular decode api now
+
+2021-12-05 - xx - lavu 57.11.100 - frame.h
+  Add AVMediaType field to AVFrame
+  Add Fields for carrying subtitle data to AVFrame
+  (subtitle_areas, subtitle_header, subtitle_pts, start/end time, etc.)
+  Add av_frame_get_buffer2() and deprecate av_frame_get_buffer()
+
+2021-12-05 - xx - lavu 57.11.100 - subfmt.h
+  Add struct AVSubtitleArea (replaces AVSubtitle)
+  Add av_get_subtitle_fmt_name() and av_get_subtitle_fmt()
+
+2021-12-05 - xx - lavu 57.11.100 - subfmt.h
+  Add enum AVSubtitleType (moved from lavc), add new values, deprecate existing
+
+2021-11-xx - xx - lavfi 8.19.100 - avfilter.h
 2022-01-04 - 78dc21b123e - lavu 57.16.100 - frame.h
   Add AV_FRAME_DATA_DOVI_METADATA.
 
diff --git a/libavcodec/version.h b/libavcodec/version.h
index a46fb05f1a..b5867ad041 100644
--- a/libavcodec/version.h
+++ b/libavcodec/version.h
@@ -28,7 +28,7 @@
 #include "libavutil/version.h"
 
 #define LIBAVCODEC_VERSION_MAJOR  59
-#define LIBAVCODEC_VERSION_MINOR  20
+#define LIBAVCODEC_VERSION_MINOR  21
 #define LIBAVCODEC_VERSION_MICRO 100
 
 #define LIBAVCODEC_VERSION_INT  AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \
diff --git a/libavutil/version.h b/libavutil/version.h
index 5bf48f6304..168e24f410 100644
--- a/libavutil/version.h
+++ b/libavutil/version.h
@@ -79,7 +79,7 @@
  */
 
 #define LIBAVUTIL_VERSION_MAJOR  57
-#define LIBAVUTIL_VERSION_MINOR  18
+#define LIBAVUTIL_VERSION_MINOR  19
 #define LIBAVUTIL_VERSION_MICRO 100
 
 #define LIBAVUTIL_VERSION_INT   AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \
-- 
ffmpeg-codebot

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH v2 23/26] avcodec/webvttenc: convert hard-space tags to  

2022-01-19 Thread ffmpegagent
From: softworkz 

Signed-off-by: softworkz 
---
 libavcodec/webvttenc.c   |  6 ++
 tests/ref/fate/sub-webvttenc | 10 +-
 2 files changed, 11 insertions(+), 5 deletions(-)

diff --git a/libavcodec/webvttenc.c b/libavcodec/webvttenc.c
index c0436f5739..48945dcb8e 100644
--- a/libavcodec/webvttenc.c
+++ b/libavcodec/webvttenc.c
@@ -123,6 +123,11 @@ static void webvtt_new_line_cb(void *priv, int forced)
 webvtt_print(priv, "\n");
 }
 
+static void webvtt_hard_space_cb(void *priv)
+{
+webvtt_print(priv, " ");
+}
+
 static void webvtt_style_cb(void *priv, char style, int close)
 {
 if (style == 's') // strikethrough unsupported
@@ -147,6 +152,7 @@ static void webvtt_end_cb(void *priv)
 static const ASSCodesCallbacks webvtt_callbacks = {
 .text = webvtt_text_cb,
 .new_line = webvtt_new_line_cb,
+.hard_space   = webvtt_hard_space_cb,
 .style= webvtt_style_cb,
 .color= NULL,
 .font_name= NULL,
diff --git a/tests/ref/fate/sub-webvttenc b/tests/ref/fate/sub-webvttenc
index f4172dcc84..ee9de2859e 100644
--- a/tests/ref/fate/sub-webvttenc
+++ b/tests/ref/fate/sub-webvttenc
@@ -132,26 +132,26 @@ but show this: {normal text}
 \ N is a forced line break
 \ h is a hard space
 Normal spaces at the start and at the end of the line are trimmed while hard 
spaces are not trimmed.
-The line will never break automatically right before or after a hard space. :-D
+The line will never break automatically right before or after a hard space. :-D
 
 00:54.501 --> 00:56.500
 
- A (05 hard spaces followed by a letter)
+ A (05 hard spaces followed by a letter)
 A (Normal  spaces followed by a letter)
 A (No hard spaces followed by a letter)
 
 00:56.501 --> 00:58.500
- A (05 hard spaces followed by a letter)
+ A (05 hard spaces followed by a letter)
 A (Normal  spaces followed by a letter)
 A (No hard spaces followed by a letter)
 Show this: \TEST and this: \-)
 
 00:58.501 --> 01:00.500
 
-A letter followed by 05 hard spaces: A 
+A letter followed by 05 hard spaces: A 
 A letter followed by normal  spaces: A
 A letter followed by no hard spaces: A
-05 hard  spaces between letters: A A
+05 hard  spaces between letters: A A
 5 normal spaces between letters: A A
 
 ^--Forced line break
-- 
ffmpeg-codebot

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH v2 22/26] avutil/ass_split: Add parsing of hard-space tags (\h)

2022-01-19 Thread ffmpegagent
From: softworkz 

The \h tag in ASS/SSA is indicating a non-breaking space. See
https://github.com/Aegisub/aegisite/blob/master/source/docs/3.2/
ASS_Tags.html.md

The ass_split implementation is used by almost all text subtitle
encoders and it didn't handle this tag. Interestingly, several
tests are testing for \h parsing and had incorrect reference data
for those tests.

The \h tag is specific to ASS and doesn't have any meaning outside
of ASS.
Still, the reference data for ttmlenc, textenc and webvttenc were
full of \h tags even though this tag doesn't have a meaning there.

Signed-off-by: softworkz 
---
 libavutil/ass_split.c|  7 +++
 tests/ref/fate/.gitattributes|  3 +++
 tests/ref/fate/mov-mp4-ttml-dfxp |  8 
 tests/ref/fate/mov-mp4-ttml-stpp |  8 
 tests/ref/fate/sub-textenc   | 10 +-
 tests/ref/fate/sub-ttmlenc   |  8 
 tests/ref/fate/sub-webvttenc | 10 +-
 7 files changed, 32 insertions(+), 22 deletions(-)
 create mode 100644 tests/ref/fate/.gitattributes

diff --git a/libavutil/ass_split.c b/libavutil/ass_split.c
index c5963351fc..30512dfc74 100644
--- a/libavutil/ass_split.c
+++ b/libavutil/ass_split.c
@@ -484,6 +484,7 @@ int avpriv_ass_split_override_codes(const ASSCodesCallbacks 
*callbacks, void *pr
 while (buf && *buf) {
 if (text && callbacks->text &&
 (sscanf(buf, "\\%1[nN]", new_line) == 1 ||
+ sscanf(buf, "\\%1[hH]", new_line) == 1 ||
  !strncmp(buf, "{\\", 2))) {
 callbacks->text(priv, text, text_len);
 text = NULL;
@@ -492,6 +493,12 @@ int avpriv_ass_split_override_codes(const 
ASSCodesCallbacks *callbacks, void *pr
 if (callbacks->new_line)
 callbacks->new_line(priv, new_line[0] == 'N');
 buf += 2;
+} else if (sscanf(buf, "\\%1[hH]", new_line) == 1) {
+if (callbacks->hard_space)
+callbacks->hard_space(priv);
+else if (callbacks->text)
+callbacks->text(priv, " ", 1);
+buf += 2;
 } else if (!strncmp(buf, "{\\", 2)) {
 buf++;
 while (*buf == '\\') {
diff --git a/tests/ref/fate/.gitattributes b/tests/ref/fate/.gitattributes
new file mode 100644
index 00..19be64d085
--- /dev/null
+++ b/tests/ref/fate/.gitattributes
@@ -0,0 +1,3 @@
+sub-textenc -diff
+sub-ttmlenc -diff
+sub-webvttenc -diff
diff --git a/tests/ref/fate/mov-mp4-ttml-dfxp b/tests/ref/fate/mov-mp4-ttml-dfxp
index e24b5d618b..e565ffa1f6 100644
--- a/tests/ref/fate/mov-mp4-ttml-dfxp
+++ b/tests/ref/fate/mov-mp4-ttml-dfxp
@@ -1,9 +1,9 @@
-2e7e01c821c111466e7a2844826b7f6d *tests/data/fate/mov-mp4-ttml-dfxp.mp4
-8519 tests/data/fate/mov-mp4-ttml-dfxp.mp4
+658884e1b789e75c454b25bdf71283c9 *tests/data/fate/mov-mp4-ttml-dfxp.mp4
+8486 tests/data/fate/mov-mp4-ttml-dfxp.mp4
 #tb 0: 1/1000
 #media_type 0: data
 #codec_id 0: none
-0,  0,  0,68500, 7866, 0x456c36b7
+0,  0,  0,68500, 7833, 0x31b22193
 {
 "packets": [
 {
@@ -15,7 +15,7 @@
 "dts_time": "0.00",
 "duration": 68500,
 "duration_time": "68.50",
-"size": "7866",
+"size": "7833",
 "pos": "44",
 "flags": "K_"
 }
diff --git a/tests/ref/fate/mov-mp4-ttml-stpp b/tests/ref/fate/mov-mp4-ttml-stpp
index 77bd23b7bf..f25b5b2d28 100644
--- a/tests/ref/fate/mov-mp4-ttml-stpp
+++ b/tests/ref/fate/mov-mp4-ttml-stpp
@@ -1,9 +1,9 @@
-cbd2c7ff864a663b0d893deac5a0caec *tests/data/fate/mov-mp4-ttml-stpp.mp4
-8547 tests/data/fate/mov-mp4-ttml-stpp.mp4
+c9570de0ccebc858b0c662a7e449582c *tests/data/fate/mov-mp4-ttml-stpp.mp4
+8514 tests/data/fate/mov-mp4-ttml-stpp.mp4
 #tb 0: 1/1000
 #media_type 0: data
 #codec_id 0: none
-0,  0,  0,68500, 7866, 0x456c36b7
+0,  0,  0,68500, 7833, 0x31b22193
 {
 "packets": [
 {
@@ -15,7 +15,7 @@ cbd2c7ff864a663b0d893deac5a0caec 
*tests/data/fate/mov-mp4-ttml-stpp.mp4
 "dts_time": "0.00",
 "duration": 68500,
 "duration_time": "68.50",
-"size": "7866",
+"size": "7833",
 "pos": "44",
 "flags": "K_"
 }
diff --git a/tests/ref/fate/sub-textenc b/tests/ref/fate/sub-textenc
index 3ea56b38f0..910ca3d6e3 100644
--- a/tests/ref/fate/sub-textenc
+++ b/tests/ref/fate/sub-textenc
@@ -160,18 +160,18 @@ but show this: {normal text}
 \ N is a forced line break
 \ h is a hard space
 Normal spaces at the start and at the end of the line are trimmed while hard 
spaces are not trimmed.
-The\hline\hwill\hnever\hbreak\hautomatically\hright\hbefore\hor\hafter\ha\hhard\hspace.\h:-D
+The line will never break automatically right before or after a hard space. :-D
 
 31
 00:00:54,501 --> 00:00:56,500
 
-\h\h\h\h\hA (05 hard spaces followed by a letter)
+ A (05 hard spaces followed by a let

[FFmpeg-devel] [PATCH v2 20/26] avcodec/subtitles: Migrate subtitle encoders to frame-based API

2022-01-19 Thread ffmpegagent
From: softworkz 

and provide a compatibility shim for the legacy api

Signed-off-by: softworkz 
---
 libavcodec/assenc.c| 189 ++---
 libavcodec/avcodec.h   |   5 +-
 libavcodec/dvbsubenc.c |  96 ++-
 libavcodec/dvdsubenc.c | 102 
 libavcodec/encode.c|  61 +++-
 libavcodec/movtextenc.c| 114 --
 libavcodec/srtenc.c| 108 ++---
 libavcodec/tests/avcodec.c |   2 -
 libavcodec/ttmlenc.c   | 101 +++-
 libavcodec/webvttenc.c |  86 -
 libavcodec/xsubenc.c   |  88 ++---
 11 files changed, 687 insertions(+), 265 deletions(-)

diff --git a/libavcodec/assenc.c b/libavcodec/assenc.c
index b0e475834b..e1401b1ac5 100644
--- a/libavcodec/assenc.c
+++ b/libavcodec/assenc.c
@@ -22,70 +22,195 @@
 #include 
 
 #include "avcodec.h"
+#include "encode.h"
 #include "libavutil/ass_internal.h"
 #include "internal.h"
 #include "libavutil/avstring.h"
 #include "libavutil/internal.h"
 #include "libavutil/mem.h"
 
+typedef struct {
+AVCodecContext *avctx;
+AVFrame* current_frame;
+int have_frame;
+int current_area;
+} AssEncContext;
+
+static void check_write_header(AVCodecContext* avctx, const AVFrame* frame)
+{
+if (avctx->extradata_size)
+return;
+
+if (frame->subtitle_header && frame->subtitle_header->size > 0) {
+const char* subtitle_header = (char*)frame->subtitle_header->data;
+avctx->extradata_size = strlen(subtitle_header);
+avctx->extradata = av_mallocz(frame->subtitle_header->size + 1);
+memcpy(avctx->extradata, subtitle_header, avctx->extradata_size);
+avctx->extradata[avctx->extradata_size] = 0;
+}
+
+if (!avctx->extradata_size) {
+const char* subtitle_header = 
avpriv_ass_get_subtitle_header_default(0);
+if (!subtitle_header)
+return;
+
+avctx->extradata_size = strlen(subtitle_header);
+avctx->extradata = av_mallocz(avctx->extradata_size + 1);
+memcpy(avctx->extradata, subtitle_header, avctx->extradata_size);
+avctx->extradata[avctx->extradata_size] = 0;
+av_freep(&subtitle_header);
+}
+}
+
 static av_cold int ass_encode_init(AVCodecContext *avctx)
 {
-avctx->extradata = av_malloc(avctx->subtitle_header_size + 1);
-if (!avctx->extradata)
-return AVERROR(ENOMEM);
-memcpy(avctx->extradata, avctx->subtitle_header, 
avctx->subtitle_header_size);
-avctx->extradata_size = avctx->subtitle_header_size;
-avctx->extradata[avctx->extradata_size] = 0;
+AssEncContext *s = avctx->priv_data;
+
+if (avctx->subtitle_header_size) {
+avctx->extradata = av_malloc(avctx->subtitle_header_size + 1);
+if (!avctx->extradata)
+return AVERROR(ENOMEM);
+memcpy(avctx->extradata, avctx->subtitle_header, 
avctx->subtitle_header_size);
+avctx->extradata_size   = avctx->subtitle_header_size;
+avctx->extradata[avctx->extradata_size] = 0;
+}
+
+s->current_frame = av_frame_alloc();
+return 0;
+}
+
+static av_cold int ass_encode_close(AVCodecContext *avctx)
+{
+AssEncContext *s = avctx->priv_data;
+av_frame_free(&s->current_frame);
 return 0;
 }
 
-static int ass_encode_frame(AVCodecContext *avctx,
-unsigned char *buf, int bufsize,
-const AVSubtitle *sub)
+static int ass_encode_frame(AVCodecContext* avctx, AVPacket* avpkt,
+const AVFrame* frame, int* got_packet)
+{
+int ret;
+size_t req_len = 0, total_len = 0;
+
+check_write_header(avctx, frame);
+
+for (unsigned i = 0; i < frame->num_subtitle_areas; i++) {
+const char *ass = frame->subtitle_areas[i]->ass;
+
+if (frame->subtitle_areas[i]->type != AV_SUBTITLE_FMT_ASS) {
+av_log(avctx, AV_LOG_ERROR, "Only AV_SUBTITLE_FMT_ASS type 
supported.\n");
+return AVERROR(EINVAL);
+}
+
+if (ass)
+req_len += strlen(ass);
+}
+
+ret = ff_get_encode_buffer(avctx, avpkt, req_len + 1, 0);
+if (ret < 0) {
+av_log(avctx, AV_LOG_ERROR, "Error getting output packet.\n");
+return ret;
+}
+
+for (unsigned i = 0; i < frame->num_subtitle_areas; i++) {
+const char *ass = frame->subtitle_areas[i]->ass;
+
+if (ass) {
+size_t len = av_strlcpy((char *)avpkt->data + total_len, ass, 
avpkt->size - total_len);
+total_len += len;
+}
+}
+
+avpkt->size = total_len;
+*got_packet = total_len > 0;
+
+return 0;
+}
+
+static int ass_receive_packet(AVCodecContext *avctx, AVPacket *avpkt)
 {
-int i, len, total_len = 0;
+AssEncContext *s = avctx-

[FFmpeg-devel] [PATCH v2 19/26] avfilter/subfeed: add subtitle feed filter

2022-01-19 Thread ffmpegagent
From: softworkz 

Signed-off-by: softworkz 
---
 libavfilter/Makefile |   1 +
 libavfilter/allfilters.c |   1 +
 libavfilter/sf_subfeed.c | 366 +++
 3 files changed, 368 insertions(+)
 create mode 100644 libavfilter/sf_subfeed.c

diff --git a/libavfilter/Makefile b/libavfilter/Makefile
index 0e3e48613e..5711c7770b 100644
--- a/libavfilter/Makefile
+++ b/libavfilter/Makefile
@@ -570,6 +570,7 @@ OBJS-$(CONFIG_TEXTMOD_FILTER)+= sf_textmod.o
 OBJS-$(CONFIG_SPLITCC_FILTER)+= sf_splitcc.o
 OBJS-$(CONFIG_STRIPSTYLES_FILTER)+= sf_stripstyles.o
 OBJS-$(CONFIG_SUBSCALE_FILTER)   += sf_subscale.o
+OBJS-$(CONFIG_SUBFEED_FILTER)+= sf_subfeed.o
 
 # multimedia filters
 OBJS-$(CONFIG_ABITSCOPE_FILTER)  += avf_abitscope.o
diff --git a/libavfilter/allfilters.c b/libavfilter/allfilters.c
index 8e4f2feca3..10b14b7b8e 100644
--- a/libavfilter/allfilters.c
+++ b/libavfilter/allfilters.c
@@ -553,6 +553,7 @@ extern const AVFilter ff_sf_showspeaker;
 extern const AVFilter ff_sf_splitcc;
 extern const AVFilter ff_sf_stripstyles;
 extern const AVFilter ff_sf_subscale;
+extern const AVFilter ff_sf_subfeed;
 extern const AVFilter ff_sf_textmod;
 extern const AVFilter ff_svf_graphicsub2video;
 extern const AVFilter ff_svf_textsub2video;
diff --git a/libavfilter/sf_subfeed.c b/libavfilter/sf_subfeed.c
new file mode 100644
index 00..7df6641f6a
--- /dev/null
+++ b/libavfilter/sf_subfeed.c
@@ -0,0 +1,366 @@
+/*
+ * Copyright (c) 2021 softworkz
+ *
+ * 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
+ * subtitle filter for feeding subtitle frames into a filtergraph in a 
contiguous way
+ *
+ *
+ * also supports
+ *   - duration fixup
+ * delaying a subtitle event with unknown duration and infer duration from 
the
+ * start time of the subsequent subtitle
+ *   - scattering
+ * splitting a subtitle event with unknown duration into multiple ones with
+ * a short and fixed duration
+ *
+ */
+
+#include "filters.h"
+#include "libavutil/opt.h"
+#include "subtitles.h"
+#include "libavutil/avassert.h"
+
+enum SubFeedMode {
+FM_REPEAT,
+FM_SCATTER,
+FM_FORWARD,
+};
+
+typedef struct SubFeedContext {
+const AVClass *class;
+enum AVSubtitleType format;
+enum SubFeedMode mode;
+
+AVRational frame_rate;
+int fix_durations;
+int fix_overlap;
+
+int current_frame_isnew;
+int eof;
+int got_first_input;
+int need_frame;
+int64_t next_pts_offset;
+int64_t recent_subtitle_pts;
+
+int64_t counter;
+
+/**
+ * Queue of frames waiting to be filtered.
+ */
+FFFrameQueue fifo;
+
+} SubFeedContext;
+
+static int64_t ms_to_avtb(int64_t ms)
+{
+return av_rescale_q(ms, (AVRational){ 1, 1000 }, AV_TIME_BASE_Q);
+}
+
+static int64_t avtb_to_ms(int64_t avtb)
+{
+return av_rescale_q(avtb, AV_TIME_BASE_Q, (AVRational){ 1, 1000 });
+}
+
+static int init(AVFilterContext *ctx)
+{
+SubFeedContext *s = ctx->priv;
+
+ff_framequeue_init(&s->fifo, NULL);
+
+return 0;
+}
+
+static void uninit(AVFilterContext *ctx)
+{
+SubFeedContext *s = ctx->priv;
+ff_framequeue_free(&s->fifo);
+}
+
+static int config_input(AVFilterLink *link)
+{
+const subfeedContext *context = link->dst->priv;
+
+return 0;
+}
+
+static int query_formats(AVFilterContext *ctx)
+{
+AVFilterFormats *formats;
+AVFilterLink *inlink0 = ctx->inputs[0];
+AVFilterLink *outlink0 = ctx->outputs[0];
+static const enum AVSubtitleType subtitle_fmts[] = { 
AV_SUBTITLE_FMT_BITMAP, AV_SUBTITLE_FMT_ASS, AV_SUBTITLE_FMT_NB };
+int ret;
+
+formats = ff_make_format_list(subtitle_fmts);
+
+if ((ret = ff_formats_ref(formats, &inlink0->outcfg.formats)) < 0)
+return ret;
+
+if ((ret = ff_formats_ref(formats, &outlink0->incfg.formats)) < 0)
+return ret;
+
+return 0;
+}
+
+static int config_output(AVFilterLink *outlink)
+{
+SubFeedContext *s = outlink->src->priv;
+const AVFilterLink *inlink = outlink->src->inputs[0];
+
+outlink->time_base = AV_TIME_BASE_Q;
+outlink->format = inlink->format;
+outlink->w = inlink->w;
+outlink->h = inlink->h;
+
+if (s->mode == FM_FORWARD)
+

[FFmpeg-devel] [PATCH v2 18/26] avfilter/subscale: Add filter for scaling and/or re-arranging graphical subtitles

2022-01-19 Thread ffmpegagent
From: softworkz 

Signed-off-by: softworkz 
---
 configure |   1 +
 doc/filters.texi  | 164 +++
 libavfilter/Makefile  |   1 +
 libavfilter/allfilters.c  |   1 +
 libavfilter/sf_subscale.c | 884 ++
 5 files changed, 1051 insertions(+)
 create mode 100644 libavfilter/sf_subscale.c

diff --git a/configure b/configure
index ee7afffb05..a8b7ce8a26 100755
--- a/configure
+++ b/configure
@@ -3731,6 +3731,7 @@ sr_filter_deps="avformat swscale"
 sr_filter_select="dnn"
 stereo3d_filter_deps="gpl"
 splitcc_filter_deps="avcodec"
+subscale_filter_deps="swscale avcodec"
 subtitles_filter_deps="avformat avcodec libass"
 super2xsai_filter_deps="gpl"
 pixfmts_super2xsai_test_deps="super2xsai_filter"
diff --git a/doc/filters.texi b/doc/filters.texi
index 9311714f82..b3d11c0ac0 100644
--- a/doc/filters.texi
+++ b/doc/filters.texi
@@ -26303,6 +26303,170 @@ Set the rendering margin in pixels.
 For rendering, alway use the latest event only, which is covering the given 
point in time.
 @end table
 
+@section subscale
+
+Provides high-quality scaling and rearranging functionality for graphical 
subtitles.
+
+The subscale filter provides multiple approaches for manipulating
+the size and position of graphical subtitle rectangles wich can
+be combined or used separately.
+Scaling is performed by converting the palettized subtitle bitmaps
+to RGBA and re-quantization to palette colors afterwards via elbg algorithm.
+
+The two major operations are 'scale' and 're-arrange' with the
+latter being separated as 'arrange_h' and 'arrange_v'.
+
+
+Inputs:
+- 0: Subtitles [bitmap]
+
+Outputs:
+- 0: Subtitles [bitmap]
+
+It accepts the following parameters:
+
+@table @option
+
+@item w, width
+Set the width of the output.
+Width and height in case of graphical subtitles are just indicating
+a virtual size for which the output (consisting of 0-n bitmap rectangles)
+is intended to be displayed on.
+
+@item h, height
+Set the height of the output.
+
+@item margin_h
+Sets a horizontal margin to be preserverved when using any
+of the arrange modes.
+
+@item margin_v
+Sets a vertical margin to be preserverved when using any
+of the arrange modes.
+
+@item force_original_aspect_ratio
+Enable decreasing or increasing output video width or height if necessary to
+keep the original aspect ratio. Possible values:
+
+@table @samp
+@item disable
+Scale the video as specified and disable this feature.
+
+@item decrease
+The output video dimensions will automatically be decreased if needed.
+
+@item increase
+The output video dimensions will automatically be increased if needed.
+
+@end table
+
+
+@item scale_mode
+Specifies how subtitle bitmaps should be scaled.
+The scale factor is determined by the the factor between input
+and output size.
+
+@table @samp
+@item none
+Do not apply any common scaling.
+
+@item uniform
+Uniformly scale all subtitle bitmaps including their positions.
+
+@item uniform_no_reposition
+Uniformly scale all subtitle bitmaps without changing positions.
+
+@end table
+
+
+@item arrange_h
+Specifies how subtitle bitmaps should be arranged horizontally.
+
+@item arrange_v
+Specifies how subtitle bitmaps should be arranged vertically.
+
+
+@table @samp
+@item none
+Do not rearrange subtitle bitmaps.
+
+@item margin_no_scale
+Move subtitle bitmaps to be positioned inside the specified
+margin (margin_h or margin_v) when possible and without scaling.
+
+@item margin_and_scale
+Move subtitle bitmaps to be positioned inside the specified
+margin (margin_h or margin_v) and scale in case it doesn't fit.
+
+@item snapalign_no_scale
+Categorize subtitle bitmap positions as one of left/center/right
+or top/bottom/middle based on original positioning and apply
+these alignments for the target positioning.
+No scaling will be applied.
+
+@item snapalign_and_scale
+Categorize subtitle bitmap positions as one of left/center/right
+or top/bottom/middle based on original positioning and apply
+these alignments for the target positioning.
+Bitmaps that do not fit inside the margins borders are
+scaled to fit.
+@end table
+
+@item eval
+Set evaluation mode for the expressions (@option{width}, @option{height}).
+
+It accepts the following values:
+@table @samp
+@item init
+Evaluate expressions only once during the filter initialization.
+
+@item frame
+Evaluate expressions for each incoming frame. This is way slower than the
+@samp{init} mode since it requires all the scalers to be re-computed, but it
+allows advanced dynamic expressions.
+@end table
+
+Default value is @samp{init}.
+
+
+@item num_colors
+Set the number of palette colors for output images.
+Choose the maximum (256) when further processing is done (e.g.
+overlaying on a video).
+When subtitles will be encoded as bitmap subtitles (e.g. dvbsub),
+a smaller number of palette colors (e.g. 4-16) might need to be used, depending
+on the target format and codec.
+
+@item bitmap_width_align
+@item bitmap_height_align
+Make s

[FFmpeg-devel] [PATCH v2 17/26] avfilter/graphicsub2text: Add new graphicsub2text filter (OCR)

2022-01-19 Thread ffmpegagent
From: softworkz 

Signed-off-by: softworkz 
---
 configure|1 +
 doc/filters.texi |   55 ++
 libavfilter/Makefile |2 +
 libavfilter/allfilters.c |1 +
 libavfilter/sf_graphicsub2text.c | 1132 ++
 5 files changed, 1191 insertions(+)
 create mode 100644 libavfilter/sf_graphicsub2text.c

diff --git a/configure b/configure
index c1d2bc41c2..ee7afffb05 100755
--- a/configure
+++ b/configure
@@ -3665,6 +3665,7 @@ frei0r_filter_deps="frei0r"
 frei0r_src_filter_deps="frei0r"
 fspp_filter_deps="gpl"
 gblur_vulkan_filter_deps="vulkan spirv_compiler"
+graphicsub2text_filter_deps="libtesseract"
 hflip_vulkan_filter_deps="vulkan spirv_compiler"
 histeq_filter_deps="gpl"
 hqdn3d_filter_deps="gpl"
diff --git a/doc/filters.texi b/doc/filters.texi
index 265a267e9d..9311714f82 100644
--- a/doc/filters.texi
+++ b/doc/filters.texi
@@ -25897,6 +25897,61 @@ ffmpeg -i 
"https://streams.videolan.org/ffmpeg/mkv_subtitles.mkv"; -filter_comple
 @end example
 @end itemize
 
+@section graphicsub2text
+
+Converts graphic subtitles to text subtitles by performing OCR.
+
+For this filter to be available, ffmpeg needs to be compiled with libtesseract 
(see https://github.com/tesseract-ocr/tesseract).
+Language models need to be downloaded from 
https://github.com/tesseract-ocr/tessdata and put into as subfolder named 
'tessdata' or into a folder specified via the environment variable 
'TESSDATA_PREFIX'.
+The path can also be specified via filter option (see below).
+
+Note: These models are including the data for both OCR modes.
+
+Inputs:
+- 0: Subtitles [bitmap]
+
+Outputs:
+- 0: Subtitles [text]
+
+It accepts the following parameters:
+
+@table @option
+@item ocr_mode
+The character recognition mode to use.
+
+Supported OCR modes are:
+
+@table @var
+@item 0, tesseract
+This is the classic libtesseract operation mode. It is fast but less accurate 
than LSTM.
+@item 1, lstm
+Newer OCR implementation based on ML models. Provides usually better results, 
requires more processing resources.
+@item 2, both
+Use a combination of both modes.
+@end table
+
+@item tessdata_path
+The path to a folder containing the language models to be used.
+
+@item language
+The recognition language. It needs to match the first three characters of a  
language model file in the tessdata path.
+
+@end table
+
+
+@subsection Examples
+
+@itemize
+@item
+Convert DVB graphic subtitles to ASS (text) subtitles
+
+Note: For this to work, you need to have the data file 'eng.traineddata' in a 
'tessdata' subfolder (see above).
+@example
+ffmpeg -loglevel verbose -i 
"https://streams.videolan.org/streams/ts/video_subs_ttxt%2Bdvbsub.ts"; 
-filter_complex "[0:13]graphicsub2text=delay_when_no_duration=1" -c:s ass -y 
output.mkv
+@end example
+@end itemize
+
+
 @section graphicsub2video
 
 Renders graphic subtitles as video frames.
diff --git a/libavfilter/Makefile b/libavfilter/Makefile
index c6a4a4f5ae..ead3e38507 100644
--- a/libavfilter/Makefile
+++ b/libavfilter/Makefile
@@ -299,6 +299,8 @@ OBJS-$(CONFIG_GBLUR_VULKAN_FILTER)   += 
vf_gblur_vulkan.o vulkan.o vulka
 OBJS-$(CONFIG_GEQ_FILTER)+= vf_geq.o
 OBJS-$(CONFIG_GRADFUN_FILTER)+= vf_gradfun.o
 OBJS-$(CONFIG_GRAPHICSUB2VIDEO_FILTER)   += vf_overlaygraphicsubs.o 
framesync.o
+OBJS-$(CONFIG_GRAPHICSUB2TEXT_FILTER)+= sf_graphicsub2text.o
+OBJS-$(CONFIG_GRAPHICSUB2VIDEO_FILTER)   += vf_overlaygraphicsubs.o 
framesync.o
 OBJS-$(CONFIG_GRAPHMONITOR_FILTER)   += f_graphmonitor.o
 OBJS-$(CONFIG_GRAYWORLD_FILTER)  += vf_grayworld.o
 OBJS-$(CONFIG_GREYEDGE_FILTER)   += vf_colorconstancy.o
diff --git a/libavfilter/allfilters.c b/libavfilter/allfilters.c
index 50498e8ec4..34576016ce 100644
--- a/libavfilter/allfilters.c
+++ b/libavfilter/allfilters.c
@@ -548,6 +548,7 @@ extern const AVFilter ff_avf_showwaves;
 extern const AVFilter ff_avf_showwavespic;
 extern const AVFilter ff_vaf_spectrumsynth;
 extern const AVFilter ff_sf_censor;
+extern const AVFilter ff_sf_graphicsub2text;
 extern const AVFilter ff_sf_showspeaker;
 extern const AVFilter ff_sf_splitcc;
 extern const AVFilter ff_sf_stripstyles;
diff --git a/libavfilter/sf_graphicsub2text.c b/libavfilter/sf_graphicsub2text.c
new file mode 100644
index 00..9b413d314e
--- /dev/null
+++ b/libavfilter/sf_graphicsub2text.c
@@ -0,0 +1,1132 @@
+/*
+ * Copyright (c) 2021 softworkz
+ *
+ * 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 Gene

[FFmpeg-devel] [PATCH v2 16/26] avfilter/splitcc: Add splitcc filter for closed caption handling

2022-01-19 Thread ffmpegagent
From: softworkz 

- splitcc {V -> VS)
  Extract closed-caption (A53) data from video
  frames as subtitle Frames

ffmpeg -y -loglevel verbose -i "https://streams.videolan.org/streams
/ts/CC/NewsStream-608-ac3.ts" -filter_complex "[0:v]splitcc[vid1],
textmod=mode=remove_chars:find='@',[vid1]overlay_textsubs" output.mkv

Signed-off-by: softworkz 
---
 configure|   1 +
 doc/filters.texi |  63 +++
 libavfilter/Makefile |   1 +
 libavfilter/allfilters.c |   1 +
 libavfilter/sf_splitcc.c | 395 +++
 5 files changed, 461 insertions(+)
 create mode 100644 libavfilter/sf_splitcc.c

diff --git a/configure b/configure
index 340a198fa6..c1d2bc41c2 100755
--- a/configure
+++ b/configure
@@ -3729,6 +3729,7 @@ spp_filter_select="fft idctdsp fdctdsp me_cmp pixblockdsp"
 sr_filter_deps="avformat swscale"
 sr_filter_select="dnn"
 stereo3d_filter_deps="gpl"
+splitcc_filter_deps="avcodec"
 subtitles_filter_deps="avformat avcodec libass"
 super2xsai_filter_deps="gpl"
 pixfmts_super2xsai_test_deps="super2xsai_filter"
diff --git a/doc/filters.texi b/doc/filters.texi
index c0f0fe13e7..265a267e9d 100644
--- a/doc/filters.texi
+++ b/doc/filters.texi
@@ -26131,6 +26131,69 @@ ffmpeg -i INPUT -filter_complex 
"showspeaker=format=colon:style='@{\\c&HDD&\
 @end example
 @end itemize
 
+
+@section splitcc
+
+Split-out closed-caption/A53 subtitles from video frame side data.
+
+This filter provides an input and an output for video frames, which are just 
passed through without modification.
+The second out provides subtitle frames which are extracted from video frame 
side data.
+
+Inputs:
+@itemize
+@item 0: Video [ALL]
+@end itemize
+
+Outputs:
+@itemize
+@item 0: Video (same as input)
+@item 1: Subtitles [TEXT]
+@end itemize
+
+It accepts the following parameters:
+
+@table @option
+
+@item use_cc_styles
+Emit closed caption style header.
+This will make closed captions appear in white font with a black rectangle 
background.
+
+@item real_time
+Emit subtitle events as they are decoded for real-time display.
+
+@item real_time_latency_msec
+Minimum elapsed time between emitting real-time subtitle events.
+Only applies to real_time mode.
+
+@item data_field
+Select data field. Possible values:
+
+@table @samp
+@item auto
+Pick first one that appears.
+@item first
+@item second
+@end table
+
+@end table
+
+@subsection Examples
+
+@itemize
+@item
+Extract closed captions as text subtitle stream and overlay it onto the video 
in cc style (black bar background):
+@example
+ffmpeg -i "https://streams.videolan.org/streams/ts/CC/NewsStream-608-ac3.ts"; 
-filter_complex  
"[0:v:0]splitcc=use_cc_styles=1[vid1][sub1];[vid1][sub1]overlaytextsubs" 
output.mkv
+@end example
+
+@item
+A nicer variant, using realtime output from cc_dec and rendering it with the 
render_latest_only parameter from overlaytextsubs to avoid ghosting by timely 
overlap.
+@example
+ffmpeg -i "https://streams.videolan.org/streams/ts/CC/NewsStream-608-ac3.ts"; 
-filter_complex  
"[0:v:0]splitcc=real_time=1:real_time_latency_msec=200[vid1][sub1];[vid1][sub1]overlaytextsubs=render_latest_only=1"
 output.mkv
+@end example
+@end itemize
+
+
 @section textsub2video
 
 Converts text subtitles to video frames.
diff --git a/libavfilter/Makefile b/libavfilter/Makefile
index d330020f67..c6a4a4f5ae 100644
--- a/libavfilter/Makefile
+++ b/libavfilter/Makefile
@@ -565,6 +565,7 @@ OBJS-$(CONFIG_NULLSINK_FILTER)   += 
vsink_nullsink.o
 OBJS-$(CONFIG_CENSOR_FILTER) += sf_textmod.o
 OBJS-$(CONFIG_SHOW_SPEAKER_FILTER)   += sf_textmod.o
 OBJS-$(CONFIG_TEXTMOD_FILTER)+= sf_textmod.o
+OBJS-$(CONFIG_SPLITCC_FILTER)+= sf_splitcc.o
 OBJS-$(CONFIG_STRIPSTYLES_FILTER)+= sf_stripstyles.o
 
 # multimedia filters
diff --git a/libavfilter/allfilters.c b/libavfilter/allfilters.c
index b0c12595af..50498e8ec4 100644
--- a/libavfilter/allfilters.c
+++ b/libavfilter/allfilters.c
@@ -549,6 +549,7 @@ extern const AVFilter ff_avf_showwavespic;
 extern const AVFilter ff_vaf_spectrumsynth;
 extern const AVFilter ff_sf_censor;
 extern const AVFilter ff_sf_showspeaker;
+extern const AVFilter ff_sf_splitcc;
 extern const AVFilter ff_sf_stripstyles;
 extern const AVFilter ff_sf_textmod;
 extern const AVFilter ff_svf_graphicsub2video;
diff --git a/libavfilter/sf_splitcc.c b/libavfilter/sf_splitcc.c
new file mode 100644
index 00..14235e822c
--- /dev/null
+++ b/libavfilter/sf_splitcc.c
@@ -0,0 +1,395 @@
+/*
+ * Copyright (c) 2021 softworkz
+ *
+ * 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
+

[FFmpeg-devel] [PATCH v2 15/26] avfilter/stripstyles: Add stripstyles filter

2022-01-19 Thread ffmpegagent
From: softworkz 

- stripstyles {S -> S)
  Remove all inline styles from subtitle events

Signed-off-by: softworkz 
---
 doc/filters.texi |  37 ++
 libavfilter/Makefile |   1 +
 libavfilter/allfilters.c |   1 +
 libavfilter/sf_stripstyles.c | 211 +++
 4 files changed, 250 insertions(+)
 create mode 100644 libavfilter/sf_stripstyles.c

diff --git a/doc/filters.texi b/doc/filters.texi
index 494ee6f062..c0f0fe13e7 100644
--- a/doc/filters.texi
+++ b/doc/filters.texi
@@ -25781,6 +25781,43 @@ ffmpeg -i 
"http://streams.videolan.org/samples/sub/SSA/subtitle_testing_complex.
 @end example
 @end itemize
 
+@section stripstyles
+
+Remove all inline styles from subtitle events.
+
+Inputs:
+@itemize
+@item 0: Subtitles[TEXT]
+@end itemize
+
+Outputs:
+@itemize
+@item 0: Subtitles[TEXT]
+@end itemize
+
+It accepts the following parameters:
+
+@table @option
+@item remove_animated
+Also remove text which is subject to animation (default: true)
+Usually, animated text elements are used used in addition to static subtitle 
lines for creating effects, so in most cases it is safe to remove the animation 
content.
+If subtitle text is missing, try setting this to false.
+
+@item select_layer
+Process only ASS subtitle events from a specific layer. This allows to filter 
out certain effects where an ASS author duplicates the text onto multiple 
layers.
+
+@end table
+
+@subsection Examples
+
+@itemize
+@item
+Remove styles and animations from ASS subtitles and output events from ass 
layer 0 only. Then convert asn save as SRT stream:
+@example
+ffmpeg -i 
"https://streams.videolan.org/samples/sub/SSA/subtitle_testing_complex.mkv"; 
-filter_complex "[0:1]stripstyles=select_layer=0" -map 0 -c:s srt output.mkv
+@end example
+@end itemize
+
 
 @section textmod
 
diff --git a/libavfilter/Makefile b/libavfilter/Makefile
index 1af4f4b9bc..d330020f67 100644
--- a/libavfilter/Makefile
+++ b/libavfilter/Makefile
@@ -565,6 +565,7 @@ OBJS-$(CONFIG_NULLSINK_FILTER)   += 
vsink_nullsink.o
 OBJS-$(CONFIG_CENSOR_FILTER) += sf_textmod.o
 OBJS-$(CONFIG_SHOW_SPEAKER_FILTER)   += sf_textmod.o
 OBJS-$(CONFIG_TEXTMOD_FILTER)+= sf_textmod.o
+OBJS-$(CONFIG_STRIPSTYLES_FILTER)+= sf_stripstyles.o
 
 # multimedia filters
 OBJS-$(CONFIG_ABITSCOPE_FILTER)  += avf_abitscope.o
diff --git a/libavfilter/allfilters.c b/libavfilter/allfilters.c
index ac7d71547b..b0c12595af 100644
--- a/libavfilter/allfilters.c
+++ b/libavfilter/allfilters.c
@@ -549,6 +549,7 @@ extern const AVFilter ff_avf_showwavespic;
 extern const AVFilter ff_vaf_spectrumsynth;
 extern const AVFilter ff_sf_censor;
 extern const AVFilter ff_sf_showspeaker;
+extern const AVFilter ff_sf_stripstyles;
 extern const AVFilter ff_sf_textmod;
 extern const AVFilter ff_svf_graphicsub2video;
 extern const AVFilter ff_svf_textsub2video;
diff --git a/libavfilter/sf_stripstyles.c b/libavfilter/sf_stripstyles.c
new file mode 100644
index 00..bc3c5d1441
--- /dev/null
+++ b/libavfilter/sf_stripstyles.c
@@ -0,0 +1,211 @@
+/*
+ * Copyright (c) 2021 softworkz
+ *
+ * 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
+ * text subtitle filter which removes inline-styles from subtitles
+ */
+
+#include "libavutil/opt.h"
+#include "internal.h"
+#include "libavutil/ass_split_internal.h"
+#include "libavutil/bprint.h"
+
+typedef struct StripStylesContext {
+const AVClass *class;
+enum AVSubtitleType format;
+int remove_animated;
+int select_layer;
+} StripStylesContext;
+
+typedef struct DialogContext {
+StripStylesContext* ss_ctx;
+AVBPrint buffer;
+int drawing_scale;
+int is_animated;
+} DialogContext;
+
+static void dialog_text_cb(void *priv, const char *text, int len)
+{
+DialogContext *s = priv;
+
+av_log(s->ss_ctx, AV_LOG_DEBUG, "dialog_text_cb: %s\n", text);
+
+if (!s->drawing_scale && (!s->is_animated || !s->ss_ctx->remove_animated))
+av_bprint_append_data(&s->buffer, text, len);
+}
+
+static void dialog_new_line_cb(void *priv, int forced)
+{
+DialogContext *s = priv;
+if (!s->drawing_scale && !s->is_animated)
+av_bprint_append_data(&s->buffer, forced ? "\\N" : "\\n", 2);
+}

[FFmpeg-devel] [PATCH v2 14/26] avfilter/textmod: Add textmod, censor and show_speaker filters

2022-01-19 Thread ffmpegagent
From: softworkz 

- textmod {S -> S)
  Modify subtitle text in a number of ways

- censor {S -> S)
  Censor subtitles using a word list

- show_speaker {S -> S)
  Prepend speaker names from ASS subtitles to the visible text lines

Signed-off-by: softworkz 
---
 doc/filters.texi | 206 
 libavfilter/Makefile |   5 +
 libavfilter/allfilters.c |   3 +
 libavfilter/sf_textmod.c | 710 +++
 4 files changed, 924 insertions(+)
 create mode 100644 libavfilter/sf_textmod.c

diff --git a/doc/filters.texi b/doc/filters.texi
index 51771f88e4..494ee6f062 100644
--- a/doc/filters.texi
+++ b/doc/filters.texi
@@ -25721,6 +25721,145 @@ existing filters using @code{--disable-filters}.
 
 Below is a description of the currently available subtitle filters.
 
+
+@section censor
+
+Censor selected words in text subtitles.
+
+Inputs:
+@itemize
+@item 0: Subtitles[TEXT]
+@end itemize
+
+Outputs:
+@itemize
+@item 0: Subtitles[TEXT]
+@end itemize
+
+It accepts the following parameters:
+
+@table @option
+@item mode
+The censoring mode to apply.
+
+Supported censoring modes are:
+
+@table @var
+@item 0, keep_first_last
+Replace all characters with the 'censor_char' except the first and the last 
character of a word.
+For words with less than 4 characters, the last character will be replaced as 
well.
+For words with less than 3 characters, the first character will be replaced as 
well.
+@item 1, keep_first
+Replace all characters with the 'censor_char' except the first character of a 
word.
+For words with less than 3 characters, the first character will be replaced as 
well.
+@item 2, all
+Replace all characters with the 'censor_char'.
+@end table
+
+@item words
+A list of words to censor, separated by 'separator'.
+
+@item words_file
+Specify a file from which to load the contents for the 'words' parameter.
+
+@item censor_char
+Single character used as replacement for censoring.
+
+@item separator
+Delimiter character for words. Used with replace_words and remove_words- Must 
be a single character.
+The default is '.'.
+
+@end table
+
+@subsection Examples
+
+@itemize
+@item
+Censor a few given words with a pound character.
+@example
+ffmpeg -i 
"http://streams.videolan.org/samples/sub/SSA/subtitle_testing_complex.mkv"; 
-filter_complex 
"[0:1]censor=words='diss,louder,hope,beam,word':censor_char='#'" -map 0 -y 
output.mkv
+@end example
+@end itemize
+
+
+@section textmod
+
+Modify subtitle text in a number of ways.
+
+Inputs:
+@itemize
+@item 0: Subtitles[TEXT]
+@end itemize
+
+Outputs:
+@itemize
+@item 0: Subtitles[TEXT]
+@end itemize
+
+It accepts the following parameters:
+
+@table @option
+@item mode
+The kind of text modification to apply
+
+Supported operation modes are:
+
+@table @var
+@item 0, leet
+Convert subtitle text to 'leet speak'. It's primarily useful for testing as 
the modification will be visible with almost all text lines.
+@item 1, to_upper
+Change all text to upper case. Might improve readability.
+@item 2, to_lower
+Change all text to lower case.
+@item 3, replace_chars
+Replace one or more characters. Requires the find and replace parameters to be 
specified.
+Both need to be equal in length.
+The first char in find is replaced by the first char in replace, same for all 
subsequent chars.
+@item 4, remove_chars
+Remove certain characters. Requires the find parameter to be specified.
+All chars in the find parameter string will be removed from all subtitle text.
+@item 5, replace_words
+Replace one or more words. Requires the find and replace parameters to be 
specified. Multiple words must be separated by the delimiter char specified vie 
the separator parameter (default: ',').
+The number of words in the find and replace parameters needs to be equal.
+The first word in find is replaced by the first word in replace, same for all 
subsequent words
+@item 6, remove_words
+Remove certain words. Requires the find parameter to be specified. Multiple 
words must be separated by the delimiter char specified vie the separator 
parameter (default: ',').
+All words in the find parameter string will be removed from all subtitle text.
+@end table
+
+@item find
+Required for replace_chars, remove_chars, replace_words and remove_words.
+
+@item find_file
+Specify a file from which to load the contents for the 'find' parameter.
+
+@item replace
+Required for replace_chars and replace_words.
+
+@item replace_file
+Specify a file from which to load the contents for the 'replace' parameter.
+
+@item separator
+Delimiter character for words. Used with replace_words and remove_words- Must 
be a single character.
+The default is '.'.
+
+@end table
+
+@subsection Examples
+
+@itemize
+@item
+Change all characters to upper case while keeping all styles and animations:
+@example
+ffmpeg -i "https://streams.videolan.org/ffmpeg/mkv_subtitles.mkv"; 
-filter_complex "[0:s]textmod=mode=to_upper" -map 0 -y out.mkv
+@end example
+@item
+Remove a set of symbol characters for am i

[FFmpeg-devel] [PATCH v2 09/26] avfilter/avfilter: Handle subtitle frames

2022-01-19 Thread ffmpegagent
From: softworkz 

Signed-off-by: softworkz 
---
 libavfilter/avfilter.c  |  8 +---
 libavfilter/avfilter.h  | 11 +++
 libavfilter/avfiltergraph.c |  5 +
 libavfilter/formats.c   | 22 ++
 libavfilter/formats.h   |  3 +++
 libavfilter/internal.h  | 18 +++---
 6 files changed, 61 insertions(+), 6 deletions(-)

diff --git a/libavfilter/avfilter.c b/libavfilter/avfilter.c
index df5b8f483c..75d5e86539 100644
--- a/libavfilter/avfilter.c
+++ b/libavfilter/avfilter.c
@@ -56,7 +56,8 @@ static void tlog_ref(void *ctx, AVFrame *ref, int end)
 ref->linesize[0], ref->linesize[1], ref->linesize[2], 
ref->linesize[3],
 ref->pts, ref->pkt_pos);
 
-if (ref->width) {
+switch(ref->type) {
+case AVMEDIA_TYPE_VIDEO:
 ff_tlog(ctx, " a:%d/%d s:%dx%d i:%c iskey:%d type:%c",
 ref->sample_aspect_ratio.num, ref->sample_aspect_ratio.den,
 ref->width, ref->height,
@@ -64,12 +65,13 @@ static void tlog_ref(void *ctx, AVFrame *ref, int end)
 ref->top_field_first ? 'T' : 'B',/* Top / Bottom */
 ref->key_frame,
 av_get_picture_type_char(ref->pict_type));
-}
-if (ref->nb_samples) {
+break;
+case AVMEDIA_TYPE_AUDIO:
 ff_tlog(ctx, " cl:%"PRId64"d n:%d r:%d",
 ref->channel_layout,
 ref->nb_samples,
 ref->sample_rate);
+break;
 }
 
 ff_tlog(ctx, "]%s", end ? "\n" : "");
diff --git a/libavfilter/avfilter.h b/libavfilter/avfilter.h
index b105dc3159..9f917deb41 100644
--- a/libavfilter/avfilter.h
+++ b/libavfilter/avfilter.h
@@ -45,6 +45,7 @@
 #include "libavutil/log.h"
 #include "libavutil/samplefmt.h"
 #include "libavutil/pixfmt.h"
+#include "libavutil/subfmt.h"
 #include "libavutil/rational.h"
 
 #include "libavfilter/version.h"
@@ -343,6 +344,12 @@ typedef struct AVFilter {
  * and outputs use the same sample rate and channel count/layout.
  */
 const enum AVSampleFormat *samples_list;
+/**
+ * Analogous to pixels, but delimited by AV_SUBTITLE_FMT_NONE
+ * and restricted to filters that only have AVMEDIA_TYPE_SUBTITLE
+ * inputs and outputs.
+ */
+const enum AVSubtitleType *subs_list;
 /**
  * Equivalent to { pix_fmt, AV_PIX_FMT_NONE } as pixels_list.
  */
@@ -351,6 +358,10 @@ typedef struct AVFilter {
  * Equivalent to { sample_fmt, AV_SAMPLE_FMT_NONE } as samples_list.
  */
 enum AVSampleFormat sample_fmt;
+/**
+ * Equivalent to { sub_fmt, AV_SUBTITLE_FMT_NONE } as subs_list.
+ */
+enum AVSubtitleType sub_fmt;
 } formats;
 
 int priv_size;  ///< size of private data to allocate for the filter
diff --git a/libavfilter/avfiltergraph.c b/libavfilter/avfiltergraph.c
index b8b432e98b..f4987654af 100644
--- a/libavfilter/avfiltergraph.c
+++ b/libavfilter/avfiltergraph.c
@@ -311,6 +311,8 @@ static int filter_link_check_formats(void *log, 
AVFilterLink *link, AVFilterForm
 return ret;
 break;
 
+case AVMEDIA_TYPE_SUBTITLE:
+return 0;
 default:
 av_assert0(!"reached");
 }
@@ -441,6 +443,9 @@ static int query_formats(AVFilterGraph *graph, void 
*log_ctx)
 if (!link)
 continue;
 
+if (link->type == AVMEDIA_TYPE_SUBTITLE)
+continue;
+
 neg = ff_filter_get_negotiation(link);
 av_assert0(neg);
 for (neg_step = 1; neg_step < neg->nb_mergers; neg_step++) {
diff --git a/libavfilter/formats.c b/libavfilter/formats.c
index ba62f73248..5c972bb183 100644
--- a/libavfilter/formats.c
+++ b/libavfilter/formats.c
@@ -19,6 +19,7 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
+#include "libavutil/subfmt.h"
 #include "libavutil/avassert.h"
 #include "libavutil/channel_layout.h"
 #include "libavutil/common.h"
@@ -431,6 +432,12 @@ int ff_add_channel_layout(AVFilterChannelLayouts **l, 
uint64_t channel_layout)
 return 0;
 }
 
+int ff_add_subtitle_type(AVFilterFormats **avff, int64_t fmt)
+{
+ADD_FORMAT(avff, fmt, ff_formats_unref, int, formats, nb_formats);
+return 0;
+}
+
 AVFilterFormats *ff_make_formats_list_singleton(int fmt)
 {
 int fmts[2] = { fmt, -1 };
@@ -450,6 +457,13 @@ AVFilterFormats *ff_all_formats(enum AVMediaType type)
 return NULL;
 fmt++;
 }
+} else if (type == AVMEDIA_TYPE_SUBTITLE) {
+if (ff_add_subtitle_type(&ret, AV_SUBTITLE_FMT_BITMAP) < 0)
+return NULL;
+if (ff_add_subtitle_type(&ret, AV_SUBTITLE_FMT_ASS) < 0)
+return NULL;
+if (ff_add_subtitle_type(&ret, AV_SUBTITLE_FMT_TEXT) < 0)
+return NULL;
 }
 
 return ret;
@@ -724,6 +738,10 @@ int ff_default_query_formats(AVFilterContext *ctx)
 type= 

[FFmpeg-devel] [PATCH v2 13/26] avfilter/overlaytextsubs: Add overlaytextsubs and textsubs2video filters

2022-01-19 Thread ffmpegagent
From: softworkz 

- overlaytextsubs {VS -> V)
  Overlay text subtitles onto a video stream.

- textsubs2video {S -> V)
  Converts text subtitles to video frames

Signed-off-by: softworkz 
---
 configure|   2 +
 doc/filters.texi | 113 ++
 libavfilter/Makefile |   2 +
 libavfilter/allfilters.c |   4 +-
 libavfilter/vf_overlaytextsubs.c | 678 +++
 5 files changed, 798 insertions(+), 1 deletion(-)
 create mode 100644 libavfilter/vf_overlaytextsubs.c

diff --git a/configure b/configure
index 7c2931bd50..340a198fa6 100755
--- a/configure
+++ b/configure
@@ -3691,6 +3691,7 @@ overlay_opencl_filter_deps="opencl"
 overlay_qsv_filter_deps="libmfx"
 overlay_qsv_filter_select="qsvvpp"
 overlay_vulkan_filter_deps="vulkan spirv_compiler"
+overlaytextsubs_filter_deps="avcodec libass"
 owdenoise_filter_deps="gpl"
 pad_opencl_filter_deps="opencl"
 pan_filter_deps="swresample"
@@ -3735,6 +3736,7 @@ superequalizer_filter_deps="avcodec"
 superequalizer_filter_select="rdft"
 surround_filter_deps="avcodec"
 surround_filter_select="rdft"
+textsub2video_filter_deps="avcodec libass"
 tinterlace_filter_deps="gpl"
 tinterlace_merge_test_deps="tinterlace_filter"
 tinterlace_pad_test_deps="tinterlace_filter"
diff --git a/doc/filters.texi b/doc/filters.texi
index 4fc4a57dbb..51771f88e4 100644
--- a/doc/filters.texi
+++ b/doc/filters.texi
@@ -25829,6 +25829,119 @@ Overlay PGS subtitles
 ffmpeg -i 
"https://streams.videolan.org/samples/sub/PGS/Girl_With_The_Dragon_Tattoo_2%3A23%3A56.mkv";
 -filter_complex "[0:0][0:1]overlaygraphicsubs" output.mp4
 @end example
 @end itemize
+
+@section overlaytextsubs
+
+Overlay text subtitles onto a video stream.
+
+This filter supersedes the classic @ref{subtitles} filter opposed to which it 
does no longer require to open and access the source stream separately, which 
is often causing problems or doesn't even work for non-local or slow sources.
+
+Inputs:
+@itemize
+@item 0: Video [YUV420P, YUV422P, YUV444P, ARGB, RGBA, ABGR, BGRA, RGB24, 
BGR24]
+@item 1: Subtitles [TEXT]
+@end itemize
+
+Outputs:
+@itemize
+@item 0: Video (same as input)
+@end itemize
+
+It accepts the following parameters:
+
+@table @option
+
+@item alpha
+Process alpha channel, by default alpha channel is untouched.
+
+@item fonts_dir
+Set a directory path containing fonts that can be used by the filter.
+These fonts will be used in addition to whatever the font provider uses.
+
+@item default_font_path
+Path to a font file to be used as the default font.
+
+@item font_size
+Set the default font size.
+
+@item fontconfig_file
+Path to ASS fontconfig configuration file.
+
+@item force_style
+Override default style or script info parameters of the subtitles. It accepts a
+string containing ASS style format @code{KEY=VALUE} couples separated by ",".
+
+@item margin
+Set the rendering margin in pixels.
+
+@item render_latest_only
+For rendering, alway use the latest event only, which is covering the given 
point in time
+@end table
+
+@subsection Examples
+
+@itemize
+@item
+Overlay ASS subtitles with animations:
+@example
+ffmpeg -i 
"http://streams.videolan.org/samples/sub/SSA/subtitle_testing_complex.mkv"; 
-filter_complex "[0:v]overlaytextsubs" -map 0 -y out.mkv
+@end example
+@end itemize
+
+@section textsub2video
+
+Converts text subtitles to video frames.
+
+For overlaying text subtitles onto video frames it is recommended to use the 
overlay_textsubs filter.
+The textsub2video is useful for for creating transparent text-frames when 
overlay is done via hw acceleration
+
+Inputs:
+@itemize
+@item 0: Subtitles [TEXT]
+@end itemize
+
+Outputs:
+@itemize
+@item 0: Video [RGB32]
+@end itemize
+
+It accepts the following parameters:
+
+@table @option
+
+@item rate, r
+Set the framerate for updating overlay frames.
+Normally, overlay frames will only be updated each time when the subtitles to 
display are changing.
+In cases where subtitles include advanced features (like animation), this 
parameter determines the frequency by which the overlay frames should be 
updated.
+
+@item size, s
+Set the output frame size.
+Allows to override the size of output video frames.
+
+@item fonts_dir
+Set a directory path containing fonts that can be used by the filter.
+These fonts will be used in addition to whatever the font provider uses.
+
+@item default_font_path
+Path to a font file to be used as the default font.
+
+@item font_size
+Set the default font size.
+
+@item fontconfig_file
+Path to ASS fontconfig configuration file.
+
+@item force_style
+Override default style or script info parameters of the subtitles. It accepts a
+string containing ASS style format @code{KEY=VALUE} couples separated by ",".
+
+@item margin
+Set the rendering margin in pixels.
+
+@item render_latest_only
+For rendering, alway use the latest event only, which is covering the given 
point in time.
+@end table
+
 @c man end SUBTITLE FILTERS
 
 @chapter Multimedia Filters
d

[FFmpeg-devel] [PATCH v2 08/26] avfilter/subtitles: Add subtitles.c for subtitle frame allocation

2022-01-19 Thread ffmpegagent
From: softworkz 

Analog to avfilter/video.c and avfilter/audio.c

Signed-off-by: softworkz 
---
 libavfilter/Makefile|  1 +
 libavfilter/avfilter.c  |  4 +++
 libavfilter/internal.h  |  1 +
 libavfilter/subtitles.c | 63 +
 libavfilter/subtitles.h | 44 
 5 files changed, 113 insertions(+)
 create mode 100644 libavfilter/subtitles.c
 create mode 100644 libavfilter/subtitles.h

diff --git a/libavfilter/Makefile b/libavfilter/Makefile
index 1adbea75bd..283dd436cd 100644
--- a/libavfilter/Makefile
+++ b/libavfilter/Makefile
@@ -19,6 +19,7 @@ OBJS = allfilters.o   
  \
framequeue.o \
graphdump.o  \
graphparser.o\
+   subtitles.o  \
video.o  \
 
 OBJS-$(HAVE_THREADS) += pthread.o
diff --git a/libavfilter/avfilter.c b/libavfilter/avfilter.c
index 7362bcdab5..df5b8f483c 100644
--- a/libavfilter/avfilter.c
+++ b/libavfilter/avfilter.c
@@ -43,6 +43,7 @@
 #include "formats.h"
 #include "framepool.h"
 #include "internal.h"
+#include "subtitles.h"
 
 #include "libavutil/ffversion.h"
 const char av_filter_ffversion[] = "FFmpeg version " FFMPEG_VERSION;
@@ -1475,6 +1476,9 @@ int ff_inlink_make_frame_writable(AVFilterLink *link, 
AVFrame **rframe)
 case AVMEDIA_TYPE_AUDIO:
 out = ff_get_audio_buffer(link, frame->nb_samples);
 break;
+case AVMEDIA_TYPE_SUBTITLE:
+out = ff_get_subtitles_buffer(link, link->format);
+break;
 default:
 return AVERROR(EINVAL);
 }
diff --git a/libavfilter/internal.h b/libavfilter/internal.h
index 1099b82b4b..fc09ef574c 100644
--- a/libavfilter/internal.h
+++ b/libavfilter/internal.h
@@ -90,6 +90,7 @@ struct AVFilterPad {
 union {
 AVFrame *(*video)(AVFilterLink *link, int w, int h);
 AVFrame *(*audio)(AVFilterLink *link, int nb_samples);
+AVFrame *(*subtitle)(AVFilterLink *link, int format);
 } get_buffer;
 
 /**
diff --git a/libavfilter/subtitles.c b/libavfilter/subtitles.c
new file mode 100644
index 00..951bfd612c
--- /dev/null
+++ b/libavfilter/subtitles.c
@@ -0,0 +1,63 @@
+/*
+ * Copyright (c) 2021 softworkz
+ *
+ * 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
+ */
+
+#include "libavutil/common.h"
+
+#include "subtitles.h"
+#include "avfilter.h"
+#include "internal.h"
+
+
+AVFrame *ff_null_get_subtitles_buffer(AVFilterLink *link, int format)
+{
+return ff_get_subtitles_buffer(link->dst->outputs[0], format);
+}
+
+AVFrame *ff_default_get_subtitles_buffer(AVFilterLink *link, int format)
+{
+AVFrame *frame;
+
+frame = av_frame_alloc();
+if (!frame)
+return NULL;
+
+frame->format = format;
+frame->type = AVMEDIA_TYPE_SUBTITLE;
+
+if (av_frame_get_buffer2(frame, 0) < 0) {
+av_frame_free(&frame);
+return NULL;
+}
+
+return frame;
+}
+
+AVFrame *ff_get_subtitles_buffer(AVFilterLink *link, int format)
+{
+AVFrame *ret = NULL;
+
+if (link->dstpad->get_buffer.subtitle)
+ret = link->dstpad->get_buffer.subtitle(link, format);
+
+if (!ret)
+ret = ff_default_get_subtitles_buffer(link, format);
+
+return ret;
+}
diff --git a/libavfilter/subtitles.h b/libavfilter/subtitles.h
new file mode 100644
index 00..4a9115126e
--- /dev/null
+++ b/libavfilter/subtitles.h
@@ -0,0 +1,44 @@
+/*
+ * Copyright (c) 2021 softworkz
+ *
+ * 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

[FFmpeg-devel] [PATCH v2 12/26] avfilter/overlaygraphicsubs: Add overlaygraphicsubs and graphicsub2video filters

2022-01-19 Thread ffmpegagent
From: softworkz 

- overlaygraphicsubs (VS -> V)
  Overlay graphic subtitles onto a video stream

- graphicsub2video {S -> V)
  Converts graphic subtitles to video frames (with alpha)
  Gets auto-inserted for retaining compatibility with
  sub2video command lines

Signed-off-by: softworkz 
---
 doc/filters.texi| 118 +
 libavfilter/Makefile|   2 +
 libavfilter/allfilters.c|   2 +
 libavfilter/vf_overlaygraphicsubs.c | 765 
 4 files changed, 887 insertions(+)
 create mode 100644 libavfilter/vf_overlaygraphicsubs.c

diff --git a/doc/filters.texi b/doc/filters.texi
index 05d4b1a56e..4fc4a57dbb 100644
--- a/doc/filters.texi
+++ b/doc/filters.texi
@@ -25713,6 +25713,124 @@ tools.
 
 @c man end VIDEO SINKS
 
+@chapter Subtitle Filters
+@c man begin SUBTITLE FILTERS
+
+When you configure your FFmpeg build, you can disable any of the
+existing filters using @code{--disable-filters}.
+
+Below is a description of the currently available subtitle filters.
+
+@section graphicsub2video
+
+Renders graphic subtitles as video frames.
+
+This filter replaces the previous "sub2video" hack which did the conversion 
implicitly and up-front as subtitle filtering wasn't possible at that time.
+To retain compatibility with earlier sub2video command lines, this filter is 
being auto-inserted in those cases.
+
+For overlaying graphicsal subtitles it is recommended to use the 
'overlay_graphicsubs' filter which is more efficient and takes less processing 
resources.
+
+This filter is still useful in cases where the overlay is done with hardware 
acceleration (e.g. overlay_qsv, overlay_vaapi, overlay_cuda) for preparing the 
overlay frames.
+
+Inputs:
+@itemize
+@item 0: Subtitles [BITMAP]
+@end itemize
+
+Outputs:
+@itemize
+@item 0: Video [RGB32]
+@end itemize
+
+
+It accepts the following parameters:
+
+@table @option
+@item size, s
+Set the size of the output video frame.
+
+@end table
+
+@subsection Examples
+
+@itemize
+@item
+Overlay PGS subtitles
+(not recommended - better use overlay_graphicsubs)
+@example
+ffmpeg -i 
"https://streams.videolan.org/samples/sub/PGS/Girl_With_The_Dragon_Tattoo_2%3A23%3A56.mkv";
 -filter_complex "[0:1]graphicsub2video[subs];[0:0][subs]overlay" output.mp4
+@end example
+
+@item
+Overlay PGS subtitles implicitly
+The graphicsub2video is inserted automatically for compatibility with legacy 
command lines.
+@example
+ffmpeg -i 
"https://streams.videolan.org/samples/sub/PGS/Girl_With_The_Dragon_Tattoo_2%3A23%3A56.mkv";
 -filter_complex "[0:0][0:1]overlay" output.mp4
+@end example
+@end itemize
+
+@section overlaygraphicsubs
+
+Overlay graphic subtitles onto a video stream.
+
+This filter can blend graphical subtitles on a video stream directly, i.e. 
without creating full-size alpha images first.
+The blending operation is limited to the area of the subtitle rectangles, 
which also means that no processing is done at times where no subtitles are to 
be displayed.
+
+Inputs:
+@itemize
+@item 0: Video [YUV420P, YUV422P, YUV444P, ARGB, RGBA, ABGR, BGRA, RGB24, 
BGR24]
+@item 1: Subtitles [BITMAP]
+@end itemize
+
+Outputs:
+@itemize
+@item 0: Video (same as input)
+@end itemize
+
+It accepts the following parameters:
+
+@table @option
+@item x
+@item y
+Set the expression for the x and y coordinates of the overlaid video
+on the main video. Default value is "0" for both expressions. In case
+the expression is invalid, it is set to a huge value (meaning that the
+overlay will not be displayed within the output visible area).
+
+@item eof_action
+See @ref{framesync}.
+
+@item eval
+Set when the expressions for @option{x}, and @option{y} are evaluated.
+
+It accepts the following values:
+@table @samp
+@item init
+only evaluate expressions once during the filter initialization or
+when a command is processed
+
+@item frame
+evaluate expressions for each incoming frame
+@end table
+
+Default value is @samp{frame}.
+
+@item shortest
+See @ref{framesync}.
+
+@end table
+
+@subsection Examples
+
+@itemize
+@item
+Overlay PGS subtitles
+@example
+ffmpeg -i 
"https://streams.videolan.org/samples/sub/PGS/Girl_With_The_Dragon_Tattoo_2%3A23%3A56.mkv";
 -filter_complex "[0:0][0:1]overlaygraphicsubs" output.mp4
+@end example
+@end itemize
+@c man end SUBTITLE FILTERS
+
 @chapter Multimedia Filters
 @c man begin MULTIMEDIA FILTERS
 
diff --git a/libavfilter/Makefile b/libavfilter/Makefile
index 283dd436cd..a372effc12 100644
--- a/libavfilter/Makefile
+++ b/libavfilter/Makefile
@@ -298,6 +298,7 @@ OBJS-$(CONFIG_GBLUR_FILTER)  += vf_gblur.o
 OBJS-$(CONFIG_GBLUR_VULKAN_FILTER)   += vf_gblur_vulkan.o vulkan.o 
vulkan_filter.o
 OBJS-$(CONFIG_GEQ_FILTER)+= vf_geq.o
 OBJS-$(CONFIG_GRADFUN_FILTER)+= vf_gradfun.o
+OBJS-$(CONFIG_GRAPHICSUB2VIDEO_FILTER)   += vf_overlaygraphicsubs.o 
framesync.o
 OBJS-$(CONFIG_GRAPHMONITOR_FILTER)   += f_graphmonitor.o
 OBJS-$(CONFIG_GRAYWORLD_FIL

[FFmpeg-devel] [PATCH v2 07/26] fftools/play, probe: Adjust for subtitle changes

2022-01-19 Thread ffmpegagent
From: softworkz 

Signed-off-by: softworkz 
---
 fftools/ffplay.c  | 102 +-
 fftools/ffprobe.c |  47 +
 2 files changed, 77 insertions(+), 72 deletions(-)

diff --git a/fftools/ffplay.c b/fftools/ffplay.c
index e7b20be76b..94286eb678 100644
--- a/fftools/ffplay.c
+++ b/fftools/ffplay.c
@@ -152,7 +152,6 @@ typedef struct Clock {
 /* Common struct for handling all types of decoded data and allocated render 
buffers. */
 typedef struct Frame {
 AVFrame *frame;
-AVSubtitle sub;
 int serial;
 double pts;   /* presentation timestamp for the frame */
 double duration;  /* estimated duration of the frame */
@@ -586,7 +585,7 @@ static int decoder_init(Decoder *d, AVCodecContext *avctx, 
PacketQueue *queue, S
 return 0;
 }
 
-static int decoder_decode_frame(Decoder *d, AVFrame *frame, AVSubtitle *sub) {
+static int decoder_decode_frame(Decoder *d, AVFrame *frame) {
 int ret = AVERROR(EAGAIN);
 
 for (;;) {
@@ -620,6 +619,9 @@ static int decoder_decode_frame(Decoder *d, AVFrame *frame, 
AVSubtitle *sub) {
 }
 }
 break;
+case AVMEDIA_TYPE_SUBTITLE:
+ret = avcodec_receive_frame(d->avctx, frame);
+break;
 }
 if (ret == AVERROR_EOF) {
 d->finished = d->pkt_serial;
@@ -652,25 +654,11 @@ static int decoder_decode_frame(Decoder *d, AVFrame 
*frame, AVSubtitle *sub) {
 av_packet_unref(d->pkt);
 } while (1);
 
-if (d->avctx->codec_type == AVMEDIA_TYPE_SUBTITLE) {
-int got_frame = 0;
-ret = avcodec_decode_subtitle2(d->avctx, sub, &got_frame, d->pkt);
-if (ret < 0) {
-ret = AVERROR(EAGAIN);
-} else {
-if (got_frame && !d->pkt->data) {
-d->packet_pending = 1;
-}
-ret = got_frame ? 0 : (d->pkt->data ? AVERROR(EAGAIN) : 
AVERROR_EOF);
-}
-av_packet_unref(d->pkt);
+if (avcodec_send_packet(d->avctx, d->pkt) == AVERROR(EAGAIN)) {
+av_log(d->avctx, AV_LOG_ERROR, "Receive_frame and send_packet both 
returned EAGAIN, which is an API violation.\n");
+d->packet_pending = 1;
 } else {
-if (avcodec_send_packet(d->avctx, d->pkt) == AVERROR(EAGAIN)) {
-av_log(d->avctx, AV_LOG_ERROR, "Receive_frame and send_packet 
both returned EAGAIN, which is an API violation.\n");
-d->packet_pending = 1;
-} else {
-av_packet_unref(d->pkt);
-}
+av_packet_unref(d->pkt);
 }
 }
 }
@@ -683,7 +671,6 @@ static void decoder_destroy(Decoder *d) {
 static void frame_queue_unref_item(Frame *vp)
 {
 av_frame_unref(vp->frame);
-avsubtitle_free(&vp->sub);
 }
 
 static int frame_queue_init(FrameQueue *f, PacketQueue *pktq, int max_size, 
int keep_last)
@@ -981,7 +968,7 @@ static void video_image_display(VideoState *is)
 if (frame_queue_nb_remaining(&is->subpq) > 0) {
 sp = frame_queue_peek(&is->subpq);
 
-if (vp->pts >= sp->pts + ((float) sp->sub.start_display_time / 
1000)) {
+if (vp->pts >= sp->pts) {
 if (!sp->uploaded) {
 uint8_t* pixels[4];
 int pitch[4];
@@ -993,25 +980,27 @@ static void video_image_display(VideoState *is)
 if (realloc_texture(&is->sub_texture, 
SDL_PIXELFORMAT_ARGB, sp->width, sp->height, SDL_BLENDMODE_BLEND, 1) < 0)
 return;
 
-for (i = 0; i < sp->sub.num_rects; i++) {
-AVSubtitleRect *sub_rect = sp->sub.rects[i];
+for (i = 0; i < sp->frame->num_subtitle_areas; i++) {
+AVSubtitleArea *area = sp->frame->subtitle_areas[i];
+SDL_Rect sdl_rect = { .x = area->x, .y = area->y, .w = 
area->w, .h = area->h };
 
-sub_rect->x = av_clip(sub_rect->x, 0, sp->width );
-sub_rect->y = av_clip(sub_rect->y, 0, sp->height);
-sub_rect->w = av_clip(sub_rect->w, 0, sp->width  - 
sub_rect->x);
-sub_rect->h = av_clip(sub_rect->h, 0, sp->height - 
sub_rect->y);
+area->x = av_clip(area->x, 0, sp->width );
+area->y = av_clip(area->y, 0, sp->height);
+area->w = av_clip(area->w, 0, sp->width  - area->x);
+area->h = av_clip(area->h, 0, sp->height - area->y);
 
 is->sub_convert_ctx = 
sws_getCachedContext(is->sub_convert_ctx,
-sub_rect->w, sub_rect->h, AV_PIX_FMT_PAL8,
-sub_rect->w, sub_rect->h, AV_PIX_FMT_BGRA,
+  

[FFmpeg-devel] [PATCH v2 11/26] avfilter/sbuffer: Add sbuffersrc and sbuffersink filters

2022-01-19 Thread ffmpegagent
From: softworkz 

Signed-off-by: softworkz 
---
 configure|  2 +-
 libavfilter/allfilters.c |  2 ++
 libavfilter/buffersink.c | 54 ++
 libavfilter/buffersink.h |  7 
 libavfilter/buffersrc.c  | 72 
 libavfilter/buffersrc.h  |  1 +
 6 files changed, 137 insertions(+), 1 deletion(-)

diff --git a/configure b/configure
index 1413122d87..7c2931bd50 100755
--- a/configure
+++ b/configure
@@ -7854,7 +7854,7 @@ print_enabled_components(){
 fi
 done
 if [ "$name" = "filter_list" ]; then
-for c in asrc_abuffer vsrc_buffer asink_abuffer vsink_buffer; do
+for c in asrc_abuffer vsrc_buffer ssrc_sbuffer asink_abuffer 
vsink_buffer ssink_sbuffer; do
 printf "&ff_%s,\n" $c >> $TMPH
 done
 fi
diff --git a/libavfilter/allfilters.c b/libavfilter/allfilters.c
index 4325a3e557..8a3bd03924 100644
--- a/libavfilter/allfilters.c
+++ b/libavfilter/allfilters.c
@@ -556,8 +556,10 @@ extern const AVFilter ff_avsrc_movie;
  * being the same while having different 'types'). */
 extern  const AVFilter ff_asrc_abuffer;
 extern  const AVFilter ff_vsrc_buffer;
+extern  const AVFilter ff_ssrc_sbuffer;
 extern  const AVFilter ff_asink_abuffer;
 extern  const AVFilter ff_vsink_buffer;
+extern  const AVFilter ff_ssink_sbuffer;
 extern const AVFilter ff_af_afifo;
 extern const AVFilter ff_vf_fifo;
 
diff --git a/libavfilter/buffersink.c b/libavfilter/buffersink.c
index c0215669e7..0b268c2fa4 100644
--- a/libavfilter/buffersink.c
+++ b/libavfilter/buffersink.c
@@ -29,6 +29,8 @@
 #include "libavutil/internal.h"
 #include "libavutil/opt.h"
 
+#include "libavcodec/avcodec.h"
+
 #define FF_INTERNAL_FIELDS 1
 #include "framequeue.h"
 
@@ -57,6 +59,10 @@ typedef struct BufferSinkContext {
 int *sample_rates;  ///< list of accepted sample rates
 int sample_rates_size;
 
+/* only used for subtitles */
+enum AVSubtitleType *subtitle_types; ///< list of accepted subtitle 
types, must be terminated with -1
+int subtitle_types_size;
+
 AVFrame *peeked_frame;
 } BufferSinkContext;
 
@@ -305,6 +311,28 @@ static int asink_query_formats(AVFilterContext *ctx)
 return 0;
 }
 
+static int ssink_query_formats(AVFilterContext *ctx)
+{
+BufferSinkContext *buf = ctx->priv;
+AVFilterFormats *formats = NULL;
+unsigned i;
+int ret;
+
+CHECK_LIST_SIZE(subtitle_types)
+if (buf->subtitle_types_size) {
+for (i = 0; i < NB_ITEMS(buf->subtitle_types); i++)
+if ((ret = ff_add_subtitle_type(&formats, buf->subtitle_types[i])) 
< 0)
+return ret;
+if ((ret = ff_set_common_formats(ctx, formats)) < 0)
+return ret;
+} else {
+if ((ret = ff_default_query_formats(ctx)) < 0)
+return ret;
+}
+
+return 0;
+}
+
 #define OFFSET(x) offsetof(BufferSinkContext, x)
 #define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM
 static const AVOption buffersink_options[] = {
@@ -322,9 +350,16 @@ static const AVOption abuffersink_options[] = {
 { NULL },
 };
 #undef FLAGS
+#define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_SUBTITLE_PARAM
+static const AVOption sbuffersink_options[] = {
+{ "subtitle_types", "set the supported subtitle formats", 
OFFSET(subtitle_types), AV_OPT_TYPE_BINARY, .flags = FLAGS },
+{ NULL },
+};
+#undef FLAGS
 
 AVFILTER_DEFINE_CLASS(buffersink);
 AVFILTER_DEFINE_CLASS(abuffersink);
+AVFILTER_DEFINE_CLASS(sbuffersink);
 
 static const AVFilterPad avfilter_vsink_buffer_inputs[] = {
 {
@@ -363,3 +398,22 @@ const AVFilter ff_asink_abuffer = {
 .outputs   = NULL,
 FILTER_QUERY_FUNC(asink_query_formats),
 };
+
+static const AVFilterPad avfilter_ssink_sbuffer_inputs[] = {
+{
+.name = "default",
+.type = AVMEDIA_TYPE_SUBTITLE,
+},
+};
+
+const AVFilter ff_ssink_sbuffer = {
+.name  = "sbuffersink",
+.description   = NULL_IF_CONFIG_SMALL("Buffer subtitle frames, and make 
them available to the end of the filter graph."),
+.priv_class= &sbuffersink_class,
+.priv_size = sizeof(BufferSinkContext),
+.init  = common_init,
+.activate  = activate,
+FILTER_INPUTS(avfilter_ssink_sbuffer_inputs),
+.outputs   = NULL,
+FILTER_QUERY_FUNC(ssink_query_formats),
+};
diff --git a/libavfilter/buffersink.h b/libavfilter/buffersink.h
index 69ed0f29a8..11905abdc5 100644
--- a/libavfilter/buffersink.h
+++ b/libavfilter/buffersink.h
@@ -129,6 +129,13 @@ typedef struct AVABufferSinkParams {
  */
 attribute_deprecated
 AVABufferSinkParams *av_abuffersink_params_alloc(void);
+
+/**
+ * Deprecated and unused struct to use for initializing an sbuffersink context.
+ */
+typedef struct AVSBufferSinkParams {
+const int *subtitle_type;
+} AVSBufferSinkParams;
 #endif
 
 /**
diff --git a/libavfilter/buffersrc.c b/libavfilter/buffersrc.c
index b0611872f1..d2362999a2 100644
--- a/liba

[FFmpeg-devel] [PATCH v2 05/26] avcodec, avutil: Move ass helper functions to avutil as avpriv_ and extend ass dialog parsing

2022-01-19 Thread ffmpegagent
From: softworkz 

Also add

- hard_space callback (for upcoming fix)
- extensible callback (for future extension)

Signed-off-by: softworkz 
---
 libavcodec/Makefile   |  56 +++
 libavcodec/ass.h  | 144 ++
 libavcodec/assdec.c   |   2 +-
 libavcodec/assenc.c   |   2 +-
 libavcodec/ccaption_dec.c |  19 +--
 libavcodec/jacosubdec.c   |   2 +-
 libavcodec/libaribb24.c   |   2 +-
 libavcodec/libzvbi-teletextdec.c  |  14 +-
 libavcodec/microdvddec.c  |   7 +-
 libavcodec/movtextdec.c   |   3 +-
 libavcodec/movtextenc.c   |  20 +--
 libavcodec/mpl2dec.c  |   2 +-
 libavcodec/realtextdec.c  |   2 +-
 libavcodec/samidec.c  |   2 +-
 libavcodec/srtdec.c   |   2 +-
 libavcodec/srtenc.c   |  16 +-
 libavcodec/subviewerdec.c |   2 +-
 libavcodec/textdec.c  |   4 +-
 libavcodec/ttmlenc.c  |  15 +-
 libavcodec/webvttdec.c|   2 +-
 libavcodec/webvttenc.c|  16 +-
 libavutil/Makefile|   2 +
 {libavcodec => libavutil}/ass.c   |  91 +--
 libavutil/ass_internal.h  | 135 
 {libavcodec => libavutil}/ass_split.c |  30 ++--
 .../ass_split_internal.h  |  32 ++--
 26 files changed, 355 insertions(+), 269 deletions(-)
 rename {libavcodec => libavutil}/ass.c (65%)
 create mode 100644 libavutil/ass_internal.h
 rename {libavcodec => libavutil}/ass_split.c (94%)
 rename libavcodec/ass_split.h => libavutil/ass_split_internal.h (86%)

diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index cfc70a3eaf..80bf8ff2d2 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -215,10 +215,10 @@ OBJS-$(CONFIG_APNG_DECODER)+= png.o pngdec.o 
pngdsp.o
 OBJS-$(CONFIG_APNG_ENCODER)+= png.o pngenc.o
 OBJS-$(CONFIG_ARBC_DECODER)+= arbc.o
 OBJS-$(CONFIG_ARGO_DECODER)+= argo.o
-OBJS-$(CONFIG_SSA_DECODER) += assdec.o ass.o
-OBJS-$(CONFIG_SSA_ENCODER) += assenc.o ass.o
-OBJS-$(CONFIG_ASS_DECODER) += assdec.o ass.o
-OBJS-$(CONFIG_ASS_ENCODER) += assenc.o ass.o
+OBJS-$(CONFIG_SSA_DECODER) += assdec.o
+OBJS-$(CONFIG_SSA_ENCODER) += assenc.o
+OBJS-$(CONFIG_ASS_DECODER) += assdec.o
+OBJS-$(CONFIG_ASS_ENCODER) += assenc.o
 OBJS-$(CONFIG_ASV1_DECODER)+= asvdec.o asv.o mpeg12data.o
 OBJS-$(CONFIG_ASV1_ENCODER)+= asvenc.o asv.o mpeg12data.o
 OBJS-$(CONFIG_ASV2_DECODER)+= asvdec.o asv.o mpeg12data.o
@@ -259,7 +259,7 @@ OBJS-$(CONFIG_BRENDER_PIX_DECODER) += brenderpix.o
 OBJS-$(CONFIG_C93_DECODER) += c93.o
 OBJS-$(CONFIG_CAVS_DECODER)+= cavs.o cavsdec.o cavsdsp.o \
   cavsdata.o
-OBJS-$(CONFIG_CCAPTION_DECODER)+= ccaption_dec.o ass.o
+OBJS-$(CONFIG_CCAPTION_DECODER)+= ccaption_dec.o
 OBJS-$(CONFIG_CDGRAPHICS_DECODER)  += cdgraphics.o
 OBJS-$(CONFIG_CDTOONS_DECODER) += cdtoons.o
 OBJS-$(CONFIG_CDXL_DECODER)+= cdxl.o
@@ -434,7 +434,7 @@ OBJS-$(CONFIG_INTERPLAY_ACM_DECODER)   += interplayacm.o
 OBJS-$(CONFIG_INTERPLAY_DPCM_DECODER)  += dpcm.o
 OBJS-$(CONFIG_INTERPLAY_VIDEO_DECODER) += interplayvideo.o
 OBJS-$(CONFIG_IPU_DECODER) += mpeg12dec.o mpeg12.o mpeg12data.o
-OBJS-$(CONFIG_JACOSUB_DECODER) += jacosubdec.o ass.o
+OBJS-$(CONFIG_JACOSUB_DECODER) += jacosubdec.o
 OBJS-$(CONFIG_JPEG2000_ENCODER)+= j2kenc.o mqcenc.o mqc.o jpeg2000.o \
   jpeg2000dwt.o
 OBJS-$(CONFIG_JPEG2000_DECODER)+= jpeg2000dec.o jpeg2000.o 
jpeg2000dsp.o \
@@ -456,7 +456,7 @@ OBJS-$(CONFIG_MAGICYUV_ENCODER)+= magicyuvenc.o
 OBJS-$(CONFIG_MDEC_DECODER)+= mdec.o mpeg12.o mpeg12data.o
 OBJS-$(CONFIG_METASOUND_DECODER)   += metasound.o metasound_data.o \
   twinvq.o
-OBJS-$(CONFIG_MICRODVD_DECODER)+= microdvddec.o ass.o
+OBJS-$(CONFIG_MICRODVD_DECODER)+= microdvddec.o
 OBJS-$(CONFIG_MIMIC_DECODER)   += mimic.o
 OBJS-$(CONFIG_MJPEG_DECODER)   += mjpegdec.o mjpegdec_common.o
 OBJS-$(CONFIG_MJPEG_QSV_DECODER)   += qsvdec.o
@@ -471,8 +471,8 @@ OBJS-$(CONFIG_MLP_ENCODER) += mlpenc.o mlp.o
 OBJS-$(CONFIG_MMVIDEO_DECODER) += mmvideo.o
 OBJS-$(CONFIG_MOBICLIP_DECODER)+= mobiclip.o
 OBJS-$(CONFIG_MOTIONPIXELS_DECODER)+= motionpixels.o
-OBJS-$(CONFIG_MOVTEXT_DECODER) += movtextdec.o ass.o
-OBJS-$(CONFIG_MOVTEXT_ENCOD

[FFmpeg-devel] [PATCH v2 06/26] avcodec/subtitles: Replace deprecated enum values

2022-01-19 Thread ffmpegagent
From: softworkz 

Signed-off-by: softworkz 
---
 libavcodec/ass.h   | 2 +-
 libavcodec/assdec.c| 2 +-
 libavcodec/dvbsubdec.c | 2 +-
 libavcodec/dvdsubdec.c | 2 +-
 libavcodec/dvdsubenc.c | 2 +-
 libavcodec/pgssubdec.c | 2 +-
 libavcodec/xsubdec.c   | 2 +-
 7 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/libavcodec/ass.h b/libavcodec/ass.h
index 8bc13d7ab8..43c5ad651a 100644
--- a/libavcodec/ass.h
+++ b/libavcodec/ass.h
@@ -83,7 +83,7 @@ static inline int avpriv_ass_add_rect(AVSubtitle *sub, const 
char *dialog,
 rects[sub->num_rects]   = av_mallocz(sizeof(*rects[0]));
 if (!rects[sub->num_rects])
 return AVERROR(ENOMEM);
-rects[sub->num_rects]->type = SUBTITLE_ASS;
+rects[sub->num_rects]->type = AV_SUBTITLE_FMT_ASS;
 ass_str = avpriv_ass_get_dialog(readorder, layer, style, speaker, dialog);
 if (!ass_str)
 return AVERROR(ENOMEM);
diff --git a/libavcodec/assdec.c b/libavcodec/assdec.c
index 7802a44e71..fd321e7004 100644
--- a/libavcodec/assdec.c
+++ b/libavcodec/assdec.c
@@ -54,7 +54,7 @@ static int ass_decode_frame(AVCodecContext *avctx, void 
*data, int *got_sub_ptr,
 if (!sub->rects[0])
 return AVERROR(ENOMEM);
 sub->num_rects = 1;
-sub->rects[0]->type = SUBTITLE_ASS;
+sub->rects[0]->type = AV_SUBTITLE_FMT_ASS;
 sub->rects[0]->ass  = av_strdup(avpkt->data);
 if (!sub->rects[0]->ass)
 return AVERROR(ENOMEM);
diff --git a/libavcodec/dvbsubdec.c b/libavcodec/dvbsubdec.c
index bc741a1de6..0d64c6e71c 100644
--- a/libavcodec/dvbsubdec.c
+++ b/libavcodec/dvbsubdec.c
@@ -795,7 +795,7 @@ static int save_subtitle_set(AVCodecContext *avctx, 
AVSubtitle *sub, int *got_ou
 rect->w = region->width;
 rect->h = region->height;
 rect->nb_colors = (1 << region->depth);
-rect->type  = SUBTITLE_BITMAP;
+rect->type  = AV_SUBTITLE_FMT_BITMAP;
 rect->linesize[0] = region->width;
 
 clut = get_clut(ctx, region->clut);
diff --git a/libavcodec/dvdsubdec.c b/libavcodec/dvdsubdec.c
index 52259f0730..b39b3d1838 100644
--- a/libavcodec/dvdsubdec.c
+++ b/libavcodec/dvdsubdec.c
@@ -406,7 +406,7 @@ static int decode_dvd_subtitles(DVDSubContext *ctx, 
AVSubtitle *sub_header,
 sub_header->rects[0]->y = y1;
 sub_header->rects[0]->w = w;
 sub_header->rects[0]->h = h;
-sub_header->rects[0]->type = SUBTITLE_BITMAP;
+sub_header->rects[0]->type = AV_SUBTITLE_FMT_BITMAP;
 sub_header->rects[0]->linesize[0] = w;
 sub_header->rects[0]->flags = is_menu ? 
AV_SUBTITLE_FLAG_FORCED : 0;
 }
diff --git a/libavcodec/dvdsubenc.c b/libavcodec/dvdsubenc.c
index ff4fbed39d..943a7466d9 100644
--- a/libavcodec/dvdsubenc.c
+++ b/libavcodec/dvdsubenc.c
@@ -268,7 +268,7 @@ static int encode_dvd_subtitles(AVCodecContext *avctx,
 if (rects == 0 || !h->rects)
 return AVERROR(EINVAL);
 for (i = 0; i < rects; i++)
-if (h->rects[i]->type != SUBTITLE_BITMAP) {
+if (h->rects[i]->type != AV_SUBTITLE_FMT_BITMAP) {
 av_log(avctx, AV_LOG_ERROR, "Bitmap subtitle required\n");
 return AVERROR(EINVAL);
 }
diff --git a/libavcodec/pgssubdec.c b/libavcodec/pgssubdec.c
index bdd20c914b..22b6616f9b 100644
--- a/libavcodec/pgssubdec.c
+++ b/libavcodec/pgssubdec.c
@@ -535,7 +535,7 @@ static int display_end_segment(AVCodecContext *avctx, void 
*data,
 if (!rect)
 return AVERROR(ENOMEM);
 sub->rects[sub->num_rects++] = rect;
-rect->type = SUBTITLE_BITMAP;
+rect->type = AV_SUBTITLE_FMT_BITMAP;
 
 /* Process bitmap */
 object = find_object(ctx->presentation.objects[i].id, &ctx->objects);
diff --git a/libavcodec/xsubdec.c b/libavcodec/xsubdec.c
index 85cd7d1c20..a4be18a1d8 100644
--- a/libavcodec/xsubdec.c
+++ b/libavcodec/xsubdec.c
@@ -107,7 +107,7 @@ static int decode_frame(AVCodecContext *avctx, void *data, 
int *got_sub_ptr,
 sub->num_rects = 1;
 rect->x = x; rect->y = y;
 rect->w = w; rect->h = h;
-rect->type = SUBTITLE_BITMAP;
+rect->type = AV_SUBTITLE_FMT_BITMAP;
 rect->linesize[0] = w;
 rect->data[0] = av_malloc(w * h);
 rect->nb_colors = 4;
-- 
ffmpeg-codebot

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH v2 10/26] avfilter/avfilter: Fix hardcoded input index

2022-01-19 Thread ffmpegagent
From: softworkz 

This fix targets (rare) cases where multiple input pads have a
.filter_frame function. ff_request_frame_to_filter needs
to call ff_request_frame with the correct input pad
instead of the hardcoded first one.

Signed-off-by: softworkz 
---
 libavfilter/avfilter.c | 18 +-
 1 file changed, 13 insertions(+), 5 deletions(-)

diff --git a/libavfilter/avfilter.c b/libavfilter/avfilter.c
index 75d5e86539..aa9aa71f53 100644
--- a/libavfilter/avfilter.c
+++ b/libavfilter/avfilter.c
@@ -463,7 +463,7 @@ static int64_t guess_status_pts(AVFilterContext *ctx, int 
status, AVRational lin
 return AV_NOPTS_VALUE;
 }
 
-static int ff_request_frame_to_filter(AVFilterLink *link)
+static int ff_request_frame_to_filter(AVFilterLink *link, int input_index)
 {
 int ret = -1;
 
@@ -472,8 +472,8 @@ static int ff_request_frame_to_filter(AVFilterLink *link)
 link->frame_blocked_in = 1;
 if (link->srcpad->request_frame)
 ret = link->srcpad->request_frame(link);
-else if (link->src->inputs[0])
-ret = ff_request_frame(link->src->inputs[0]);
+else if (link->src->inputs[input_index])
+ret = ff_request_frame(link->src->inputs[input_index]);
 if (ret < 0) {
 if (ret != AVERROR(EAGAIN) && ret != link->status_in)
 ff_avfilter_link_set_in_status(link, ret, 
guess_status_pts(link->src, ret, link->time_base));
@@ -1172,6 +1172,14 @@ static int forward_status_change(AVFilterContext 
*filter, AVFilterLink *in)
 {
 unsigned out = 0, progress = 0;
 int ret;
+int input_index = 0;
+
+for (int i = 0; i < in->dst->nb_inputs; i++) {
+if (&in->dst->input_pads[i] == in->dstpad) {
+input_index = i;
+break;
+}
+}
 
 av_assert0(!in->status_out);
 if (!filter->nb_outputs) {
@@ -1181,7 +1189,7 @@ static int forward_status_change(AVFilterContext *filter, 
AVFilterLink *in)
 while (!in->status_out) {
 if (!filter->outputs[out]->status_in) {
 progress++;
-ret = ff_request_frame_to_filter(filter->outputs[out]);
+ret = ff_request_frame_to_filter(filter->outputs[out], 
input_index);
 if (ret < 0)
 return ret;
 }
@@ -1218,7 +1226,7 @@ static int ff_filter_activate_default(AVFilterContext 
*filter)
 for (i = 0; i < filter->nb_outputs; i++) {
 if (filter->outputs[i]->frame_wanted_out &&
 !filter->outputs[i]->frame_blocked_in) {
-return ff_request_frame_to_filter(filter->outputs[i]);
+return ff_request_frame_to_filter(filter->outputs[i], 0);
 }
 }
 return FFERROR_NOT_READY;
-- 
ffmpeg-codebot

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH v2 04/26] avfilter/subtitles: Update vf_subtitles to use new decoding api

2022-01-19 Thread ffmpegagent
From: softworkz 

Signed-off-by: softworkz 
---
 libavfilter/vf_subtitles.c | 56 +-
 1 file changed, 43 insertions(+), 13 deletions(-)

diff --git a/libavfilter/vf_subtitles.c b/libavfilter/vf_subtitles.c
index 3fc4eeb63d..25e217e845 100644
--- a/libavfilter/vf_subtitles.c
+++ b/libavfilter/vf_subtitles.c
@@ -35,14 +35,12 @@
 # include "libavformat/avformat.h"
 #endif
 #include "libavutil/avstring.h"
-#include "libavutil/imgutils.h"
 #include "libavutil/opt.h"
 #include "libavutil/parseutils.h"
 #include "drawutils.h"
 #include "avfilter.h"
 #include "internal.h"
 #include "formats.h"
-#include "video.h"
 
 typedef struct AssContext {
 const AVClass *class;
@@ -292,6 +290,29 @@ static int attachment_is_font(AVStream * st)
 return 0;
 }
 
+static int decode(AVCodecContext *avctx, AVFrame *frame, int *got_frame, 
AVPacket *pkt)
+{
+int ret;
+
+*got_frame = 0;
+
+if (pkt) {
+ret = avcodec_send_packet(avctx, pkt);
+// In particular, we don't expect AVERROR(EAGAIN), because we read all
+// decoded frames with avcodec_receive_frame() until done.
+if (ret < 0 && ret != AVERROR_EOF)
+return ret;
+}
+
+ret = avcodec_receive_frame(avctx, frame);
+if (ret < 0 && ret != AVERROR(EAGAIN))
+return ret;
+if (ret >= 0)
+*got_frame = 1;
+
+return 0;
+}
+
 AVFILTER_DEFINE_CLASS(subtitles);
 
 static av_cold int init_subtitles(AVFilterContext *ctx)
@@ -306,6 +327,7 @@ static av_cold int init_subtitles(AVFilterContext *ctx)
 AVStream *st;
 AVPacket pkt;
 AssContext *ass = ctx->priv;
+enum AVSubtitleType subtitle_format;
 
 /* Init libass */
 ret = init(ctx);
@@ -386,13 +408,17 @@ static av_cold int init_subtitles(AVFilterContext *ctx)
 ret = AVERROR_DECODER_NOT_FOUND;
 goto end;
 }
+
 dec_desc = avcodec_descriptor_get(st->codecpar->codec_id);
-if (dec_desc && !(dec_desc->props & AV_CODEC_PROP_TEXT_SUB)) {
+subtitle_format = avcodec_descriptor_get_subtitle_format(dec_desc);
+
+if (subtitle_format != AV_SUBTITLE_FMT_ASS) {
 av_log(ctx, AV_LOG_ERROR,
-   "Only text based subtitles are currently supported\n");
-ret = AVERROR_PATCHWELCOME;
+   "Only text based subtitles are supported by this filter\n");
+ret = AVERROR_INVALIDDATA;
 goto end;
 }
+
 if (ass->charenc)
 av_dict_set(&codec_opts, "sub_charenc", ass->charenc, 0);
 
@@ -448,27 +474,31 @@ static av_cold int init_subtitles(AVFilterContext *ctx)
   dec_ctx->subtitle_header_size);
 while (av_read_frame(fmt, &pkt) >= 0) {
 int i, got_subtitle;
-AVSubtitle sub = {0};
+AVFrame *sub = av_frame_alloc();
+if (!sub) {
+ret = AVERROR(ENOMEM);
+goto end;
+}
 
 if (pkt.stream_index == sid) {
-ret = avcodec_decode_subtitle2(dec_ctx, &sub, &got_subtitle, &pkt);
+ret = decode(dec_ctx, sub, &got_subtitle, &pkt);
 if (ret < 0) {
 av_log(ctx, AV_LOG_WARNING, "Error decoding: %s (ignored)\n",
av_err2str(ret));
 } else if (got_subtitle) {
-const int64_t start_time = av_rescale_q(sub.pts, 
AV_TIME_BASE_Q, av_make_q(1, 1000));
-const int64_t duration   = sub.end_display_time;
-for (i = 0; i < sub.num_rects; i++) {
-char *ass_line = sub.rects[i]->ass;
+const int64_t start_time = 
av_rescale_q(sub->subtitle_timing.start_pts, AV_TIME_BASE_Q, av_make_q(1, 
1000));
+const int64_t duration   = 
av_rescale_q(sub->subtitle_timing.duration, AV_TIME_BASE_Q, av_make_q(1, 1000));
+for (i = 0; i < sub->num_subtitle_areas; i++) {
+char *ass_line = sub->subtitle_areas[i]->ass;
 if (!ass_line)
-break;
+continue;
 ass_process_chunk(ass->track, ass_line, strlen(ass_line),
   start_time, duration);
 }
 }
 }
 av_packet_unref(&pkt);
-avsubtitle_free(&sub);
+av_frame_free(&sub);
 }
 
 end:
-- 
ffmpeg-codebot

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH v2 03/26] avcodec/subtitles: Introduce new frame-based subtitle decoding API

2022-01-19 Thread ffmpegagent
From: softworkz 

- Modify avcodec_send_packet() to support subtitles via the regular
  frame based decoding API
- Add decode_subtitle_shim() which takes subtitle frames,
  and serves as a compatibility shim to the legacy subtitle decoding
  API until all subtitle decoders are migrated to the frame-based API
- Add additional methods for conversion between old and new API

Signed-off-by: softworkz 
---
 libavcodec/avcodec.h|   8 +-
 libavcodec/codec_desc.c |  11 +++
 libavcodec/codec_desc.h |   8 ++
 libavcodec/decode.c |  60 +++--
 libavcodec/internal.h   |  16 
 libavcodec/utils.c  | 184 
 6 files changed, 278 insertions(+), 9 deletions(-)

diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h
index fe5a83cf85..9d59f6e840 100644
--- a/libavcodec/avcodec.h
+++ b/libavcodec/avcodec.h
@@ -1675,7 +1675,7 @@ typedef struct AVCodecContext {
 
 /**
  * Header containing style information for text subtitles.
- * For SUBTITLE_ASS subtitle type, it should contain the whole ASS
+ * For AV_SUBTITLE_FMT_ASS subtitle type, it should contain the whole ASS
  * [Script Info] and [V4+ Styles] section, plus the [Events] line and
  * the Format line following. It shouldn't include any Dialogue line.
  * - encoding: Set/allocated/freed by user (before avcodec_open2())
@@ -2415,7 +2415,10 @@ int avcodec_close(AVCodecContext *avctx);
  * Free all allocated data in the given subtitle struct.
  *
  * @param sub AVSubtitle to free.
+ *
+ * @deprecated Use the regular frame based encode and decode APIs instead.
  */
+attribute_deprecated
 void avsubtitle_free(AVSubtitle *sub);
 
 /**
@@ -2508,7 +2511,10 @@ enum AVChromaLocation avcodec_chroma_pos_to_enum(int 
xpos, int ypos);
  * must be freed with avsubtitle_free if *got_sub_ptr is set.
  * @param[in,out] got_sub_ptr Zero if no subtitle could be decompressed, 
otherwise, it is nonzero.
  * @param[in] avpkt The input AVPacket containing the input buffer.
+ *
+ * @deprecated Use the new decode API (avcodec_send_packet, 
avcodec_receive_frame) instead.
  */
+attribute_deprecated
 int avcodec_decode_subtitle2(AVCodecContext *avctx, AVSubtitle *sub,
 int *got_sub_ptr,
 AVPacket *avpkt);
diff --git a/libavcodec/codec_desc.c b/libavcodec/codec_desc.c
index 0974ee03de..e48e4532ba 100644
--- a/libavcodec/codec_desc.c
+++ b/libavcodec/codec_desc.c
@@ -3548,3 +3548,14 @@ enum AVMediaType avcodec_get_type(enum AVCodecID 
codec_id)
 const AVCodecDescriptor *desc = avcodec_descriptor_get(codec_id);
 return desc ? desc->type : AVMEDIA_TYPE_UNKNOWN;
 }
+
+enum AVSubtitleType avcodec_descriptor_get_subtitle_format(const 
AVCodecDescriptor *codec_descriptor)
+{
+if(codec_descriptor->props & AV_CODEC_PROP_BITMAP_SUB)
+return AV_SUBTITLE_FMT_BITMAP;
+
+if(codec_descriptor->props & AV_CODEC_PROP_TEXT_SUB)
+return AV_SUBTITLE_FMT_ASS;
+
+return AV_SUBTITLE_FMT_UNKNOWN;
+}
diff --git a/libavcodec/codec_desc.h b/libavcodec/codec_desc.h
index 126b52df47..ba68d24e0e 100644
--- a/libavcodec/codec_desc.h
+++ b/libavcodec/codec_desc.h
@@ -121,6 +121,14 @@ const AVCodecDescriptor *avcodec_descriptor_next(const 
AVCodecDescriptor *prev);
  */
 const AVCodecDescriptor *avcodec_descriptor_get_by_name(const char *name);
 
+/**
+ * Return subtitle format from a codec descriptor
+ *
+ * @param codec_descriptor codec descriptor
+ * @return the subtitle type (e.g. bitmap, text)
+ */
+enum AVSubtitleType avcodec_descriptor_get_subtitle_format(const 
AVCodecDescriptor *codec_descriptor);
+
 /**
  * @}
  */
diff --git a/libavcodec/decode.c b/libavcodec/decode.c
index 0912f86a14..e3cf1cfa3d 100644
--- a/libavcodec/decode.c
+++ b/libavcodec/decode.c
@@ -576,6 +576,39 @@ static int decode_receive_frame_internal(AVCodecContext 
*avctx, AVFrame *frame)
 return ret;
 }
 
+static int decode_subtitle2_priv(AVCodecContext *avctx, AVSubtitle *sub,
+ int *got_sub_ptr, AVPacket *avpkt);
+
+static int decode_subtitle_shim(AVCodecContext *avctx, AVFrame *frame, 
AVPacket *avpkt)
+{
+int ret, got_sub_ptr = 0;
+AVSubtitle subtitle = { 0 };
+
+if (frame->buf[0])
+return AVERROR(EAGAIN);
+
+av_frame_unref(frame);
+
+ret = decode_subtitle2_priv(avctx, &subtitle, &got_sub_ptr, avpkt);
+
+if (ret >= 0 && got_sub_ptr) {
+frame->type = AVMEDIA_TYPE_SUBTITLE;
+frame->format = subtitle.format;
+ret = av_frame_get_buffer2(frame, 0);
+
+if (ret >= 0)
+ret = ff_frame_put_subtitle(frame, &subtitle);
+
+frame->width = avctx->width;
+frame->height = avctx->height;
+frame->pkt_dts = avpkt->dts;
+}
+
+avsubtitle_free(&subtitle);
+
+return ret;
+}
+
 int attribute_align_arg avcodec_send_packet(AVCodecContext *avctx, const 
AVPacket *avpkt)
 {
 AVCodecInternal *avci = avctx->internal;
@@ -59

[FFmpeg-devel] [PATCH v2 02/26] avutil/frame: Prepare AVFrame for subtitle handling

2022-01-19 Thread ffmpegagent
From: softworkz 

Root commit for adding subtitle filtering capabilities.
In detail:

- Add type (AVMediaType) field to AVFrame
  Replaces previous way of distinction which was based on checking
  width and height to determine whether a frame is audio or video
- Add subtitle fields to AVFrame
- Add new struct AVSubtitleArea, similar to AVSubtitleRect, but
  different allocation logic. Cannot and must not be used
  interchangeably, hence the new struct

Signed-off-by: softworkz 
---
 libavutil/Makefile |   1 +
 libavutil/frame.c  | 211 -
 libavutil/frame.h  |  85 +-
 libavutil/subfmt.c |  45 ++
 libavutil/subfmt.h |  47 ++
 5 files changed, 364 insertions(+), 25 deletions(-)
 create mode 100644 libavutil/subfmt.c

diff --git a/libavutil/Makefile b/libavutil/Makefile
index ce644f4d48..8bc0a14942 100644
--- a/libavutil/Makefile
+++ b/libavutil/Makefile
@@ -160,6 +160,7 @@ OBJS = adler32.o
\
slicethread.o\
spherical.o  \
stereo3d.o   \
+   subfmt.o \
threadmessage.o  \
time.o   \
timecode.o   \
diff --git a/libavutil/frame.c b/libavutil/frame.c
index 8997c85e35..2b95830b6f 100644
--- a/libavutil/frame.c
+++ b/libavutil/frame.c
@@ -26,6 +26,7 @@
 #include "imgutils.h"
 #include "mem.h"
 #include "samplefmt.h"
+#include "subfmt.h"
 #include "hwcontext.h"
 
 #define CHECK_CHANNELS_CONSISTENCY(frame) \
@@ -50,6 +51,9 @@ const char *av_get_colorspace_name(enum AVColorSpace val)
 return name[val];
 }
 #endif
+
+static int frame_copy_subtitles(AVFrame *dst, const AVFrame *src, int 
copy_data);
+
 static void get_frame_defaults(AVFrame *frame)
 {
 memset(frame, 0, sizeof(*frame));
@@ -70,7 +74,12 @@ static void get_frame_defaults(AVFrame *frame)
 frame->colorspace  = AVCOL_SPC_UNSPECIFIED;
 frame->color_range = AVCOL_RANGE_UNSPECIFIED;
 frame->chroma_location = AVCHROMA_LOC_UNSPECIFIED;
-frame->flags   = 0;
+frame->num_subtitle_areas  = 0;
+frame->subtitle_areas  = NULL;
+frame->subtitle_header = NULL;
+frame->repeat_sub  = 0;
+frame->subtitle_timing.start_pts = 0;
+frame->subtitle_timing.duration  = 0;
 }
 
 static void free_side_data(AVFrameSideData **ptr_sd)
@@ -240,23 +249,55 @@ static int get_audio_buffer(AVFrame *frame, int align)
 
 }
 
+static int get_subtitle_buffer(AVFrame *frame)
+{
+// Buffers in AVFrame->buf[] are not used in case of subtitle frames.
+// To accomodate with existing code, checking ->buf[0] to determine
+// whether a frame is ref-counted or has data, we're adding a 1-byte
+// buffer here, which marks the subtitle frame to contain data.
+frame->buf[0] = av_buffer_alloc(1);
+if (!frame->buf[0]) {
+av_frame_unref(frame);
+return AVERROR(ENOMEM);
+}
+
+frame->extended_data = frame->data;
+
+return 0;
+}
+
 int av_frame_get_buffer(AVFrame *frame, int align)
+{
+if (frame->width > 0 && frame->height > 0)
+frame->type = AVMEDIA_TYPE_VIDEO;
+else if (frame->nb_samples > 0 && (frame->channel_layout || 
frame->channels > 0))
+frame->type = AVMEDIA_TYPE_AUDIO;
+
+return av_frame_get_buffer2(frame, align);
+}
+
+int av_frame_get_buffer2(AVFrame *frame, int align)
 {
 if (frame->format < 0)
 return AVERROR(EINVAL);
 
-if (frame->width > 0 && frame->height > 0)
+switch(frame->type) {
+case AVMEDIA_TYPE_VIDEO:
 return get_video_buffer(frame, align);
-else if (frame->nb_samples > 0 && (frame->channel_layout || 
frame->channels > 0))
+case AVMEDIA_TYPE_AUDIO:
 return get_audio_buffer(frame, align);
-
-return AVERROR(EINVAL);
+case AVMEDIA_TYPE_SUBTITLE:
+return get_subtitle_buffer(frame);
+default:
+return AVERROR(EINVAL);
+}
 }
 
 static int frame_copy_props(AVFrame *dst, const AVFrame *src, int force_copy)
 {
 int ret, i;
 
+dst->type   = src->type;
 dst->key_frame  = src->key_frame;
 dst->pict_type  = src->pict_type;
 dst->sample_aspect_ratio= src->sample_aspect_ratio;
@@ -288,6 +329,12 @@ static int frame_copy_props(AVFrame *dst, const AVFrame 
*src, int force_copy)
 dst->colorspace = src->colorspace;
 dst->color_range= src->color_range;
 dst->chroma_location= src->chroma_location;
+dst->repeat_sub = src->repeat_sub;
+dst->subtitle_timing.start_pts = src->subtitle_timing.start_pts;
+  

[FFmpeg-devel] [PATCH v2 01/26] avcodec, avutil: Move enum AVSubtitleType to avutil, add new and deprecate old values

2022-01-19 Thread ffmpegagent
From: softworkz 

Signed-off-by: softworkz 
---
 libavcodec/avcodec.h | 19 +
 libavutil/Makefile   |  1 +
 libavutil/subfmt.h   | 68 
 libavutil/version.h  |  1 +
 4 files changed, 71 insertions(+), 18 deletions(-)
 create mode 100644 libavutil/subfmt.h

diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h
index ec1a0566a4..fe5a83cf85 100644
--- a/libavcodec/avcodec.h
+++ b/libavcodec/avcodec.h
@@ -35,6 +35,7 @@
 #include "libavutil/frame.h"
 #include "libavutil/log.h"
 #include "libavutil/pixfmt.h"
+#include "libavutil/subfmt.h"
 #include "libavutil/rational.h"
 
 #include "codec.h"
@@ -2238,24 +2239,6 @@ typedef struct AVHWAccel {
  * @}
  */
 
-enum AVSubtitleType {
-SUBTITLE_NONE,
-
-SUBTITLE_BITMAP,///< A bitmap, pict will be set
-
-/**
- * Plain text, the text field must be set by the decoder and is
- * authoritative. ass and pict fields may contain approximations.
- */
-SUBTITLE_TEXT,
-
-/**
- * Formatted text, the ass field must be set by the decoder and is
- * authoritative. pict and text fields may contain approximations.
- */
-SUBTITLE_ASS,
-};
-
 #define AV_SUBTITLE_FLAG_FORCED 0x0001
 
 typedef struct AVSubtitleRect {
diff --git a/libavutil/Makefile b/libavutil/Makefile
index d17876df1a..ce644f4d48 100644
--- a/libavutil/Makefile
+++ b/libavutil/Makefile
@@ -74,6 +74,7 @@ HEADERS = adler32.h   
  \
   sha512.h  \
   spherical.h   \
   stereo3d.h\
+  subfmt.h  \
   threadmessage.h   \
   time.h\
   timecode.h\
diff --git a/libavutil/subfmt.h b/libavutil/subfmt.h
new file mode 100644
index 00..791b45519f
--- /dev/null
+++ b/libavutil/subfmt.h
@@ -0,0 +1,68 @@
+/*
+ * Copyright (c) 2021 softworkz
+ *
+ * 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
+ */
+
+#ifndef AVUTIL_SUBFMT_H
+#define AVUTIL_SUBFMT_H
+
+#include "version.h"
+
+enum AVSubtitleType {
+
+/**
+ * Subtitle format unknown.
+ */
+AV_SUBTITLE_FMT_NONE = -1,
+
+/**
+ * Subtitle format unknown.
+ */
+AV_SUBTITLE_FMT_UNKNOWN = 0,
+#if FF_API_OLD_SUBTITLES
+SUBTITLE_NONE = 0,  ///< Deprecated, use AV_SUBTITLE_FMT_NONE 
instead.
+#endif
+
+/**
+ * Bitmap area in AVSubtitleRect.data, pixfmt AV_PIX_FMT_PAL8.
+ */
+AV_SUBTITLE_FMT_BITMAP = 1,
+#if FF_API_OLD_SUBTITLES
+SUBTITLE_BITMAP = 1,///< Deprecated, use AV_SUBTITLE_FMT_BITMAP 
instead.
+#endif
+
+/**
+ * Plain text in AVSubtitleRect.text.
+ */
+AV_SUBTITLE_FMT_TEXT = 2,
+#if FF_API_OLD_SUBTITLES
+SUBTITLE_TEXT = 2,  ///< Deprecated, use AV_SUBTITLE_FMT_TEXT 
instead.
+#endif
+
+/**
+ * Text Formatted as per ASS specification, contained AVSubtitleRect.ass.
+ */
+AV_SUBTITLE_FMT_ASS = 3,
+#if FF_API_OLD_SUBTITLES
+SUBTITLE_ASS = 3,   ///< Deprecated, use AV_SUBTITLE_FMT_ASS 
instead.
+#endif
+
+AV_SUBTITLE_FMT_NB, ///< number of subtitle formats, DO NOT USE 
THIS if you want to link with shared libav* because the number of formats might 
differ between versions.
+};
+
+#endif /* AVUTIL_SUBFMT_H */
diff --git a/libavutil/version.h b/libavutil/version.h
index 953aac9d94..5bf48f6304 100644
--- a/libavutil/version.h
+++ b/libavutil/version.h
@@ -110,6 +110,7 @@
 #define FF_API_COLORSPACE_NAME  (LIBAVUTIL_VERSION_MAJOR < 58)
 #define FF_API_AV_MALLOCZ_ARRAY (LIBAVUTIL_VERSION_MAJOR < 58)
 #define FF_API_FIFO_PEEK2   (LIBAVUTIL_VERSION_MAJOR < 58)
+#define FF_API_OLD_SUBTITLES(LIBAVUTIL_VERSION_MAJOR < 58)
 
 /**
  * @}
-- 
ffmpeg-codebot

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or ema

[FFmpeg-devel] [PATCH v2 00/26] Subtitle Filtering 2022

2022-01-19 Thread ffmpegagent


Subtitle Filtering 2022
===

This is a substantial update to the earlier subtitle filtering patch series.
A primary goal has been to address others' concerns as much as possible on
one side and to provide more clarity and control over the way things are
working. Clarity is is specifically important to allow for a better
understanding of the need for a subtitle start pts value that can be
different from the frame's pts value. This is done by refactoring the
subtitle timing fields in AVFrame, adding a frame field to indicate repeated
subtitle frames, and finally the full removal of the heartbeat
functionality, replaced by a new 'subfeed' filter that provides different
modes for arbitrating subtitle frames in a filter graph. Finally, each
subtitle filter's documentation has been amended by a section describing the
filter's timeline behavior (in v3 update).

The update also includes major improvements to graphicsub2text and lots of
other details.

Versioning is restarting at v1 due to the new submission procedure.


Changes in v2
=

 * added .gitattributes file to enforce binary diffs for the test refs that
   cannot be applied when being sent via e-mail
 * perform filter graph re-init due to subtitle "frame size" change only
   when the size was unknown before and not set via -canvas_size
 * overlaytextsubs: Make sure to request frames on the subtitle input
 * avfilter/splitcc: Start parsing cc data on key frames only
 * avcodec/webvttenc: Don't encode ass drawing codes and empty lines
 * stripstyles: fix mem leak
 * gs2t: improve color detection
 * gs2t: empty frames must not be skipped
 * subfeed: fix name
 * textmod: preserve margins
 * added .gitattributes file to enforce binary diffs for the test refs that
   cannot be applied when being sent via e-mail
 * perform filter graph re-init due to subtitle "frame size" change only
   when the size was unknown before and not set via -canvas_size
 * avcodec/dvbsubdec: Fix conditions for fallback to default resolution
 * Made changes suggested by Andreas
 * Fixed failing command line reported by Michael

Changes from previous version v24:


AVFrame
===

 * Removed sub_start_time The start time is now added to the subtitle
   start_pts during decoding The sub_end_time field is adjusted accordingly
 * Renamed sub_end_time to duration which it is effectively after removing
   the start_time
 * Added a sub-struct 'subtitle_timing' to av frame Contains subtitle_pts
   renamed to 'subtitle_timing.start_pts' and 'subtitle_timing.duration'
 * Change both fields to (fixed) time_base AV_TIMEBASE
 * add repeat_sub field provides a clear indication whether a subtitle frame
   is an actual subtitle event or a repeated subtitle frame in a filter
   graph


Heartbeat Removal
=

 * completely removed the earlier heartbeat implementation
 * filtering arbitration is now implemented in a new filter: 'subfeed'
 * subfeed will be auto-inserted for compatiblity with sub2video command
   lines
 * the new behavior is not exactly identical to the earlier behavior, but it
   basically allows to achieve the same results


New 'subfeed' Filter


 * a versatile filter for solving all kinds of problems with subtile frame
   flow in filter graphs
 * Can be inserted at any position in a graph
 * Auto-inserted for sub2video command lines (in repeat-mode)
 * Allows duration fixup delay input frames with unknown duration and infer
   duration from start of subsequent frame
 * Provides multiple modes of operation:
   * repeat mode (default) Queues input frames Outputs frames at a fixed
 (configurable) rate Either sends a matching input frame (repeatedly) or
 empty frames otherwise
   * scatter mode similar to repeat mode, but splits input frames by
 duration into small segments with same content
   * forward mode No fixed output rate Useful in combination with duration
 fixup or overlap fixup


ffmpeg Tool Changes
===

 * delay subtitle output stream initialization (like for audio and video)
   This is needed for example when a format header depends on having
   received an initial frame to derive certain header values from
 * decoding: set subtitle frame size from decoding context
 * re-init graph when subtitle size changes
 * always insert subscale filter for sub2video command lines (to ensure
   correct scaling)


Subtitle Encoding
=

 * ignore repeated frames for encoding based on repeat_sub field in AVFrame
 * support multi-area encoding for text subtitles Subtitle OCR can create
   multiple areas at different positions. Previously, the texts were always
   squashed into a single area ('subtitle rect'), which was not ideal.
   Multiple text areas are now generally supported:
   * ASS Encoder Changed to use the 'receive_packet' encoding API A single
 frame with multiple text areas will create multiple packets now
   * All other text subtitle encoders A newline is inserte

[FFmpeg-devel] [PATCH] avformat/hlsenc: Fix path handling on Windows

2022-01-14 Thread ffmpegagent
From: softworkz 

Signed-off-by: softworkz 
---
avformat/hlsenc: Fix path handling on Windows

Handling for DOS path separators was missing

Published-As: 
https://github.com/ffstaging/FFmpeg/releases/tag/pr-ffstaging-19%2Fsoftworkz%2Fsubmit_hlspath-v1
Fetch-It-Via: git fetch https://github.com/ffstaging/FFmpeg 
pr-ffstaging-19/softworkz/submit_hlspath-v1
Pull-Request: https://github.com/ffstaging/FFmpeg/pull/19

 libavformat/hlsenc.c | 4 
 1 file changed, 4 insertions(+)

diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c
index ef8973cea1..eff7f4212e 100644
--- a/libavformat/hlsenc.c
+++ b/libavformat/hlsenc.c
@@ -3028,6 +3028,10 @@ static int hls_init(AVFormatContext *s)
 }
 
 p = strrchr(vs->m3u8_name, '/');
+#if HAVE_DOS_PATHS
+p = FFMAX(p, strrchr(vs->m3u8_name, '\\'));
+#endif
+
 if (p) {
 char tmp = *(++p);
 *p = '\0';

base-commit: c936c319bd54f097cc1d75b1ee1c407d53215d71
-- 
ffmpeg-codebot
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH 24/24] doc/APIchanges: update for subtitle filtering changes

2022-01-13 Thread ffmpegagent
From: softworkz 

Signed-off-by: softworkz 
---
 doc/APIchanges   | 24 
 libavcodec/version.h |  2 +-
 libavutil/version.h  |  2 +-
 3 files changed, 26 insertions(+), 2 deletions(-)

diff --git a/doc/APIchanges b/doc/APIchanges
index 8df0364e4c..c8238fb008 100644
--- a/doc/APIchanges
+++ b/doc/APIchanges
@@ -14,6 +14,30 @@ libavutil: 2021-04-27
 
 API changes, most recent first:
 
+2021-12-05 - xx - lavc 59.15.100 - avcodec.h
+  Deprecate avcodec_encode_subtitle(), use regular encode api now
+
+2021-12-05 - xx - lavc 59.15.100 - codec_desc.h
+  Add avcodec_descriptor_get_subtitle_format()
+
+2021-12-05 - xx - lavc 59.15.100 - avcodec.h
+  Deprecate avsubtitle_free()
+  Deprecate avcodec_decode_subtitle2(), use regular decode api now
+
+2021-12-05 - xx - lavu 57.11.100 - frame.h
+  Add AVMediaType field to AVFrame
+  Add Fields for carrying subtitle data to AVFrame
+  (subtitle_areas, subtitle_header, subtitle_pts, start/end time, etc.)
+  Add av_frame_get_buffer2() and deprecate av_frame_get_buffer()
+
+2021-12-05 - xx - lavu 57.11.100 - subfmt.h
+  Add struct AVSubtitleArea (replaces AVSubtitle)
+  Add av_get_subtitle_fmt_name() and av_get_subtitle_fmt()
+
+2021-12-05 - xx - lavu 57.11.100 - subfmt.h
+  Add enum AVSubtitleType (moved from lavc), add new values, deprecate existing
+
+2021-11-xx - xx - lavfi 8.19.100 - avfilter.h
 2022-01-04 - 78dc21b123e - lavu 57.16.100 - frame.h
   Add AV_FRAME_DATA_DOVI_METADATA.
 
diff --git a/libavcodec/version.h b/libavcodec/version.h
index a46fb05f1a..b5867ad041 100644
--- a/libavcodec/version.h
+++ b/libavcodec/version.h
@@ -28,7 +28,7 @@
 #include "libavutil/version.h"
 
 #define LIBAVCODEC_VERSION_MAJOR  59
-#define LIBAVCODEC_VERSION_MINOR  20
+#define LIBAVCODEC_VERSION_MINOR  21
 #define LIBAVCODEC_VERSION_MICRO 100
 
 #define LIBAVCODEC_VERSION_INT  AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \
diff --git a/libavutil/version.h b/libavutil/version.h
index 5bf48f6304..168e24f410 100644
--- a/libavutil/version.h
+++ b/libavutil/version.h
@@ -79,7 +79,7 @@
  */
 
 #define LIBAVUTIL_VERSION_MAJOR  57
-#define LIBAVUTIL_VERSION_MINOR  18
+#define LIBAVUTIL_VERSION_MINOR  19
 #define LIBAVUTIL_VERSION_MICRO 100
 
 #define LIBAVUTIL_VERSION_INT   AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \
-- 
ffmpeg-codebot
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH 23/24] avcodec/webvttenc: convert hard-space tags to  

2022-01-13 Thread ffmpegagent
From: softworkz 

Signed-off-by: softworkz 
---
 libavcodec/webvttenc.c   |  6 ++
 tests/ref/fate/sub-webvttenc | 10 +-
 2 files changed, 11 insertions(+), 5 deletions(-)

diff --git a/libavcodec/webvttenc.c b/libavcodec/webvttenc.c
index c0436f5739..48945dcb8e 100644
--- a/libavcodec/webvttenc.c
+++ b/libavcodec/webvttenc.c
@@ -123,6 +123,11 @@ static void webvtt_new_line_cb(void *priv, int forced)
 webvtt_print(priv, "\n");
 }
 
+static void webvtt_hard_space_cb(void *priv)
+{
+webvtt_print(priv, " ");
+}
+
 static void webvtt_style_cb(void *priv, char style, int close)
 {
 if (style == 's') // strikethrough unsupported
@@ -147,6 +152,7 @@ static void webvtt_end_cb(void *priv)
 static const ASSCodesCallbacks webvtt_callbacks = {
 .text = webvtt_text_cb,
 .new_line = webvtt_new_line_cb,
+.hard_space   = webvtt_hard_space_cb,
 .style= webvtt_style_cb,
 .color= NULL,
 .font_name= NULL,
diff --git a/tests/ref/fate/sub-webvttenc b/tests/ref/fate/sub-webvttenc
index f4172dcc84..ee9de2859e 100644
--- a/tests/ref/fate/sub-webvttenc
+++ b/tests/ref/fate/sub-webvttenc
@@ -132,26 +132,26 @@ but show this: {normal text}
 \ N is a forced line break
 \ h is a hard space
 Normal spaces at the start and at the end of the line are trimmed while hard 
spaces are not trimmed.
-The line will never break automatically right before or after a hard space. :-D
+The line will never break automatically right before or after a hard space. :-D
 
 00:54.501 --> 00:56.500
 
- A (05 hard spaces followed by a letter)
+ A (05 hard spaces followed by a letter)
 A (Normal  spaces followed by a letter)
 A (No hard spaces followed by a letter)
 
 00:56.501 --> 00:58.500
- A (05 hard spaces followed by a letter)
+ A (05 hard spaces followed by a letter)
 A (Normal  spaces followed by a letter)
 A (No hard spaces followed by a letter)
 Show this: \TEST and this: \-)
 
 00:58.501 --> 01:00.500
 
-A letter followed by 05 hard spaces: A 
+A letter followed by 05 hard spaces: A 
 A letter followed by normal  spaces: A
 A letter followed by no hard spaces: A
-05 hard  spaces between letters: A A
+05 hard  spaces between letters: A A
 5 normal spaces between letters: A A
 
 ^--Forced line break
-- 
ffmpeg-codebot

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".


[FFmpeg-devel] [PATCH 22/24] avutil/ass_split: Add parsing of hard-space tags (\h)

2022-01-13 Thread ffmpegagent
From: softworkz 

The \h tag in ASS/SSA is indicating a non-breaking space. See
https://github.com/Aegisub/aegisite/blob/master/source/docs/3.2/
ASS_Tags.html.md

The ass_split implementation is used by almost all text subtitle
encoders and it didn't handle this tag. Interestingly, several
tests are testing for \h parsing and had incorrect reference data
for those tests.

The \h tag is specific to ASS and doesn't have any meaning outside
of ASS.
Still, the reference data for ttmlenc, textenc and webvttenc were
full of \h tags even though this tag doesn't have a meaning there.

Signed-off-by: softworkz 
---
 libavutil/ass_split.c|  7 +++
 tests/ref/fate/mov-mp4-ttml-dfxp |  8 
 tests/ref/fate/mov-mp4-ttml-stpp |  8 
 tests/ref/fate/sub-textenc   | 10 +-
 tests/ref/fate/sub-ttmlenc   |  8 
 tests/ref/fate/sub-webvttenc | 10 +-
 6 files changed, 29 insertions(+), 22 deletions(-)

diff --git a/libavutil/ass_split.c b/libavutil/ass_split.c
index c5963351fc..30512dfc74 100644
--- a/libavutil/ass_split.c
+++ b/libavutil/ass_split.c
@@ -484,6 +484,7 @@ int avpriv_ass_split_override_codes(const ASSCodesCallbacks 
*callbacks, void *pr
 while (buf && *buf) {
 if (text && callbacks->text &&
 (sscanf(buf, "\\%1[nN]", new_line) == 1 ||
+ sscanf(buf, "\\%1[hH]", new_line) == 1 ||
  !strncmp(buf, "{\\", 2))) {
 callbacks->text(priv, text, text_len);
 text = NULL;
@@ -492,6 +493,12 @@ int avpriv_ass_split_override_codes(const 
ASSCodesCallbacks *callbacks, void *pr
 if (callbacks->new_line)
 callbacks->new_line(priv, new_line[0] == 'N');
 buf += 2;
+} else if (sscanf(buf, "\\%1[hH]", new_line) == 1) {
+if (callbacks->hard_space)
+callbacks->hard_space(priv);
+else if (callbacks->text)
+callbacks->text(priv, " ", 1);
+buf += 2;
 } else if (!strncmp(buf, "{\\", 2)) {
 buf++;
 while (*buf == '\\') {
diff --git a/tests/ref/fate/mov-mp4-ttml-dfxp b/tests/ref/fate/mov-mp4-ttml-dfxp
index e24b5d618b..e565ffa1f6 100644
--- a/tests/ref/fate/mov-mp4-ttml-dfxp
+++ b/tests/ref/fate/mov-mp4-ttml-dfxp
@@ -1,9 +1,9 @@
-2e7e01c821c111466e7a2844826b7f6d *tests/data/fate/mov-mp4-ttml-dfxp.mp4
-8519 tests/data/fate/mov-mp4-ttml-dfxp.mp4
+658884e1b789e75c454b25bdf71283c9 *tests/data/fate/mov-mp4-ttml-dfxp.mp4
+8486 tests/data/fate/mov-mp4-ttml-dfxp.mp4
 #tb 0: 1/1000
 #media_type 0: data
 #codec_id 0: none
-0,  0,  0,68500, 7866, 0x456c36b7
+0,  0,  0,68500, 7833, 0x31b22193
 {
 "packets": [
 {
@@ -15,7 +15,7 @@
 "dts_time": "0.00",
 "duration": 68500,
 "duration_time": "68.50",
-"size": "7866",
+"size": "7833",
 "pos": "44",
 "flags": "K_"
 }
diff --git a/tests/ref/fate/mov-mp4-ttml-stpp b/tests/ref/fate/mov-mp4-ttml-stpp
index 77bd23b7bf..f25b5b2d28 100644
--- a/tests/ref/fate/mov-mp4-ttml-stpp
+++ b/tests/ref/fate/mov-mp4-ttml-stpp
@@ -1,9 +1,9 @@
-cbd2c7ff864a663b0d893deac5a0caec *tests/data/fate/mov-mp4-ttml-stpp.mp4
-8547 tests/data/fate/mov-mp4-ttml-stpp.mp4
+c9570de0ccebc858b0c662a7e449582c *tests/data/fate/mov-mp4-ttml-stpp.mp4
+8514 tests/data/fate/mov-mp4-ttml-stpp.mp4
 #tb 0: 1/1000
 #media_type 0: data
 #codec_id 0: none
-0,  0,  0,68500, 7866, 0x456c36b7
+0,  0,  0,68500, 7833, 0x31b22193
 {
 "packets": [
 {
@@ -15,7 +15,7 @@ cbd2c7ff864a663b0d893deac5a0caec 
*tests/data/fate/mov-mp4-ttml-stpp.mp4
 "dts_time": "0.00",
 "duration": 68500,
 "duration_time": "68.50",
-"size": "7866",
+"size": "7833",
 "pos": "44",
 "flags": "K_"
 }
diff --git a/tests/ref/fate/sub-textenc b/tests/ref/fate/sub-textenc
index 3ea56b38f0..910ca3d6e3 100644
--- a/tests/ref/fate/sub-textenc
+++ b/tests/ref/fate/sub-textenc
@@ -160,18 +160,18 @@ but show this: {normal text}
 \ N is a forced line break
 \ h is a hard space
 Normal spaces at the start and at the end of the line are trimmed while hard 
spaces are not trimmed.
-The\hline\hwill\hnever\hbreak\hautomatically\hright\hbefore\hor\hafter\ha\hhard\hspace.\h:-D
+The line will never break automatically right before or after a hard space. :-D
 
 31
 00:00:54,501 --> 00:00:56,500
 
-\h\h\h\h\hA (05 hard spaces followed by a letter)
+ A (05 hard spaces followed by a letter)
 A (Normal  spaces followed by a letter)
 A (No hard spaces followed by a letter)
 
 32
 00:00:56,501 --> 00:00:58,500
-\h\h\h\h\hA (05 hard spaces followed by a letter)
+ A (05 hard spaces followed by a letter)
 A (Normal  spaces followed by a letter)
 A (No hard spaces followed by a letter)
 Show this: \TEST and this: \-)
@@ -179,

[FFmpeg-devel] [PATCH 20/24] avfilter/subfeed: add subtitle feed filter

2022-01-13 Thread ffmpegagent
From: softworkz 

Signed-off-by: softworkz 
---
 libavfilter/Makefile |   1 +
 libavfilter/allfilters.c |   1 +
 libavfilter/sf_subfeed.c | 366 +++
 3 files changed, 368 insertions(+)
 create mode 100644 libavfilter/sf_subfeed.c

diff --git a/libavfilter/Makefile b/libavfilter/Makefile
index 0e3e48613e..5711c7770b 100644
--- a/libavfilter/Makefile
+++ b/libavfilter/Makefile
@@ -570,6 +570,7 @@ OBJS-$(CONFIG_TEXTMOD_FILTER)+= sf_textmod.o
 OBJS-$(CONFIG_SPLITCC_FILTER)+= sf_splitcc.o
 OBJS-$(CONFIG_STRIPSTYLES_FILTER)+= sf_stripstyles.o
 OBJS-$(CONFIG_SUBSCALE_FILTER)   += sf_subscale.o
+OBJS-$(CONFIG_SUBFEED_FILTER)+= sf_subfeed.o
 
 # multimedia filters
 OBJS-$(CONFIG_ABITSCOPE_FILTER)  += avf_abitscope.o
diff --git a/libavfilter/allfilters.c b/libavfilter/allfilters.c
index 8e4f2feca3..10b14b7b8e 100644
--- a/libavfilter/allfilters.c
+++ b/libavfilter/allfilters.c
@@ -553,6 +553,7 @@ extern const AVFilter ff_sf_showspeaker;
 extern const AVFilter ff_sf_splitcc;
 extern const AVFilter ff_sf_stripstyles;
 extern const AVFilter ff_sf_subscale;
+extern const AVFilter ff_sf_subfeed;
 extern const AVFilter ff_sf_textmod;
 extern const AVFilter ff_svf_graphicsub2video;
 extern const AVFilter ff_svf_textsub2video;
diff --git a/libavfilter/sf_subfeed.c b/libavfilter/sf_subfeed.c
new file mode 100644
index 00..8a7ac5528b
--- /dev/null
+++ b/libavfilter/sf_subfeed.c
@@ -0,0 +1,366 @@
+/*
+ * Copyright (c) 2021 softworkz
+ *
+ * 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
+ * subtitle filter for feeding subtitle frames into a filtergraph in a 
contiguous way
+ *
+ *
+ * also supports
+ *   - duration fixup
+ * delaying a subtitle event with unknown duration and infer duration from 
the
+ * start time of the subsequent subtitle
+ *   - scattering
+ * splitting a subtitle event with unknown duration into multiple ones with
+ * a short and fixed duration
+ *
+ */
+
+#include "filters.h"
+#include "libavutil/opt.h"
+#include "subtitles.h"
+#include "libavutil/avassert.h"
+
+enum SubFeedMode {
+FM_REPEAT,
+FM_SCATTER,
+FM_FORWARD,
+};
+
+typedef struct SubFeedContext {
+const AVClass *class;
+enum AVSubtitleType format;
+enum SubFeedMode mode;
+
+AVRational frame_rate;
+int fix_durations;
+int fix_overlap;
+
+int current_frame_isnew;
+int eof;
+int got_first_input;
+int need_frame;
+int64_t next_pts_offset;
+int64_t recent_subtitle_pts;
+
+int64_t counter;
+
+/**
+ * Queue of frames waiting to be filtered.
+ */
+FFFrameQueue fifo;
+
+} SubFeedContext;
+
+static int64_t ms_to_avtb(int64_t ms)
+{
+return av_rescale_q(ms, (AVRational){ 1, 1000 }, AV_TIME_BASE_Q);
+}
+
+static int64_t avtb_to_ms(int64_t avtb)
+{
+return av_rescale_q(avtb, AV_TIME_BASE_Q, (AVRational){ 1, 1000 });
+}
+
+static int init(AVFilterContext *ctx)
+{
+SubFeedContext *s = ctx->priv;
+
+ff_framequeue_init(&s->fifo, NULL);
+
+return 0;
+}
+
+static void uninit(AVFilterContext *ctx)
+{
+SubFeedContext *s = ctx->priv;
+ff_framequeue_free(&s->fifo);
+}
+
+static int config_input(AVFilterLink *link)
+{
+const subfeedContext *context = link->dst->priv;
+
+return 0;
+}
+
+static int query_formats(AVFilterContext *ctx)
+{
+AVFilterFormats *formats;
+AVFilterLink *inlink0 = ctx->inputs[0];
+AVFilterLink *outlink0 = ctx->outputs[0];
+static const enum AVSubtitleType subtitle_fmts[] = { 
AV_SUBTITLE_FMT_BITMAP, AV_SUBTITLE_FMT_ASS, AV_SUBTITLE_FMT_NB };
+int ret;
+
+formats = ff_make_format_list(subtitle_fmts);
+
+if ((ret = ff_formats_ref(formats, &inlink0->outcfg.formats)) < 0)
+return ret;
+
+if ((ret = ff_formats_ref(formats, &outlink0->incfg.formats)) < 0)
+return ret;
+
+return 0;
+}
+
+static int config_output(AVFilterLink *outlink)
+{
+SubFeedContext *s = outlink->src->priv;
+const AVFilterLink *inlink = outlink->src->inputs[0];
+
+outlink->time_base = AV_TIME_BASE_Q;
+outlink->format = inlink->format;
+outlink->w = inlink->w;
+outlink->h = inlink->h;
+
+if (s->mode == FM_FORWARD)
+

[FFmpeg-devel] [PATCH 19/24] avfilter/subscale: Add filter for scaling and/or re-arranging graphical subtitles

2022-01-13 Thread ffmpegagent
From: softworkz 

Signed-off-by: softworkz 
---
 configure |   1 +
 doc/filters.texi  | 164 +++
 libavfilter/Makefile  |   1 +
 libavfilter/allfilters.c  |   1 +
 libavfilter/sf_subscale.c | 884 ++
 5 files changed, 1051 insertions(+)
 create mode 100644 libavfilter/sf_subscale.c

diff --git a/configure b/configure
index ee7afffb05..a8b7ce8a26 100755
--- a/configure
+++ b/configure
@@ -3731,6 +3731,7 @@ sr_filter_deps="avformat swscale"
 sr_filter_select="dnn"
 stereo3d_filter_deps="gpl"
 splitcc_filter_deps="avcodec"
+subscale_filter_deps="swscale avcodec"
 subtitles_filter_deps="avformat avcodec libass"
 super2xsai_filter_deps="gpl"
 pixfmts_super2xsai_test_deps="super2xsai_filter"
diff --git a/doc/filters.texi b/doc/filters.texi
index 7bc02b9415..ee6e184882 100644
--- a/doc/filters.texi
+++ b/doc/filters.texi
@@ -26303,6 +26303,170 @@ Set the rendering margin in pixels.
 For rendering, alway use the latest event only, which is covering the given 
point in time.
 @end table
 
+@section subscale
+
+Provides high-quality scaling and rearranging functionality for graphical 
subtitles.
+
+The subscale filter provides multiple approaches for manipulating
+the size and position of graphical subtitle rectangles wich can
+be combined or used separately.
+Scaling is performed by converting the palettized subtitle bitmaps
+to RGBA and re-quantization to palette colors afterwards via elbg algorithm.
+
+The two major operations are 'scale' and 're-arrange' with the
+latter being separated as 'arrange_h' and 'arrange_v'.
+
+
+Inputs:
+- 0: Subtitles [bitmap]
+
+Outputs:
+- 0: Subtitles [bitmap]
+
+It accepts the following parameters:
+
+@table @option
+
+@item w, width
+Set the width of the output.
+Width and height in case of graphical subtitles are just indicating
+a virtual size for which the output (consisting of 0-n bitmap rectangles)
+is intended to be displayed on.
+
+@item h, height
+Set the height of the output.
+
+@item margin_h
+Sets a horizontal margin to be preserverved when using any
+of the arrange modes.
+
+@item margin_v
+Sets a vertical margin to be preserverved when using any
+of the arrange modes.
+
+@item force_original_aspect_ratio
+Enable decreasing or increasing output video width or height if necessary to
+keep the original aspect ratio. Possible values:
+
+@table @samp
+@item disable
+Scale the video as specified and disable this feature.
+
+@item decrease
+The output video dimensions will automatically be decreased if needed.
+
+@item increase
+The output video dimensions will automatically be increased if needed.
+
+@end table
+
+
+@item scale_mode
+Specifies how subtitle bitmaps should be scaled.
+The scale factor is determined by the the factor between input
+and output size.
+
+@table @samp
+@item none
+Do not apply any common scaling.
+
+@item uniform
+Uniformly scale all subtitle bitmaps including their positions.
+
+@item uniform_no_reposition
+Uniformly scale all subtitle bitmaps without changing positions.
+
+@end table
+
+
+@item arrange_h
+Specifies how subtitle bitmaps should be arranged horizontally.
+
+@item arrange_v
+Specifies how subtitle bitmaps should be arranged vertically.
+
+
+@table @samp
+@item none
+Do not rearrange subtitle bitmaps.
+
+@item margin_no_scale
+Move subtitle bitmaps to be positioned inside the specified
+margin (margin_h or margin_v) when possible and without scaling.
+
+@item margin_and_scale
+Move subtitle bitmaps to be positioned inside the specified
+margin (margin_h or margin_v) and scale in case it doesn't fit.
+
+@item snapalign_no_scale
+Categorize subtitle bitmap positions as one of left/center/right
+or top/bottom/middle based on original positioning and apply
+these alignments for the target positioning.
+No scaling will be applied.
+
+@item snapalign_and_scale
+Categorize subtitle bitmap positions as one of left/center/right
+or top/bottom/middle based on original positioning and apply
+these alignments for the target positioning.
+Bitmaps that do not fit inside the margins borders are
+scaled to fit.
+@end table
+
+@item eval
+Set evaluation mode for the expressions (@option{width}, @option{height}).
+
+It accepts the following values:
+@table @samp
+@item init
+Evaluate expressions only once during the filter initialization.
+
+@item frame
+Evaluate expressions for each incoming frame. This is way slower than the
+@samp{init} mode since it requires all the scalers to be re-computed, but it
+allows advanced dynamic expressions.
+@end table
+
+Default value is @samp{init}.
+
+
+@item num_colors
+Set the number of palette colors for output images.
+Choose the maximum (256) when further processing is done (e.g.
+overlaying on a video).
+When subtitles will be encoded as bitmap subtitles (e.g. dvbsub),
+a smaller number of palette colors (e.g. 4-16) might need to be used, depending
+on the target format and codec.
+
+@item bitmap_width_align
+@item bitmap_height_align
+Make s

  1   2   >