Re: [FFmpeg-devel] [PATCH 01/17] avcodec/svq3: Mark decoder as init-threadsafe

2022-02-16 Thread Andreas Rheinhardt
Andreas Rheinhardt:
> The only interesting thing done in SVQ3's init function
> is using zlib, but this is fine: https://zlib.net/zlib_faq.html#faq21
> 
> Signed-off-by: Andreas Rheinhardt 
> ---
>  libavcodec/svq3.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/libavcodec/svq3.c b/libavcodec/svq3.c
> index be95e222aa..da61617f4e 100644
> --- a/libavcodec/svq3.c
> +++ b/libavcodec/svq3.c
> @@ -1601,5 +1601,5 @@ const AVCodec ff_svq3_decoder = {
>AV_CODEC_CAP_DELAY,
>  .pix_fmts   = (const enum AVPixelFormat[]) { AV_PIX_FMT_YUVJ420P,
>   AV_PIX_FMT_NONE},
> -.caps_internal  = FF_CODEC_CAP_INIT_CLEANUP,
> +.caps_internal  = FF_CODEC_CAP_INIT_THREADSAFE | 
> FF_CODEC_CAP_INIT_CLEANUP,
>  };

Will apply the rest of this patchset tonight unless there are objections.

- Andreas
___
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 3/3] avformat/movenc: Add support for AVIF muxing

2022-02-16 Thread Vignesh Venkatasubramanian
Add an AVIF muxer by re-using the existing the mov/mp4 muxer.

AVIF Specifiation: https://aomediacodec.github.io/av1-avif

Sample usage for still image:
ffmpeg -i image.png -c:v libaom-av1 -avif-image 1 image.avif

Sample usage for animated AVIF image:
ffmpeg -i video.mp4 animated.avif

We can re-use any of the AV1 encoding options that will make
sense for image encoding (like bitrate, tiles, encoding speed,
etc).

The files generated by this muxer has been verified to be valid
AVIF files by the following:
1) Displays on Chrome (both still and animated images).
2) Displays on Firefox (only still images, firefox does not support
   animated AVIF yet).
3) Verfied to be valid by Compliance Warden:
   https://github.com/gpac/ComplianceWarden

Fixes the encoder/muxer part of Trac Ticket #7621

Signed-off-by: Vignesh Venkatasubramanian 
---
 configure|   1 +
 libavformat/allformats.c |   1 +
 libavformat/movenc.c | 300 +++
 libavformat/movenc.h |   5 +
 4 files changed, 283 insertions(+), 24 deletions(-)

diff --git a/configure b/configure
index 1535dc3c5b..87b380fe3a 100755
--- a/configure
+++ b/configure
@@ -3393,6 +3393,7 @@ asf_stream_muxer_select="asf_muxer"
 av1_demuxer_select="av1_frame_merge_bsf av1_parser"
 avi_demuxer_select="riffdec exif"
 avi_muxer_select="riffenc"
+avif_muxer_select="mov_muxer"
 caf_demuxer_select="iso_media"
 caf_muxer_select="iso_media"
 dash_muxer_select="mp4_muxer"
diff --git a/libavformat/allformats.c b/libavformat/allformats.c
index d066a7745b..400c17afbd 100644
--- a/libavformat/allformats.c
+++ b/libavformat/allformats.c
@@ -81,6 +81,7 @@ extern const AVOutputFormat ff_au_muxer;
 extern const AVInputFormat  ff_av1_demuxer;
 extern const AVInputFormat  ff_avi_demuxer;
 extern const AVOutputFormat ff_avi_muxer;
+extern const AVOutputFormat ff_avif_muxer;
 extern const AVInputFormat  ff_avisynth_demuxer;
 extern const AVOutputFormat ff_avm2_muxer;
 extern const AVInputFormat  ff_avr_demuxer;
diff --git a/libavformat/movenc.c b/libavformat/movenc.c
index 1a746a67fd..69b5f4bc76 100644
--- a/libavformat/movenc.c
+++ b/libavformat/movenc.c
@@ -1303,7 +1303,7 @@ static int mov_write_av1c_tag(AVIOContext *pb, MOVTrack 
*track)
 
 avio_wb32(pb, 0);
 ffio_wfourcc(pb, "av1C");
-ff_isom_write_av1c(pb, track->vos_data, track->vos_len, 1);
+ff_isom_write_av1c(pb, track->vos_data, track->vos_len, track->mode != 
MODE_AVIF);
 return update_size(pb, pos);
 }
 
@@ -2004,12 +2004,13 @@ static int mov_write_colr_tag(AVIOContext *pb, MOVTrack 
*track, int prefer_icc)
 }
 }
 
-/* We should only ever be called by MOV or MP4. */
-av_assert0(track->mode == MODE_MOV || track->mode == MODE_MP4);
+/* We should only ever be called for MOV, MP4 and AVIF. */
+av_assert0(track->mode == MODE_MOV || track->mode == MODE_MP4 ||
+   track->mode == MODE_AVIF);
 
 avio_wb32(pb, 0); /* size */
 ffio_wfourcc(pb, "colr");
-if (track->mode == MODE_MP4)
+if (track->mode == MODE_MP4 || track->mode == MODE_AVIF)
 ffio_wfourcc(pb, "nclx");
 else
 ffio_wfourcc(pb, "nclc");
@@ -2019,7 +2020,7 @@ static int mov_write_colr_tag(AVIOContext *pb, MOVTrack 
*track, int prefer_icc)
 avio_wb16(pb, track->par->color_primaries);
 avio_wb16(pb, track->par->color_trc);
 avio_wb16(pb, track->par->color_space);
-if (track->mode == MODE_MP4) {
+if (track->mode == MODE_MP4 || track->mode == MODE_AVIF) {
 int full_range = track->par->color_range == AVCOL_RANGE_JPEG;
 avio_w8(pb, full_range << 7);
 }
@@ -2103,6 +2104,8 @@ static void find_compressor(char * compressor_name, int 
len, MOVTrack *track)
 av_strlcatf(compressor_name, len, " %d%c", track->par->height, 
interlaced ? 'i' : 'p');
 
 av_strlcatf(compressor_name, len, "%d", rate * (interlaced + 1));
+} else if (track->par->codec_id == AV_CODEC_ID_AV1) {
+av_strlcatf(compressor_name, len, "libaom Encoder");
 }
 }
 
@@ -2123,6 +2126,8 @@ static int mov_write_video_tag(AVFormatContext *s, 
AVIOContext *pb, MOVMuxContex
 avio_wb32(pb, 0); /* size */
 if (mov->encryption_scheme != MOV_ENC_NONE) {
 ffio_wfourcc(pb, "encv");
+} else if (track->mode == MODE_AVIF) {
+ffio_wfourcc(pb, "av01");
 } else {
 avio_wl32(pb, track->tag); // store it byteswapped
 }
@@ -2239,7 +2244,7 @@ static int mov_write_video_tag(AVFormatContext *s, 
AVIOContext *pb, MOVMuxContex
 else
 av_log(mov->fc, AV_LOG_WARNING, "Not writing 'gama' atom. Format 
is not MOV.\n");
 }
-if (track->mode == MODE_MOV || track->mode == MODE_MP4) {
+if (track->mode == MODE_MOV || track->mode == MODE_MP4 || track->mode == 
MODE_AVIF) {
 int has_color_info = track->par->color_primaries != 
AVCOL_PRI_UNSPECIFIED &&
  track->par->color_trc != AVCOL_TRC_UNSPECIFIED &&
  

[FFmpeg-devel] [PATCH 2/3] avformat/av1: Add a parameter to av1c to omit seq header

2022-02-16 Thread Vignesh Venkatasubramanian
Add a parameter to omit seq header when generating the av1C atom.

For now, this does not change any behavior. This will be used by a
follow-up patch to add AVIF support.

Signed-off-by: Vignesh Venkatasubramanian 
---
 libavformat/av1.c | 7 +--
 libavformat/av1.h | 4 +++-
 libavformat/matroskaenc.c | 4 ++--
 libavformat/movenc.c  | 2 +-
 4 files changed, 11 insertions(+), 6 deletions(-)

diff --git a/libavformat/av1.c b/libavformat/av1.c
index 1fcfac2356..95ca7cc47f 100644
--- a/libavformat/av1.c
+++ b/libavformat/av1.c
@@ -361,7 +361,8 @@ int ff_av1_parse_seq_header(AV1SequenceParameters *seq, 
const uint8_t *buf, int
 return AVERROR_INVALIDDATA;
 }
 
-int ff_isom_write_av1c(AVIOContext *pb, const uint8_t *buf, int size)
+int ff_isom_write_av1c(AVIOContext *pb, const uint8_t *buf, int size,
+   int write_seq_header)
 {
 AVIOContext *meta_pb;
 AV1SequenceParameters seq_params;
@@ -451,7 +452,9 @@ int ff_isom_write_av1c(AVIOContext *pb, const uint8_t *buf, 
int size)
 flush_put_bits();
 
 avio_write(pb, header, sizeof(header));
-avio_write(pb, seq, seq_size);
+if (write_seq_header) {
+avio_write(pb, seq, seq_size);
+}
 
 meta_size = avio_get_dyn_buf(meta_pb, );
 if (meta_size)
diff --git a/libavformat/av1.h b/libavformat/av1.h
index f57dabe986..a393fbb78f 100644
--- a/libavformat/av1.h
+++ b/libavformat/av1.h
@@ -96,9 +96,11 @@ int ff_av1_parse_seq_header(AV1SequenceParameters *seq, 
const uint8_t *buf, int
  * @param pb pointer to the AVIOContext where the av1C box shall be written
  * @param buf input data buffer
  * @param size size in bytes of the input data buffer
+ * @param write_seq_header If 1, Sequence Header OBU will be written inside the
+ *   av1C box. Otherwise, Sequence Header OBU will be omitted.
  *
  * @return >= 0 in case of success, a negative AVERROR code in case of failure
  */
-int ff_isom_write_av1c(AVIOContext *pb, const uint8_t *buf, int size);
+int ff_isom_write_av1c(AVIOContext *pb, const uint8_t *buf, int size, int 
write_seq_header);
 
 #endif /* AVFORMAT_AV1_H */
diff --git a/libavformat/matroskaenc.c b/libavformat/matroskaenc.c
index 38d9485288..5061961283 100644
--- a/libavformat/matroskaenc.c
+++ b/libavformat/matroskaenc.c
@@ -1087,7 +1087,7 @@ static int mkv_write_native_codecprivate(AVFormatContext 
*s, AVIOContext *pb,
 case AV_CODEC_ID_AV1:
 if (par->extradata_size)
 return ff_isom_write_av1c(dyn_cp, par->extradata,
-  par->extradata_size);
+  par->extradata_size, 1);
 else
 put_ebml_void(pb, 4 + 3);
 break;
@@ -2663,7 +2663,7 @@ static int mkv_check_new_extra_data(AVFormatContext *s, 
const AVPacket *pkt)
 ret = avio_open_dyn_buf(_cp);
 if (ret < 0)
 return ret;
-ff_isom_write_av1c(dyn_cp, side_data, side_data_size);
+ff_isom_write_av1c(dyn_cp, side_data, side_data_size, 1);
 codecpriv_size = avio_get_dyn_buf(dyn_cp, );
 if ((ret = dyn_cp->error) < 0 ||
 !codecpriv_size && (ret = AVERROR_INVALIDDATA)) {
diff --git a/libavformat/movenc.c b/libavformat/movenc.c
index 4c868919ae..1a746a67fd 100644
--- a/libavformat/movenc.c
+++ b/libavformat/movenc.c
@@ -1303,7 +1303,7 @@ static int mov_write_av1c_tag(AVIOContext *pb, MOVTrack 
*track)
 
 avio_wb32(pb, 0);
 ffio_wfourcc(pb, "av1C");
-ff_isom_write_av1c(pb, track->vos_data, track->vos_len);
+ff_isom_write_av1c(pb, track->vos_data, track->vos_len, 1);
 return update_size(pb, pos);
 }
 
-- 
2.35.1.265.g69c8d7142f-goog

___
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 1/3] avcodec/libaomenc: Add parameter for avif single image encoding

2022-02-16 Thread Vignesh Venkatasubramanian
Add a parameter to libaom-av1 encoder to enforce some of the single
image constraints in the AV1 encoder. Setting this flag will limit
the encoder to producing exactly one frame and the sequence header
that is produced by the encoder will be conformant to the AVIF
specification [1].

Part of Fixing Trac ticket #7621

[1] https://aomediacodec.github.io/av1-avif

Signed-off-by:: Vignesh Venkatasubramanian 
---
 libavcodec/libaomenc.c | 14 ++
 1 file changed, 14 insertions(+)

diff --git a/libavcodec/libaomenc.c b/libavcodec/libaomenc.c
index 963cc1bcbc..0398060a2f 100644
--- a/libavcodec/libaomenc.c
+++ b/libavcodec/libaomenc.c
@@ -99,6 +99,7 @@ typedef struct AOMEncoderContext {
 int enable_restoration;
 int usage;
 int tune;
+int is_avif;
 int enable_rect_partitions;
 int enable_1to4_partitions;
 int enable_ab_partitions;
@@ -746,6 +747,18 @@ static av_cold int aom_init(AVCodecContext *avctx,
 if (res < 0)
 return res;
 
+if (ctx->is_avif) {
+// Set the maximum number of frames to 1. This will let libaom set
+// still_picture and reduced_still_picture_header to 1 in the Sequence
+// Header as required by AVIF still images.
+enccfg.g_limit = 1;
+// Reduce memory usage for still images.
+enccfg.g_lag_in_frames = 0;
+// All frames will be key frames.
+enccfg.kf_max_dist = 0;
+enccfg.kf_mode = AOM_KF_DISABLED;
+}
+
 /* Construct Encoder Context */
 res = aom_codec_enc_init(>encoder, iface, , flags);
 if (res != AOM_CODEC_OK) {
@@ -1290,6 +1303,7 @@ static const AVOption options[] = {
 { "psnr",NULL, 0, AV_OPT_TYPE_CONST, {.i64 = 
AOM_TUNE_PSNR}, 0, 0, VE, "tune"},
 { "ssim",NULL, 0, AV_OPT_TYPE_CONST, {.i64 = 
AOM_TUNE_SSIM}, 0, 0, VE, "tune"},
 FF_AV1_PROFILE_OPTS
+{ "avif-image", "Encode in single frame mode for still AVIF images.", 
OFFSET(is_avif), AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 1, VE },
 { "enable-rect-partitions", "Enable rectangular partitions", 
OFFSET(enable_rect_partitions), AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 1, VE},
 { "enable-1to4-partitions", "Enable 1:4/4:1 partitions", 
OFFSET(enable_1to4_partitions), AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 1, VE},
 { "enable-ab-partitions",   "Enable ab shape partitions",
OFFSET(enable_ab_partitions),   AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 1, VE},
-- 
2.35.1.265.g69c8d7142f-goog

___
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".


Re: [FFmpeg-devel] [PATCH v2] libavcodec/qsvenc_hevc: encode RGB format rawvideo

2022-02-16 Thread Xiang, Haihao
On Tue, 2022-02-15 at 15:00 +0800, Wenbin Chen wrote:
> Add support for hevc_qsv to input RGB format frame. It will
> transform frame to yuv inside MediaSDK instead of using auto
> scale. Now hevc_qsv supports directly encoding BGRA and X2RGB10
> format. X2RGB10 is only supported in VDENC (-low_power 1).
> The X2RGB10 correspond to the A2RGB20 format in MediaSDK.
> 
> Signed-off-by: Wenbin Chen 
> ---
>  libavcodec/qsv.c | 16 
>  libavcodec/qsvenc.c  | 13 +
>  libavcodec/qsvenc_hevc.c |  6 ++
>  3 files changed, 35 insertions(+)
> 
> diff --git a/libavcodec/qsv.c b/libavcodec/qsv.c
> index 1a432dbd82..b75877e698 100644
> --- a/libavcodec/qsv.c
> +++ b/libavcodec/qsv.c
> @@ -189,6 +189,12 @@ enum AVPixelFormat ff_qsv_map_fourcc(uint32_t fourcc)
>  case MFX_FOURCC_NV12: return AV_PIX_FMT_NV12;
>  case MFX_FOURCC_P010: return AV_PIX_FMT_P010;
>  case MFX_FOURCC_P8:   return AV_PIX_FMT_PAL8;
> +#if QSV_VERSION_ATLEAST(1, 9)
> +case MFX_FOURCC_A2RGB10: return AV_PIX_FMT_X2RGB10;
> +#endif
> +#if QSV_VERSION_ATLEAST(1, 17)
> +case MFX_FOURCC_RGB4: return AV_PIX_FMT_BGRA;
> +#endif
>  #if CONFIG_VAAPI
>  case MFX_FOURCC_YUY2: return AV_PIX_FMT_YUYV422;
>  #if QSV_VERSION_ATLEAST(1, 27)
> @@ -211,6 +217,16 @@ int ff_qsv_map_pixfmt(enum AVPixelFormat format, uint32_t
> *fourcc)
>  case AV_PIX_FMT_P010:
>  *fourcc = MFX_FOURCC_P010;
>  return AV_PIX_FMT_P010;
> +#if QSV_VERSION_ATLEAST(1, 9)
> +case AV_PIX_FMT_X2RGB10:
> +*fourcc = MFX_FOURCC_A2RGB10;
> +return AV_PIX_FMT_X2RGB10;
> +#endif
> +#if QSV_VERSION_ATLEAST(1, 17)
> +case AV_PIX_FMT_BGRA:
> +*fourcc = MFX_FOURCC_RGB4;
> +return AV_PIX_FMT_BGRA;
> +#endif
>  #if CONFIG_VAAPI
>  case AV_PIX_FMT_YUV422P:
>  case AV_PIX_FMT_YUYV422:
> diff --git a/libavcodec/qsvenc.c b/libavcodec/qsvenc.c
> index 07be4287b7..104133fc59 100644
> --- a/libavcodec/qsvenc.c
> +++ b/libavcodec/qsvenc.c
> @@ -715,6 +715,11 @@ static int init_video_param(AVCodecContext *avctx,
> QSVEncContext *q)
>  if (ret < 0)
>  return AVERROR_BUG;
>  
> +if (sw_format == AV_PIX_FMT_X2RGB10 && q->low_power != 1) {

The SDK may choose a workable mode if low_power is set to auto.

Thanks
Haihao

> +av_log(avctx, AV_LOG_ERROR, "Only VDENC support encoding x2rgb10\n");
> +return AVERROR(EINVAL);
> +}
> +
>  q->param.mfx.FrameInfo.CropX  = 0;
>  q->param.mfx.FrameInfo.CropY  = 0;
>  q->param.mfx.FrameInfo.CropW  = avctx->width;
> @@ -1616,6 +1621,14 @@ static int submit_frame(QSVEncContext *q, const AVFrame
> *frame,
>  qf->surface.Data.V = qf->surface.Data.UV + 2;
>  break;
>  
> +case AV_PIX_FMT_X2RGB10:
> +case AV_PIX_FMT_BGRA:
> +qf->surface.Data.B = qf->frame->data[0];
> +qf->surface.Data.G = qf->frame->data[0] + 1;
> +qf->surface.Data.R = qf->frame->data[0] + 2;
> +qf->surface.Data.A = qf->frame->data[0] + 3;
> +break;
> +
>  default:
>  /* should not reach here */
>  av_assert0(0);
> diff --git a/libavcodec/qsvenc_hevc.c b/libavcodec/qsvenc_hevc.c
> index 5cac141c4d..ade546d4ca 100644
> --- a/libavcodec/qsvenc_hevc.c
> +++ b/libavcodec/qsvenc_hevc.c
> @@ -304,6 +304,12 @@ const AVCodec ff_hevc_qsv_encoder = {
>  .pix_fmts   = (const enum AVPixelFormat[]){ AV_PIX_FMT_NV12,
>  AV_PIX_FMT_P010,
>  AV_PIX_FMT_QSV,
> +#if QSV_VERSION_ATLEAST(1, 17)
> +AV_PIX_FMT_BGRA,
> +#endif
> +#if QSV_VERSION_ATLEAST(1, 9)
> +AV_PIX_FMT_X2RGB10,
> +#endif
>  AV_PIX_FMT_NONE },
>  .priv_class = ,
>  .defaults   = qsv_enc_defaults,
___
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".


Re: [FFmpeg-devel] [PATCH 3/3] configure: check avisynth header version

2022-02-16 Thread Stephen Hutchinson

On 2/16/22 1:25 PM, Helmut K. C. Tessarek wrote:


On 2022-02-16 02:37, Stephen Hutchinson wrote:

There is another option, basically what Gyan suggested earlier: grab the
release build of 3.7.1, fetch the extra headers from the Github repo,
then copy either all the contents of the tarball's /usr directory into
the system /usr directory (or wherever your working ${prefix} is), or
just the 'avisynth' directory into ${prefix}/include.  Then try FFmpeg
again.


This does not work. I compile static binaries. The filesonly tarball only
has dylibs.

As I mentioned nefore:. 3 days ago everything worked fine. Now the ffmpeg
builds are broken and I can no longer compile ffmpeg.

Is there any chancf you can add something to make it work again with 3.5.1
which compiled withtout issues on macOS 10.14 and which I've been using
since it was released.




FFmpeg dlopens AviSynth, it only needs the headers and doesn't try to 
link it.  It has never linked to AviSynth.


If 3.5.1 is working (and by that I assume you mean you're opening a 
Version() script in FFplay and it's showing you the video clip with the 
version and copyright information), then libavisynth.dylib is somewhere 
on your DYLD_LIBRARY_PATH, and you could just as easily set 
DYLD_LIBRARY_PATH to the /usr/lib directory in the -filesonly package 
and that Version() script will start reporting 3.7.1 instead.


After fetching the extra headers in that sequence of commands, copy the 
fixed-up /usr/include/avisynth in the -filesonly package to wherever it 
is on your system you point FFmpeg's configure to to see AviSynth's 
headers, whether that's the default /usr/local/include or /usr/include 
or somewhere in your build root.  You can completely omit copying the 
.dylibs and it won't care.


At this point, just use latest git, since that's where the HEADERS_ONLY 
fix resides:

git clone https://github.com/AviSynth/AviSynthPlus
cd AviSynthPlus
mkdir build && cd build
cmake -DCMAKE_INSTALL_PREFIX:PATH=${TARGET} -DHEADERS_ONLY=ON ../
make VersionGen install

And HEADERS_ONLY is exactly what it says on the tin: it only sets CMake 
to install the headers, and stops it from building the library, which 
wouldn't get linked to anyway.


This all did expose a major problem with the version detection inside 
the frame properties initialization area in the demuxer, so that check 
needs to be simplified and not try to be so clever.  Between 
HEADERS_ONLY from AviSynth+-git and the simplifying patch*, which I'll 
need to push sometime in the next day or so, that should completely 
resolve the problem.


*http://ffmpeg.org/pipermail/ffmpeg-devel/2022-February/293128.html
___
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] avformat/avisynth: fix frameprop version check

2022-02-16 Thread Stephen Hutchinson
Trying to be clever about determining between interface version 8
and 8.1 ended up with pre-8.1 versions of AviSynth+ segfaulting.

The amount of time between interface version 8.1 and 9 is small,
so just restrict the frameprop awareness to version 9 and call it
a day.
---
 libavformat/avisynth.c | 23 ++-
 1 file changed, 6 insertions(+), 17 deletions(-)

diff --git a/libavformat/avisynth.c b/libavformat/avisynth.c
index 8bc39869a3..b345f5efe2 100644
--- a/libavformat/avisynth.c
+++ b/libavformat/avisynth.c
@@ -502,24 +502,13 @@ static int avisynth_create_stream_video(AVFormatContext 
*s, AVStream *st)
 /* Read AviSynth+'s frame properties to set additional info.
  *
  * Due to a bug preventing the C interface from accessing frame
- * properties in earlier versions of interface version 8, only
- * enable this if we detect version 8.1 at the minimum. */
+ * properties in earlier versions of interface version 8, and
+ * previous attempts at being clever resulting in pre-8 versions
+ * of AviSynth+ segfaulting, only enable this if we detect
+ * version 9 at the minimum.  Technically, 8.1 works, but the time
+ * distance between 8.1 and 9 is very small, so just restrict it to 9. */
 
-if (!avs_library.avs_get_env_property) {
-av_log(s, AV_LOG_TRACE, "%s\n",
-   "avs_get_env_property does not exist in AviSynth library; frame 
properties won't be checked.");
-frameprop = false;
-} else {
-if (avs_library.avs_get_env_property(avs->env, 
AVS_AEP_INTERFACE_BUGFIX)) {
-av_log(s, AV_LOG_TRACE, "%s\n", "Using interface version 8.1 or 
higher, reading frame properties.");
-frameprop = true;
-} else {
-av_log(s, AV_LOG_TRACE, "%s\n", "Using interface version 8.0, need 
8.1+ to read frame properties.");
-frameprop = false;
-}
-}
-
-if (frameprop = true) {
+if (avs_library.avs_get_version(avs->clip) >= 9) {
 
 frame  = avs_library.avs_get_frame(avs->clip, framedata);
 avsmap = avs_library.avs_get_frame_props_ro(avs->env, frame);
-- 
2.32.0

___
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".


Re: [FFmpeg-devel] [PATCH 3/3] configure: check avisynth header version

2022-02-16 Thread Helmut K. C. Tessarek
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA512


On 2022-02-16 18:04, hydra3...@gmail.com wrote:
> This probably will not help you, since I cross-compile under Ubuntu for
> target Win10. However, for the record I did this, not quite according to
> the git instructions, and it did not abort:
> 
> # Changed dir from
> /home/u/Desktop/_working/workdir/x86_64/AviSynthPlus_git to subfolder
> avisynth-build
> 
> cmake ..
> -DCMAKE_TOOLCHAIN_FILE="/home/u/Desktop/_working/workdir/mingw_toolchain.cma
ke"
> -G"Ninja" 
> -DCMAKE_INSTALL_PREFIX=/home/u/Desktop/_working/workdir/toolchain/x86_64-w64
- -mingw32/x86_64-w64-mingw32
> -DHEADERS_ONLY:bool=on
> 
> ninja VersionGen -j 6
> 
> ninja install  -j 6

The file you are referencing is not even in the AviSynthPlus source tree.
Also a mingw cmake file would not be very useful on macOS.

But thanks anyway.


- -- 
regards Helmut K. C. Tessarek  KeyID 0x172380A011EF4944
Key fingerprint = 8A55 70C1 BD85 D34E ADBC 386C 1723 80A0 11EF 4944

/*
   Thou shalt not follow the NULL pointer for chaos and madness
   await thee at its end.
*/
-BEGIN PGP SIGNATURE-

iQIzBAEBCgAdFiEE191csiqpm8f5Ln9WvgmFNJ1E3QAFAmINhS4ACgkQvgmFNJ1E
3QDtrBAAr+DFCh6UXswzSlJ7lE6J8GX7FxofZgq7H97L5SgCOBS7azjuF9isM6d1
OrY2WqGPsBiK6NnTvlDUtaPmtxJkZQ8OEc2YwfsX1K0lSdjWmtBlbjIoWNZTiwja
H1xydX+XueWeb6Gm5c4NEXNyxsIquFW8nGTX2q8mZ8w54K3nFZhNhbPTtskzS0k6
GUyFYf8RxMICyXO1EcJhsHLu1zWTXDV72yVEIiHcyg4SNjggkJv9f4lnJSTZ9Igd
FzZAWT+Z7tLg8laAftFUDeEWj1vjbUF007ldvBUl6lbg5aWfLdvsau3eEn4EKeSQ
Sspl5mieo/XKljdqOugfaPRNdaK4BNv9Q/oX6gxXJ9jYacU5HhHwo8FekKXP+wbn
VNvB9sYdzp/NaAlPjQE71e/jdQHMA74ETb3duV3fjaWCPehnxX0iOWhBPfhPzM0O
RerC+6rCoYEJoD30jHuYDPB029Z/jdU0Y6BUCWt03MSG2M1bknsKxTcrYjRJFJ+V
Rzrnh34iRwTU5sBwoevG6oI6aojHSjXY9aY4sfHmttVbkpPbVpEVpyO8/QRaysBI
0r908qY3Q1GjTBX8iNKiGyp4E0DUbtVBb7oki/7X7ZR7klSuM2jyRt+Fj7OlQCsA
4NMB3iXwMODo/OwAQ1AYVdF0j6vl+auwxo9gDMcrlHstNRehOGI=
=hF9U
-END PGP SIGNATURE-
___
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".


Re: [FFmpeg-devel] [PATCH 3/3] configure: check avisynth header version

2022-02-16 Thread hydra3333
> On 2022-02-16 02:37, Stephen Hutchinson wrote:
> > There is another option, basically what Gyan suggested earlier: grab the 
> > release build of 3.7.1, fetch the extra headers from the Github repo,
> > then copy either all the contents of the tarball's /usr directory into
> > the system /usr directory (or wherever your working ${prefix} is), or
> > just the 'avisynth' directory into ${prefix}/include.  Then try FFmpeg
> > again.
>
> This does not work. I compile static binaries. The filesonly tarball only
> has dylibs.
>
> As I mentioned nefore:. 3 days ago everything worked fine. Now the ffmpeg
> builds are broken and I can no longer compile ffmpeg.
>
> Is there any chancf you can add something to make it work again with 3.5.1
> which compiled withtout issues on macOS 10.14 and which I've been using
> since it was released.
>
> - -- 
> regards Helmut K. C. Tessarek  KeyID 0x172380A011EF4944

Hello.

This probably will not help you, since I cross-compile under Ubuntu for target 
Win10.
However, for the record I did this, not quite according to the git 
instructions, and it did not abort:

# Changed dir from /home/u/Desktop/_working/workdir/x86_64/AviSynthPlus_git to 
subfolder avisynth-build

cmake .. 
-DCMAKE_TOOLCHAIN_FILE="/home/u/Desktop/_working/workdir/mingw_toolchain.cmake" 
-G"Ninja"
-DCMAKE_INSTALL_PREFIX=/home/u/Desktop/_working/workdir/toolchain/x86_64-w64-mingw32/x86_64-w64-mingw32
 -DHEADERS_ONLY:bool=on

ninja VersionGen -j 6

ninja install  -j 6

Cheers

___
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 1/1] avformat: Add IPFS protocol support.

2022-02-16 Thread Mark Gaiser
This patch adds support for:
- ffplay ipfs://
- ffplay ipns://

IPFS data can be played from so called "ipfs gateways".
A gateway is essentially a webserver that gives access to the
distributed IPFS network.

This protocol support (ipfs and ipns) therefore translates
ipfs:// and ipns:// to a http:// url. This resulting url is
then handled by the http protocol. It could also be https
depending on the gateway provided.

To use this protocol, a gateway must be provided.
If you do nothing it will try to find it in your
$HOME/.ipfs/gateway file. The ways to set it manually are:
1. Define a -gateway  to the gateway.
2. Define $IPFS_GATEWAY with the full http link to the gateway.
3. Define $IPFS_PATH and point it to the IPFS data path.
4. Have IPFS running in your local user folder (under $HOME/.ipfs).

Signed-off-by: Mark Gaiser 
---
 configure |   2 +
 doc/protocols.texi|  30 
 libavformat/Makefile  |   2 +
 libavformat/ipfsgateway.c | 312 ++
 libavformat/protocols.c   |   2 +
 5 files changed, 348 insertions(+)
 create mode 100644 libavformat/ipfsgateway.c

diff --git a/configure b/configure
index 5b19a35f59..6ff09e7974 100755
--- a/configure
+++ b/configure
@@ -3585,6 +3585,8 @@ udp_protocol_select="network"
 udplite_protocol_select="network"
 unix_protocol_deps="sys_un_h"
 unix_protocol_select="network"
+ipfs_protocol_select="https_protocol"
+ipns_protocol_select="https_protocol"
 
 # external library protocols
 libamqp_protocol_deps="librabbitmq"
diff --git a/doc/protocols.texi b/doc/protocols.texi
index d207df0b52..7c9c0a4808 100644
--- a/doc/protocols.texi
+++ b/doc/protocols.texi
@@ -2025,5 +2025,35 @@ decoding errors.
 
 @end table
 
+@section ipfs
+
+InterPlanetary File System (IPFS) protocol support. One can access files 
stored 
+on the IPFS network through so called gateways. Those are http(s) endpoints.
+This protocol wraps the IPFS native protocols (ipfs:// and ipns://) to be send 
+to such a gateway. Users can (and should) host their own node which means this 
+protocol will use your local machine gateway to access files on the IPFS 
network.
+
+If a user doesn't have a node of their own then the public gateway dweb.link 
is 
+used by default.
+
+You can use this protocol in 2 ways. Using IPFS:
+@example
+ffplay ipfs://QmbGtJg23skhvFmu9mJiePVByhfzu5rwo74MEkVDYAmF5T
+@end example
+
+Or the IPNS protocol (IPNS is mutable IPFS):
+@example
+ffplay ipns://QmbGtJg23skhvFmu9mJiePVByhfzu5rwo74MEkVDYAmF5T
+@end example
+
+You can also change the gateway to be used:
+
+@table @option
+
+@item gateway
+Defines the gateway to use. When nothing is provided the protocol will first 
try 
+your local gateway. If that fails dweb.link will be used.
+
+@end table
 
 @c man end PROTOCOLS
diff --git a/libavformat/Makefile b/libavformat/Makefile
index 3dc6a479cc..4edce8420f 100644
--- a/libavformat/Makefile
+++ b/libavformat/Makefile
@@ -656,6 +656,8 @@ OBJS-$(CONFIG_SRTP_PROTOCOL) += srtpproto.o 
srtp.o
 OBJS-$(CONFIG_SUBFILE_PROTOCOL)  += subfile.o
 OBJS-$(CONFIG_TEE_PROTOCOL)  += teeproto.o tee_common.o
 OBJS-$(CONFIG_TCP_PROTOCOL)  += tcp.o
+OBJS-$(CONFIG_IPFS_PROTOCOL) += ipfsgateway.o
+OBJS-$(CONFIG_IPNS_PROTOCOL) += ipfsgateway.o
 TLS-OBJS-$(CONFIG_GNUTLS)+= tls_gnutls.o
 TLS-OBJS-$(CONFIG_LIBTLS)+= tls_libtls.o
 TLS-OBJS-$(CONFIG_MBEDTLS)   += tls_mbedtls.o
diff --git a/libavformat/ipfsgateway.c b/libavformat/ipfsgateway.c
new file mode 100644
index 00..35456c00c4
--- /dev/null
+++ b/libavformat/ipfsgateway.c
@@ -0,0 +1,312 @@
+/*
+ * IPFS and IPNS protocol support through IPFS Gateway.
+ * Copyright (c) 2022 Mark Gaiser
+ *
+ * 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 "avformat.h"
+#include "libavutil/avassert.h"
+#include "libavutil/avstring.h"
+#include "libavutil/internal.h"
+#include "libavutil/opt.h"
+#include "libavutil/tree.h"
+#include 
+#if HAVE_IO_H
+#include 
+#endif
+#if HAVE_UNISTD_H
+#include 
+#endif
+#include "os_support.h"
+#include "url.h"
+#include 
+#include 
+
+typedef struct IPFSGatewayContext {
+AVClass *class;
+URLContext *inner;
+// Is filled by the -gateway 

[FFmpeg-devel] [PATCH v7 0/1] Add IPFS protocol support.

2022-02-16 Thread Mark Gaiser
Hi,

This patch series adds support for IPFS.
V7:
- Removed sanitize_ipfs_gateway. Only the http/https check stayed and that's
  now in translate_ipfs_to_http.
- Added a check for ipfs_cid. It's only to show an error is someone happens to
  profide `ffplay ipfs://` without a cid.
- All snprintf usages are now checked.
- Adding a / to a gateway if it didn't end with it is now done in the same line
  that composes the full resulting url.
- And a couple more minor things.
V6:
- Moved the gateway buffer (now called gateway_buffer) to IPFSGatewayContext
- Changed nearly all PATH_MAX uses to sizeof(...) uses for future flexibility
- The rest is relatively minor feedback changes
V5:
- "c->gateway" is now not modified anymore
- Moved most variables to the stack
- Even more strict checks with the auto detection logic
- Errors are now AVERROR :)
- Added more logging and changed some debug ones to info ones as they are 
  valuable to aid debugging as a user when something goes wrong.
V3 (V4):
- V4: title issue from V3..
- A lot of style changes
- Made url checks a lot more strict
- av_asprintf leak fixes
- So many changes that a diff to v2 is again not sensible.
V2:
- Squashed and changed so much that a diff to v1 was not sensible.

The following is a short summary. In the IPFS ecosystem you access it's content
by a "Content IDentifier" (CID). This CID is, in simplified terms, a hash of 
the content. IPFS itself is a distributed network where any user can run a node
to be part of the network and access files by their CID. If any reachable node 
within that network has the CID, you can get it.

IPFS (as a technology) has two protocols, ipfs and ipns.
The ipfs protocol is the immutable way to access content.
The ipns protocol is a mutable layer on top of it. It's essentially a new CID 
that points to a ipfs CID. This "pointer" if you will can be changed to point 
to something else.
Much more information on how this technology works can be found here [1].

This patch series allows to interact natively with IPFS. That means being able
to access files like:
- ffplay ipfs://
- ffplay ipns://

There are multiple ways to access files on the IPFS network. This patch series
uses the gateway driven way. An IPFS node - by default - exposes a local 
gateway (say http://localhost:8080) which is then used to get content from IPFS.
The gateway functionality on the IPFS side contains optimizations to
be as ideal to streaming data as it can be. Optimizations that the http protocol
in ffmpeg also has and are thus reused for free in this approach.

A note on other "more appropiate" ways, as I received some feedback on that.
For ffmpeg purposes the gateway approach is ideal! There is a "libipfs" but
that would spin up an ipfs node with the overhead of:
- bootstrapping
- connecting to nodes
- finding other nodes to connect too
- finally finding your file

This alternative approach could take minutes before a file is played. The
gateway approach immediately connects to an already running node thus gives
the file the fastest.

Much of the logic in this patch series is to find that gateway and essentially 
rewrite:

"ipfs://"

to:

"http://localhost:8080/ipfs/"

Once that's found it's forwared to the protocol handler where eventually the
http protocol is going to handle it. Note that it could also be https. There's 
enough flexibility in the implementation to allow the user to provide a 
gateway. There are also public https gateways which can be used just as well.

After this patch is accepted, I'll work on getting IPFS supported in:
- mpv (requires this ffmpeg patch)
- vlc (prefers this patch but can be made to work without this patch)
- kodi (requires this ffmpeg patch)

Best regards,
Mark Gaiser

[1] https://docs.ipfs.io/concepts/

Mark Gaiser (1):
  avformat: Add IPFS protocol support.

 configure |   2 +
 doc/protocols.texi|  30 
 libavformat/Makefile  |   2 +
 libavformat/ipfsgateway.c | 312 ++
 libavformat/protocols.c   |   2 +
 5 files changed, 348 insertions(+)
 create mode 100644 libavformat/ipfsgateway.c

-- 
2.35.1

___
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".


Re: [FFmpeg-devel] [PATCH 1/5] libswscale: Re-factor ff_shuffle_filter_coefficients.

2022-02-16 Thread Michael Niedermayer
On Wed, Feb 09, 2022 at 10:09:45AM +0100, Alan Kelly wrote:
> Make the code more readable and follow the style guide.
> ---
>  libswscale/utils.c | 64 +++---
>  1 file changed, 37 insertions(+), 27 deletions(-)
> 
> diff --git a/libswscale/utils.c b/libswscale/utils.c
> index c5ea8853d5..1d919e863a 100644
> --- a/libswscale/utils.c
> +++ b/libswscale/utils.c
> @@ -278,39 +278,49 @@ static const FormatEntry format_entries[] = {
>  [AV_PIX_FMT_P416LE]  = { 1, 1 },
>  };
>  
> -void ff_shuffle_filter_coefficients(SwsContext *c, int *filterPos, int 
> filterSize, int16_t *filter, int dstW){
> +void ff_shuffle_filter_coefficients(SwsContext *c, int *filterPos,
> +   int filterSize, int16_t *filter,
> +   int dstW)
> +{
>  #if ARCH_X86_64
> -int i, j, k, l;
> +int i, j, k;
>  int cpu_flags = av_get_cpu_flags();
> +// avx2 hscale filter processes 16 pixel blocks.
> +if (!filter || dstW % 16 != 0)
> +return;
>  if (EXTERNAL_AVX2_FAST(cpu_flags) && !(cpu_flags & 
> AV_CPU_FLAG_SLOW_GATHER)) {
> -if ((c->srcBpc == 8) && (c->dstBpc <= 14)){
> -if (dstW % 16 == 0){
> -if (filter != NULL){
> -for (i = 0; i < dstW; i += 8){
> -FFSWAP(int, filterPos[i + 2], filterPos[i+4]);
> -FFSWAP(int, filterPos[i + 3], filterPos[i+5]);
> -}
> -if (filterSize > 4){
> -int16_t *tmp2 = av_malloc(dstW * filterSize * 2);
> -memcpy(tmp2, filter, dstW * filterSize * 2);
> -for (i = 0; i < dstW; i += 16){//pixel
> -for (k = 0; k < filterSize / 4; ++k){//fcoeff
> -for (j = 0; j < 16; ++j){//inner pixel
> -for (l = 0; l < 4; ++l){//coeff
> -int from = i * filterSize + j * 
> filterSize + k * 4 + l;
> -int to = (i) * filterSize + j * 4 + 
> l + k * 64;
> -filter[to] = tmp2[from];
> -}
> -}
> -}
> -}
> -av_free(tmp2);
> -}
> -}
> -}
> +if ((c->srcBpc == 8) && (c->dstBpc <= 14)) {
> +   int16_t *filterCopy = NULL;
> +   if (filterSize > 4) {

> +   if (!FF_ALLOC_TYPED_ARRAY(filterCopy, dstW * filterSize))
> +   return;

this is not a matter of style, it changes a null pointer dereference on error
to simply returning with no error handling. I know the next patches
change this again but that makes it just more messy


> +   memcpy(filterCopy, filter, dstW * filterSize * 
> sizeof(int16_t));
> +   }
> +   // Do not swap filterPos for pixels which won't be processed by
> +   // the main loop.
> +   for (i = 0; i + 8 <= dstW; i += 8) {
> +   FFSWAP(int, filterPos[i + 2], filterPos[i + 4]);
> +   FFSWAP(int, filterPos[i + 3], filterPos[i + 5]);
> +   }
> +   if (filterSize > 4) {
> +   // 16 pixels are processed at a time.
> +   for (i = 0; i + 16 <= dstW; i += 16) {
> +   // 4 filter coeffs are processed at a time.
> +   for (k = 0; k + 4 <= filterSize; k += 4) {
> +   for (j = 0; j < 16; ++j) {
> +   int from = (i + j) * filterSize + k;
> +   int to = i * filterSize + j * 4 + k * 16;
> +   memcpy([to], [from], 4 * 
> sizeof(int16_t));
> +   }
> +   }
> +   }
> +   }

> +   if (filterCopy)
> +   av_free(filterCopy);

The null check is unneeded


[...]
-- 
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

Does the universe only have a finite lifespan? No, its going to go on
forever, its just that you wont like living in it. -- Hiranya Peiri


signature.asc
Description: PGP signature
___
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".


Re: [FFmpeg-devel] [FFmpeg-cvslog] avfilter/af_speechnorm: speed up filtering code

2022-02-16 Thread James Almer

ffmpeg | branch: master | Paul B Mahol  | Wed Feb 16 
19:31:31 2022 +0100| [698de27f25bea278ce7155fc387b3d59b478d46b] | committer: Paul B 
Mahol

avfilter/af_speechnorm: speed up filtering code

Reduce some asserts by default.


http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=698de27f25bea278ce7155fc387b3d59b478d46b

---

 libavfilter/af_speechnorm.c | 133 
 1 file changed, 73 insertions(+), 60 deletions(-)

diff --git a/libavfilter/af_speechnorm.c b/libavfilter/af_speechnorm.c
index 212a926f36..7fa87f814a 100644
--- a/libavfilter/af_speechnorm.c
+++ b/libavfilter/af_speechnorm.c
@@ -128,7 +128,7 @@ static int get_pi_samples(PeriodItem *pi, int start, int 
end, int remain)
 start = 0;
 if (pi[start].type == 0)
 break;
-av_assert0(pi[start].size > 0);
+av_assert1(pi[start].size > 0);
 sum += pi[start].size;
 }
 
@@ -156,7 +156,7 @@ static void consume_pi(ChannelContext *cc, int nb_samples)

 if (cc->pi_size >= nb_samples) {
 cc->pi_size -= nb_samples;
 } else {
-av_assert0(0);
+av_assert1(0);


You removed an assert meant to always trigger if that path is chosen. 
This has nothing to do with speed.


Same at the end of the commit.

___
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".


Re: [FFmpeg-devel] [PATCH 1/3] avfilter: Rename blend_modes.c -> blend_modes_template.c

2022-02-16 Thread Michael Niedermayer
On Wed, Feb 16, 2022 at 05:38:04AM +0100, Andreas Rheinhardt wrote:
> Michael Niedermayer:
> > This is more consistent with similar usage
> > 
> > Signed-off-by: Michael Niedermayer 
> > ---
> >  .../{blend_modes.c => blend_modes_template.c}  |  0
> >  libavfilter/vf_blend.c | 14 +++---
> >  2 files changed, 7 insertions(+), 7 deletions(-)
> >  rename libavfilter/{blend_modes.c => blend_modes_template.c} (100%)
> > 
> > diff --git a/libavfilter/blend_modes.c b/libavfilter/blend_modes_template.c
> > similarity index 100%
> > rename from libavfilter/blend_modes.c
> > rename to libavfilter/blend_modes_template.c
> > diff --git a/libavfilter/vf_blend.c b/libavfilter/vf_blend.c
> > index 2d433e439f..e912ba4cb8 100644
> > --- a/libavfilter/vf_blend.c
> > +++ b/libavfilter/vf_blend.c
> > @@ -34,31 +34,31 @@
> >  #define BOTTOM 1
> >  
> >  #define DEPTH 8
> > -#include "blend_modes.c"
> > +#include "blend_modes_template.c"
> >  
> >  #undef DEPTH
> >  #define DEPTH 9
> > -#include "blend_modes.c"
> > +#include "blend_modes_template.c"
> >  
> >  #undef DEPTH
> >  #define DEPTH 10
> > -#include "blend_modes.c"
> > +#include "blend_modes_template.c"
> >  
> >  #undef DEPTH
> >  #define DEPTH 12
> > -#include "blend_modes.c"
> > +#include "blend_modes_template.c"
> >  
> >  #undef DEPTH
> >  #define DEPTH 14
> > -#include "blend_modes.c"
> > +#include "blend_modes_template.c"
> >  
> >  #undef DEPTH
> >  #define DEPTH 16
> > -#include "blend_modes.c"
> > +#include "blend_modes_template.c"
> >  
> >  #undef DEPTH
> >  #define DEPTH 32
> > -#include "blend_modes.c"
> > +#include "blend_modes_template.c"
> >  
> >  typedef struct BlendContext {
> >  const AVClass *class;
> 
> Right now make's vf_blend.d contains an entry
> src/libavfilter/blend_modes.c; if one applies this patch, said file does
> no longer exist and make errors out with "No rule to make target
> 'src/libavfilter/blend_modes.c', needed by 'libavfilter/vf_blend.o'.",
> because the blend_modes.c prerequisite can't be made. In
> 3044d0efee9136c19dfdcf6dcdf957e910a73fd5 I made the build process treat
> templates just like headers so that they can be deleted without this
> error. Would there be any negative side-effects of doing the same for
> all files?
> (Btw: The AC-3 decoder also uses a misnamed template; I didn't fix it
> because of the aforementioned issue.)

Iam no makefile guru
but if you give a rule to fake-make any .c file then .o files build from
.asm could pick the .c route
i dont know when that happens but it does happen sometimes:

  Considering target file 'libavcodec/x86/fpel.o'.
   Looking for an implicit rule for 'libavcodec/x86/fpel.o'.
   Trying pattern rule with stem 'fpel'.
   Trying implicit prerequisite 'libavcodec/x86/fpel.c'.
   Found prerequisite 'libavcodec/x86/fpel.c' as VPATH 
'src/libavcodec/x86/fpel.c'
   Found an implicit rule for 'libavcodec/x86/fpel.o'.
Considering target file 'src/libavcodec/x86/fpel.c'.
 File 'src/libavcodec/x86/fpel.c' does not exist.
 Looking for an implicit rule for 'src/libavcodec/x86/fpel.c'.
 Trying pattern rule with stem 'fpel'.
 Found an implicit rule for 'src/libavcodec/x86/fpel.c'.
 Finished prerequisites of target file 'src/libavcodec/x86/fpel.c'.
Must remake target 'src/libavcodec/x86/fpel.c'.
Successfully remade target file 'src/libavcodec/x86/fpel.c'.
Pruning file 'libavcodec/'.
Pruning file 'libavcodec/x86/'.
Considering target file 'src/libavcodec/x86/fpel.asm'.
 Looking for an implicit rule for 'src/libavcodec/x86/fpel.asm'.
 Trying pattern rule with stem 'fpel.asm'.
 Trying implicit prerequisite 'src/libavcodec/x86/fpel.asm,v'.
 Trying pattern rule with stem 'fpel.asm'.
 Trying implicit prerequisite 'src/libavcodec/x86/RCS/fpel.asm,v'.
 Trying pattern rule with stem 'fpel.asm'.
 Trying implicit prerequisite 'src/libavcodec/x86/RCS/fpel.asm'.
 Trying pattern rule with stem 'fpel.asm'.
 Trying implicit prerequisite 'src/libavcodec/x86/s.fpel.asm'.
 Trying pattern rule with stem 'fpel.asm'.
 Trying implicit prerequisite 'src/libavcodec/x86/SCCS/s.fpel.asm'.
 No implicit rule found for 'src/libavcodec/x86/fpel.asm'.
 Finished prerequisites of target file 'src/libavcodec/x86/fpel.asm'.
No need to remake target 'src/libavcodec/x86/fpel.asm'.
Pruning file 'config.asm'.
Pruning file 'src//libavutil/x86/x86util.asm'.
Pruning file 'src//libavutil/x86/x86inc.asm'.
   Finished prerequisites of target file 'libavcodec/x86/fpel.o'.
   Prerequisite 'src/libavcodec/x86/fpel.c' of target 
'libavcodec/x86/fpel.o' does not exist.
   Prerequisite 'libavcodec/' is order-only for target 
'libavcodec/x86/fpel.o'.
   Prerequisite 'libavcodec/x86/' is order-only for target 
'libavcodec/x86/fpel.o'.
   

Re: [FFmpeg-devel] [PATCH 3/3] configure: check avisynth header version

2022-02-16 Thread Helmut K. C. Tessarek
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA512


On 2022-02-16 02:37, Stephen Hutchinson wrote:
> There is another option, basically what Gyan suggested earlier: grab the 
> release build of 3.7.1, fetch the extra headers from the Github repo,
> then copy either all the contents of the tarball's /usr directory into
> the system /usr directory (or wherever your working ${prefix} is), or
> just the 'avisynth' directory into ${prefix}/include.  Then try FFmpeg
> again.

This does not work. I compile static binaries. The filesonly tarball only
has dylibs.

As I mentioned nefore:. 3 days ago everything worked fine. Now the ffmpeg
builds are broken and I can no longer compile ffmpeg.

Is there any chancf you can add something to make it work again with 3.5.1
which compiled withtout issues on macOS 10.14 and which I've been using
since it was released.


- -- 
regards Helmut K. C. Tessarek  KeyID 0x172380A011EF4944
Key fingerprint = 8A55 70C1 BD85 D34E ADBC 386C 1723 80A0 11EF 4944

/*
   Thou shalt not follow the NULL pointer for chaos and madness
   await thee at its end.
*/
-BEGIN PGP SIGNATURE-

iQIzBAEBCgAdFiEE191csiqpm8f5Ln9WvgmFNJ1E3QAFAmINQXwACgkQvgmFNJ1E
3QAphA//aAu21aLcSYXTtFdb2DlW/lAdN3y7MhIftRXuy3zqTy7BnPOpiWwm6jtw
lq7Ck4IJMtFSbtH2Xh7RHqYKk1UVNZiwjIiPHhx/mBDxr+40wRdV44u00NPuQaGl
3ZHHqVSlODr0TSR9HjsW1ywM5BcxX4+FiilFHyM0JVlxTpEp6kqyisN8pRsL3Zyk
o00DVvTvTQD2GDd/eN+TRVl39d+8HD0DU16PzKF6ptuQs7Xyehoh/gt89fIhv5om
7/JWhJY9ritGQYyjzZq8J7vUrQ4dB7dLQMHbULnDaRC+7XQLdeTw5IU5NuNxqw4C
IUh4PbuYiiVLK0cE5HpvlPs6LwbkVvbw6Er9QtOUAtWEIys+d0sQxS5STm4NqUrB
92MXmkPqwDE8MgW5QJGo2n+vT1N4zDT49ot9aIa5NGb7PJ3WLRmqcx6RUbUKPPXn
JxtM1JYaVGHQIkqzxXh1Y8nWaMX5ynkXXj/TqIL8qjOuGgpaaqX9+mo6Uj7ZU3Vp
94AvAofrTXL6t7ZvnQGR53GNwroXsmy9/ffxZLhQSRQZj7oUasIeXRgDWkuJFaPd
CDvda7MXBw2A3v1Z60GhIYwZe2rbpsCL61lHFX0SmcIjy8eLk0ZbucwapnpCit0Y
IVtRbJCoDDrSCEwXgmXGkrlQ/KXGlCAX35C4Rw8T5hJLKqShE58=
=oTu0
-END PGP SIGNATURE-
___
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".


Re: [FFmpeg-devel] [PATCH 275/281] avfilter: convert to new channel layout API

2022-02-16 Thread Anton Khirnov
Quoting James Almer (2022-01-13 03:09:07)
> diff --git a/libavfilter/af_channelsplit.c b/libavfilter/af_channelsplit.c
> index 1a2519dd32..31453823c5 100644
> --- a/libavfilter/af_channelsplit.c
> +++ b/libavfilter/af_channelsplit.c
> @@ -36,7 +36,7 @@
>  typedef struct ChannelSplitContext {
>  const AVClass *class;
>  
> -uint64_t channel_layout;
> +AVChannelLayout channel_layout;
>  char*channel_layout_str;
>  char*channels_str;
>  
> @@ -57,11 +57,11 @@ AVFILTER_DEFINE_CLASS(channelsplit);
>  static av_cold int init(AVFilterContext *ctx)
>  {
>  ChannelSplitContext *s = ctx->priv;
> -uint64_t channel_layout;
> +AVChannelLayout channel_layout = { 0 };
>  int nb_channels;
>  int all = 0, ret = 0, i;
>  
> -if (!(s->channel_layout = av_get_channel_layout(s->channel_layout_str))) 
> {
> +if ((ret = av_channel_layout_from_string(>channel_layout, 
> s->channel_layout_str)) < 0) {
>  av_log(ctx, AV_LOG_ERROR, "Error parsing channel layout '%s'.\n",
> s->channel_layout_str);
>  ret = AVERROR(EINVAL);
> @@ -70,27 +70,32 @@ static av_cold int init(AVFilterContext *ctx)
>  
>  
>  if (!strcmp(s->channels_str, "all")) {
> -nb_channels = av_get_channel_layout_nb_channels(s->channel_layout);
> +nb_channels = s->channel_layout.nb_channels;
>  channel_layout = s->channel_layout;
>  all = 1;
>  } else {
> -if ((ret = av_get_extended_channel_layout(s->channels_str, 
> _layout, _channels)) < 0)
> +if ((ret = av_channel_layout_from_string(_layout, 
> s->channels_str)) < 0)
>  return ret;
>  }
>  
>  for (i = 0; i < nb_channels; i++) {
> -uint64_t channel = av_channel_layout_extract_channel(channel_layout, 
> i);
> -AVFilterPad pad  = { 0 };
> +int channel = av_channel_layout_channel_from_index(_layout, 
> i);
> +char buf[64];
> +AVFilterPad pad = { .flags = AVFILTERPAD_FLAG_FREE_NAME };
>  
> +av_channel_name(buf, sizeof(buf), channel);
>  pad.type = AVMEDIA_TYPE_AUDIO;
> -pad.name = av_get_channel_name(channel);
> +pad.name = av_strdup(buf);
> +if (!pad.name)
> +return AVERROR(ENOMEM);
>  
>  if (all) {
>  s->map[i] = i;

Should either make map dynamically allocated or check that there are
fewer than 64 channels in the layout.

>  } else {
> -if ((ret = 
> av_get_channel_layout_channel_index(s->channel_layout, channel)) < 0) {
> +if ((ret = 
> av_channel_layout_index_from_channel(>channel_layout, channel)) < 0) {
>  av_log(ctx, AV_LOG_ERROR, "Channel name '%s' not present in 
> channel layout '%s'.\n",
> -   av_get_channel_name(channel), s->channel_layout_str);
> +   pad.name, s->channel_layout_str);
> +av_freep();
>  return ret;
>  }
>  
> @@ -115,15 +120,18 @@ static int query_formats(AVFilterContext *ctx)
>  (ret = ff_set_common_all_samplerates(ctx)) < 0)
>  return ret;
>  
> -if ((ret = ff_add_channel_layout(_layouts, s->channel_layout)) < 0 ||
> +if ((ret = ff_add_channel_layout(_layouts, >channel_layout)) < 0 ||
>  (ret = ff_channel_layouts_ref(in_layouts, 
> >inputs[0]->outcfg.channel_layouts)) < 0)
>  return ret;
>  
>  for (i = 0; i < ctx->nb_outputs; i++) {
> +AVChannelLayout channel_layout = { 0 };
>  AVFilterChannelLayouts *out_layouts = NULL;
> -uint64_t channel = 
> av_channel_layout_extract_channel(s->channel_layout, s->map[i]);
> +int channel = 
> av_channel_layout_channel_from_index(>channel_layout, s->map[i]);
>  
> -if ((ret = ff_add_channel_layout(_layouts, channel)) < 0 ||
> +if ((channel < 0) ||
> +(ret = av_channel_layout_from_mask(_layout, 1ULL << 
> channel)) < 0 ||
> +(ret = ff_add_channel_layout(_layouts, _layout)) < 0 
> ||
>  (ret = ff_channel_layouts_ref(out_layouts, 
> >outputs[i]->incfg.channel_layouts)) < 0)
>  return ret;
>  }
> @@ -139,6 +147,7 @@ static int filter_frame(AVFilterLink *inlink, AVFrame 
> *buf)
>  
>  for (i = 0; i < ctx->nb_outputs; i++) {
>  AVFrame *buf_out = av_frame_clone(buf);
> +int channel = av_channel_layout_channel_from_index(>ch_layout, 
> s->map[i]);
>  
>  if (!buf_out) {
>  ret = AVERROR(ENOMEM);
> @@ -146,9 +155,16 @@ static int filter_frame(AVFilterLink *inlink, AVFrame 
> *buf)
>  }
>  
>  buf_out->data[0] = buf_out->extended_data[0] = 
> buf_out->extended_data[s->map[i]];
> +ret = av_channel_layout_from_mask(_out->ch_layout, 1ULL << 
> channel);

potential invalid shift?

> diff --git a/libavfilter/avfilter.c b/libavfilter/avfilter.c
> index 7362bcdab5..acb2d7db51 100644
> --- a/libavfilter/avfilter.c
> +++ b/libavfilter/avfilter.c
> @@ -204,6 +204,7 

Re: [FFmpeg-devel] [PATCH v3 2/4] avformat/imf: fix missing error reporting when opening resources

2022-02-16 Thread Pierre-Anthony Lemieux
On Wed, Feb 16, 2022 at 3:45 AM Zane van Iperen  wrote:
>
>
>
>
> On 3/2/22 14:07, p...@sandflow.com wrote:
> > From: Pierre-Anthony Lemieux 
> >
> > ---
> >   libavformat/imfdec.c | 4 +++-
> >   1 file changed, 3 insertions(+), 1 deletion(-)
> >
> > diff --git a/libavformat/imfdec.c b/libavformat/imfdec.c
> > index e6a1020ecc..658ddc40f2 100644
> > --- a/libavformat/imfdec.c
> > +++ b/libavformat/imfdec.c
> > @@ -550,7 +550,9 @@ static int 
> > set_context_streams_from_tracks(AVFormatContext *s)
> >   AVStream *first_resource_stream;
> >
> >   /* Open the first resource of the track to get stream information 
> > */
> > -open_track_resource_context(s, >tracks[i]->resources[0]);
> > +ret = open_track_resource_context(s, >tracks[i]->resources[0]);
> > +if (ret)
> > +return ret;
> >   first_resource_stream = 
> > c->tracks[i]->resources[0].ctx->streams[0];
> >   av_log(s, AV_LOG_DEBUG, "Open the first resource of track %d\n", 
> > c->tracks[i]->index);
> >
>
> Can you please squash this into the previous patch?

Addressed by v4

>
> The rest looks mostly okay.
> ___
> 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 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 3/3] avformat/imf: document IMFVirtualTrackResourcePlaybackCtx

2022-02-16 Thread pal
From: Pierre-Anthony Lemieux 

---
 libavformat/imfdec.c | 12 ++--
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/libavformat/imfdec.c b/libavformat/imfdec.c
index 17a21f5ef9..143f1086b6 100644
--- a/libavformat/imfdec.c
+++ b/libavformat/imfdec.c
@@ -96,12 +96,12 @@ typedef struct IMFAssetLocatorMap {
 } IMFAssetLocatorMap;
 
 typedef struct IMFVirtualTrackResourcePlaybackCtx {
-IMFAssetLocator *locator;
-FFIMFTrackFileResource *resource;
-AVFormatContext *ctx;
-AVRational start_time;
-AVRational end_time;
-AVRational ts_offset;
+IMFAssetLocator *locator;  /**< Location of the resource */
+FFIMFTrackFileResource *resource;  /**< Underlying IMF CPL resource */
+AVFormatContext *ctx;  /**< Context associated with the 
resource */
+AVRational start_time; /**< inclusive start time of the 
resource on the CPL timeline (s) */
+AVRational end_time;   /**< exclusive end time of the resource 
on the CPL timeline (s) */
+AVRational ts_offset;  /**< start_time minus the entry point 
into the resource (s) */
 } IMFVirtualTrackResourcePlaybackCtx;
 
 typedef struct IMFVirtualTrackPlaybackCtx {
-- 
2.17.1

___
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 2/3] avformat/imf: fix packet pts, dts and muxing

2022-02-16 Thread pal
From: Pierre-Anthony Lemieux 

The IMF demuxer does not set the DTS and PTS of packets accurately in all
scenarios. Moreover, audio packets are not trimmed when they exceed the
duration of the underlying resource.

imf-cpl-with-repeat FATE ref file is regenerated.

Addresses https://trac.ffmpeg.org/ticket/9611

---
 libavformat/imfdec.c   | 263 +++--
 tests/ref/fate/imf-cpl-with-repeat |  20 +--
 2 files changed, 181 insertions(+), 102 deletions(-)

diff --git a/libavformat/imfdec.c b/libavformat/imfdec.c
index 48bd5c78e8..17a21f5ef9 100644
--- a/libavformat/imfdec.c
+++ b/libavformat/imfdec.c
@@ -65,8 +65,10 @@
 #include "avio_internal.h"
 #include "imf.h"
 #include "internal.h"
+#include "libavcodec/packet.h"
 #include "libavutil/avstring.h"
 #include "libavutil/bprint.h"
+#include "libavutil/intreadwrite.h"
 #include "libavutil/opt.h"
 #include "mxf.h"
 #include "url.h"
@@ -97,6 +99,9 @@ typedef struct IMFVirtualTrackResourcePlaybackCtx {
 IMFAssetLocator *locator;
 FFIMFTrackFileResource *resource;
 AVFormatContext *ctx;
+AVRational start_time;
+AVRational end_time;
+AVRational ts_offset;
 } IMFVirtualTrackResourcePlaybackCtx;
 
 typedef struct IMFVirtualTrackPlaybackCtx {
@@ -108,7 +113,6 @@ typedef struct IMFVirtualTrackPlaybackCtx {
 IMFVirtualTrackResourcePlaybackCtx *resources; /**< Buffer holding the 
resources */
 int32_t current_resource_index;/**< Index of the current 
resource in resources,
 or < 0 if a current 
resource has yet to be selected */
-int64_t last_pts;  /**< Last timestamp */
 } IMFVirtualTrackPlaybackCtx;
 
 typedef struct IMFContext {
@@ -342,6 +346,7 @@ static int open_track_resource_context(AVFormatContext *s,
 int ret = 0;
 int64_t entry_point;
 AVDictionary *opts = NULL;
+AVStream *st;
 
 if (track_resource->ctx) {
 av_log(s,
@@ -383,23 +388,28 @@ static int open_track_resource_context(AVFormatContext *s,
 }
 av_dict_free();
 
-/* Compare the source timebase to the resource edit rate,
- * considering the first stream of the source file
- */
-if (av_cmp_q(track_resource->ctx->streams[0]->time_base,
- av_inv_q(track_resource->resource->base.edit_rate)))
+/* make sure there is only one stream in the file */
+
+if (track_resource->ctx->nb_streams != 1) {
+ret = AVERROR_INVALIDDATA;
+goto cleanup;
+}
+
+st = track_resource->ctx->streams[0];
+
+/* Warn if the resource time base does not match the file time base */
+if (av_cmp_q(st->time_base, 
av_inv_q(track_resource->resource->base.edit_rate)))
 av_log(s,
AV_LOG_WARNING,
-   "Incoherent source stream timebase %d/%d regarding resource 
edit rate: %d/%d",
-   track_resource->ctx->streams[0]->time_base.num,
-   track_resource->ctx->streams[0]->time_base.den,
+   "Incoherent source stream timebase " AVRATIONAL_FORMAT
+   "regarding resource edit rate: " AVRATIONAL_FORMAT,
+   st->time_base.num,
+   st->time_base.den,
track_resource->resource->base.edit_rate.den,
track_resource->resource->base.edit_rate.num);
 
-entry_point = (int64_t)track_resource->resource->base.entry_point
-* track_resource->resource->base.edit_rate.den
-* AV_TIME_BASE
-/ track_resource->resource->base.edit_rate.num;
+entry_point = av_rescale_q(track_resource->resource->base.entry_point, 
st->time_base,
+   
av_inv_q(track_resource->resource->base.edit_rate));
 
 if (entry_point) {
 av_log(s,
@@ -407,7 +417,7 @@ static int open_track_resource_context(AVFormatContext *s,
"Seek at resource %s entry point: %" PRIu32 "\n",
track_resource->locator->absolute_uri,
track_resource->resource->base.entry_point);
-ret = avformat_seek_file(track_resource->ctx, -1, entry_point, 
entry_point, entry_point, 0);
+ret = avformat_seek_file(track_resource->ctx, 0, entry_point, 
entry_point, entry_point, 0);
 if (ret < 0) {
 av_log(s,
AV_LOG_ERROR,
@@ -470,11 +480,16 @@ static int open_track_file_resource(AVFormatContext *s,
 vt_ctx.locator = asset_locator;
 vt_ctx.resource = track_file_resource;
 vt_ctx.ctx = NULL;
-track->resources[track->resource_count++] = vt_ctx;
-track->duration = av_add_q(track->duration,
+vt_ctx.start_time = track->duration;
+vt_ctx.ts_offset = av_sub_q(vt_ctx.start_time,
+
av_div_q(av_make_q((int)track_file_resource->base.entry_point, 1),
+ 
track_file_resource->base.edit_rate));
+vt_ctx.end_time = av_add_q(track->duration,
 

[FFmpeg-devel] [PATCH v4 1/3] avformat/imf: open resources only when first needed

2022-02-16 Thread pal
From: Pierre-Anthony Lemieux 

IMF CPLs can reference thousands of files, which can result in system limits
for the number of open files to be exceeded. The following patch opens and
closes files as needed.

Addresses https://trac.ffmpeg.org/ticket/9623

---
 libavformat/imfdec.c | 17 ++---
 1 file changed, 10 insertions(+), 7 deletions(-)

diff --git a/libavformat/imfdec.c b/libavformat/imfdec.c
index 847dead7f0..48bd5c78e8 100644
--- a/libavformat/imfdec.c
+++ b/libavformat/imfdec.c
@@ -103,10 +103,11 @@ typedef struct IMFVirtualTrackPlaybackCtx {
 int32_t index; /**< Track index in 
playlist */
 AVRational current_timestamp;  /**< Current temporal 
position */
 AVRational duration;   /**< Overall duration */
-uint32_t resource_count;   /**< Number of resources */
+uint32_t resource_count;   /**< Number of resources 
(<= INT32_MAX) */
 unsigned int resources_alloc_sz;   /**< Size of the buffer 
holding the resource */
 IMFVirtualTrackResourcePlaybackCtx *resources; /**< Buffer holding the 
resources */
-uint32_t current_resource_index;   /**< Current resource */
+int32_t current_resource_index;/**< Index of the current 
resource in resources,
+or < 0 if a current 
resource has yet to be selected */
 int64_t last_pts;  /**< Last timestamp */
 } IMFVirtualTrackPlaybackCtx;
 
@@ -435,7 +436,6 @@ static int open_track_file_resource(AVFormatContext *s,
 IMFContext *c = s->priv_data;
 IMFAssetLocator *asset_locator;
 void *tmp;
-int ret;
 
 asset_locator = find_asset_map_locator(>asset_locator_map, 
track_file_resource->track_file_uuid);
 if (!asset_locator) {
@@ -452,7 +452,7 @@ static int open_track_file_resource(AVFormatContext *s,
UID_ARG(asset_locator->uuid),
asset_locator->absolute_uri);
 
-if (track->resource_count > UINT32_MAX - 
track_file_resource->base.repeat_count
+if (track->resource_count > INT32_MAX - 
track_file_resource->base.repeat_count
 || (track->resource_count + track_file_resource->base.repeat_count)
 > INT_MAX / sizeof(IMFVirtualTrackResourcePlaybackCtx))
 return AVERROR(ENOMEM);
@@ -470,8 +470,6 @@ static int open_track_file_resource(AVFormatContext *s,
 vt_ctx.locator = asset_locator;
 vt_ctx.resource = track_file_resource;
 vt_ctx.ctx = NULL;
-if ((ret = open_track_resource_context(s, _ctx)) != 0)
-return ret;
 track->resources[track->resource_count++] = vt_ctx;
 track->duration = av_add_q(track->duration,

av_make_q((int)track_file_resource->base.duration
@@ -501,6 +499,7 @@ static int open_virtual_track(AVFormatContext *s,
 
 if (!(track = av_mallocz(sizeof(IMFVirtualTrackPlaybackCtx
 return AVERROR(ENOMEM);
+track->current_resource_index = -1;
 track->index = track_index;
 track->duration = av_make_q(0, 1);
 
@@ -551,6 +550,9 @@ static int set_context_streams_from_tracks(AVFormatContext 
*s)
 AVStream *first_resource_stream;
 
 /* Open the first resource of the track to get stream information */
+ret = open_track_resource_context(s, >tracks[i]->resources[0]);
+if (ret)
+return ret;
 first_resource_stream = c->tracks[i]->resources[0].ctx->streams[0];
 av_log(s, AV_LOG_DEBUG, "Open the first resource of track %d\n", 
c->tracks[i]->index);
 
@@ -741,7 +743,8 @@ static IMFVirtualTrackResourcePlaybackCtx 
*get_resource_context_for_timestamp(AV
track->index);
 if (open_track_resource_context(s, &(track->resources[i])) != 
0)
 return NULL;
-
avformat_close_input(&(track->resources[track->current_resource_index].ctx));
+if (track->current_resource_index > 0)
+
avformat_close_input(>resources[track->current_resource_index].ctx);
 track->current_resource_index = i;
 }
 
-- 
2.17.1

___
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".


Re: [FFmpeg-devel] [PATCH v3 4/5] fftools/cmdutils.c: Replace MAX_PATH-sized buffers with dynamically sized ones

2022-02-16 Thread Martin Storsjö


> On Feb 16, 2022, at 18:32, nil-admir...@mailo.com wrote:
> 
> Previously there was GetModuleFileNameA. wchartoansi is used to match old 
> behaviour. I can replace it with wchartoutf8 if you wish.

Oh, right. Well yes - if the path later is going to end up in a codepath that 
expects it to be UTF8 (please do check!), then we should go that way instead, 
then the existing code had a latent bug wrt that.

(Also, don’t top post!)

// Martin

___
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".


Re: [FFmpeg-devel] [PATCH v3 4/5] fftools/cmdutils.c: Replace MAX_PATH-sized buffers with dynamically sized ones

2022-02-16 Thread nil-admirari
Previously there was GetModuleFileNameA. wchartoansi is used to match old 
behaviour. I can replace it with wchartoutf8 if you wish.

> - if (GetModuleFileNameA(GetModuleHandleA(NULL), datadir, sizeof(datadir) - 
> 1))
> + if (wchartoansi(datadir_w, ))
> + datadir = NULL;

From: Martin Storsjö 
To: FFmpeg development discussions and patches 
Subject: Re: [FFmpeg-devel] [PATCH v3 4/5] fftools/cmdutils.c: Replace 
MAX_PATH-sized buffers with dynamically sized ones
Date: 16/02/2022 17:08:12 Europe/Moscow

Why would you use ansi here? Aren't all internal char based paths supposed 
to be UTF-8, unless passing them to an external API that expects e.g. ACP 
paths?

// Martin



___
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".


Re: [FFmpeg-devel] [PATCH v3 4/5] fftools/cmdutils.c: Replace MAX_PATH-sized buffers with dynamically sized ones

2022-02-16 Thread Martin Storsjö

On Wed, 16 Feb 2022, nihil-admirari wrote:


---
fftools/cmdutils.c | 31 +--
1 file changed, 25 insertions(+), 6 deletions(-)

diff --git a/fftools/cmdutils.c b/fftools/cmdutils.c
index 4b50e15..ea78897 100644
--- a/fftools/cmdutils.c
+++ b/fftools/cmdutils.c
@@ -62,6 +62,7 @@
#endif
#ifdef _WIN32
#include 
+#include "compat/w32dlfcn.h"
#endif

static int init_report(const char *env);
@@ -2065,6 +2066,9 @@ FILE *get_preset_file(char *filename, size_t 
filename_size,
{
FILE *f = NULL;
int i;
+#if HAVE_GETMODULEHANDLE && defined(_WIN32)
+char *datadir = NULL;
+#endif
const char *base[3] = { getenv("FFMPEG_DATADIR"),
getenv("HOME"),
FFMPEG_DATADIR, };
@@ -2074,19 +2078,31 @@ FILE *get_preset_file(char *filename, size_t 
filename_size,
f = fopen(filename, "r");
} else {
#if HAVE_GETMODULEHANDLE && defined(_WIN32)
-char datadir[MAX_PATH], *ls;
+wchar_t *datadir_w = get_module_filename(NULL);
base[2] = NULL;

-if (GetModuleFileNameA(GetModuleHandleA(NULL), datadir, 
sizeof(datadir) - 1))
+if (wchartoansi(datadir_w, ))
+datadir = NULL;


Why would you use ansi here? Aren't all internal char based paths supposed 
to be UTF-8, unless passing them to an external API that expects e.g. ACP 
paths?


// Martin

___
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".


Re: [FFmpeg-devel] [PATCH v2] Long path support for Windows (fixes #8885)

2022-02-16 Thread nil-admirari
ANSI functions do not support long paths, so I had to change
LoadLibraryExA to LoadLibraryExW.in compat/w32dlfcn.h as well.

I cannot find other uses of WinAPI functions ending with ..A(.
Looks like FFmpeg doesn't use ANSI functions anywhere else,
but the codebase is huge, so who knows.

Previous patch generated a warning: The first line of the commit message must 
start with a context...: 
https://patchwork.ffmpeg.org/project/ffmpeg/patch/20220214095146.13432-1-nil-admir...@mailo.com/.
Patch affected multiple files, so in order to specify the context the patch had 
to be split into pieces.

A new version of the patch is at 
https://ffmpeg.org/pipermail/ffmpeg-devel/2022-February/293106.html.



___
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 2/5] libavformat/avisynth.c: Replace MAX_PATH-sized buffers with dynamically sized ones

2022-02-16 Thread nihil-admirari
---
 libavformat/avisynth.c | 12 +++-
 1 file changed, 7 insertions(+), 5 deletions(-)

diff --git a/libavformat/avisynth.c b/libavformat/avisynth.c
index 8bc3986..219f307 100644
--- a/libavformat/avisynth.c
+++ b/libavformat/avisynth.c
@@ -36,6 +36,7 @@
 /* Platform-specific directives. */
 #ifdef _WIN32
   #include "compat/w32dlfcn.h"
+  #include "libavutil/wchar_filename.h"
   #undef EXTERN_C
   #define AVISYNTH_LIB "avisynth"
 #else
@@ -806,8 +807,7 @@ static int avisynth_open_file(AVFormatContext *s)
 AVS_Value arg, val;
 int ret;
 #ifdef _WIN32
-char filename_ansi[MAX_PATH * 4];
-wchar_t filename_wc[MAX_PATH * 4];
+char *filename_ansi = NULL;
 #endif
 
 if (ret = avisynth_context_create(s))
@@ -815,10 +815,12 @@ static int avisynth_open_file(AVFormatContext *s)
 
 #ifdef _WIN32
 /* Convert UTF-8 to ANSI code page */
-MultiByteToWideChar(CP_UTF8, 0, s->url, -1, filename_wc, MAX_PATH * 4);
-WideCharToMultiByte(CP_THREAD_ACP, 0, filename_wc, -1, filename_ansi,
-MAX_PATH * 4, NULL, NULL);
+if (utf8toansi(s->url, _ansi)) {
+ret = AVERROR_UNKNOWN;
+goto fail;
+}
 arg = avs_new_value_string(filename_ansi);
+av_free(filename_ansi);
 #else
 arg = avs_new_value_string(s->url);
 #endif
-- 
2.32.0



___
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 5/5] fftools: Enable long path support on Windows (fixes #8885)

2022-02-16 Thread nihil-admirari
---
 fftools/Makefile |  5 +
 fftools/long_paths_utf8.manifest | 12 
 fftools/long_paths_utf8.rc   |  3 +++
 3 files changed, 20 insertions(+)
 create mode 100644 fftools/long_paths_utf8.manifest
 create mode 100644 fftools/long_paths_utf8.rc

diff --git a/fftools/Makefile b/fftools/Makefile
index da42078..53438b6 100644
--- a/fftools/Makefile
+++ b/fftools/Makefile
@@ -11,6 +11,11 @@ ALLAVPROGS_G = $(AVBASENAMES:%=%$(PROGSSUF)_g$(EXESUF))
 
 OBJS-ffmpeg+= fftools/ffmpeg_opt.o 
fftools/ffmpeg_filter.o fftools/ffmpeg_hw.o
 
+# Windows resource files
+OBJS-ffmpeg-$(HAVE_GNU_WINDRES) += fftools/long_paths_utf8.o
+OBJS-ffplay-$(HAVE_GNU_WINDRES) += fftools/long_paths_utf8.o
+OBJS-ffprobe-$(HAVE_GNU_WINDRES) += fftools/long_paths_utf8.o
+
 define DOFFTOOL
 OBJS-$(1) += fftools/cmdutils.o fftools/$(1).o $(OBJS-$(1)-yes)
 $(1)$(PROGSSUF)_g$(EXESUF): $$(OBJS-$(1))
diff --git a/fftools/long_paths_utf8.manifest b/fftools/long_paths_utf8.manifest
new file mode 100644
index 000..d1ac1e4
--- /dev/null
+++ b/fftools/long_paths_utf8.manifest
@@ -0,0 +1,12 @@
+
+
+
+  
+  
+http://schemas.microsoft.com/SMI/2016/WindowsSettings;
+ 
xmlns:ws2019="http://schemas.microsoft.com/SMI/2019/WindowsSettings;>
+  true
+  UTF-8
+
+  
+
diff --git a/fftools/long_paths_utf8.rc b/fftools/long_paths_utf8.rc
new file mode 100644
index 000..f33de76
--- /dev/null
+++ b/fftools/long_paths_utf8.rc
@@ -0,0 +1,3 @@
+#include 
+
+CREATEPROCESS_MANIFEST_RESOURCE_ID RT_MANIFEST "long_paths_utf8.manifest"
-- 
2.32.0



___
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 4/5] fftools/cmdutils.c: Replace MAX_PATH-sized buffers with dynamically sized ones

2022-02-16 Thread nihil-admirari
---
 fftools/cmdutils.c | 31 +--
 1 file changed, 25 insertions(+), 6 deletions(-)

diff --git a/fftools/cmdutils.c b/fftools/cmdutils.c
index 4b50e15..ea78897 100644
--- a/fftools/cmdutils.c
+++ b/fftools/cmdutils.c
@@ -62,6 +62,7 @@
 #endif
 #ifdef _WIN32
 #include 
+#include "compat/w32dlfcn.h"
 #endif
 
 static int init_report(const char *env);
@@ -2065,6 +2066,9 @@ FILE *get_preset_file(char *filename, size_t 
filename_size,
 {
 FILE *f = NULL;
 int i;
+#if HAVE_GETMODULEHANDLE && defined(_WIN32)
+char *datadir = NULL;
+#endif
 const char *base[3] = { getenv("FFMPEG_DATADIR"),
 getenv("HOME"),
 FFMPEG_DATADIR, };
@@ -2074,19 +2078,31 @@ FILE *get_preset_file(char *filename, size_t 
filename_size,
 f = fopen(filename, "r");
 } else {
 #if HAVE_GETMODULEHANDLE && defined(_WIN32)
-char datadir[MAX_PATH], *ls;
+wchar_t *datadir_w = get_module_filename(NULL);
 base[2] = NULL;
 
-if (GetModuleFileNameA(GetModuleHandleA(NULL), datadir, 
sizeof(datadir) - 1))
+if (wchartoansi(datadir_w, ))
+datadir = NULL;
+av_free(datadir_w);
+
+if (datadir)
 {
-for (ls = datadir; ls < datadir + strlen(datadir); ls++)
+char *ls;
+for (ls = datadir; *ls; ls++)
 if (*ls == '\\') *ls = '/';
 
 if (ls = strrchr(datadir, '/'))
 {
-*ls = 0;
-strncat(datadir, "/ffpresets",  sizeof(datadir) - 1 - 
strlen(datadir));
-base[2] = datadir;
+const int datadir_len = ls - datadir;
+const int desired_size = datadir_len + strlen("/ffpresets") + 
1;
+char *new_datadir = av_realloc_array(
+datadir, desired_size, sizeof *datadir);
+if (new_datadir) {
+datadir = new_datadir;
+datadir[datadir_len] = 0;
+strncat(datadir, "/ffpresets",  desired_size - 1 - 
datadir_len);
+base[2] = datadir;
+}
 }
 }
 #endif
@@ -2106,6 +2122,9 @@ FILE *get_preset_file(char *filename, size_t 
filename_size,
 }
 }
 
+#if HAVE_GETMODULEHANDLE && defined(_WIN32)
+av_free(datadir);
+#endif
 return f;
 }
 
-- 
2.32.0



___
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 3/5] compat/w32dlfcn.h: Replace MAX_PATH-sized buffers with dynamically sized ones

2022-02-16 Thread nihil-admirari
Also replaces a call to LoadLibraryExA with LoadLibraryExW
since ANSI functions do not support long paths.
---
 compat/w32dlfcn.h | 74 ++-
 1 file changed, 61 insertions(+), 13 deletions(-)

diff --git a/compat/w32dlfcn.h b/compat/w32dlfcn.h
index 52a94ef..a8ac780 100644
--- a/compat/w32dlfcn.h
+++ b/compat/w32dlfcn.h
@@ -25,6 +25,30 @@
 #if (_WIN32_WINNT < 0x0602) || HAVE_WINRT
 #include "libavutil/wchar_filename.h"
 #endif
+
+static inline wchar_t *get_module_filename(const HMODULE module)
+{
+wchar_t *path = NULL;
+int path_size = 0, path_len = 0;
+
+do {
+path_size = path_size ? 1.5 * path_size : MAX_PATH;
+wchar_t *new_path = av_realloc_array(path, path_size, sizeof *path);
+if (!new_path) {
+av_free(path);
+return NULL;
+}
+path = new_path;
+path_len = GetModuleFileNameW(module, path, path_size);
+} while (path_len && path_size <= 32768 && path_size <= path_len);
+
+if (!path_len) {
+av_free(path);
+return NULL;
+}
+return path;
+}
+
 /**
  * Safe function used to open dynamic libs. This attempts to improve program 
security
  * by removing the current directory from the dll search path. Only dll's 
found in the
@@ -34,28 +58,50 @@
  */
 static inline HMODULE win32_dlopen(const char *name)
 {
+wchar_t *name_w = NULL;
+if (utf8towchar(name, _w))
+name_w = NULL;
 #if _WIN32_WINNT < 0x0602
 // Need to check if KB2533623 is available
 if (!GetProcAddress(GetModuleHandleW(L"kernel32.dll"), 
"SetDefaultDllDirectories")) {
 HMODULE module = NULL;
-wchar_t *path = NULL, *name_w = NULL;
-DWORD pathlen;
-if (utf8towchar(name, _w))
+wchar_t *path = NULL, *new_path = NULL;
+DWORD pathlen, pathsize, namelen;
+if (!name_w)
 goto exit;
-path = (wchar_t *)av_calloc(MAX_PATH, sizeof(wchar_t));
+namelen = wcslen(name_w);
 // Try local directory first
-pathlen = GetModuleFileNameW(NULL, path, MAX_PATH);
-pathlen = wcsrchr(path, '\\') - path;
-if (pathlen == 0 || pathlen + wcslen(name_w) + 2 > MAX_PATH)
+path = get_module_filename(NULL);
+if (!path)
 goto exit;
-path[pathlen] = '\\';
+new_path = wcsrchr(path, '\\');
+if (!new_path)
+goto exit;
+pathlen = new_path - path;
+pathsize = pathlen + namelen + 2;
+new_path = av_realloc_array(path, pathsize, sizeof *path);
+if (!new_path)
+goto exit;
+path = new_path;
 wcscpy(path + pathlen + 1, name_w);
 module = LoadLibraryExW(path, NULL, LOAD_WITH_ALTERED_SEARCH_PATH);
 if (module == NULL) {
 // Next try System32 directory
-pathlen = GetSystemDirectoryW(path, MAX_PATH);
-if (pathlen == 0 || pathlen + wcslen(name_w) + 2 > MAX_PATH)
+pathlen = GetSystemDirectoryW(path, pathsize);
+if (!pathlen)
 goto exit;
+if (pathlen + namelen + 2 > pathsize) {
+pathsize = pathlen + namelen + 2;
+new_path = av_realloc_array(path, pathsize, sizeof *path);
+if (!new_path)
+goto exit;
+path = new_path;
+// The buffer might have been not enough for system directory
+// in the first place.
+pathlen = GetSystemDirectoryW(path, pathsize);
+if (!pathlen)
+goto exit;
+}
 path[pathlen] = '\\';
 wcscpy(path + pathlen + 1, name_w);
 module = LoadLibraryExW(path, NULL, LOAD_WITH_ALTERED_SEARCH_PATH);
@@ -73,15 +119,17 @@ exit:
 #   define LOAD_LIBRARY_SEARCH_SYSTEM320x0800
 #endif
 #if HAVE_WINRT
-wchar_t *name_w = NULL;
 int ret;
-if (utf8towchar(name, _w))
+if (!name_w)
 return NULL;
 ret = LoadPackagedLibrary(name_w, 0);
 av_free(name_w);
 return ret;
 #else
-return LoadLibraryExA(name, NULL, LOAD_LIBRARY_SEARCH_APPLICATION_DIR | 
LOAD_LIBRARY_SEARCH_SYSTEM32);
+/* filename may be be in CP_ACP */
+if (!name_w)
+return LoadLibraryExA(name, NULL, LOAD_LIBRARY_SEARCH_APPLICATION_DIR 
| LOAD_LIBRARY_SEARCH_SYSTEM32);
+return LoadLibraryExW(name_w, NULL, LOAD_LIBRARY_SEARCH_APPLICATION_DIR | 
LOAD_LIBRARY_SEARCH_SYSTEM32);
 #endif
 }
 #define dlopen(name, flags) win32_dlopen(name)
-- 
2.32.0



___
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 1/5] libavutil/wchar_filename.h: Add wchartoansi and utf8toansi

2022-02-16 Thread nihil-admirari
These functions are going to be used in libavformat/avisynth.c
and fftools/cmdutils.c when replacing MAX_PATH-sized buffers
with dynamically sized ones.
---
 libavutil/wchar_filename.h | 37 +
 1 file changed, 37 insertions(+)

diff --git a/libavutil/wchar_filename.h b/libavutil/wchar_filename.h
index 90f0824..32260a4 100644
--- a/libavutil/wchar_filename.h
+++ b/libavutil/wchar_filename.h
@@ -40,6 +40,43 @@ static inline int utf8towchar(const char *filename_utf8, 
wchar_t **filename_w)
 MultiByteToWideChar(CP_UTF8, 0, filename_utf8, -1, *filename_w, num_chars);
 return 0;
 }
+
+av_warn_unused_result
+static inline int wchartoansi(const wchar_t *filename_w, char **filename)
+{
+const int num_chars = WideCharToMultiByte(CP_THREAD_ACP, 0, filename_w, -1,
+  NULL, 0, NULL, NULL);
+if (num_chars <= 0) {
+*filename = NULL;
+return 0;
+}
+*filename = (char *)av_calloc(num_chars, sizeof(char));
+if (!*filename) {
+errno = ENOMEM;
+return -1;
+}
+WideCharToMultiByte(CP_THREAD_ACP, 0, filename_w, -1,
+*filename, num_chars, NULL, NULL);
+return 0;
+}
+
+av_warn_unused_result
+static inline int utf8toansi(const char *filename_utf8, char **filename)
+{
+wchar_t *filename_w = NULL;
+int ret = -1;
+if (utf8towchar(filename_utf8, _w))
+return -1;
+
+if (!filename_w) {
+*filename = NULL;
+return 0;
+}
+
+ret = wchartoansi(filename_w, filename);
+av_free(filename_w);
+return ret;
+}
 #endif
 
 #endif /* AVUTIL_WCHAR_FILENAME_H */
-- 
2.32.0



___
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] avcodec/libsvtav1: add a svtav1-params option to pass a list of key=value parameters

2022-02-16 Thread James Almer
Signed-off-by: James Almer 
---
 doc/encoders.texi  |  3 +++
 libavcodec/libsvtav1.c | 52 ++
 2 files changed, 41 insertions(+), 14 deletions(-)

diff --git a/doc/encoders.texi b/doc/encoders.texi
index bfb6c7eef6..1a040bccdd 100644
--- a/doc/encoders.texi
+++ b/doc/encoders.texi
@@ -1816,6 +1816,9 @@ Set log2 of the number of rows of tiles to use (0-6).
 @item tile_columns
 Set log2 of the number of columns of tiles to use (0-4).
 
+@item svtav1-params
+Set the SVT-AV1 configuration using a :-separated list of key=value parameters
+
 @end table
 
 @section libkvazaar
diff --git a/libavcodec/libsvtav1.c b/libavcodec/libsvtav1.c
index 6196da25e6..ce3b0ba7ac 100644
--- a/libavcodec/libsvtav1.c
+++ b/libavcodec/libsvtav1.c
@@ -60,6 +60,7 @@ typedef struct SvtContext {
 EOS_STATUS eos_flag;
 
 // User options.
+AVDictionary *svtav1_opts;
 int hierarchical_level;
 int la_depth;
 int enc_mode;
@@ -151,6 +152,41 @@ static int config_enc_params(EbSvtAv1EncConfiguration 
*param,
 {
 SvtContext *svt_enc = avctx->priv_data;
 const AVPixFmtDescriptor *desc;
+AVDictionaryEntry *en = NULL;
+
+// Update param from options
+param->hierarchical_levels  = svt_enc->hierarchical_level;
+param->enc_mode = svt_enc->enc_mode;
+param->tier = svt_enc->tier;
+param->rate_control_mode= svt_enc->rc_mode;
+param->scene_change_detection   = svt_enc->scd;
+param->qp   = svt_enc->qp;
+
+if (svt_enc->la_depth >= 0)
+param->look_ahead_distance  = svt_enc->la_depth;
+
+param->tile_columns = svt_enc->tile_columns;
+param->tile_rows= svt_enc->tile_rows;
+
+#if SVT_AV1_CHECK_VERSION(0, 9, 1)
+while ((en = av_dict_get(svt_enc->svtav1_opts, "", en, 
AV_DICT_IGNORE_SUFFIX))) {
+EbErrorType ret = svt_av1_enc_parse_parameter(param, en->key, 
en->value);
+if (ret != EB_ErrorNone) {
+int level = (avctx->err_recognition & AV_EF_EXPLODE) ? 
AV_LOG_ERROR : AV_LOG_WARNING;
+av_log(avctx, level, "Error parsing option %s: %s.\n", en->key, 
en->value);
+if (avctx->err_recognition & AV_EF_EXPLODE)
+return AVERROR(EINVAL);
+}
+}
+#else
+if ((en = av_dict_get(svt_enc->svtav1_opts, "", NULL, 
AV_DICT_IGNORE_SUFFIX))) {
+int level = (avctx->err_recognition & AV_EF_EXPLODE) ? AV_LOG_ERROR : 
AV_LOG_WARNING;
+av_log(avctx, level, "svt-params needs libavcodec to be compiled with 
SVT-AV1 "
+ "headers >= 0.9.1.\n");
+if (avctx->err_recognition & AV_EF_EXPLODE)
+return AVERROR(ENOSYS);
+}
+#endif
 
 param->source_width = avctx->width;
 param->source_height= avctx->height;
@@ -184,14 +220,6 @@ static int config_enc_params(EbSvtAv1EncConfiguration 
*param,
 param->profile = FF_PROFILE_AV1_HIGH;
 }
 
-// Update param from options
-param->hierarchical_levels  = svt_enc->hierarchical_level;
-param->enc_mode = svt_enc->enc_mode;
-param->tier = svt_enc->tier;
-param->rate_control_mode= svt_enc->rc_mode;
-param->scene_change_detection   = svt_enc->scd;
-param->qp   = svt_enc->qp;
-
 param->target_bit_rate  = avctx->bit_rate;
 
 if (avctx->gop_size > 0)
@@ -214,12 +242,6 @@ static int config_enc_params(EbSvtAv1EncConfiguration 
*param,
 /* 2 = IDR, closed GOP, 1 = CRA, open GOP */
 param->intra_refresh_type = avctx->flags & AV_CODEC_FLAG_CLOSED_GOP ? 2 : 
1;
 
-if (svt_enc->la_depth >= 0)
-param->look_ahead_distance  = svt_enc->la_depth;
-
-param->tile_columns = svt_enc->tile_columns;
-param->tile_rows= svt_enc->tile_rows;
-
 return 0;
 }
 
@@ -535,6 +557,8 @@ static const AVOption options[] = {
 { "tile_columns", "Log2 of number of tile columns to use", 
OFFSET(tile_columns), AV_OPT_TYPE_INT, {.i64 = 0}, 0, 4, VE},
 { "tile_rows", "Log2 of number of tile rows to use", OFFSET(tile_rows), 
AV_OPT_TYPE_INT, {.i64 = 0}, 0, 6, VE},
 
+{ "svtav1-params", "Set the SVT-AV1 configuration using a :-separated list 
of key=value parameters", OFFSET(svtav1_opts), AV_OPT_TYPE_DICT, { 0 }, 0, 0, 
VE },
+
 {NULL},
 };
 
-- 
2.35.1

___
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".


Re: [FFmpeg-devel] [PATCH v6 1/1] avformat: Add IPFS protocol support.

2022-02-16 Thread Mark Gaiser
On Wed, Feb 16, 2022 at 10:40 AM Tomas Härdin  wrote:

>
> > +// Test $IPFS_GATEWAY.
> > +if (getenv("IPFS_GATEWAY") != NULL) {
> > +snprintf(c->gateway_buffer, sizeof(c->gateway_buffer), "%s",
> > + getenv("IPFS_GATEWAY"));
>
> might want to error check this one
>
> > +ret = 1;
> > +goto err;
> > +} else
> > +av_log(h, AV_LOG_DEBUG, "$IPFS_GATEWAY is empty.\n");
> > +
> > +// We need to know the IPFS folder to - eventually - read the
> > contents of
> > +// the "gateway" file which would tell us the gateway to use.
> > +if (getenv("IPFS_PATH") == NULL) {
> > +av_log(h, AV_LOG_DEBUG, "$IPFS_PATH is empty.\n");
> > +
> > +// Try via the home folder.
> > +if (getenv("HOME") == NULL) {
> > +av_log(h, AV_LOG_ERROR, "$HOME appears to be empty.\n");
> > +ret = AVERROR(EINVAL);
> > +goto err;
> > +}
> > +
> > +// Verify the composed path fits.
> > +if (snprintf(ipfs_full_data_folder,
> > sizeof(ipfs_full_data_folder),
> > + "%s/.ipfs/", getenv("HOME")) >
> > sizeof(ipfs_full_data_folder)) {
>
> >= not > since snprintf() returns the number of character written sans
> the terminating NUL
>
> > +av_log(h, AV_LOG_ERROR, "The IPFS data path exceeds the
> > max path length (%li)\n", sizeof(ipfs_full_data_folder));
> > +ret = AVERROR(EINVAL);
> > +goto err;
> > +}
> > +
> > +// Stat the folder.
> > +// It should exist in a default IPFS setup when run as local
> > user.
> > +#ifndef _WIN32
> > +stat_ret = stat(ipfs_full_data_folder, );
> > +#else
> > +stat_ret = win32_stat(ipfs_full_data_folder, );
> > +#endif
> > +if (stat_ret < 0) {
> > +av_log(h, AV_LOG_INFO, "Unable to find IPFS folder. We
> > tried:\n");
> > +av_log(h, AV_LOG_INFO, "- $IPFS_PATH, which was
> > empty.\n");
> > +av_log(h, AV_LOG_INFO, "- $HOME/.ipfs (full uri: %s)
> > which doesn't exist.\n", ipfs_full_data_folder);
> > +ret = AVERROR(ENOENT);
> > +goto err;
> > +}
> > +} else
> > +snprintf(ipfs_full_data_folder,
> > sizeof(ipfs_full_data_folder), "%s",
> > + getenv("IPFS_PATH"));
>
> not checked
>
> > +
> > +// Copy the fully composed gateway path into ipfs_gateway_file.
> > +if (snprintf(ipfs_gateway_file, sizeof(gateway_file_data),
> > "%sgateway",
> > + ipfs_full_data_folder) > sizeof(ipfs_gateway_file))
> > {
>
> >=
>
> > +// At this point gateway_file_data contains at least something.
> > +// Copy it into c->gateway_buffer.
> > +if (snprintf(c->gateway_buffer, sizeof(c->gateway_buffer), "%s",
> > + gateway_file_data) > 0) {
> > +ret = 1;
> > +goto err;
> > +} else
> > +av_log(h, AV_LOG_DEBUG, "Unknown error in the IPFS gateway
> > file.\n");
>
> why not read directly into c->gateway_buffer?
>

Yes! That would be cleaner, thank you for this suggestion!
I didn't do that before because there was no buffer like this before. But
now that it's there, I might as well use it.

>
> > +// Pppulate c->gateway_buffer with whatever is in c->gateway
> > +if (c->gateway != NULL)
> > +snprintf(c->gateway_buffer, sizeof(c->gateway_buffer), "%s",
> > c->gateway);
> > +else
> > +c->gateway_buffer[0] = '\0';
> > +
> > +// Only do the auto detection logic if the gateway_buffer is
> > empty
> > +if (c->gateway_buffer[0] == '\0') {
>
> these two ifs can be rolled together
>

Smart!

>
> > +// Concatenate the url.
> > +// This ends up with something like:
> > http://localhost:8080/ipfs/Qm.
> > +fulluri = av_asprintf("%s%s%s", c->gateway_buffer,
> > +  (is_ipns) ? "ipns/" : "ipfs/",
> > +  ipfs_cid);
>
> it is here that I mean you can stick in the / if necessary. that would
> make the code much simpler
>

Would it?
I specifically tried to keep gateway url adjustments in
sanitize_ipfs_gateway.
At this moment all that logic is in sanitize_ipfs_gateway. Are you sure
you want me to pull out one part and have it here instead?

Adding it here would essentially wrap the first argument in a ternary like:
(c->gateway_buffer[strlen(c->gateway_buffer) - 1] == '/') ? "%s%s%s" :
"%s/%s%s"

I prefer to keep this in sanitize_ipfs_gateway.
I'll wait for your response on this one to see if I need to move it or if
it can stay as is.



>
> /Tomas
>
>
___
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".


Re: [FFmpeg-devel] [PATCH v3 2/4] avformat/imf: fix missing error reporting when opening resources

2022-02-16 Thread Zane van Iperen





On 3/2/22 14:07, p...@sandflow.com wrote:

From: Pierre-Anthony Lemieux 

---
  libavformat/imfdec.c | 4 +++-
  1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/libavformat/imfdec.c b/libavformat/imfdec.c
index e6a1020ecc..658ddc40f2 100644
--- a/libavformat/imfdec.c
+++ b/libavformat/imfdec.c
@@ -550,7 +550,9 @@ static int set_context_streams_from_tracks(AVFormatContext 
*s)
  AVStream *first_resource_stream;
  
  /* Open the first resource of the track to get stream information */

-open_track_resource_context(s, >tracks[i]->resources[0]);
+ret = open_track_resource_context(s, >tracks[i]->resources[0]);
+if (ret)
+return ret;
  first_resource_stream = c->tracks[i]->resources[0].ctx->streams[0];
  av_log(s, AV_LOG_DEBUG, "Open the first resource of track %d\n", 
c->tracks[i]->index);
  


Can you please squash this into the previous patch?

The rest looks mostly okay.
___
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] tests/checkasm/nlmeans: Add check for av_calloc

2022-02-16 Thread Jiasheng Jiang
As the potential failure of the av_calloc(), it should be better
to check it and fail() if fails in order to avoid the dereference
of the NULL pointer.

Fixes: f679711c1b ("checkasm: add vf_nlmeans test for ssd_integral_image")
Signed-off-by: Jiasheng Jiang 
---
 tests/checkasm/vf_nlmeans.c | 14 --
 1 file changed, 12 insertions(+), 2 deletions(-)

diff --git a/tests/checkasm/vf_nlmeans.c b/tests/checkasm/vf_nlmeans.c
index 87474d6803..82370bbeec 100644
--- a/tests/checkasm/vf_nlmeans.c
+++ b/tests/checkasm/vf_nlmeans.c
@@ -47,9 +47,9 @@ void checkasm_check_nlmeans(void)
 const int ii_h = h + e*2;
 const int ii_lz_32 = FFALIGN(ii_w + 1, 4);
 uint32_t *ii_orig_ref = av_calloc(ii_h + 1, ii_lz_32 * 
sizeof(*ii_orig_ref));
-uint32_t *ii_ref = ii_orig_ref + ii_lz_32 + 1;
+uint32_t *ii_ref;
 uint32_t *ii_orig_new = av_calloc(ii_h + 1, ii_lz_32 * 
sizeof(*ii_orig_new));
-uint32_t *ii_new = ii_orig_new + ii_lz_32 + 1;
+uint32_t *ii_new;
 const int src_lz = FFALIGN(w, 16);
 uint8_t *src = av_calloc(h, src_lz);
 
@@ -58,6 +58,16 @@ void checkasm_check_nlmeans(void)
  const uint8_t *s2, ptrdiff_t linesize2,
  int w, int h);
 
+if (!ii_orig_ref || !ii_orig_new || !src) {
+av_free(ii_orig_ref);
+av_free(ii_orig_new);
+av_free(src);
+fail();
+}
+
+ii_ref = ii_orig_ref + ii_lz_32 + 1;
+ii_new = ii_orig_new + ii_lz_32 + 1;
+
 randomize_buffer(src, h * src_lz);
 
 for (offy = -r; offy <= r; offy++) {
-- 
2.25.1

___
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".


Re: [FFmpeg-devel] [PATCH v6 1/1] avformat: Add IPFS protocol support.

2022-02-16 Thread Tomas Härdin

> +    // Test $IPFS_GATEWAY.
> +    if (getenv("IPFS_GATEWAY") != NULL) {
> +    snprintf(c->gateway_buffer, sizeof(c->gateway_buffer), "%s",
> + getenv("IPFS_GATEWAY"));

might want to error check this one

> +    ret = 1;
> +    goto err;
> +    } else
> +    av_log(h, AV_LOG_DEBUG, "$IPFS_GATEWAY is empty.\n");
> +
> +    // We need to know the IPFS folder to - eventually - read the
> contents of
> +    // the "gateway" file which would tell us the gateway to use.
> +    if (getenv("IPFS_PATH") == NULL) {
> +    av_log(h, AV_LOG_DEBUG, "$IPFS_PATH is empty.\n");
> +
> +    // Try via the home folder.
> +    if (getenv("HOME") == NULL) {
> +    av_log(h, AV_LOG_ERROR, "$HOME appears to be empty.\n");
> +    ret = AVERROR(EINVAL);
> +    goto err;
> +    }
> +
> +    // Verify the composed path fits.
> +    if (snprintf(ipfs_full_data_folder,
> sizeof(ipfs_full_data_folder),
> + "%s/.ipfs/", getenv("HOME")) >
> sizeof(ipfs_full_data_folder)) {

>= not > since snprintf() returns the number of character written sans
the terminating NUL

> +    av_log(h, AV_LOG_ERROR, "The IPFS data path exceeds the
> max path length (%li)\n", sizeof(ipfs_full_data_folder));
> +    ret = AVERROR(EINVAL);
> +    goto err;
> +    }
> +
> +    // Stat the folder.
> +    // It should exist in a default IPFS setup when run as local
> user.
> +#ifndef _WIN32
> +    stat_ret = stat(ipfs_full_data_folder, );
> +#else
> +    stat_ret = win32_stat(ipfs_full_data_folder, );
> +#endif
> +    if (stat_ret < 0) {
> +    av_log(h, AV_LOG_INFO, "Unable to find IPFS folder. We
> tried:\n");
> +    av_log(h, AV_LOG_INFO, "- $IPFS_PATH, which was
> empty.\n");
> +    av_log(h, AV_LOG_INFO, "- $HOME/.ipfs (full uri: %s)
> which doesn't exist.\n", ipfs_full_data_folder);
> +    ret = AVERROR(ENOENT);
> +    goto err;
> +    }
> +    } else
> +    snprintf(ipfs_full_data_folder,
> sizeof(ipfs_full_data_folder), "%s",
> + getenv("IPFS_PATH"));

not checked

> +
> +    // Copy the fully composed gateway path into ipfs_gateway_file.
> +    if (snprintf(ipfs_gateway_file, sizeof(gateway_file_data),
> "%sgateway",
> + ipfs_full_data_folder) > sizeof(ipfs_gateway_file))
> {

>=

> +    // At this point gateway_file_data contains at least something.
> +    // Copy it into c->gateway_buffer.
> +    if (snprintf(c->gateway_buffer, sizeof(c->gateway_buffer), "%s",
> + gateway_file_data) > 0) {
> +    ret = 1;
> +    goto err;
> +    } else
> +    av_log(h, AV_LOG_DEBUG, "Unknown error in the IPFS gateway
> file.\n");

why not read directly into c->gateway_buffer?

> +    // Pppulate c->gateway_buffer with whatever is in c->gateway
> +    if (c->gateway != NULL)
> +    snprintf(c->gateway_buffer, sizeof(c->gateway_buffer), "%s",
> c->gateway);
> +    else
> +    c->gateway_buffer[0] = '\0';
> +
> +    // Only do the auto detection logic if the gateway_buffer is
> empty
> +    if (c->gateway_buffer[0] == '\0') {

these two ifs can be rolled together

> +    // Concatenate the url.
> +    // This ends up with something like:  
> http://localhost:8080/ipfs/Qm.
> +    fulluri = av_asprintf("%s%s%s", c->gateway_buffer,
> +  (is_ipns) ? "ipns/" : "ipfs/",
> +  ipfs_cid);

it is here that I mean you can stick in the / if necessary. that would
make the code much simpler

/Tomas

___
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".


Re: [FFmpeg-devel] [PATCH 2/2] fate/h264: add test case for h264-loss_packet_for_prev_frame_num_offset

2022-02-16 Thread Steven Liu


> 2022年2月16日 下午4:51,Steven Liu  写道:
> 
> From: Steven Liu 
> 
> Signed-off-by: Steven Liu 
> ---
> tests/fate/h264.mak   |  2 ++
> ...h264-loss_packet_for_prev_frame_num_offset | 23 +++
> 2 files changed, 25 insertions(+)
> create mode 100644 tests/ref/fate/h264-loss_packet_for_prev_frame_num_offset
> 
> diff --git a/tests/fate/h264.mak b/tests/fate/h264.mak
> index e075b6f67f..142a4ea708 100644
> --- a/tests/fate/h264.mak
> +++ b/tests/fate/h264.mak
> @@ -195,6 +195,7 @@ FATE_H264  := $(FATE_H264:%=fate-h264-conformance-%)  
>   \
>   fate-h264-lossless\
>   fate-h264-3386\
>   fate-h264-missing-frame   \
> +  fate-h264-loss_packet_for_prev_frame_num_offset   \
>   fate-h264-ref-pic-mod-overflow\
>   fate-h264-timecode\
>   fate-h264-encparams
> @@ -442,6 +443,7 @@ fate-h264-twofields-packet:   CMD = 
> framecrc -i $(TARGET_SAM
> fate-h264-unescaped-extradata:CMD = framecrc -i 
> $(TARGET_SAMPLES)/h264/unescaped_extradata.mp4 -an -frames 10
> fate-h264-3386:   CMD = framecrc -i 
> $(TARGET_SAMPLES)/h264/bbc2.sample.h264
> fate-h264-missing-frame:  CMD = framecrc -i 
> $(TARGET_SAMPLES)/h264/nondeterministic_cut.h264
> +fate-h264-loss_packet_for_prev_frame_num_offset:  CMD = framecrc -i 
> $(TARGET_SAMPLES)/h264/loss_packet_for_prev_frame_num_offset.h264
> fate-h264-timecode:   CMD = framecrc -i 
> $(TARGET_SAMPLES)/h264/crew_cif_timecode-2.h264
> 
> fate-h264-reinit-%:   CMD = framecrc -i 
> $(TARGET_SAMPLES)/h264/$(@:fate-h264-%=%).h264 -vf 
> scale,format=yuv444p10le,scale=w=352:h=288
> diff --git a/tests/ref/fate/h264-loss_packet_for_prev_frame_num_offset 
> b/tests/ref/fate/h264-loss_packet_for_prev_frame_num_offset
> new file mode 100644
> index 00..df8a88f5d4
> --- /dev/null
> +++ b/tests/ref/fate/h264-loss_packet_for_prev_frame_num_offset
> @@ -0,0 +1,23 @@
> +#tb 0: 1/25
> +#media_type 0: video
> +#codec_id 0: rawvideo
> +#dimensions 0: 1280x720
> +#sar 0: 0/1
> +0,  0,  0,1,  1382400, 0xa21b9a12
> +0,  1,  1,1,  1382400, 0x9f266c66
> +0,  2,  2,1,  1382400, 0x08604d2c
> +0,  3,  3,1,  1382400, 0x0f59c63a
> +0,  4,  4,1,  1382400, 0xe9588c5d
> +0,  5,  5,1,  1382400, 0x01c3559a
> +0,  6,  6,1,  1382400, 0x40791f04
> +0,  7,  7,1,  1382400, 0x2047c562
> +0,  8,  8,1,  1382400, 0x24f7b450
> +0,  9,  9,1,  1382400, 0xfa3d00ed
> +0, 10, 10,1,  1382400, 0x8c3384ed
> +0, 11, 11,1,  1382400, 0xfa7c59e0
> +0, 12, 12,1,  1382400, 0x0d16c5d1
> +0, 13, 13,1,  1382400, 0x665bd32c
> +0, 14, 14,1,  1382400, 0xe8771b9d
> +0, 15, 15,1,  1382400, 0xd9824ab1
> +0, 16, 16,1,  1382400, 0xa7264481
> +0, 17, 17,1,  1382400, 0xdcaec99a
> -- 
> 2.25.0
> 
> ___
> 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".
> 

attach test file


loss_packet_for_prev_frame_num_offset.h264
Description: Binary data

Thanks

Steven Liu

___
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 1/2] avcodec/h264_slice: compute prev_frame_num_offset to correct value

2022-02-16 Thread Steven Liu
From: Shitao Wang 

If H.264 stream decode under loss packet transport network, h264_slice
will process prev_frame_num_offset in wrong way, it will dup picture,
This is different to JM, so compute the prev_frame_num_offset when
prev_frame_num >= (1 << sps->log2_max_frame_num), then it will
same as JM.

Signed-off-by: Shitao Wang 
Signed-off-by: Steven Liu 
---
 libavcodec/h264_slice.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/libavcodec/h264_slice.c b/libavcodec/h264_slice.c
index 110a41772a..6f21c48b2d 100644
--- a/libavcodec/h264_slice.c
+++ b/libavcodec/h264_slice.c
@@ -1667,6 +1667,8 @@ static int h264_field_start(H264Context *h, const 
H264SliceContext *sl,
 }
 
 h->poc.prev_frame_num++;
+if (h->poc.prev_frame_num >= (1 << sps->log2_max_frame_num))
+h->poc.prev_frame_num_offset += 1 << sps->log2_max_frame_num;
 h->poc.prev_frame_num%= 1 << sps->log2_max_frame_num;
 h->cur_pic_ptr->frame_num = h->poc.prev_frame_num;
 h->cur_pic_ptr->invalid_gap = !sps->gaps_in_frame_num_allowed_flag;
-- 
2.25.0

___
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 2/2] fate/h264: add test case for h264-loss_packet_for_prev_frame_num_offset

2022-02-16 Thread Steven Liu
From: Steven Liu 

Signed-off-by: Steven Liu 
---
 tests/fate/h264.mak   |  2 ++
 ...h264-loss_packet_for_prev_frame_num_offset | 23 +++
 2 files changed, 25 insertions(+)
 create mode 100644 tests/ref/fate/h264-loss_packet_for_prev_frame_num_offset

diff --git a/tests/fate/h264.mak b/tests/fate/h264.mak
index e075b6f67f..142a4ea708 100644
--- a/tests/fate/h264.mak
+++ b/tests/fate/h264.mak
@@ -195,6 +195,7 @@ FATE_H264  := $(FATE_H264:%=fate-h264-conformance-%)
\
   fate-h264-lossless\
   fate-h264-3386\
   fate-h264-missing-frame   \
+  fate-h264-loss_packet_for_prev_frame_num_offset   \
   fate-h264-ref-pic-mod-overflow\
   fate-h264-timecode\
   fate-h264-encparams
@@ -442,6 +443,7 @@ fate-h264-twofields-packet:   CMD = 
framecrc -i $(TARGET_SAM
 fate-h264-unescaped-extradata:CMD = framecrc -i 
$(TARGET_SAMPLES)/h264/unescaped_extradata.mp4 -an -frames 10
 fate-h264-3386:   CMD = framecrc -i 
$(TARGET_SAMPLES)/h264/bbc2.sample.h264
 fate-h264-missing-frame:  CMD = framecrc -i 
$(TARGET_SAMPLES)/h264/nondeterministic_cut.h264
+fate-h264-loss_packet_for_prev_frame_num_offset:  CMD = framecrc -i 
$(TARGET_SAMPLES)/h264/loss_packet_for_prev_frame_num_offset.h264
 fate-h264-timecode:   CMD = framecrc -i 
$(TARGET_SAMPLES)/h264/crew_cif_timecode-2.h264
 
 fate-h264-reinit-%:   CMD = framecrc -i 
$(TARGET_SAMPLES)/h264/$(@:fate-h264-%=%).h264 -vf 
scale,format=yuv444p10le,scale=w=352:h=288
diff --git a/tests/ref/fate/h264-loss_packet_for_prev_frame_num_offset 
b/tests/ref/fate/h264-loss_packet_for_prev_frame_num_offset
new file mode 100644
index 00..df8a88f5d4
--- /dev/null
+++ b/tests/ref/fate/h264-loss_packet_for_prev_frame_num_offset
@@ -0,0 +1,23 @@
+#tb 0: 1/25
+#media_type 0: video
+#codec_id 0: rawvideo
+#dimensions 0: 1280x720
+#sar 0: 0/1
+0,  0,  0,1,  1382400, 0xa21b9a12
+0,  1,  1,1,  1382400, 0x9f266c66
+0,  2,  2,1,  1382400, 0x08604d2c
+0,  3,  3,1,  1382400, 0x0f59c63a
+0,  4,  4,1,  1382400, 0xe9588c5d
+0,  5,  5,1,  1382400, 0x01c3559a
+0,  6,  6,1,  1382400, 0x40791f04
+0,  7,  7,1,  1382400, 0x2047c562
+0,  8,  8,1,  1382400, 0x24f7b450
+0,  9,  9,1,  1382400, 0xfa3d00ed
+0, 10, 10,1,  1382400, 0x8c3384ed
+0, 11, 11,1,  1382400, 0xfa7c59e0
+0, 12, 12,1,  1382400, 0x0d16c5d1
+0, 13, 13,1,  1382400, 0x665bd32c
+0, 14, 14,1,  1382400, 0xe8771b9d
+0, 15, 15,1,  1382400, 0xd9824ab1
+0, 16, 16,1,  1382400, 0xa7264481
+0, 17, 17,1,  1382400, 0xdcaec99a
-- 
2.25.0

___
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".


Re: [FFmpeg-devel] [PATCH] avformat/nutdec: Add check for avformat_new_stream

2022-02-16 Thread Jiasheng Jiang
Andreas Rheinhardt:
>> As the potential failure of the memory allocation,
>> the avformat_new_stream() could return NULL pointer.
>> Therefore, it should be better to check it and return
>> error if fails.
>> 
>> Fixes: 84ad31ff18 ("lavf: replace av_new_stream->avformat_new_stream part 
>> II.")
>
> This commit did not introduce this bug; it merely replaced the unchecked
> function.
>
> If you look at nut_read_header() you will see that it just retries even
> on allocation failure. So this is not a complete fix. And if it retries
> and finds a different packet header, it adds ever more streams, because
> the already created streams have not been deleted. A proper fix would
> need to check the return value of decode_main_header for ENOMEM, but if
> time_base_count were invalid and huge, one could get an allocation error
> even though there might be a valid header somewhere else. So one would
> need an equivalent of NUT_MAX_STREAMS for timebases or some other
> criterion to rule this out.

Fine, I have submit a v2 to fix the problems above.

Jiang

___
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".


Re: [FFmpeg-devel] [PATCH v2] avformat/nutdec: Add check for avformat_new_stream

2022-02-16 Thread Jiasheng Jiang
Andreas Rheinhardt:
>> As the potential failure of the memory allocation,
>> the avformat_new_stream() could return NULL pointer.
>> Therefore, it should be better to check it and return
>> error if fails.
>> 
>> Fixes: 84ad31ff18 ("lavf: replace av_new_stream->avformat_new_stream part 
>> II.")
>
> This commit did not introduce this bug; it merely replaced the unchecked
> function.
>
> If you look at nut_read_header() you will see that it just retries even
> on allocation failure. So this is not a complete fix. And if it retries
> and finds a different packet header, it adds ever more streams, because
> the already created streams have not been deleted. A proper fix would
> need to check the return value of decode_main_header for ENOMEM, but if
> time_base_count were invalid and huge, one could get an allocation error
> even though there might be a valid header somewhere else. So one would
> need an equivalent of NUT_MAX_STREAMS for timebases or some other
> criterion to rule this out.

Fine, I have submit a v2 to fix the problems above.

Jiang

___
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] avformat/nutdec: Add check for avformat_new_stream

2022-02-16 Thread Jiasheng Jiang
As the potential failure of the memory allocation,
the avformat_new_stream() could return NULL pointer.
Therefore, it should be better to check it and return
error if fails.
Also, the caller, nut_read_header(), needs to deal with
the return value of the decode_main_header() and return
error if memory allocation fails.
To avoid mishandling the invalid 'time_base_count', another
check for the 'time_base_count' is needed and return different
error if fails.

Fixes: 619d8e2e58 ("updating nut demuxer to latest spec no muxing yet no index 
yet no seeking yet libnuts crcs dont match mine (didnt investigate yet) 
samplerate is stored wrong by libnut (demuxer has a workaround) code is not 
clean or beautifull yet, but i thought its better to commit early before 
someone unneccesarily wastes his time duplicating the work demuxer split from 
muxer")
Signed-off-by: Jiasheng Jiang 
---
Changelog:

v1 -> v2

* Change 1. Add the error handling for ENOMEM from decode_main_header()
in nut_read_header().
* Change 2. Check for the 'time_base_count'.
---
 libavformat/nutdec.c | 21 +
 1 file changed, 17 insertions(+), 4 deletions(-)

diff --git a/libavformat/nutdec.c b/libavformat/nutdec.c
index 0a8a700acf..4cbccb20d9 100644
--- a/libavformat/nutdec.c
+++ b/libavformat/nutdec.c
@@ -220,6 +220,10 @@ static int decode_main_header(NUTContext *nut)
 }
 
 GET_V(nut->time_base_count, tmp > 0 && tmp < INT_MAX / sizeof(AVRational) 
&& tmp < length/2);
+
+if (nut->time_base_count > NUT_MAX_STREAMS)
+return AVERROR_INVALIDDATA;
+
 nut->time_base = av_malloc_array(nut->time_base_count, sizeof(AVRational));
 if (!nut->time_base)
 return AVERROR(ENOMEM);
@@ -351,8 +355,13 @@ static int decode_main_header(NUTContext *nut)
 ret = AVERROR(ENOMEM);
 goto fail;
 }
-for (i = 0; i < stream_count; i++)
-avformat_new_stream(s, NULL);
+for (i = 0; i < stream_count; i++) {
+if (!avformat_new_stream(s, NULL)) {
+av_free(nut->stream);
+ret = AVERROR(ENOMEM);
+goto fail;
+}
+}
 
 return 0;
 fail:
@@ -800,19 +809,23 @@ static int nut_read_header(AVFormatContext *s)
 NUTContext *nut = s->priv_data;
 AVIOContext *bc = s->pb;
 int64_t pos;
-int initialized_stream_count;
+int initialized_stream_count, ret;
 
 nut->avf = s;
 
 /* main header */
 pos = 0;
+ret = 0;
 do {
+if (ret == AVERROR(ENOMEM))
+return ret;
+
 pos = find_startcode(bc, MAIN_STARTCODE, pos) + 1;
 if (pos < 0 + 1) {
 av_log(s, AV_LOG_ERROR, "No main startcode found.\n");
 return AVERROR_INVALIDDATA;
 }
-} while (decode_main_header(nut) < 0);
+} while ((ret = decode_main_header(nut)) < 0);
 
 /* stream headers */
 pos = 0;
-- 
2.25.1

___
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".


Re: [FFmpeg-devel] [PATCH] avfilter/fifo: Remove unused buffer frame

2022-02-16 Thread Paul B Mahol
On Wed, Feb 16, 2022 at 7:02 AM Andreas Rheinhardt <
andreas.rheinha...@outlook.com> wrote:

> Forgotten in 03c8fe49ea3f2a2444607e541dff15a1ccd7f0c2.
>
> Signed-off-by: Andreas Rheinhardt 
> ---
> What is actually the use-case of these filters? The documentation states
> that they are auto-inserted, yet this is no longer true any more since
> 4ca1fb9d2a91757c8c4c34dd456abf340e3f765f.
>

Now avfilter buffers internally if needed, so filters are no longer useful.
Also they seems to call malloc for every input frame.


>
>  libavfilter/fifo.c | 9 -
>  1 file changed, 9 deletions(-)
>
> diff --git a/libavfilter/fifo.c b/libavfilter/fifo.c
> index 1c7be88ae1..8b34055fde 100644
> --- a/libavfilter/fifo.c
> +++ b/libavfilter/fifo.c
> @@ -38,13 +38,6 @@ typedef struct Buf {
>  typedef struct FifoContext {
>  Buf  root;
>  Buf *last;   ///< last buffered frame
> -
> -/**
> - * When a specific number of output samples is requested, the partial
> - * buffer is stored here
> - */
> -AVFrame *out;
> -int allocated_samples;  ///< number of samples out was allocated
> for
>  } FifoContext;
>
>  static av_cold int init(AVFilterContext *ctx)
> @@ -65,8 +58,6 @@ static av_cold void uninit(AVFilterContext *ctx)
>  av_frame_free(>frame);
>  av_free(buf);
>  }
> -
> -av_frame_free(>out);
>  }
>
>  static int add_to_queue(AVFilterLink *inlink, AVFrame *frame)
> --
> 2.32.0
>
> ___
> 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 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".