Re: [FFmpeg-devel] [PATCH v3 1/2] avcodec: add external enc libvvenc for H266/VVC

2024-05-16 Thread Christian


> On 14. May 2024, at 18:49, Andreas Rheinhardt 
>  wrote:
> 
> Christian Bartnik:
>> From: Thomas Siedel 
>> 
>> Add external encoder VVenC for H266/VVC encoding.
>> Register new encoder libvvenc.
>> Add libvvenc to wrap the vvenc interface.
>> libvvenc implements encoder option: preset,qp,period,subjopt,
>> vvenc-params,levelidc,tier.
>> Enable encoder by adding --enable-libvvenc in configure step.
>> 
>> Co-authored-by: Christian Bartnik chris1031...@gmail.com
>> Signed-off-by: Christian Bartnik 
>> ---
>> configure  |   4 +
>> doc/encoders.texi  |  65 +
>> libavcodec/Makefile|   1 +
>> libavcodec/allcodecs.c |   1 +
>> libavcodec/libvvenc.c  | 566 +
>> 5 files changed, 637 insertions(+)
>> create mode 100644 libavcodec/libvvenc.c
>> 
>> diff --git a/configure b/configure
>> index a909b0689c..5d9a14821b 100755
>> --- a/configure
>> +++ b/configure
>> @@ -293,6 +293,7 @@ External library support:
>>   --enable-libvorbis   enable Vorbis en/decoding via libvorbis,
>>native implementation exists [no]
>>   --enable-libvpx  enable VP8 and VP9 de/encoding via libvpx [no]
>> +  --enable-libvvencenable H.266/VVC encoding via vvenc [no]
>>   --enable-libwebp enable WebP encoding via libwebp [no]
>>   --enable-libx264 enable H.264 encoding via x264 [no]
>>   --enable-libx265 enable HEVC encoding via x265 [no]
>> @@ -1966,6 +1967,7 @@ EXTERNAL_LIBRARY_LIST="
>> libvmaf
>> libvorbis
>> libvpx
>> +libvvenc
>> libwebp
>> libxevd
>> libxeve
>> @@ -3558,6 +3560,7 @@ libvpx_vp8_decoder_deps="libvpx"
>> libvpx_vp8_encoder_deps="libvpx"
>> libvpx_vp9_decoder_deps="libvpx"
>> libvpx_vp9_encoder_deps="libvpx"
>> +libvvenc_encoder_deps="libvvenc"
>> libwebp_encoder_deps="libwebp"
>> libwebp_anim_encoder_deps="libwebp"
>> libx262_encoder_deps="libx262"
>> @@ -7025,6 +7028,7 @@ enabled libvpx&& {
>> die "libvpx enabled but no supported decoders found"
>> fi
>> }
>> +enabled libvvenc  && require_pkg_config libvvenc "libvvenc >= 
>> 1.6.1" "vvenc/vvenc.h" vvenc_get_version
>> 
>> enabled libwebp   && {
>> enabled libwebp_encoder  && require_pkg_config libwebp "libwebp >= 
>> 0.2.0" webp/encode.h WebPGetEncoderVersion
>> diff --git a/doc/encoders.texi b/doc/encoders.texi
>> index c82f316f94..92aab17c49 100644
>> --- a/doc/encoders.texi
>> +++ b/doc/encoders.texi
>> @@ -2378,6 +2378,71 @@ Indicates frame duration
>> For more information about libvpx see:
>> @url{http://www.webmproject.org/}
>> 
>> +@section libvvenc
>> +
>> +VVenC H.266/VVC encoder wrapper.
>> +
>> +This encoder requires the presence of the libvvenc headers and library
>> +during configuration. You need to explicitly configure the build with
>> +@option{--enable-libvvenc}.
>> +
>> +The VVenC project website is at
>> +@url{https://github.com/fraunhoferhhi/vvenc}.
>> +
>> +@subsection Supported Pixel Formats
>> +
>> +VVenC supports only 10-bit color spaces as input. But the internal (encoded)
>> +bit depth can be set to 8-bit or 10-bit at runtime.
>> +
>> +@subsection Options
>> +
>> +@table @option
>> +@item b
>> +Sets target video bitrate.
>> +
>> +@item g
>> +Set the GOP size. Currently support for g=1 (Intra only) or default.
>> +
>> +@item preset
>> +Set the VVenC preset.
>> +
>> +@item levelidc
>> +Set level idc.
>> +
>> +@item tier
>> +Set vvc tier.
>> +
>> +@item qp
>> +Set constant quantization parameter.
>> +
>> +@item subopt @var{boolean}
>> +Set subjective (perceptually motivated) optimization. Default is 1 (on).
>> +
>> +@item bitdepth8 @var{boolean}
>> +Set 8bit coding mode instead of using 10bit. Default is 0 (off).
>> +
>> +@item period
>> +set (intra) refresh period in seconds.
>> +
>> +@item vvenc-params
>> +Set vvenc options using a list of @var{key}=@var{value} couples separated
>> +by ":". See @command{vvencapp --fullhelp} or @command{vvencFFapp 
>> --fullhelp} for a list of options.
>> +
>> +For example, the options might be provided as:
&

Re: [FFmpeg-devel] [PATCH v3 2/2] avcodec: add external dec libvvdec for H266/VVC

2024-05-17 Thread Christian



> On 14. May 2024, at 18:28, Lynne via ffmpeg-devel  
> wrote:
> 
> On 14/05/2024 17:09, Christian Bartnik wrote:
>> From: Thomas Siedel 
>> Add external decoder VVdeC for H266/VVC decoding.
>> Register new decoder libvvdec.
>> Add libvvdec to wrap the vvdec interface.
>> Enable decoder by adding --enable-libvvdec in configure step.
>> Co-authored-by: Christian Bartnik chris1031...@gmail.com
>> Signed-off-by: Christian Bartnik 
>> ---
>>  configure  |   5 +
>>  libavcodec/Makefile|   1 +
>>  libavcodec/allcodecs.c |   1 +
>>  libavcodec/libvvdec.c  | 617 +
>>  4 files changed, 624 insertions(+)
>>  create mode 100644 libavcodec/libvvdec.c
> 
> I would prefer to have this one skipped, as initially suggested.

Ok, the next patch version will only contain libvvenc


> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org <mailto:ffmpeg-devel@ffmpeg.org>
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
> 
> To unsubscribe, visit link above, or email
> ffmpeg-devel-requ...@ffmpeg.org <mailto: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".


Re: [FFmpeg-devel] [PATCH v4 1/1] avcodec: add external enc libvvenc for H266/VVC

2024-06-04 Thread Christian


> On 4. Jun 2024, at 11:21, Anton Khirnov  wrote:
> 
> Quoting Christian Bartnik (2024-05-28 18:26:29)
>> +static const AVOption options[] = {
>> +{ "passlogfile",  "Filename for 2 pass stats", OFFSET(stats), 
>> AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0, VE},
>> +{ "stats","Filename for 2 pass stats", OFFSET(stats), 
>> AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0, VE},
> 
> These option names conflict with ffmpeg CLI options.

I´m aware of this and I´m using exactly the same approach as libx264 does. 

passlogfile is overwriting the CLI option to make the generated passfile 
filename from the CLI availalbe to the codec.

In the review of my latest version of my patch I was told to use the 
'passlogfile' option.

Please let me know how I should pass the passlogfile filename from the CLI to 
the codec implementation.

> 
> -- 
> Anton Khirnov
> ___
> 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 v2 0/2] Add support for H266/VVC encoding

2024-05-04 Thread Christian
This patchset is based on the latest patchset from Thomas Siedel
(thomas...@spin-digital.com <mailto:thomas...@spin-digital.com>).
Since almost all changes from the patchset but libvvenc and libvvdec has been
merged this patch only implements the libvvenc and libvvdec wrapper
implementation.
As ffmpeg already has it´s own vvc decoder, feel free to cherry pick libvvenc
only.
The libvvenc patch only has been aligend to the current master without changing
the implementation.
The libvvdec patch has been cleaned up by removing the extradata parsing files
and using existing code from cbs_h266.

Christian Bartnik (2):
 avcodec: add external enc libvvenc for H266/VVC
 avcodec: add external dec libvvdec for H266/VVC

configure  |   9 +
libavcodec/Makefile|   2 +
libavcodec/allcodecs.c |   2 +
libavcodec/libvvdec.c  | 617 +
libavcodec/libvvenc.c  | 501 +
5 files changed, 1131 insertions(+)
create mode 100644 libavcodec/libvvdec.c
create mode 100644 libavcodec/libvvenc.c

--
2.34.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 v2 1/2] avcodec: add external enc libvvenc for H266/VVC

2024-05-04 Thread Christian
Add external encoder VVenC for H266/VVC encoding.
Register new encoder libvvenc.
Add libvvenc to wrap the vvenc interface.
libvvenc implements encoder option: preset,qp,period,subjopt,
vvenc-params,levelidc,tier.
Enable encoder by adding --enable-libvvenc in configure step.

Co-authored-by: Christian Bartnik chris1031...@gmail.com 
<mailto:chris1031...@gmail.com>
Signed-off-by: Christian Bartnik mailto:chris1031...@gmail.com>>
---
configure  |   4 +
libavcodec/Makefile|   1 +
libavcodec/allcodecs.c |   1 +
libavcodec/libvvenc.c  | 501 +
4 files changed, 507 insertions(+)
create mode 100644 libavcodec/libvvenc.c

diff --git a/configure b/configure
index ed74583a6f..cb312d9c73 100755
--- a/configure
+++ b/configure
@@ -293,6 +293,7 @@ External library support:
  --enable-libvorbis   enable Vorbis en/decoding via libvorbis,
   native implementation exists [no]
  --enable-libvpx  enable VP8 and VP9 de/encoding via libvpx [no]
+  --enable-libvvencenable H.266/VVC encoding via vvenc [no]
  --enable-libwebp enable WebP encoding via libwebp [no]
  --enable-libx264 enable H.264 encoding via x264 [no]
  --enable-libx265 enable HEVC encoding via x265 [no]
@@ -1966,6 +1967,7 @@ EXTERNAL_LIBRARY_LIST="
libvmaf
libvorbis
libvpx
+libvvenc
libwebp
libxevd
libxeve
@@ -3548,6 +3550,7 @@ libvpx_vp8_decoder_deps="libvpx"
libvpx_vp8_encoder_deps="libvpx"
libvpx_vp9_decoder_deps="libvpx"
libvpx_vp9_encoder_deps="libvpx"
+libvvenc_encoder_deps="libvvenc"
libwebp_encoder_deps="libwebp"
libwebp_anim_encoder_deps="libwebp"
libx262_encoder_deps="libx262"
@@ -7010,6 +7013,7 @@ enabled libvpx&& {
die "libvpx enabled but no supported decoders found"
fi
}
+enabled libvvenc  && require_pkg_config libvvenc "libvvenc >= 1.6.1" 
"vvenc/vvenc.h" vvenc_get_version

enabled libwebp   && {
enabled libwebp_encoder  && require_pkg_config libwebp "libwebp >= 
0.2.0" webp/encode.h WebPGetEncoderVersion
diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index cff6347bdb..54d85f6aaa 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -1155,6 +1155,7 @@ OBJS-$(CONFIG_LIBVPX_VP8_DECODER)   += libvpxdec.o
OBJS-$(CONFIG_LIBVPX_VP8_ENCODER) += libvpxenc.o
OBJS-$(CONFIG_LIBVPX_VP9_DECODER) += libvpxdec.o
OBJS-$(CONFIG_LIBVPX_VP9_ENCODER) += libvpxenc.o
+OBJS-$(CONFIG_LIBVVENC_ENCODER)   += libvvenc.o
OBJS-$(CONFIG_LIBWEBP_ENCODER)+= libwebpenc_common.o libwebpenc.o
OBJS-$(CONFIG_LIBWEBP_ANIM_ENCODER)   += libwebpenc_common.o 
libwebpenc_animencoder.o
OBJS-$(CONFIG_LIBX262_ENCODER)+= libx264.o
diff --git a/libavcodec/allcodecs.c b/libavcodec/allcodecs.c
index f4705651fb..bb2c3ce017 100644
--- a/libavcodec/allcodecs.c
+++ b/libavcodec/allcodecs.c
@@ -801,6 +801,7 @@ extern const FFCodec ff_libvpx_vp8_encoder;
extern const FFCodec ff_libvpx_vp8_decoder;
extern FFCodec ff_libvpx_vp9_encoder;
extern const FFCodec ff_libvpx_vp9_decoder;
+extern const FFCodec ff_libvvenc_encoder;
/* preferred over libwebp */
extern const FFCodec ff_libwebp_anim_encoder;
extern const FFCodec ff_libwebp_encoder;
diff --git a/libavcodec/libvvenc.c b/libavcodec/libvvenc.c
new file mode 100644
index 00..c459273f44
--- /dev/null
+++ b/libavcodec/libvvenc.c
@@ -0,0 +1,501 @@
+/*
+ * H.266 encoding using the VVenC library
+ *
+ * Copyright (C) 2022, Thomas Siedel
+ *
+ * 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 "config_components.h"
+
+#include 
+#include 
+#include 
+
+#include "avcodec.h"
+#include "codec_internal.h"
+#include "encode.h"
+#include "internal.h"
+#include "packet_internal.h"
+#include "profiles.h"
+
+#include "libavutil/avutil.h"
+#include "libavutil/mem.h"
+#include "libavutil/pixdesc.h"
+#include "libavutil/opt.h"
+#include "libavutil/common.h"
+#include "li

[FFmpeg-devel] [PATCH v2 2/2] avcodec: add external dec libvvdec for H266/VVC

2024-05-04 Thread Christian
Add external decoder VVdeC for H266/VVC decoding.
Register new decoder libvvdec.
Add vvc_parse_extradata to support parse/probe of vvcC stream input.
Add vvc_paramset that implements the parser of vvcC configuration boxes.
Add libvvdec to wrap the vvdec interface.
Enable decoder by adding --enable-libvvdec in configure step.

Co-authored-by: Christian Bartnik chris1031...@gmail.com 
<mailto:chris1031...@gmail.com>
Signed-off-by: Christian Bartnik mailto:chris1031...@gmail.com>>
---
configure  |   5 +
libavcodec/Makefile|   1 +
libavcodec/allcodecs.c |   1 +
libavcodec/libvvdec.c  | 617 +
4 files changed, 624 insertions(+)
create mode 100644 libavcodec/libvvdec.c

diff --git a/configure b/configure
index cb312d9c73..a7a9da3276 100755
--- a/configure
+++ b/configure
@@ -294,6 +294,7 @@ External library support:
   native implementation exists [no]
  --enable-libvpx  enable VP8 and VP9 de/encoding via libvpx [no]
  --enable-libvvencenable H.266/VVC encoding via vvenc [no]
+  --enable-libvvdecenable H.266/VVC decoding via vvdec [no]
  --enable-libwebp enable WebP encoding via libwebp [no]
  --enable-libx264 enable H.264 encoding via x264 [no]
  --enable-libx265 enable HEVC encoding via x265 [no]
@@ -1968,6 +1969,7 @@ EXTERNAL_LIBRARY_LIST="
libvorbis
libvpx
libvvenc
+libvvdec
libwebp
libxevd
libxeve
@@ -3551,6 +3553,8 @@ libvpx_vp8_encoder_deps="libvpx"
libvpx_vp9_decoder_deps="libvpx"
libvpx_vp9_encoder_deps="libvpx"
libvvenc_encoder_deps="libvvenc"
+libvvdec_decoder_deps="libvvdec"
+libvvdec_decoder_select="vvc_mp4toannexb_bsf"
libwebp_encoder_deps="libwebp"
libwebp_anim_encoder_deps="libwebp"
libx262_encoder_deps="libx262"
@@ -7014,6 +7018,7 @@ enabled libvpx&& {
fi
}
enabled libvvenc  && require_pkg_config libvvenc "libvvenc >= 1.6.1" 
"vvenc/vvenc.h" vvenc_get_version
+enabled libvvdec  && require_pkg_config libvvdec "libvvdec >= 1.6.0" 
"vvdec/vvdec.h" vvdec_get_version

enabled libwebp   && {
enabled libwebp_encoder  && require_pkg_config libwebp "libwebp >= 
0.2.0" webp/encode.h WebPGetEncoderVersion
diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index 54d85f6aaa..851b62179d 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -1156,6 +1156,7 @@ OBJS-$(CONFIG_LIBVPX_VP8_ENCODER)   += libvpxenc.o
OBJS-$(CONFIG_LIBVPX_VP9_DECODER) += libvpxdec.o
OBJS-$(CONFIG_LIBVPX_VP9_ENCODER) += libvpxenc.o
OBJS-$(CONFIG_LIBVVENC_ENCODER)   += libvvenc.o
+OBJS-$(CONFIG_LIBVVDEC_DECODER)   += libvvdec.o
OBJS-$(CONFIG_LIBWEBP_ENCODER)+= libwebpenc_common.o libwebpenc.o
OBJS-$(CONFIG_LIBWEBP_ANIM_ENCODER)   += libwebpenc_common.o 
libwebpenc_animencoder.o
OBJS-$(CONFIG_LIBX262_ENCODER)+= libx264.o
diff --git a/libavcodec/allcodecs.c b/libavcodec/allcodecs.c
index bb2c3ce017..9e0ad00b23 100644
--- a/libavcodec/allcodecs.c
+++ b/libavcodec/allcodecs.c
@@ -802,6 +802,7 @@ extern const FFCodec ff_libvpx_vp8_decoder;
extern FFCodec ff_libvpx_vp9_encoder;
extern const FFCodec ff_libvpx_vp9_decoder;
extern const FFCodec ff_libvvenc_encoder;
+extern const FFCodec ff_libvvdec_decoder;
/* preferred over libwebp */
extern const FFCodec ff_libwebp_anim_encoder;
extern const FFCodec ff_libwebp_encoder;
diff --git a/libavcodec/libvvdec.c b/libavcodec/libvvdec.c
new file mode 100644
index 00..7f94a81b37
--- /dev/null
+++ b/libavcodec/libvvdec.c
@@ -0,0 +1,617 @@
+/*
+ * H.266 decoding using the VVdeC library
+ *
+ * Copyright (C) 2022, Thomas Siedel
+ *
+ * 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 "config_components.h"
+
+#include 
+
+#include "libavutil/common.h"
+#include "libavutil/avutil.h"
+#include "libavutil/pixdesc.h"
+#include "libavutil/opt.h"
+#include "libavutil/imgutils.h"
+#include "libavutil/frame.h"
+#include "libavutil/m

Re: [FFmpeg-devel] [PATCH v2 1/2] avcodec: add external enc libvvenc for H266/VVC

2024-05-07 Thread Christian

> On 7. May 2024, at 03:53, Nuo Mi  wrote:
> 
> Hi Christian,
> Thank you for the patch.
> Let us review and merge the encoder part.
> 
> On Tue, May 7, 2024 at 1:05 AM Christian Bartnik  <mailto:chris1031...@gmail.com>>
> wrote:
> 
>> From: Thomas Siedel 
>> 
>> Add external encoder VVenC for H266/VVC encoding.
>> Register new encoder libvvenc.
>> Add libvvenc to wrap the vvenc interface.
>> libvvenc implements encoder option: preset,qp,period,subjopt,
>> vvenc-params,levelidc,tier.
>> Enable encoder by adding --enable-libvvenc in configure step.
>> 
>> Co-authored-by: Christian Bartnik chris1031...@gmail.com
>> Signed-off-by: Christian Bartnik 
>> ---
>> configure  |   4 +
>> libavcodec/Makefile|   1 +
>> libavcodec/allcodecs.c |   1 +
>> libavcodec/libvvenc.c  | 501 +
>> 4 files changed, 507 insertions(+)
>> create mode 100644 libavcodec/libvvenc.c
>> 
>> diff --git a/configure b/configure
>> index ed74583a6f..cb312d9c73 100755
>> --- a/configure
>> +++ b/configure
>> @@ -293,6 +293,7 @@ External library support:
>>   --enable-libvorbis   enable Vorbis en/decoding via libvorbis,
>>native implementation exists [no]
>>   --enable-libvpx  enable VP8 and VP9 de/encoding via libvpx [no]
>> +  --enable-libvvencenable H.266/VVC encoding via vvenc [no]
>>   --enable-libwebp enable WebP encoding via libwebp [no]
>>   --enable-libx264 enable H.264 encoding via x264 [no]
>>   --enable-libx265 enable HEVC encoding via x265 [no]
>> @@ -1966,6 +1967,7 @@ EXTERNAL_LIBRARY_LIST="
>> libvmaf
>> libvorbis
>> libvpx
>> +libvvenc
>> libwebp
>> libxevd
>> libxeve
>> @@ -3548,6 +3550,7 @@ libvpx_vp8_decoder_deps="libvpx"
>> libvpx_vp8_encoder_deps="libvpx"
>> libvpx_vp9_decoder_deps="libvpx"
>> libvpx_vp9_encoder_deps="libvpx"
>> +libvvenc_encoder_deps="libvvenc"
>> libwebp_encoder_deps="libwebp"
>> libwebp_anim_encoder_deps="libwebp"
>> libx262_encoder_deps="libx262"
>> @@ -7010,6 +7013,7 @@ enabled libvpx&& {
>> die "libvpx enabled but no supported decoders found"
>> fi
>> }
>> +enabled libvvenc  && require_pkg_config libvvenc "libvvenc >=
>> 1.6.1" "vvenc/vvenc.h" vvenc_get_version
>> 
>> enabled libwebp   && {
>> enabled libwebp_encoder  && require_pkg_config libwebp "libwebp
>>> = 0.2.0" webp/encode.h WebPGetEncoderVersion
>> diff --git a/libavcodec/Makefile b/libavcodec/Makefile
>> index cff6347bdb..54d85f6aaa 100644
>> --- a/libavcodec/Makefile
>> +++ b/libavcodec/Makefile
>> @@ -1155,6 +1155,7 @@ OBJS-$(CONFIG_LIBVPX_VP8_DECODER) +=
>> libvpxdec.o
>> OBJS-$(CONFIG_LIBVPX_VP8_ENCODER) += libvpxenc.o
>> OBJS-$(CONFIG_LIBVPX_VP9_DECODER) += libvpxdec.o
>> OBJS-$(CONFIG_LIBVPX_VP9_ENCODER) += libvpxenc.o
>> +OBJS-$(CONFIG_LIBVVENC_ENCODER)   += libvvenc.o
>> OBJS-$(CONFIG_LIBWEBP_ENCODER)+= libwebpenc_common.o
>> libwebpenc.o
>> OBJS-$(CONFIG_LIBWEBP_ANIM_ENCODER)   += libwebpenc_common.o
>> libwebpenc_animencoder.o
>> OBJS-$(CONFIG_LIBX262_ENCODER)+= libx264.o
>> diff --git a/libavcodec/allcodecs.c b/libavcodec/allcodecs.c
>> index f4705651fb..bb2c3ce017 100644
>> --- a/libavcodec/allcodecs.c
>> +++ b/libavcodec/allcodecs.c
>> @@ -801,6 +801,7 @@ extern const FFCodec ff_libvpx_vp8_encoder;
>> extern const FFCodec ff_libvpx_vp8_decoder;
>> extern FFCodec ff_libvpx_vp9_encoder;
>> extern const FFCodec ff_libvpx_vp9_decoder;
>> +extern const FFCodec ff_libvvenc_encoder;
>> /* preferred over libwebp */
>> extern const FFCodec ff_libwebp_anim_encoder;
>> extern const FFCodec ff_libwebp_encoder;
>> diff --git a/libavcodec/libvvenc.c b/libavcodec/libvvenc.c
>> new file mode 100644
>> index 00..c459273f44
>> --- /dev/null
>> +++ b/libavcodec/libvvenc.c
>> @@ -0,0 +1,501 @@
>> +/*
>> + * H.266 encoding using the VVenC library
>> + *
>> + * Copyright (C) 2022, Thomas Siedel
>> + *
>> + * 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

[FFmpeg-devel] [PATCH v4 0/1] Add support for H266/VVC encoding

2024-05-28 Thread Christian Bartnik
This patch is based on the latest patchset from Thomas Siedel
(thomas...@spin-digital.com).

The libvvenc patch has been changed with following changes:
  avcodec: add external encoder libvvenc for H266/VVC
- complete makeover (renaming,cleanup)
- remove struct VVenCOptions, move option members to VVenCContext
- using int-based version number for macros instead of major/minor/patch
- fix initialization of framerate
- use av_dict_iterate() insteat of av_dict_get()
- changing 2pass mode handling (not using vvenc-params anymore,
  using -pass and -stats|-passlogfile for statistics filename)
- remove options: bitdepth8, subjopt
- add option: qpa to switch between ssim/psnr based optimization (default: 
enabled)
- fix payload allocation check
- fix supported colorspace from AV_PIX_FMT_YUV420P10LE to AV_PIX_FMT_YUV420P10
- change level option by using either -level(int) or -level:v (char*) as 
libx264 does
- adding capability AV_CODEC_CAP_DR1
- adding caps_internal FF_CODEC_CAP_INIT_CLEANUP and remove calls: 
vvenc_encoder_close
- fftools/ffmpeg_mux_init.c set default stats filename as for libx264
- add vvenc documentation in doc/encoders.texi

The libvvdec patch has been removed from this patchset.

Christian Bartnik (1):
  avcodec: add external enc libvvenc for H266/VVC

 configure |   4 +
 doc/encoders.texi |  64 +
 fftools/ffmpeg_mux_init.c |   2 +-
 libavcodec/Makefile   |   1 +
 libavcodec/allcodecs.c|   1 +
 libavcodec/libvvenc.c | 524 ++
 6 files changed, 595 insertions(+), 1 deletion(-)
 create mode 100644 libavcodec/libvvenc.c

--
2.34.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 1/1] avcodec: add external enc libvvenc for H266/VVC

2024-05-28 Thread Christian Bartnik
From: Thomas Siedel 

Add external encoder VVenC for H266/VVC encoding.
Register new encoder libvvenc.
Add libvvenc to wrap the vvenc interface.
libvvenc implements encoder option: preset,qp,qpa,period,
passlogfile,stats,vvenc-params,level,tier.
Enable encoder by adding --enable-libvvenc in configure step.

Co-authored-by: Christian Bartnik chris1031...@gmail.com
Signed-off-by: Thomas Siedel 
---
 configure |   4 +
 doc/encoders.texi |  64 +
 fftools/ffmpeg_mux_init.c |   2 +-
 libavcodec/Makefile   |   1 +
 libavcodec/allcodecs.c|   1 +
 libavcodec/libvvenc.c | 507 ++
 6 files changed, 578 insertions(+), 1 deletion(-)
 create mode 100644 libavcodec/libvvenc.c

diff --git a/configure b/configure
index 96b181fd21..082cbca7bb 100755
--- a/configure
+++ b/configure
@@ -293,6 +293,7 @@ External library support:
   --enable-libvorbis   enable Vorbis en/decoding via libvorbis,
native implementation exists [no]
   --enable-libvpx  enable VP8 and VP9 de/encoding via libvpx [no]
+  --enable-libvvencenable H.266/VVC encoding via vvenc [no]
   --enable-libwebp enable WebP encoding via libwebp [no]
   --enable-libx264 enable H.264 encoding via x264 [no]
   --enable-libx265 enable HEVC encoding via x265 [no]
@@ -1966,6 +1967,7 @@ EXTERNAL_LIBRARY_LIST="
 libvmaf
 libvorbis
 libvpx
+libvvenc
 libwebp
 libxevd
 libxeve
@@ -3560,6 +3562,7 @@ libvpx_vp8_decoder_deps="libvpx"
 libvpx_vp8_encoder_deps="libvpx"
 libvpx_vp9_decoder_deps="libvpx"
 libvpx_vp9_encoder_deps="libvpx"
+libvvenc_encoder_deps="libvvenc"
 libwebp_encoder_deps="libwebp"
 libwebp_anim_encoder_deps="libwebp"
 libx262_encoder_deps="libx262"
@@ -7030,6 +7033,7 @@ enabled libvpx&& {
 fi
 }
 
+enabled libvvenc  && require_pkg_config libvvenc "libvvenc >= 1.6.1" 
"vvenc/vvenc.h" vvenc_get_version
 enabled libwebp   && {
 enabled libwebp_encoder  && require_pkg_config libwebp "libwebp >= 
0.2.0" webp/encode.h WebPGetEncoderVersion
 enabled libwebp_anim_encoder && check_pkg_config libwebp_anim_encoder 
"libwebpmux >= 0.4.0" webp/mux.h WebPAnimEncoderOptionsInit; }
diff --git a/doc/encoders.texi b/doc/encoders.texi
index c82f316f94..496852faeb 100644
--- a/doc/encoders.texi
+++ b/doc/encoders.texi
@@ -2378,6 +2378,70 @@ Indicates frame duration
 For more information about libvpx see:
 @url{http://www.webmproject.org/}
 
+@section libvvenc
+
+VVenC H.266/VVC encoder wrapper.
+
+This encoder requires the presence of the libvvenc headers and library
+during configuration. You need to explicitly configure the build with
+@option{--enable-libvvenc}.
+
+The VVenC project website is at
+@url{https://github.com/fraunhoferhhi/vvenc}.
+
+@subsection Supported Pixel Formats
+
+VVenC supports only 10-bit color spaces as input. But the internal (encoded)
+bit depth can be set to 8-bit or 10-bit at runtime.
+
+@subsection Options
+
+@table @option
+@item b
+Sets target video bitrate.
+
+@item g
+Set the GOP size. Currently support for g=1 (Intra only) or default.
+
+@item preset
+Set the VVenC preset.
+
+@item levelidc
+Set level idc.
+
+@item tier
+Set vvc tier.
+
+@item qp
+Set constant quantization parameter.
+
+@item subopt @var{boolean}
+Set subjective (perceptually motivated) optimization. Default is 1 (on).
+
+@item bitdepth8 @var{boolean}
+Set 8bit coding mode instead of using 10bit. Default is 0 (off).
+
+@item period
+set (intra) refresh period in seconds.
+
+@item vvenc-params
+Set vvenc options using a list of @var{key}=@var{value} couples separated
+by ":". See @command{vvencapp --fullhelp} or @command{vvencFFapp --fullhelp} 
for a list of options.
+
+For example, the options might be provided as:
+
+@example
+intraperiod=64:decodingrefreshtype=idr:poc0idr=1:internalbitdepth=8
+@end example
+
+For example the encoding options might be provided with @option{-vvenc-params}:
+
+@example
+ffmpeg -i input -c:v libvvenc -b 1M -vvenc-params 
intraperiod=64:decodingrefreshtype=idr:poc0idr=1:internalbitdepth=8 output.mp4
+@end example
+
+@end table
+
 @section libwebp
 
 libwebp WebP Image encoder wrapper
diff --git a/fftools/ffmpeg_mux_init.c b/fftools/ffmpeg_mux_init.c
index 8797265145..ef2922854a 100644
--- a/fftools/ffmpeg_mux_init.c
+++ b/fftools/ffmpeg_mux_init.c
@@ -739,7 +739,7 @@ static int new_stream_video(Muxer *mux, const 
OptionsContext *o,
  ost->logfile_prefix ? ost->logfile_prefix :
DEFAULT_PASS_LOGFILENAME_PREFIX,
  ost_idx);
-if (!strcmp(ost->enc_ctx->codec->name, "libx264")) {
+if (!strcmp(ost->enc_ctx->codec->na

[FFmpeg-devel] [PATCH v5 0/1] Add support for H266/VVC encoding

2024-06-05 Thread Christian Bartnik
This patch is based on the latest patchset from Thomas Siedel
(thomas...@spin-digital.com).

The libvvenc patch has been changed with following changes:
  avcodec: add external encoder libvvenc for H266/VVC
- sort includes alphabetically
- remove unneeded cast
- do not separate variables declaration and definition
- change if ((ret = func()) != 0) to: ret = func(); if (ret != 0)
- remove check for correct pix_fmt
- remove call of ff_side_data_set_encoder_stats

Christian Bartnik (1):
  avcodec: add external enc libvvenc for H266/VVC

 configure |   4 +
 doc/encoders.texi |  64 +
 fftools/ffmpeg_mux_init.c |   2 +-
 libavcodec/Makefile   |   1 +
 libavcodec/allcodecs.c|   1 +
 libavcodec/libvvenc.c | 492 ++
 6 files changed, 563 insertions(+), 1 deletion(-)
 create mode 100644 libavcodec/libvvenc.c

-- 
2.34.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 v5 1/1] avcodec: add external enc libvvenc for H266/VVC

2024-06-05 Thread Christian Bartnik
From: Thomas Siedel 

Add external encoder VVenC for H266/VVC encoding.
Register new encoder libvvenc.
Add libvvenc to wrap the vvenc interface.
libvvenc implements encoder option: preset,qp,qpa,period,
passlogfile,stats,vvenc-params,level,tier.
Enable encoder by adding --enable-libvvenc in configure step.

Co-authored-by: Christian Bartnik chris1031...@gmail.com
Signed-off-by: Thomas Siedel 
---
 configure |   4 +
 doc/encoders.texi |  64 +
 fftools/ffmpeg_mux_init.c |   2 +-
 libavcodec/Makefile   |   1 +
 libavcodec/allcodecs.c|   1 +
 libavcodec/libvvenc.c | 492 ++
 6 files changed, 563 insertions(+), 1 deletion(-)
 create mode 100644 libavcodec/libvvenc.c

diff --git a/configure b/configure
index 6c5b8aab9a..37ece23376 100755
--- a/configure
+++ b/configure
@@ -293,6 +293,7 @@ External library support:
   --enable-libvorbis   enable Vorbis en/decoding via libvorbis,
native implementation exists [no]
   --enable-libvpx  enable VP8 and VP9 de/encoding via libvpx [no]
+  --enable-libvvencenable H.266/VVC encoding via vvenc [no]
   --enable-libwebp enable WebP encoding via libwebp [no]
   --enable-libx264 enable H.264 encoding via x264 [no]
   --enable-libx265 enable HEVC encoding via x265 [no]
@@ -1966,6 +1967,7 @@ EXTERNAL_LIBRARY_LIST="
 libvmaf
 libvorbis
 libvpx
+libvvenc
 libwebp
 libxevd
 libxeve
@@ -3560,6 +3562,7 @@ libvpx_vp8_decoder_deps="libvpx"
 libvpx_vp8_encoder_deps="libvpx"
 libvpx_vp9_decoder_deps="libvpx"
 libvpx_vp9_encoder_deps="libvpx"
+libvvenc_encoder_deps="libvvenc"
 libwebp_encoder_deps="libwebp"
 libwebp_anim_encoder_deps="libwebp"
 libx262_encoder_deps="libx262"
@@ -7030,6 +7033,7 @@ enabled libvpx&& {
 fi
 }
 
+enabled libvvenc  && require_pkg_config libvvenc "libvvenc >= 1.6.1" 
"vvenc/vvenc.h" vvenc_get_version
 enabled libwebp   && {
 enabled libwebp_encoder  && require_pkg_config libwebp "libwebp >= 
0.2.0" webp/encode.h WebPGetEncoderVersion
 enabled libwebp_anim_encoder && check_pkg_config libwebp_anim_encoder 
"libwebpmux >= 0.4.0" webp/mux.h WebPAnimEncoderOptionsInit; }
diff --git a/doc/encoders.texi b/doc/encoders.texi
index c82f316f94..496852faeb 100644
--- a/doc/encoders.texi
+++ b/doc/encoders.texi
@@ -2378,6 +2378,70 @@ Indicates frame duration
 For more information about libvpx see:
 @url{http://www.webmproject.org/}
 
+@section libvvenc
+
+VVenC H.266/VVC encoder wrapper.
+
+This encoder requires the presence of the libvvenc headers and library
+during configuration. You need to explicitly configure the build with
+@option{--enable-libvvenc}.
+
+The VVenC project website is at
+@url{https://github.com/fraunhoferhhi/vvenc}.
+
+@subsection Supported Pixel Formats
+
+VVenC supports only 10-bit color spaces as input. But the internal (encoded)
+bit depth can be set to 8-bit or 10-bit at runtime.
+
+@subsection Options
+
+@table @option
+@item b
+Sets target video bitrate.
+
+@item g
+Set the GOP size. Currently support for g=1 (Intra only) or default.
+
+@item preset
+Set the VVenC preset.
+
+@item levelidc
+Set level idc.
+
+@item tier
+Set vvc tier.
+
+@item qp
+Set constant quantization parameter.
+
+@item subopt @var{boolean}
+Set subjective (perceptually motivated) optimization. Default is 1 (on).
+
+@item bitdepth8 @var{boolean}
+Set 8bit coding mode instead of using 10bit. Default is 0 (off).
+
+@item period
+set (intra) refresh period in seconds.
+
+@item vvenc-params
+Set vvenc options using a list of @var{key}=@var{value} couples separated
+by ":". See @command{vvencapp --fullhelp} or @command{vvencFFapp --fullhelp} 
for a list of options.
+
+For example, the options might be provided as:
+
+@example
+intraperiod=64:decodingrefreshtype=idr:poc0idr=1:internalbitdepth=8
+@end example
+
+For example the encoding options might be provided with @option{-vvenc-params}:
+
+@example
+ffmpeg -i input -c:v libvvenc -b 1M -vvenc-params 
intraperiod=64:decodingrefreshtype=idr:poc0idr=1:internalbitdepth=8 output.mp4
+@end example
+
+@end table
+
 @section libwebp
 
 libwebp WebP Image encoder wrapper
diff --git a/fftools/ffmpeg_mux_init.c b/fftools/ffmpeg_mux_init.c
index 8797265145..ef2922854a 100644
--- a/fftools/ffmpeg_mux_init.c
+++ b/fftools/ffmpeg_mux_init.c
@@ -739,7 +739,7 @@ static int new_stream_video(Muxer *mux, const 
OptionsContext *o,
  ost->logfile_prefix ? ost->logfile_prefix :
DEFAULT_PASS_LOGFILENAME_PREFIX,
  ost_idx);
-if (!strcmp(ost->enc_ctx->codec->name, "libx264")) {
+if (!strcmp(ost->enc_ctx->codec->na

[FFmpeg-devel] HRTF SOFA reader lib

2016-12-05 Thread Christian Hoene
Hi,

currently, we are writing a small library to read HRTF SOFA files.
https://github.com/choene/libmysofa

It is intended for embedded devices or mobiles that have a small (code)
memory footprint. Of course, it might be useful for ffmpeg, too – because you do
not need the hdf5 and netcdf libs.

It is not yet fully finished but I though it is time to collect feedback so that
I can enhance it.

If you have same spare time, please let me know on what to change to make
it useful for you guys…

Best regards,

 Christian Hoene

--
Symonics GmbH
Geierweg 25
72144 Dußlingen
Tel +49 7072 8006100
Fax +49 7072 8006109
Email: christian.ho...@symonics.com
Geschäftsführer/President: Dr. Christian Hoene 
Sitz der Gesellschaft/Place of Business: Tübingen
Registereintrag/Commercial Register: Amtsgericht Stuttgart, HRB 739918
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] HRTF SOFA reader lib

2016-12-06 Thread Christian Hoene
Hi Paul,

give me some more time until it passed all the tests.

It is going to be ready for Christmas...

Best,

 Christian


> Paul B Mahol  hat am 6. Dezember 2016 um 09:03 geschrieben:
> 
> 
> On 12/6/16, Christian Hoene  wrote:
> > Hi,
> 
> Hi,
> 
> >
> > currently, we are writing a small library to read HRTF SOFA files.
> > https://github.com/choene/libmysofa
> >
> > It is intended for embedded devices or mobiles that have a small (code)
> > memory footprint. Of course, it might be useful for ffmpeg, too - because
> > you do
> > not need the hdf5 and netcdf libs.
> >
> > It is not yet fully finished but I though it is time to collect feedback so
> > that
> > I can enhance it.
> >
> > If you have same spare time, please let me know on what to change to make
> > it useful for you guys...
> 
> Awesome news!
> 
> Can it be already used?
> 
> I'm interested because netcdf is very bloated imho and I will use this one
> instead if it works without issues.
> 
> Thanks for your work.
> 
> >
> > Best regards,
> >
> >  Christian Hoene
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


[FFmpeg-devel] [PATCH v2 2/2] avcodec: add external dec libvvdec for H266/VVC

2024-05-06 Thread Christian Bartnik
From: Thomas Siedel 

Add external decoder VVdeC for H266/VVC decoding.
Register new decoder libvvdec.
Add vvc_parse_extradata to support parse/probe of vvcC stream input.
Add vvc_paramset that implements the parser of vvcC configuration boxes.
Add libvvdec to wrap the vvdec interface.
Enable decoder by adding --enable-libvvdec in configure step.

Co-authored-by: Christian Bartnik chris1031...@gmail.com
Signed-off-by: Christian Bartnik 
---
 configure  |   5 +
 libavcodec/Makefile|   1 +
 libavcodec/allcodecs.c |   1 +
 libavcodec/libvvdec.c  | 617 +
 4 files changed, 624 insertions(+)
 create mode 100644 libavcodec/libvvdec.c

diff --git a/configure b/configure
index cb312d9c73..a7a9da3276 100755
--- a/configure
+++ b/configure
@@ -294,6 +294,7 @@ External library support:
native implementation exists [no]
   --enable-libvpx  enable VP8 and VP9 de/encoding via libvpx [no]
   --enable-libvvencenable H.266/VVC encoding via vvenc [no]
+  --enable-libvvdecenable H.266/VVC decoding via vvdec [no]
   --enable-libwebp enable WebP encoding via libwebp [no]
   --enable-libx264 enable H.264 encoding via x264 [no]
   --enable-libx265 enable HEVC encoding via x265 [no]
@@ -1968,6 +1969,7 @@ EXTERNAL_LIBRARY_LIST="
 libvorbis
 libvpx
 libvvenc
+libvvdec
 libwebp
 libxevd
 libxeve
@@ -3551,6 +3553,8 @@ libvpx_vp8_encoder_deps="libvpx"
 libvpx_vp9_decoder_deps="libvpx"
 libvpx_vp9_encoder_deps="libvpx"
 libvvenc_encoder_deps="libvvenc"
+libvvdec_decoder_deps="libvvdec"
+libvvdec_decoder_select="vvc_mp4toannexb_bsf"
 libwebp_encoder_deps="libwebp"
 libwebp_anim_encoder_deps="libwebp"
 libx262_encoder_deps="libx262"
@@ -7014,6 +7018,7 @@ enabled libvpx&& {
 fi
 }
 enabled libvvenc  && require_pkg_config libvvenc "libvvenc >= 1.6.1" 
"vvenc/vvenc.h" vvenc_get_version
+enabled libvvdec  && require_pkg_config libvvdec "libvvdec >= 1.6.0" 
"vvdec/vvdec.h" vvdec_get_version

 enabled libwebp   && {
 enabled libwebp_encoder  && require_pkg_config libwebp "libwebp >= 
0.2.0" webp/encode.h WebPGetEncoderVersion
diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index 54d85f6aaa..851b62179d 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -1156,6 +1156,7 @@ OBJS-$(CONFIG_LIBVPX_VP8_ENCODER) += libvpxenc.o
 OBJS-$(CONFIG_LIBVPX_VP9_DECODER) += libvpxdec.o
 OBJS-$(CONFIG_LIBVPX_VP9_ENCODER) += libvpxenc.o
 OBJS-$(CONFIG_LIBVVENC_ENCODER)   += libvvenc.o
+OBJS-$(CONFIG_LIBVVDEC_DECODER)   += libvvdec.o
 OBJS-$(CONFIG_LIBWEBP_ENCODER)+= libwebpenc_common.o libwebpenc.o
 OBJS-$(CONFIG_LIBWEBP_ANIM_ENCODER)   += libwebpenc_common.o 
libwebpenc_animencoder.o
 OBJS-$(CONFIG_LIBX262_ENCODER)+= libx264.o
diff --git a/libavcodec/allcodecs.c b/libavcodec/allcodecs.c
index bb2c3ce017..9e0ad00b23 100644
--- a/libavcodec/allcodecs.c
+++ b/libavcodec/allcodecs.c
@@ -802,6 +802,7 @@ extern const FFCodec ff_libvpx_vp8_decoder;
 extern FFCodec ff_libvpx_vp9_encoder;
 extern const FFCodec ff_libvpx_vp9_decoder;
 extern const FFCodec ff_libvvenc_encoder;
+extern const FFCodec ff_libvvdec_decoder;
 /* preferred over libwebp */
 extern const FFCodec ff_libwebp_anim_encoder;
 extern const FFCodec ff_libwebp_encoder;
diff --git a/libavcodec/libvvdec.c b/libavcodec/libvvdec.c
new file mode 100644
index 00..7f94a81b37
--- /dev/null
+++ b/libavcodec/libvvdec.c
@@ -0,0 +1,617 @@
+/*
+ * H.266 decoding using the VVdeC library
+ *
+ * Copyright (C) 2022, Thomas Siedel
+ *
+ * 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 "config_components.h"
+
+#include 
+
+#include "libavutil/common.h"
+#include "libavutil/avutil.h"
+#include "libavutil/pixdesc.h"
+#include "libavutil/opt.h"
+#include "libavutil/imgutils.h"
+#include "libavutil/frame.h"
+#include "libavutil/mastering_dis

[FFmpeg-devel] [PATCH v2 1/2] avcodec: add external enc libvvenc for H266/VVC

2024-05-06 Thread Christian Bartnik
From: Thomas Siedel 

Add external encoder VVenC for H266/VVC encoding.
Register new encoder libvvenc.
Add libvvenc to wrap the vvenc interface.
libvvenc implements encoder option: preset,qp,period,subjopt,
vvenc-params,levelidc,tier.
Enable encoder by adding --enable-libvvenc in configure step.

Co-authored-by: Christian Bartnik chris1031...@gmail.com
Signed-off-by: Christian Bartnik 
---
 configure  |   4 +
 libavcodec/Makefile|   1 +
 libavcodec/allcodecs.c |   1 +
 libavcodec/libvvenc.c  | 501 +
 4 files changed, 507 insertions(+)
 create mode 100644 libavcodec/libvvenc.c

diff --git a/configure b/configure
index ed74583a6f..cb312d9c73 100755
--- a/configure
+++ b/configure
@@ -293,6 +293,7 @@ External library support:
   --enable-libvorbis   enable Vorbis en/decoding via libvorbis,
native implementation exists [no]
   --enable-libvpx  enable VP8 and VP9 de/encoding via libvpx [no]
+  --enable-libvvencenable H.266/VVC encoding via vvenc [no]
   --enable-libwebp enable WebP encoding via libwebp [no]
   --enable-libx264 enable H.264 encoding via x264 [no]
   --enable-libx265 enable HEVC encoding via x265 [no]
@@ -1966,6 +1967,7 @@ EXTERNAL_LIBRARY_LIST="
 libvmaf
 libvorbis
 libvpx
+libvvenc
 libwebp
 libxevd
 libxeve
@@ -3548,6 +3550,7 @@ libvpx_vp8_decoder_deps="libvpx"
 libvpx_vp8_encoder_deps="libvpx"
 libvpx_vp9_decoder_deps="libvpx"
 libvpx_vp9_encoder_deps="libvpx"
+libvvenc_encoder_deps="libvvenc"
 libwebp_encoder_deps="libwebp"
 libwebp_anim_encoder_deps="libwebp"
 libx262_encoder_deps="libx262"
@@ -7010,6 +7013,7 @@ enabled libvpx&& {
 die "libvpx enabled but no supported decoders found"
 fi
 }
+enabled libvvenc  && require_pkg_config libvvenc "libvvenc >= 1.6.1" 
"vvenc/vvenc.h" vvenc_get_version

 enabled libwebp   && {
 enabled libwebp_encoder  && require_pkg_config libwebp "libwebp >= 
0.2.0" webp/encode.h WebPGetEncoderVersion
diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index cff6347bdb..54d85f6aaa 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -1155,6 +1155,7 @@ OBJS-$(CONFIG_LIBVPX_VP8_DECODER) += libvpxdec.o
 OBJS-$(CONFIG_LIBVPX_VP8_ENCODER) += libvpxenc.o
 OBJS-$(CONFIG_LIBVPX_VP9_DECODER) += libvpxdec.o
 OBJS-$(CONFIG_LIBVPX_VP9_ENCODER) += libvpxenc.o
+OBJS-$(CONFIG_LIBVVENC_ENCODER)   += libvvenc.o
 OBJS-$(CONFIG_LIBWEBP_ENCODER)+= libwebpenc_common.o libwebpenc.o
 OBJS-$(CONFIG_LIBWEBP_ANIM_ENCODER)   += libwebpenc_common.o 
libwebpenc_animencoder.o
 OBJS-$(CONFIG_LIBX262_ENCODER)+= libx264.o
diff --git a/libavcodec/allcodecs.c b/libavcodec/allcodecs.c
index f4705651fb..bb2c3ce017 100644
--- a/libavcodec/allcodecs.c
+++ b/libavcodec/allcodecs.c
@@ -801,6 +801,7 @@ extern const FFCodec ff_libvpx_vp8_encoder;
 extern const FFCodec ff_libvpx_vp8_decoder;
 extern FFCodec ff_libvpx_vp9_encoder;
 extern const FFCodec ff_libvpx_vp9_decoder;
+extern const FFCodec ff_libvvenc_encoder;
 /* preferred over libwebp */
 extern const FFCodec ff_libwebp_anim_encoder;
 extern const FFCodec ff_libwebp_encoder;
diff --git a/libavcodec/libvvenc.c b/libavcodec/libvvenc.c
new file mode 100644
index 00..c459273f44
--- /dev/null
+++ b/libavcodec/libvvenc.c
@@ -0,0 +1,501 @@
+/*
+ * H.266 encoding using the VVenC library
+ *
+ * Copyright (C) 2022, Thomas Siedel
+ *
+ * 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 "config_components.h"
+
+#include 
+#include 
+#include 
+
+#include "avcodec.h"
+#include "codec_internal.h"
+#include "encode.h"
+#include "internal.h"
+#include "packet_internal.h"
+#include "profiles.h"
+
+#include "libavutil/avutil.h"
+#include "libavutil/mem.h"
+#include "libavutil/pixdesc.h"
+#include "libavutil/opt.h"
+#include "libavutil/common.h"
+#include "libavutil/imgu

[FFmpeg-devel] [PATCH v2 0/2] Add support for H266/VVC encoding

2024-05-06 Thread Christian Bartnik
This patchset is based on the latest patchset from Thomas Siedel
(thomas...@spin-digital.com).
Since almost all changes from the patchset but libvvenc and libvvdec has been
merged this patch only implements the libvvenc and libvvdec wrapper
implementation.
As ffmpeg already has it´s own vvc decoder, feel free to cherry pick libvvenc
only.
The libvvenc patch only has been aligend to the current master without changing
the implementation.
The libvvdec patch has been cleaned up by removing the extradata parsing files
and using existing code from cbs_h266.

Christian Bartnik (2):
  avcodec: add external enc libvvenc for H266/VVC
  avcodec: add external dec libvvdec for H266/VVC

 configure  |   9 +
 libavcodec/Makefile|   2 +
 libavcodec/allcodecs.c |   2 +
 libavcodec/libvvdec.c  | 617 +
 libavcodec/libvvenc.c  | 501 +
 5 files changed, 1131 insertions(+)
 create mode 100644 libavcodec/libvvdec.c
 create mode 100644 libavcodec/libvvenc.c

--
2.34.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 v3 0/2] Add support for H266/VVC encoding

2024-05-14 Thread Christian Bartnik
This patchset is based on the latest patchset from Thomas Siedel
(thomas...@spin-digital.com).
Since almost all changes from the patchset but libvvenc and libvvdec has been
merged this patch only implements the libvvenc and libvvdec wrapper
implementation.
As ffmpeg already has it´s own vvc decoder, feel free to cherry pick libvvenc
only.
The libvvdec patch has been cleaned up by removing the extradata parsing files
and using existing code from cbs_h266.

The libvvenc patch only has been cleaned up with following changes:
- add defaults struct vvenc_defaults
- fix: init qp value (typo)
- cleanup init function (move code into sub functions)
- cleanup verbosity
- add check for payload allocation
- vvenc-params return error for invalid options or values
- add support for capped CRF mode (QP + subj.Optimization + max. bitrate) if 
vvenc version >= 1.11.0
- add vvenc documentation in doc/encoders.texi

Christian Bartnik (2):
  avcodec: add external enc libvvenc for H266/VVC
  avcodec: add external dec libvvdec for H266/VVC

 configure  |   9 +
 doc/encoders.texi  |  65 +
 libavcodec/Makefile|   2 +
 libavcodec/allcodecs.c |   2 +
 libavcodec/libvvdec.c  | 617 +
 libavcodec/libvvenc.c  | 566 +
 6 files changed, 1261 insertions(+)
 create mode 100644 libavcodec/libvvdec.c
 create mode 100644 libavcodec/libvvenc.c

--
2.34.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 v3 1/2] avcodec: add external enc libvvenc for H266/VVC

2024-05-14 Thread Christian Bartnik
From: Thomas Siedel 

Add external encoder VVenC for H266/VVC encoding.
Register new encoder libvvenc.
Add libvvenc to wrap the vvenc interface.
libvvenc implements encoder option: preset,qp,period,subjopt,
vvenc-params,levelidc,tier.
Enable encoder by adding --enable-libvvenc in configure step.

Co-authored-by: Christian Bartnik chris1031...@gmail.com
Signed-off-by: Christian Bartnik 
---
 configure  |   4 +
 doc/encoders.texi  |  65 +
 libavcodec/Makefile|   1 +
 libavcodec/allcodecs.c |   1 +
 libavcodec/libvvenc.c  | 566 +
 5 files changed, 637 insertions(+)
 create mode 100644 libavcodec/libvvenc.c

diff --git a/configure b/configure
index a909b0689c..5d9a14821b 100755
--- a/configure
+++ b/configure
@@ -293,6 +293,7 @@ External library support:
   --enable-libvorbis   enable Vorbis en/decoding via libvorbis,
native implementation exists [no]
   --enable-libvpx  enable VP8 and VP9 de/encoding via libvpx [no]
+  --enable-libvvencenable H.266/VVC encoding via vvenc [no]
   --enable-libwebp enable WebP encoding via libwebp [no]
   --enable-libx264 enable H.264 encoding via x264 [no]
   --enable-libx265 enable HEVC encoding via x265 [no]
@@ -1966,6 +1967,7 @@ EXTERNAL_LIBRARY_LIST="
 libvmaf
 libvorbis
 libvpx
+libvvenc
 libwebp
 libxevd
 libxeve
@@ -3558,6 +3560,7 @@ libvpx_vp8_decoder_deps="libvpx"
 libvpx_vp8_encoder_deps="libvpx"
 libvpx_vp9_decoder_deps="libvpx"
 libvpx_vp9_encoder_deps="libvpx"
+libvvenc_encoder_deps="libvvenc"
 libwebp_encoder_deps="libwebp"
 libwebp_anim_encoder_deps="libwebp"
 libx262_encoder_deps="libx262"
@@ -7025,6 +7028,7 @@ enabled libvpx&& {
 die "libvpx enabled but no supported decoders found"
 fi
 }
+enabled libvvenc  && require_pkg_config libvvenc "libvvenc >= 1.6.1" 
"vvenc/vvenc.h" vvenc_get_version

 enabled libwebp   && {
 enabled libwebp_encoder  && require_pkg_config libwebp "libwebp >= 
0.2.0" webp/encode.h WebPGetEncoderVersion
diff --git a/doc/encoders.texi b/doc/encoders.texi
index c82f316f94..92aab17c49 100644
--- a/doc/encoders.texi
+++ b/doc/encoders.texi
@@ -2378,6 +2378,71 @@ Indicates frame duration
 For more information about libvpx see:
 @url{http://www.webmproject.org/}
 
+@section libvvenc
+
+VVenC H.266/VVC encoder wrapper.
+
+This encoder requires the presence of the libvvenc headers and library
+during configuration. You need to explicitly configure the build with
+@option{--enable-libvvenc}.
+
+The VVenC project website is at
+@url{https://github.com/fraunhoferhhi/vvenc}.
+
+@subsection Supported Pixel Formats
+
+VVenC supports only 10-bit color spaces as input. But the internal (encoded)
+bit depth can be set to 8-bit or 10-bit at runtime.
+
+@subsection Options
+
+@table @option
+@item b
+Sets target video bitrate.
+
+@item g
+Set the GOP size. Currently support for g=1 (Intra only) or default.
+
+@item preset
+Set the VVenC preset.
+
+@item levelidc
+Set level idc.
+
+@item tier
+Set vvc tier.
+
+@item qp
+Set constant quantization parameter.
+
+@item subopt @var{boolean}
+Set subjective (perceptually motivated) optimization. Default is 1 (on).
+
+@item bitdepth8 @var{boolean}
+Set 8bit coding mode instead of using 10bit. Default is 0 (off).
+
+@item period
+set (intra) refresh period in seconds.
+
+@item vvenc-params
+Set vvenc options using a list of @var{key}=@var{value} couples separated
+by ":". See @command{vvencapp --fullhelp} or @command{vvencFFapp --fullhelp} 
for a list of options.
+
+For example, the options might be provided as:
+
+@example
+intraperiod=64:decodingrefreshtype=idr:poc0idr=1:internalbitdepth=8
+@end example
+
+For example the encoding options for 2-pass encoding might be provided with 
@option{-vvenc-params}:
+
+@example
+ffmpeg -i input -c:v libvvenc -b 1M -vvenc-params 
passes=2:pass=1:rcstatsfile=stats.json output.mp4
+ffmpeg -i input -c:v libvvenc -b 1M -vvenc-params 
passes=2:pass=2:rcstatsfile=stats.json output.mp4
+@end example
+
+@end table
+
 @section libwebp
 
 libwebp WebP Image encoder wrapper
diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index 2443d2c6fd..5d7349090e 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -1153,6 +1153,7 @@ OBJS-$(CONFIG_LIBVPX_VP8_DECODER) += libvpxdec.o
 OBJS-$(CONFIG_LIBVPX_VP8_ENCODER) += libvpxenc.o
 OBJS-$(CONFIG_LIBVPX_VP9_DECODER) += libvpxdec.o
 OBJS-$(CONFIG_LIBVPX_VP9_ENCODER) += libvpxenc.o
+OBJS-$(CONFIG_LIBVVENC_ENCODER)   += libvvenc.o
 OBJS-$(CONFIG_LIBWEBP_ENCODER)+= libwebpenc_common.o libwebpenc.o
 OBJS-$(CONFIG_LIBWEBP_ANIM_ENCODER)   += libwebpenc_common.o 
libwebpenc_animencoder.o
 OBJS-$(CONFIG

[FFmpeg-devel] [PATCH v3 2/2] avcodec: add external dec libvvdec for H266/VVC

2024-05-14 Thread Christian Bartnik
From: Thomas Siedel 

Add external decoder VVdeC for H266/VVC decoding.
Register new decoder libvvdec.
Add libvvdec to wrap the vvdec interface.
Enable decoder by adding --enable-libvvdec in configure step.

Co-authored-by: Christian Bartnik chris1031...@gmail.com
Signed-off-by: Christian Bartnik 
---
 configure  |   5 +
 libavcodec/Makefile|   1 +
 libavcodec/allcodecs.c |   1 +
 libavcodec/libvvdec.c  | 617 +
 4 files changed, 624 insertions(+)
 create mode 100644 libavcodec/libvvdec.c

diff --git a/configure b/configure
index 5d9a14821b..a5df482215 100755
--- a/configure
+++ b/configure
@@ -294,6 +294,7 @@ External library support:
native implementation exists [no]
   --enable-libvpx  enable VP8 and VP9 de/encoding via libvpx [no]
   --enable-libvvencenable H.266/VVC encoding via vvenc [no]
+  --enable-libvvdecenable H.266/VVC decoding via vvdec [no]
   --enable-libwebp enable WebP encoding via libwebp [no]
   --enable-libx264 enable H.264 encoding via x264 [no]
   --enable-libx265 enable HEVC encoding via x265 [no]
@@ -1968,6 +1969,7 @@ EXTERNAL_LIBRARY_LIST="
 libvorbis
 libvpx
 libvvenc
+libvvdec
 libwebp
 libxevd
 libxeve
@@ -3561,6 +3563,8 @@ libvpx_vp8_encoder_deps="libvpx"
 libvpx_vp9_decoder_deps="libvpx"
 libvpx_vp9_encoder_deps="libvpx"
 libvvenc_encoder_deps="libvvenc"
+libvvdec_decoder_deps="libvvdec"
+libvvdec_decoder_select="vvc_mp4toannexb_bsf"
 libwebp_encoder_deps="libwebp"
 libwebp_anim_encoder_deps="libwebp"
 libx262_encoder_deps="libx262"
@@ -7029,6 +7033,7 @@ enabled libvpx&& {
 fi
 }
 enabled libvvenc  && require_pkg_config libvvenc "libvvenc >= 1.6.1" 
"vvenc/vvenc.h" vvenc_get_version
+enabled libvvdec  && require_pkg_config libvvdec "libvvdec >= 1.6.0" 
"vvdec/vvdec.h" vvdec_get_version
 
 enabled libwebp   && {
 enabled libwebp_encoder  && require_pkg_config libwebp "libwebp >= 
0.2.0" webp/encode.h WebPGetEncoderVersion
diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index 5d7349090e..318b22a1fa 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -1154,6 +1154,7 @@ OBJS-$(CONFIG_LIBVPX_VP8_ENCODER) += libvpxenc.o
 OBJS-$(CONFIG_LIBVPX_VP9_DECODER) += libvpxdec.o
 OBJS-$(CONFIG_LIBVPX_VP9_ENCODER) += libvpxenc.o
 OBJS-$(CONFIG_LIBVVENC_ENCODER)   += libvvenc.o
+OBJS-$(CONFIG_LIBVVDEC_DECODER)   += libvvdec.o
 OBJS-$(CONFIG_LIBWEBP_ENCODER)+= libwebpenc_common.o libwebpenc.o
 OBJS-$(CONFIG_LIBWEBP_ANIM_ENCODER)   += libwebpenc_common.o 
libwebpenc_animencoder.o
 OBJS-$(CONFIG_LIBX262_ENCODER)+= libx264.o
diff --git a/libavcodec/allcodecs.c b/libavcodec/allcodecs.c
index 59d36dbd56..4120681d17 100644
--- a/libavcodec/allcodecs.c
+++ b/libavcodec/allcodecs.c
@@ -801,6 +801,7 @@ extern const FFCodec ff_libvpx_vp8_decoder;
 extern FFCodec ff_libvpx_vp9_encoder;
 extern const FFCodec ff_libvpx_vp9_decoder;
 extern const FFCodec ff_libvvenc_encoder;
+extern const FFCodec ff_libvvdec_decoder;
 /* preferred over libwebp */
 extern const FFCodec ff_libwebp_anim_encoder;
 extern const FFCodec ff_libwebp_encoder;
diff --git a/libavcodec/libvvdec.c b/libavcodec/libvvdec.c
new file mode 100644
index 00..7f94a81b37
--- /dev/null
+++ b/libavcodec/libvvdec.c
@@ -0,0 +1,617 @@
+/*
+ * H.266 decoding using the VVdeC library
+ *
+ * Copyright (C) 2022, Thomas Siedel
+ *
+ * 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 "config_components.h"
+
+#include 
+
+#include "libavutil/common.h"
+#include "libavutil/avutil.h"
+#include "libavutil/pixdesc.h"
+#include "libavutil/opt.h"
+#include "libavutil/imgutils.h"
+#include "libavutil/frame.h"
+#include "libavutil/mastering_display_metadata.h"
+#include "libavutil/log.h"
+
+#include "avcodec.h"
+#include "codec_internal.h"
+#include &

[FFmpeg-devel] [PATCH v3] avfilter: add XPSNR filter

2024-07-04 Thread Helmrich, Christian
This is a continuation of last year's version of this filter patch, see also

https://ffmpeg.org/pipermail/ffmpeg-devel/2023-January/305517.html

It includes a fix in one of the stride variables and some cleanup in order

to adhere even more to the FFmpeg coding guidelines.


Christian Helmrich

Fraunhofer HHI
From 6a020fc9279ab2fd66e6dd8596f566ee6578cb35 Mon Sep 17 00:00:00 2001
From: Christian Helmrich 
Date: Thu, 4 Jul 2024 17:10:29 +0200
Subject: [PATCH v3] avfilter: add XPSNR filter

Add XPSNR video filter
Register new filter xpsnr.

Signed-off-by: Christian Helmrich 
---
 doc/filters.texi|  68 +++
 libavfilter/Makefile|   1 +
 libavfilter/allfilters.c|   1 +
 libavfilter/vf_xpsnr.c  | 739 
 libavfilter/x86/Makefile|   1 +
 libavfilter/x86/vf_xpsnr_init.c |  43 ++
 libavfilter/xpsnr.h |  48 +++
 7 files changed, 901 insertions(+)
 create mode 100644 libavfilter/vf_xpsnr.c
 create mode 100644 libavfilter/x86/vf_xpsnr_init.c
 create mode 100644 libavfilter/xpsnr.h

diff --git a/doc/filters.texi b/doc/filters.texi
index c9c4f7cf6b..c9d1254352 100644
--- a/doc/filters.texi
+++ b/doc/filters.texi
@@ -19944,6 +19944,7 @@ 
pseudocolor="'if(between(val,ymax,amax),lerp(ymin,ymax,(val-ymax)/(amax-ymax)),-
 @end example
 @end itemize

+@anchor{psnr}
 @section psnr

 Obtain the average, maximum and minimum PSNR (Peak Signal to Noise
@@ -26032,6 +26033,73 @@ minimum values, and @code{1} maximum values.

 This filter supports all above options as @ref{commands}, excluding option 
@code{inputs}.

+@anchor{xpsnr}
+@section xpsnr
+
+Obtain the average (across all input frames) and minimum (across all color 
plane averages)
+eXtended Perceptually weighted peak Signal-to-Noise Ratio (XPSNR) between two 
input videos.
+
+The XPSNR is a low-complexity psychovisually motivated distortion measurement 
algorithm for
+assessing the difference between two video streams or images. This is 
especially useful for
+objectively quantifying the distortions caused by video and image codecs, as 
an alternative
+to a formal subjective test. The logarithmic XPSNR output values are in a 
similar range as
+those of traditional @ref{psnr} assessments but better reflect human 
impressions of visual
+coding quality. More details on the XPSNR measure, which essentially 
represents a blockwise
+weighted variant of the PSNR measure, can be found in the following freely 
available papers:
+
+@itemize
+@item
+C. R. Helmrich, M. Siekmann, S. Becker, S. Bosse, D. Marpe, and T. Wiegand, 
"XPSNR: A
+Low-Complexity Extension of the Perceptually Weighted Peak Signal-to-Noise 
Ratio for
+High-Resolution Video Quality Assessment," in Proc. IEEE Int. Conf. Acoustics, 
Speech,
+Sig. Process. (ICASSP), virt./online, May 2020. @url{www.ecodis.de/xpsnr.htm}
+
+@item
+C. R. Helmrich, S. Bosse, H. Schwarz, D. Marpe, and T. Wiegand, "A Study of the
+Extended Perceptually Weighted Peak Signal-to-Noise Ratio (XPSNR) for Video 
Compression
+with Different Resolutions and Bit Depths," ITU Journal: ICT Discoveries, vol. 
3, no.
+1, pp. 65 - 72, May 2020. @url{http://handle.itu.int/11.1002/pub/8153d78b-en}
+@end itemize
+
+When publishing the results of XPSNR assessments obtained using, e.g., this 
FFmpeg filter, a
+reference to the above papers as a means of documentation is strongly 
encouraged. The filter
+requires two input videos. The first input is considered a (usually not 
distorted) reference
+source and is passed unchanged to the output, whereas the second input is a 
(distorted) test
+signal. Except for the bit depth, these two video inputs must have the same 
pixel format. In
+addition, for best performance, both compared input videos should be in YCbCr 
color format.
+
+The obtained overall XPSNR values mentioned above are printed through the 
logging system. In
+case of input with multiple color planes, we suggest reporting of the minimum 
XPSNR average.
+
+The following parameter, which behaves like the one for the @ref{psnr} filter, 
is accepted:
+
+@table @option
+@item stats_file, f
+If specified, the filter will use the named file to save the XPSNR value of 
each individual
+frame and color plane. When the file name equals "-", that data is sent to 
standard output.
+@end table
+
+This filter also supports the @ref{framesync} options.
+
+@subsection Examples
+@itemize
+@item
+XPSNR analysis of two 1080p HD videos, ref_source.yuv and test_video.yuv, both 
at 24 frames
+per second, with color format 4:2:0, bit depth 8, and output of a logfile 
named "xpsnr.log":
+@example
+ffmpeg -s 1920x1080 -framerate 24 -pix_fmt yuv420p -i ref_source.yuv -s 
1920x1080 -framerate
+24 -pix_fmt yuv420p -i test_video.yuv -lavfi xpsnr="stats_file=xpsnr.log" -f 
null -
+@end example
+
+@item
+XPSNR analysis of two 2160p UHD videos, ref_source.yuv with bit depth 8 and 
test_video.yuv
+with bit depth 10, both at

Re: [FFmpeg-devel] [PATCH v3] avfilter: add XPSNR filter

2024-07-25 Thread Helmrich, Christian
ping


Should anything be changed in this patch?


Christian Helmrich




Von: Helmrich, Christian
Gesendet: Donnerstag, 4. Juli 2024 17:50
An: ffmpeg-devel@ffmpeg.org
Betreff: [PATCH v3] avfilter: add XPSNR filter


This is a continuation of last year's version of this filter patch, see also

https://ffmpeg.org/pipermail/ffmpeg-devel/2023-January/305517.html

It includes a fix in one of the stride variables and some cleanup in order

to adhere even more to the FFmpeg coding guidelines.


Christian Helmrich

Fraunhofer HHI
___
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] [RFC] 7.1 Release

2024-08-21 Thread Helmrich, Christian
> On Sat, Aug 17, 2024 at 5:38 AM Marth64  wrote:

> >
> >  I would like to get DVD seeking in and some recent bugfixes (initial
> > patchset was sent, working on revision). I'm chasing one last
> > lingering issue with chapter-based extraction.
> > Hopefully, I can make a breakthrough or get help to fix it soon.
> > Beyond that I plan to leave DVD alone for a long time.
> >
> > On Wed, Aug 14, 2024 at 9:52 AM Lynne via ffmpeg-devel
> >  wrote:
> > >
> > > On 14/08/2024 14:41, Michael Niedermayer wrote:
> > > > Hi all
> > > >
> > > > Are there any upcoming LTS releases that want to/could include FFmpeg 
> > > > 7.1 ?
> > > > If so please reply here and list the date before which we would have to
> > > > finish the 7.1 release so it can be included with no problems
> > > >
> > > > Otherwise, are there any preferrances of the general/approximate 
> > > > release date?
> > > >
> > > > thx
> > > >
> > > >
> > > > ___
> > > > 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".
> > >
> > > I'd like to have Vulkan encoding support merged before 7.1 is branched.
> > > Working on the patches ATM, merging them one by one.
> > >
> > > The first week of September seems like a nice target for a release,
> > > which would mean we'd need to branch at the end of this month.
>
> Hi,
>
> I would like the mediacodec audio support merged before 7.1 is
> branched. I will have time to work on it start of next week and submit
> a v2 of the original patch.

Hi,

would it also be possible to merge the following avfilter before branching?
We haven't received any comments since early last year (the first version
of the patch was from January 2023), not even on the new patch version 3.

https://patchwork.ffmpeg.org/project/ffmpeg/patch/9aab9416fa7c4aec9b49cc6a94612...@hhi.fraunhofer.de/
https://ffmpeg.org/pipermail/ffmpeg-devel/2024-July/330691.html

Thanks,

Christian

[...]

___
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] avfilter: add XPSNR filter

2024-08-26 Thread Helmrich, Christian
Hi and thanks for taking a look at this!

> maybe you can add a fate test

I understand my colleague (who supports me on this) right, he's still looking 
into how to do that.
But to have some quick progress on your other comments:

> libavfilter/vf_xpsnr.c:38:10: fatal error: internal.h: No such file or 
> directory
>   38 | #include "internal.h"

Thanks, fixed in v4 (attached).

> the casts are unneeded

Thanks, fixed in v4.

> av_free*(NULL) is safe

Thanks, fixed in v4.

Christian Helmrich

Fraunhofer HHI



Von: ffmpeg-devel  im Auftrag von Michael 
Niedermayer 
Gesendet: Freitag, 23. August 2024 22:00
An: FFmpeg development discussions and patches
Betreff: Re: [FFmpeg-devel] [PATCH v3] avfilter: add XPSNR filter

On Thu, Jul 04, 2024 at 03:50:34PM +, Helmrich, Christian wrote:
> This is a continuation of last year's version of this filter patch, see also
>
> https://ffmpeg.org/pipermail/ffmpeg-devel/2023-January/305517.html
>
> It includes a fix in one of the stride variables and some cleanup in order
>
> to adhere even more to the FFmpeg coding guidelines.
>
>
> Christian Helmrich
>
> Fraunhofer HHI

>  doc/filters.texi|   68 +++
>  libavfilter/Makefile|1
>  libavfilter/allfilters.c|1
>  libavfilter/vf_xpsnr.c  |  739 
> 
>  libavfilter/x86/Makefile|1
>  libavfilter/x86/vf_xpsnr_init.c |   43 ++
>  libavfilter/xpsnr.h |   48 ++
>  7 files changed, 901 insertions(+)

maybe you can add a fate test


> 50878de1981bb30903785175d4030e4c065c6c85  
> v3-0001-avfilter-add-XPSNR-filter.patch
> From 6a020fc9279ab2fd66e6dd8596f566ee6578cb35 Mon Sep 17 00:00:00 2001
> From: Christian Helmrich 
> Date: Thu, 4 Jul 2024 17:10:29 +0200
> Subject: [PATCH v3] avfilter: add XPSNR filter
>
> Add XPSNR video filter
> Register new filter xpsnr.
[...]

> +#include "libavutil/avstring.h"
> +#include "libavutil/file_open.h"
> +#include "libavutil/mem.h"
> +#include "libavutil/opt.h"
> +#include "libavutil/pixdesc.h"
> +#include "avfilter.h"
> +#include "drawutils.h"
> +#include "framesync.h"

> +#include "internal.h"

libavfilter/vf_xpsnr.c:38:10: fatal error: internal.h: No such file or directory
   38 | #include "internal.h"

[...]
> +/* prepare XPSNR calculations: allocate temporary picture and block 
> memory */
> +if (s->sse_luma == NULL)
> +s->sse_luma = (double *) av_malloc_array(w_blk * h_blk, 
> sizeof(double));
> +if (s->weights  == NULL)
> +s->weights  = (double *) av_malloc_array(w_blk * h_blk, 
> sizeof(double));

the casts are unneeded


[...]
> +if (s->sse_luma)
> +av_freep(&s->sse_luma);
> +if (s->weights )
> +av_freep(&s->weights );

av_free*(NULL) is safe

thx

[...]

--
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

Those who are too smart to engage in politics are punished by being
governed by those who are dumber. -- Plato
From 0ef09ee4347894086659acdc7c55ac44f3327596 Mon Sep 17 00:00:00 2001
From: Christian Helmrich 
Date: Mon, 26 Aug 2024 16:30:26 +0200
Subject: [PATCH v4] avfilter: add XPSNR filter

Add XPSNR video filter
Register new filter xpsnr.
---
 doc/filters.texi|  68 +++
 libavfilter/Makefile|   1 +
 libavfilter/allfilters.c|   1 +
 libavfilter/vf_xpsnr.c  | 735 
 libavfilter/x86/Makefile|   1 +
 libavfilter/x86/vf_xpsnr_init.c |  43 ++
 libavfilter/xpsnr.h |  48 +++
 7 files changed, 897 insertions(+)
 create mode 100644 libavfilter/vf_xpsnr.c
 create mode 100644 libavfilter/x86/vf_xpsnr_init.c
 create mode 100644 libavfilter/xpsnr.h

diff --git a/doc/filters.texi b/doc/filters.texi
index 2eb4a380fb..a40b1b17be 100644
--- a/doc/filters.texi
+++ b/doc/filters.texi
@@ -19944,6 +19944,7 @@ 
pseudocolor="'if(between(val,ymax,amax),lerp(ymin,ymax,(val-ymax)/(amax-ymax)),-
 @end example
 @end itemize
 
+@anchor{psnr}
 @section psnr
 
 Obtain the average, maximum and minimum PSNR (Peak Signal to Noise
@@ -26064,6 +26065,73 @@ minimum values, and @code{1} maximum values.
 
 This filter supports all above options as @ref{commands}, excluding option 
@code{inputs}.
 
+@anchor{xpsnr}
+@section xpsnr
+
+Obtain the average (across all input frames) and minimum (across all color 
plane averages)
+eXtended Perceptually weighted peak Signal-to-Noise Ratio (XPSNR) between two 
input videos.
+
+The XPSNR is a low-complexity psychovisually motivated distortion measurement 
algorithm for
+assessing the difference between two video streams or images. This is 
espec

[FFmpeg-devel] [PATCH v5] avfilter: add XPSNR filter

2024-08-28 Thread Helmrich, Christian
Following up on this: attached a (final, in our view) v5. Changes over v3:


- cleanup and align to psnr filter
- add metadata
- add xpsnr tests for yuv and rgb


Christian



Von: Helmrich, Christian
Gesendet: Montag, 26. August 2024 19:41
An: FFmpeg development discussions and patches
Betreff: [FFmpeg-devel] [PATCH v4] avfilter: add XPSNR filter


Hi and thanks for taking a look at this!

> maybe you can add a fate test

I understand my colleague (who supports me on this) right, he's still looking 
into how to do that.
But to have some quick progress on your other comments:

> libavfilter/vf_xpsnr.c:38:10: fatal error: internal.h: No such file or 
> directory
>   38 | #include "internal.h"

Thanks, fixed in v4 (attached).

> the casts are unneeded

Thanks, fixed in v4.

> av_free*(NULL) is safe

Thanks, fixed in v4.

Christian Helmrich

Fraunhofer HHI



Von: ffmpeg-devel  im Auftrag von Michael 
Niedermayer 
Gesendet: Freitag, 23. August 2024 22:00
An: FFmpeg development discussions and patches
Betreff: Re: [FFmpeg-devel] [PATCH v3] avfilter: add XPSNR filter

On Thu, Jul 04, 2024 at 03:50:34PM +, Helmrich, Christian wrote:
> This is a continuation of last year's version of this filter patch, see also
>
> https://ffmpeg.org/pipermail/ffmpeg-devel/2023-January/305517.html
>
> It includes a fix in one of the stride variables and some cleanup in order
>
> to adhere even more to the FFmpeg coding guidelines.
>
>
> Christian Helmrich
>
> Fraunhofer HHI

>  doc/filters.texi|   68 +++
>  libavfilter/Makefile|1
>  libavfilter/allfilters.c|1
>  libavfilter/vf_xpsnr.c  |  739 
> 
>  libavfilter/x86/Makefile|1
>  libavfilter/x86/vf_xpsnr_init.c |   43 ++
>  libavfilter/xpsnr.h |   48 ++
>  7 files changed, 901 insertions(+)

maybe you can add a fate test


> 50878de1981bb30903785175d4030e4c065c6c85  
> v3-0001-avfilter-add-XPSNR-filter.patch
> From 6a020fc9279ab2fd66e6dd8596f566ee6578cb35 Mon Sep 17 00:00:00 2001
> From: Christian Helmrich 
> Date: Thu, 4 Jul 2024 17:10:29 +0200
> Subject: [PATCH v3] avfilter: add XPSNR filter
>
> Add XPSNR video filter
> Register new filter xpsnr.
[...]

> +#include "libavutil/avstring.h"
> +#include "libavutil/file_open.h"
> +#include "libavutil/mem.h"
> +#include "libavutil/opt.h"
> +#include "libavutil/pixdesc.h"
> +#include "avfilter.h"
> +#include "drawutils.h"
> +#include "framesync.h"

> +#include "internal.h"

libavfilter/vf_xpsnr.c:38:10: fatal error: internal.h: No such file or directory
   38 | #include "internal.h"

[...]
> +/* prepare XPSNR calculations: allocate temporary picture and block 
> memory */
> +if (s->sse_luma == NULL)
> +s->sse_luma = (double *) av_malloc_array(w_blk * h_blk, 
> sizeof(double));
> +if (s->weights  == NULL)
> +s->weights  = (double *) av_malloc_array(w_blk * h_blk, 
> sizeof(double));

the casts are unneeded


[...]
> +if (s->sse_luma)
> +av_freep(&s->sse_luma);
> +if (s->weights )
> +av_freep(&s->weights );

av_free*(NULL) is safe

thx

[...]

--
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

Those who are too smart to engage in politics are punished by being
governed by those who are dumber. -- Plato
From ae0de58e4a3250d3e5bc5aa13f633d600d4d112b Mon Sep 17 00:00:00 2001
From: Christian Helmrich 
Date: Wed, 28 Aug 2024 11:28:49 +0200
Subject: [PATCH v5] avfilter: add XPSNR filter

Add XPSNR video filter
Register new filter xpsnr.
---
 doc/filters.texi   |  68 +++
 libavfilter/Makefile   |   1 +
 libavfilter/allfilters.c   |   1 +
 libavfilter/vf_xpsnr.c | 759 +
 libavfilter/x86/Makefile   |   1 +
 libavfilter/x86/vf_xpsnr_init.c|  43 ++
 libavfilter/xpsnr.h|  48 ++
 tests/fate/filter-video.mak|   6 +
 tests/ref/fate/filter-refcmp-xpsnr-rgb |  20 +
 tests/ref/fate/filter-refcmp-xpsnr-yuv |  20 +
 10 files changed, 967 insertions(+)
 create mode 100644 libavfilter/vf_xpsnr.c
 create mode 100644 libavfilter/x86/vf_xpsnr_init.c
 create mode 100644 libavfilter/xpsnr.h
 create mode 100644 tests/ref/fate/filter-refcmp-xpsnr-rgb
 create mode 100644 tests/ref/fate/filter-refcmp-xpsnr-yuv

diff --git a/doc/filters.texi b/doc/filters.texi
index 2eb4a380fb..a40b1b17be 100644
--- a/doc/filters.texi
+++ b/doc/filters.texi
@@ -19944,6 +19944,7 @@ 
pseudocolor="'if(between(val,ymax,amax),lerp(ymin,ymax,(val-ymax)/(amax-yma

[FFmpeg-devel] [PATCH v1] XPSNR: add maintainers

2024-09-06 Thread Helmrich, Christian
Hi, adding us XPSNR authors to MAINTAINERS, as requested/suggested in

https://ffmpeg.org/pipermail/ffmpeg-devel/2024-September/332940.html


Best,


Christian Helmrich

Fraunhofer HHI



Von: Helmrich, Christian
Gesendet: Montag, 26. August 2024 19:41
An: FFmpeg development discussions and patches
Betreff: [FFmpeg-devel] [PATCH v4] avfilter: add XPSNR filter


Hi and thanks for taking a look at this!

> maybe you can add a fate test

I understand my colleague (who supports me on this) right, he's still looking 
into how to do that.
But to have some quick progress on your other comments:

> libavfilter/vf_xpsnr.c:38:10: fatal error: internal.h: No such file or 
> directory
>   38 | #include "internal.h"

Thanks, fixed in v4 (attached).

> the casts are unneeded

Thanks, fixed in v4.

> av_free*(NULL) is safe

Thanks, fixed in v4.

Christian Helmrich

Fraunhofer HHI



Von: ffmpeg-devel  im Auftrag von Michael 
Niedermayer 
Gesendet: Freitag, 23. August 2024 22:00
An: FFmpeg development discussions and patches
Betreff: Re: [FFmpeg-devel] [PATCH v3] avfilter: add XPSNR filter

On Thu, Jul 04, 2024 at 03:50:34PM +, Helmrich, Christian wrote:
> This is a continuation of last year's version of this filter patch, see also
>
> https://ffmpeg.org/pipermail/ffmpeg-devel/2023-January/305517.html
>
> It includes a fix in one of the stride variables and some cleanup in order
>
> to adhere even more to the FFmpeg coding guidelines.
>
>
> Christian Helmrich
>
> Fraunhofer HHI

>  doc/filters.texi|   68 +++
>  libavfilter/Makefile|1
>  libavfilter/allfilters.c|1
>  libavfilter/vf_xpsnr.c  |  739 
> 
>  libavfilter/x86/Makefile|1
>  libavfilter/x86/vf_xpsnr_init.c |   43 ++
>  libavfilter/xpsnr.h |   48 ++
>  7 files changed, 901 insertions(+)

maybe you can add a fate test


> 50878de1981bb30903785175d4030e4c065c6c85  
> v3-0001-avfilter-add-XPSNR-filter.patch
> From 6a020fc9279ab2fd66e6dd8596f566ee6578cb35 Mon Sep 17 00:00:00 2001
> From: Christian Helmrich 
> Date: Thu, 4 Jul 2024 17:10:29 +0200
> Subject: [PATCH v3] avfilter: add XPSNR filter
>
> Add XPSNR video filter
> Register new filter xpsnr.
[...]

> +#include "libavutil/avstring.h"
> +#include "libavutil/file_open.h"
> +#include "libavutil/mem.h"
> +#include "libavutil/opt.h"
> +#include "libavutil/pixdesc.h"
> +#include "avfilter.h"
> +#include "drawutils.h"
> +#include "framesync.h"

> +#include "internal.h"

libavfilter/vf_xpsnr.c:38:10: fatal error: internal.h: No such file or directory
   38 | #include "internal.h"

[...]
> +/* prepare XPSNR calculations: allocate temporary picture and block 
> memory */
> +if (s->sse_luma == NULL)
> +s->sse_luma = (double *) av_malloc_array(w_blk * h_blk, 
> sizeof(double));
> +if (s->weights  == NULL)
> +s->weights  = (double *) av_malloc_array(w_blk * h_blk, 
> sizeof(double));

the casts are unneeded


[...]
> +if (s->sse_luma)
> +av_freep(&s->sse_luma);
> +if (s->weights )
> +av_freep(&s->weights );

av_free*(NULL) is safe

thx

[...]

--
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

Those who are too smart to engage in politics are punished by being
governed by those who are dumber. -- Plato
From 6a020fc9279ab2fd66e6dd8596f566ee6578cb35 Mon Sep 17 00:00:00 2001
From: Christian Helmrich 
Date: Fri, 6 Sep 2024 17:00:00 +0200
Subject: [PATCH v1] XPSNR: add maintainers

Add XPSNR authors to MAINTAINERS
---

diff --git a/MAINTAINERS b/MAINTAINERS
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -344,6 +344,7 @@
   vf_readvitc.c Tobias Rapp (CC t.rapp at noa-archive 
dot com)
   vf_scale.c[2] Michael Niedermayer
   vf_tonemap_opencl.c   Ruiling Song
+  vf_xpsnr.cChristian Helmrich, Christian Lehmann
   vf_yadif.c[2] Michael Niedermayer
 
 Sources:
--
2.43.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] Request for adding XPSNR avfilter

2023-01-11 Thread Helmrich, Christian
Hi,


> Also please fix style of code, ... example vf_psnr.c filter ... "for () {\n" 
> instead of "for () \n{\n}"


Done, I aligned block encapsulation, indentation, and some other things with 
those in vf_psnr.c


> Compare clang compiled ffmpeg without this asm code and with it, and tell if 
> any difference.

> I'might do it anyway later.

Strange, the asm code is now only barely (a few percent at most) faster than 
the C-loop code on
our side. Maybe the compilers or CPUs have improved since we last tested? 
Anway, we decided
to make a new patch without the asm file, but keep the function pointers in 
case we manage to
write better SIMD for the highds, diff1st, and diff2nd function later (for a 
smaller patch then).

I prepared a new avfilter_xpsnr_v2.patch. Do I need to change the email 
(thread) title somehow
so that a new pipeline is being triggered?


Best,


Christian Helmrich

Fraunhofer HHI, Video Coding and Analytics Department



Von: ffmpeg-devel  im Auftrag von Paul B Mahol 

Gesendet: Mittwoch, 11. Januar 2023 12:53
An: FFmpeg development discussions and patches
Cc: Stoffers, Christian
Betreff: Re: [FFmpeg-devel] [PATCH] Request for adding XPSNR avfilter

On 1/11/23, Paul B Mahol  wrote:
> On 1/11/23, Helmrich, Christian 
> wrote:
>> Hi,
>>
>>
>>> So its better to use that instead of human written assembly? Does clang
>>> generate faster code without this asm?
>>
>>
>> I'm not sure I fully understand your questions, but I hope the following
>> answers it. The reason why we auto-converted our intrinsics code to asm
>> is
>> not a technical one, we unfortunately just don't have the knowledge or
>> resources to manually write asm code. If I remember correctly, the SIMD
>> optimized code runs about twice as fast as the C code, especially on UHD
>> input.
>
> Compare clang compiled ffmpeg without this asm code and with it, and
> tell if any difference.
> I'might do it anyway later.

Also please fix style of code, look at other filters in codebase, for
example vf_psnr.c filter

Use "for () {\n" instead of "for () \n{\n}"

>
>>
>>
>>> Please remove SLICE_THREADS related flag as there is no call to execute
>>> to
>>> filter in slices. Please remove stdbool.h header and adapt code to
>>> compile
>>> without it.
>>
>>
>> Done, please find attached a second version (v1) of the XPSNR avfilter
>> patch.
>>
>>
>> Thanks and best,
>>
>>
>> Christian Helmrich
>>
>> Fraunhofer HHI, Video Coding and Analytics Department
>>
>>
>> 
>> Von: ffmpeg-devel  im Auftrag von Paul B
>> Mahol 
>> Gesendet: Dienstag, 10. Januar 2023 21:43
>> An: FFmpeg development discussions and patches
>> Cc: Stoffers, Christian
>> Betreff: Re: [FFmpeg-devel] [PATCH] Request for adding XPSNR avfilter
>>
>> On 1/10/23, Helmrich, Christian 
>> wrote:
>>> Hi,
>>>
>>> please find attached a patch (relative to FFmpeg master as of early
>>> January
>>> 10, 2023)
>>> adding avfilter support for extended perceptually weighted peak
>>> signal-to-noise ratio
>>> (XPSNR) measurements for videos, as described in the related addition to
>>> filters.texi.
>>>
>>> The XPSNR code was originally vectorized using SIMD intrinsics, but we
>>> concluded that
>>> FFmpeg code requires asm instead of such intrinsics, so we let gcc
>>> auto-convert these
>>
>> So its better to use that instead of human written assembly?
>> Does clang generate faster code without this asm?
>>
>>> instructions to pure assembly; see the vf_xpsnr.asm file. If the added
>>> asm
>>> code is too
>>> lengthy, intrinsics would be possible, or something else is missing,
>>> please
>>> let us know.
>>>
>>
>> Please remove SLICE_THREADS related flag as there is no call to
>> execute to filter in slices.
>> Please remove stdbool.h header and adapt code to compile without it.
>>
>>> Best,
>>>
>>> Christian Helmrich and Christian Stoffers
>>> Fraunhofer HHI
>>>
>> ___
>> 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 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] Request for adding XPSNR avfilter

2023-01-11 Thread Helmrich, Christian
Hi,


> just attach patch with proper authorship, made with git fformat-patch.


Done, attached.


Best,


Christian Helmrich

Fraunhofer HHI, Video Coding and Analytics Department



Von: ffmpeg-devel  im Auftrag von Paul B Mahol 

Gesendet: Mittwoch, 11. Januar 2023 19:33
An: FFmpeg development discussions and patches
Cc: Stoffers, Christian
Betreff: Re: [FFmpeg-devel] [PATCH] Request for adding XPSNR avfilter

On 1/11/23, Helmrich, Christian  wrote:
> Hi,
>
>
>> Also please fix style of code, ... example vf_psnr.c filter ... "for ()
>> {\n" instead of "for () \n{\n}"
>
>
> Done, I aligned block encapsulation, indentation, and some other things with
> those in vf_psnr.c
>
>
>> Compare clang compiled ffmpeg without this asm code and with it, and tell
>> if any difference.
>
>> I'might do it anyway later.
>
> Strange, the asm code is now only barely (a few percent at most) faster than
> the C-loop code on
> our side. Maybe the compilers or CPUs have improved since we last tested?
> Anway, we decided
> to make a new patch without the asm file, but keep the function pointers in
> case we manage to
> write better SIMD for the highds, diff1st, and diff2nd function later (for a
> smaller patch then).
>
> I prepared a new avfilter_xpsnr_v2.patch. Do I need to change the email
> (thread) title somehow
> so that a new pipeline is being triggered?

Not needed, just attach patch with proper authorship, made with git
format-patch.

>
>
> Best,
>
>
> Christian Helmrich
>
> Fraunhofer HHI, Video Coding and Analytics Department
>
>
> 
> Von: ffmpeg-devel  im Auftrag von Paul B
> Mahol 
> Gesendet: Mittwoch, 11. Januar 2023 12:53
> An: FFmpeg development discussions and patches
> Cc: Stoffers, Christian
> Betreff: Re: [FFmpeg-devel] [PATCH] Request for adding XPSNR avfilter
>
> On 1/11/23, Paul B Mahol  wrote:
>> On 1/11/23, Helmrich, Christian 
>> wrote:
>>> Hi,
>>>
>>>
>>>> So its better to use that instead of human written assembly? Does clang
>>>> generate faster code without this asm?
>>>
>>>
>>> I'm not sure I fully understand your questions, but I hope the following
>>> answers it. The reason why we auto-converted our intrinsics code to asm
>>> is
>>> not a technical one, we unfortunately just don't have the knowledge or
>>> resources to manually write asm code. If I remember correctly, the SIMD
>>> optimized code runs about twice as fast as the C code, especially on UHD
>>> input.
>>
>> Compare clang compiled ffmpeg without this asm code and with it, and
>> tell if any difference.
>> I'might do it anyway later.
>
> Also please fix style of code, look at other filters in codebase, for
> example vf_psnr.c filter
>
> Use "for () {\n" instead of "for () \n{\n}"
>
>>
>>>
>>>
>>>> Please remove SLICE_THREADS related flag as there is no call to execute
>>>> to
>>>> filter in slices. Please remove stdbool.h header and adapt code to
>>>> compile
>>>> without it.
>>>
>>>
>>> Done, please find attached a second version (v1) of the XPSNR avfilter
>>> patch.
>>>
>>>
>>> Thanks and best,
>>>
>>>
>>> Christian Helmrich
>>>
>>> Fraunhofer HHI, Video Coding and Analytics Department
>>>
>>>
>>> 
>>> Von: ffmpeg-devel  im Auftrag von Paul
>>> B
>>> Mahol 
>>> Gesendet: Dienstag, 10. Januar 2023 21:43
>>> An: FFmpeg development discussions and patches
>>> Cc: Stoffers, Christian
>>> Betreff: Re: [FFmpeg-devel] [PATCH] Request for adding XPSNR avfilter
>>>
>>> On 1/10/23, Helmrich, Christian 
>>> wrote:
>>>> Hi,
>>>>
>>>> please find attached a patch (relative to FFmpeg master as of early
>>>> January
>>>> 10, 2023)
>>>> adding avfilter support for extended perceptually weighted peak
>>>> signal-to-noise ratio
>>>> (XPSNR) measurements for videos, as described in the related addition
>>>> to
>>>> filters.texi.
>>>>
>>>> The XPSNR code was originally vectorized using SIMD intrinsics, but we
>>>> concluded that
>>>> FFmpeg code requires asm instead of such intrinsics, so we let gcc
>>>> auto-convert these
>>>
>>> So its better to use that inste

Re: [FFmpeg-devel] [PATCH] Request for adding XPSNR avfilter

2023-01-17 Thread Helmrich, Christian
> just attach patch with proper authorship, made with git format-patch.


Small update, replacing our own MAX( ) define with FFmpeg's existing FFMAX( ) 
and

adding a v2 to the patch so that, hopefully, the fate pipeline is triggered now.


Best,


Christian Helmrich

Fraunhofer HHI, Video Coding and Analytics Department



Von: ffmpeg-devel  im Auftrag von Helmrich, 
Christian 
Gesendet: Mittwoch, 11. Januar 2023 20:15
An: FFmpeg development discussions and patches
Cc: Stoffers, Christian
Betreff: Re: [FFmpeg-devel] [PATCH] Request for adding XPSNR avfilter

Hi,


> just attach patch with proper authorship, made with git fformat-patch.


Done, attached.


Best,


Christian Helmrich

Fraunhofer HHI, Video Coding and Analytics Department



Von: ffmpeg-devel  im Auftrag von Paul B Mahol 

Gesendet: Mittwoch, 11. Januar 2023 19:33
An: FFmpeg development discussions and patches
Cc: Stoffers, Christian
Betreff: Re: [FFmpeg-devel] [PATCH] Request for adding XPSNR avfilter

On 1/11/23, Helmrich, Christian  wrote:
> Hi,
>
>
>> Also please fix style of code, ... example vf_psnr.c filter ... "for ()
>> {\n" instead of "for () \n{\n}"
>
>
> Done, I aligned block encapsulation, indentation, and some other things with
> those in vf_psnr.c
>
>
>> Compare clang compiled ffmpeg without this asm code and with it, and tell
>> if any difference.
>
>> I'might do it anyway later.
>
> Strange, the asm code is now only barely (a few percent at most) faster than
> the C-loop code on
> our side. Maybe the compilers or CPUs have improved since we last tested?
> Anway, we decided
> to make a new patch without the asm file, but keep the function pointers in
> case we manage to
> write better SIMD for the highds, diff1st, and diff2nd function later (for a
> smaller patch then).
>
> I prepared a new avfilter_xpsnr_v2.patch. Do I need to change the email
> (thread) title somehow
> so that a new pipeline is being triggered?

Not needed, just attach patch with proper authorship, made with git
format-patch.

>
>
> Best,
>
>
> Christian Helmrich
>
> Fraunhofer HHI, Video Coding and Analytics Department
>
>
> ____
> Von: ffmpeg-devel  im Auftrag von Paul B
> Mahol 
> Gesendet: Mittwoch, 11. Januar 2023 12:53
> An: FFmpeg development discussions and patches
> Cc: Stoffers, Christian
> Betreff: Re: [FFmpeg-devel] [PATCH] Request for adding XPSNR avfilter
>
> On 1/11/23, Paul B Mahol  wrote:
>> On 1/11/23, Helmrich, Christian 
>> wrote:
>>> Hi,
>>>
>>>
>>>> So its better to use that instead of human written assembly? Does clang
>>>> generate faster code without this asm?
>>>
>>>
>>> I'm not sure I fully understand your questions, but I hope the following
>>> answers it. The reason why we auto-converted our intrinsics code to asm
>>> is
>>> not a technical one, we unfortunately just don't have the knowledge or
>>> resources to manually write asm code. If I remember correctly, the SIMD
>>> optimized code runs about twice as fast as the C code, especially on UHD
>>> input.
>>
>> Compare clang compiled ffmpeg without this asm code and with it, and
>> tell if any difference.
>> I'might do it anyway later.
>
> Also please fix style of code, look at other filters in codebase, for
> example vf_psnr.c filter
>
> Use "for () {\n" instead of "for () \n{\n}"
>
>>
>>>
>>>
>>>> Please remove SLICE_THREADS related flag as there is no call to execute
>>>> to
>>>> filter in slices. Please remove stdbool.h header and adapt code to
>>>> compile
>>>> without it.
>>>
>>>
>>> Done, please find attached a second version (v1) of the XPSNR avfilter
>>> patch.
>>>
>>>
>>> Thanks and best,
>>>
>>>
>>> Christian Helmrich
>>>
>>> Fraunhofer HHI, Video Coding and Analytics Department
>>>
>>>
>>> 
>>> Von: ffmpeg-devel  im Auftrag von Paul
>>> B
>>> Mahol 
>>> Gesendet: Dienstag, 10. Januar 2023 21:43
>>> An: FFmpeg development discussions and patches
>>> Cc: Stoffers, Christian
>>> Betreff: Re: [FFmpeg-devel] [PATCH] Request for adding XPSNR avfilter
>>>
>>> On 1/10/23, Helmrich, Christian 
>>> wrote:
>>>> Hi,
>>>>
>>>> please find attached a patch (relative to FFmpeg master as of early
>>>> 

[FFmpeg-devel] [PATCH] avformat/hlsenc: added HLS encryption

2014-11-26 Thread Christian Suloway
Signed-off-by: Christian Suloway 
---
 libavformat/crypto.c | 233 ---
 libavformat/hlsenc.c | 387 ++-
 2 files changed, 567 insertions(+), 53 deletions(-)

diff --git a/libavformat/crypto.c b/libavformat/crypto.c
index a9b6e47..dc3dc88 100644
--- a/libavformat/crypto.c
+++ b/libavformat/crypto.c
@@ -38,17 +38,35 @@ typedef struct {
 int indata, indata_used, outdata;
 int eof;
 uint8_t *key;
-int keylen;
+int key_len;
 uint8_t *iv;
-int ivlen;
-struct AVAES *aes;
+int iv_len;
+uint8_t *decrypt_key;
+int decrypt_key_len;
+uint8_t *decrypt_iv;
+int decrypt_iv_len;
+uint8_t *encrypt_key;
+int encrypt_key_len;
+uint8_t *encrypt_iv;
+int encrypt_iv_len;
+struct AVAES *aes_decrypt;
+struct AVAES *aes_encrypt;
+
+uint8_t pad[BLOCKSIZE];
+int pad_len;
+
 } CryptoContext;
 
 #define OFFSET(x) offsetof(CryptoContext, x)
 #define D AV_OPT_FLAG_DECODING_PARAM
+#define E AV_OPT_FLAG_ENCODING_PARAM
 static const AVOption options[] = {
-{"key", "AES decryption key", OFFSET(key), AV_OPT_TYPE_BINARY, .flags = D 
},
-{"iv",  "AES decryption initialization vector", OFFSET(iv), 
AV_OPT_TYPE_BINARY, .flags = D },
+{"key", "AES encryption/decryption key",   OFFSET(key),
 AV_OPT_TYPE_BINARY, .flags = D|E },
+{"iv",  "AES encryption/decryption initialization vector", OFFSET(iv), 
 AV_OPT_TYPE_BINARY, .flags = D|E },
+{"decryption_key", "AES decryption key",   
OFFSET(decrypt_key), AV_OPT_TYPE_BINARY, .flags = D },
+{"decryption_iv",  "AES decryption initialization vector", 
OFFSET(decrypt_iv),  AV_OPT_TYPE_BINARY, .flags = D },
+{"encryption_key", "AES encryption key",   
OFFSET(encrypt_key), AV_OPT_TYPE_BINARY, .flags = E },
+{"encryption_iv",  "AES encryption initialization vector", 
OFFSET(encrypt_iv),  AV_OPT_TYPE_BINARY, .flags = E },
 { NULL }
 };
 
@@ -72,28 +90,145 @@ static int crypto_open2(URLContext *h, const char *uri, 
int flags, AVDictionary
 goto err;
 }
 
-if (c->keylen < BLOCKSIZE || c->ivlen < BLOCKSIZE) {
-av_log(h, AV_LOG_ERROR, "Key or IV not set\n");
-ret = AVERROR(EINVAL);
-goto err;
+if (flags & AVIO_FLAG_READ) {
+if (!c->decrypt_key_len) {
+if (!c->key_len) {
+av_log(h, AV_LOG_ERROR, "decryption key not set\n");
+ret = AVERROR(EINVAL);
+goto err;
+} else if (c->key_len != BLOCKSIZE) {
+av_log(h, AV_LOG_ERROR, "invalid key size "
+"(%d bytes, block size is %d)\n",
+c->key_len, BLOCKSIZE);
+ret = AVERROR(EINVAL);
+goto err;
+}
+c->decrypt_key = av_malloc(c->key_len);
+if (!c->decrypt_key) {
+ret = AVERROR(ENOMEM);
+goto err;
+}
+memcpy(c->decrypt_key, c->key, c->key_len);
+c->decrypt_key_len = c->key_len;
+} else if (c->decrypt_key_len != BLOCKSIZE) {
+av_log(h, AV_LOG_ERROR, "invalid decryption key size "
+"(%d bytes, block size is %d)\n",
+c->decrypt_key_len, BLOCKSIZE);
+ret = AVERROR(EINVAL);
+goto err;
+}
+if (!c->decrypt_iv_len) {
+if (!c->iv_len) {
+av_log(h, AV_LOG_ERROR, "decryption IV not set\n");
+ret = AVERROR(EINVAL);
+goto err;
+} else if (c->iv_len != BLOCKSIZE) {
+av_log(h, AV_LOG_ERROR, "invalid IV size "
+"(%d bytes, block size is %d)\n",
+c->iv_len, BLOCKSIZE);
+ret = AVERROR(EINVAL);
+goto err;
+}
+c->decrypt_iv = av_malloc(c->iv_len);
+if (!c->decrypt_iv) {
+ret = AVERROR(ENOMEM);
+goto err;
+}
+memcpy(c->decrypt_iv, c->iv, c->iv_len);
+c->decrypt_iv_len = c->iv_len;
+} else if (c->decrypt_iv_len != BLOCKSIZE) {
+av_log(h, AV_LOG_ERROR, "invalid decryption IV size "
+"(%d bytes, block size is %d)\n",
+c->decrypt_iv_len, BLOCKSIZE);
+ret = AVERROR(EINVAL);
+

[FFmpeg-devel] [PATCH 3/4] avformat/hlsenc: added segment file deletion

2014-12-01 Thread Christian Suloway
Option removes segments no longer in playlist when older than playlist + 
segment duration

Signed-off-by: Christian Suloway 
---
 libavformat/hlsenc.c | 72 
 1 file changed, 67 insertions(+), 5 deletions(-)

diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c
index 0a48919..11817a9 100644
--- a/libavformat/hlsenc.c
+++ b/libavformat/hlsenc.c
@@ -19,8 +19,13 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
+#include "config.h"
 #include 
 #include 
+#if HAVE_UNISTD_H
+#include 
+#endif
+#include 
 
 #include "libavutil/avassert.h"
 #include "libavutil/mathematics.h"
@@ -58,6 +63,7 @@ typedef struct HLSContext {
 float time;// Set by a private option.
 int max_nb_segments;   // Set by a private option.
 int  wrap; // Set by a private option.
+int delete_segments;
 uint32_t flags;// enum HLSFlags
 
 int allowcache;
@@ -72,6 +78,7 @@ typedef struct HLSContext {
 
 HLSSegment *segments;
 HLSSegment *last_segment;
+HLSSegment *old_segments;
 
 char *dirname;
 char *basename;
@@ -90,6 +97,52 @@ static void hls_free_segment(HLSSegment *en)
 av_freep(&en);
 }
 
+static int hls_delete_old_segments(HLSContext *hls) {
+
+HLSSegment *segment, *previous_segment = NULL;
+float playlist_duration = 0.0f;
+int path_size;
+char *path;
+
+segment = hls->segments;
+while (segment) {
+playlist_duration += segment->duration;
+segment = segment->next;
+}
+
+segment = hls->old_segments;
+while (segment) {
+playlist_duration -= segment->duration;
+previous_segment = segment;
+segment = segment->next;
+if (playlist_duration <= 0.0f) {
+previous_segment->next = NULL;
+break;
+}
+}
+
+while (segment) {
+av_log(hls, AV_LOG_DEBUG, "deleting old segment %s\n",
+  segment->filename);
+path_size = strlen(hls->dirname) + strlen(segment->filename) + 1;
+path = av_malloc(path_size);
+if (!path)
+return AVERROR(ENOMEM);
+av_strlcpy(path, hls->dirname, path_size);
+av_strlcat(path, segment->filename, path_size);
+if (unlink(path) < 0) {
+av_log(hls, AV_LOG_ERROR, "failed to delete old segment %s: %s\n",
+ path, strerror(errno));
+}
+av_free(path);
+previous_segment = segment;
+segment = segment->next;
+hls_free_segment(previous_segment);
+}
+
+return 0;
+}
+
 static int hls_mux_init(AVFormatContext *s)
 {
 HLSContext *hls = s->priv_data;
@@ -124,6 +177,7 @@ static int hls_append_segment(HLSContext *hls, double 
duration, int64_t pos,
   int64_t size)
 {
 HLSSegment *en = av_malloc(sizeof(*en));
+int ret;
 
 if (!en)
 return AVERROR(ENOMEM);
@@ -147,7 +201,14 @@ static int hls_append_segment(HLSContext *hls, double 
duration, int64_t pos,
 if (hls->max_nb_segments && hls->nb_entries >= hls->max_nb_segments) {
 en = hls->segments;
 hls->segments = en->next;
-hls_free_segment(en);
+
+if (en && hls->delete_segments && !hls->wrap) {
+en->next = hls->old_segments;
+hls->old_segments = en;
+if ((ret = hls_delete_old_segments(hls)) < 0)
+return ret;
+} else
+hls_free_segment(en);
 } else
 hls->nb_entries++;
 
@@ -156,9 +217,9 @@ static int hls_append_segment(HLSContext *hls, double 
duration, int64_t pos,
 return 0;
 }
 
-static void hls_free_segments(HLSContext *hls)
+static void hls_free_segments(HLSSegment *p)
 {
-HLSSegment *p = hls->segments, *en;
+HLSSegment *en;
 
 while(p) {
 en = p;
@@ -197,7 +258,6 @@ static int hls_window(AVFormatContext *s, int last)
sequence);
 
 for (en = hls->segments; en; en = en->next) {
-
 avio_printf(hls->pb, "#EXTINF:%f,\n", en->duration);
 if (hls->flags & HLS_SINGLE_FILE)
  avio_printf(hls->pb, "#EXT-X-BYTERANGE:%"PRIi64"@%"PRIi64"\n",
@@ -442,7 +502,8 @@ static int hls_write_trailer(struct AVFormatContext *s)
 hls->avf = NULL;
 hls_window(s, 1);
 
-hls_free_segments(hls);
+hls_free_segments(hls->segments);
+hls_free_segments(hls->old_segments);
 av_free(hls->dirname);
 
 avio_close(hls->pb);
@@ -458,6 +519,7 @@ static const AVOption options[] = {
 {"hls_list_size", "set maximum number of playlist entries",  
OFFSET(max_nb_segments),AV_OPT_TYPE_INT,{.i64 = 5}, 0, INT_MAX, E},
 

[FFmpeg-devel] [PATCH 2/4] avformat/hlsenc: added segment filename template

2014-12-01 Thread Christian Suloway
Signed-off-by: Christian Suloway 
---
 libavformat/hlsenc.c | 87 +---
 1 file changed, 69 insertions(+), 18 deletions(-)

diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c
index e13f438..0a48919 100644
--- a/libavformat/hlsenc.c
+++ b/libavformat/hlsenc.c
@@ -33,7 +33,7 @@
 #include "internal.h"
 
 typedef struct HLSSegment {
-char filename[1024];
+char *filename;
 double duration; /* in seconds */
 int64_t pos;
 int64_t size;
@@ -73,14 +73,23 @@ typedef struct HLSContext {
 HLSSegment *segments;
 HLSSegment *last_segment;
 
+char *dirname;
 char *basename;
 char *baseurl;
 char *format_options_str;
 AVDictionary *format_options;
 
+char *segment_filename;
+
 AVIOContext *pb;
 } HLSContext;
 
+static void hls_free_segment(HLSSegment *en)
+{
+av_freep(&en->filename);
+av_freep(&en);
+}
+
 static int hls_mux_init(AVFormatContext *s)
 {
 HLSContext *hls = s->priv_data;
@@ -119,7 +128,9 @@ static int hls_append_segment(HLSContext *hls, double 
duration, int64_t pos,
 if (!en)
 return AVERROR(ENOMEM);
 
-av_strlcpy(en->filename, av_basename(hls->avf->filename), 
sizeof(en->filename));
+en->filename = av_strdup(hls->avf->filename);
+if (!en->filename)
+return AVERROR(ENOMEM);
 
 en->duration = duration;
 en->pos  = pos;
@@ -136,7 +147,7 @@ static int hls_append_segment(HLSContext *hls, double 
duration, int64_t pos,
 if (hls->max_nb_segments && hls->nb_entries >= hls->max_nb_segments) {
 en = hls->segments;
 hls->segments = en->next;
-av_free(en);
+hls_free_segment(en);
 } else
 hls->nb_entries++;
 
@@ -152,7 +163,7 @@ static void hls_free_segments(HLSContext *hls)
 while(p) {
 en = p;
 p = p->next;
-av_free(en);
+hls_free_segment(en);
 }
 }
 
@@ -186,6 +197,7 @@ static int hls_window(AVFormatContext *s, int last)
sequence);
 
 for (en = hls->segments; en; en = en->next) {
+
 avio_printf(hls->pb, "#EXTINF:%f,\n", en->duration);
 if (hls->flags & HLS_SINGLE_FILE)
  avio_printf(hls->pb, "#EXT-X-BYTERANGE:%"PRIi64"@%"PRIi64"\n",
@@ -208,6 +220,8 @@ static int hls_start(AVFormatContext *s)
 HLSContext *c = s->priv_data;
 AVFormatContext *oc = c->avf;
 int err = 0;
+int filename_size;
+char *filename;
 
 if (c->flags & HLS_SINGLE_FILE)
 av_strlcpy(oc->filename, c->basename,
@@ -220,8 +234,18 @@ static int hls_start(AVFormatContext *s)
 }
 c->number++;
 
-if ((err = avio_open2(&oc->pb, oc->filename, AVIO_FLAG_WRITE,
-  &s->interrupt_callback, NULL)) < 0)
+filename_size = strlen(c->dirname) + strlen(oc->filename) + 1;
+filename = av_malloc(filename_size);
+if (!filename)
+return AVERROR(ENOMEM);
+*filename = '\0';
+av_strlcat(filename, c->dirname, filename_size);
+av_strlcat(filename, oc->filename, filename_size);
+
+err = avio_open2(&oc->pb, filename, AVIO_FLAG_WRITE,
+ &s->interrupt_callback, NULL);
+av_free(filename);
+if (err < 0)
 return err;
 
 if (oc->oformat->priv_class && oc->priv_data)
@@ -237,15 +261,13 @@ static int hls_write_header(AVFormatContext *s)
 char *p;
 const char *pattern = "%d.ts";
 AVDictionary *options = NULL;
-int basename_size = strlen(s->filename) + strlen(pattern) + 1;
+int basename_size;
+char *basename;
 
 hls->sequence   = hls->start_sequence;
 hls->recording_time = hls->time * AV_TIME_BASE;
 hls->start_pts  = AV_NOPTS_VALUE;
 
-if (hls->flags & HLS_SINGLE_FILE)
-pattern = ".ts";
-
 if (hls->format_options_str) {
 ret = av_dict_parse_string(&hls->format_options, 
hls->format_options_str, "=", ":", 0);
 if (ret < 0) {
@@ -270,21 +292,45 @@ static int hls_write_header(AVFormatContext *s)
 goto fail;
 }
 
-hls->basename = av_malloc(basename_size);
-
-if (!hls->basename) {
+hls->dirname = av_strdup(s->filename);
+if (!hls->dirname) {
 ret = AVERROR(ENOMEM);
 goto fail;
 }
 
-strcpy(hls->basename, s->filename);
+basename = (char *)av_basename(hls->dirname);
 
-p = strrchr(hls->basename, '.');
+if (hls->segment_filename) {
+hls->basename = av_strdup(av_basename(hls->segment_filename));
+if (!hls->basename) {
+ret = AVERROR(ENOMEM);
+goto fail;
+}
+if (strlen(hls->basename) != strlen(hl

[FFmpeg-devel] [PATCH 1/4] avformat/crypto: added encryption

2014-12-01 Thread Christian Suloway
Signed-off-by: Christian Suloway 
---
 libavformat/crypto.c | 166 ---
 1 file changed, 146 insertions(+), 20 deletions(-)

diff --git a/libavformat/crypto.c b/libavformat/crypto.c
index a9b6e47..f3a85c7 100644
--- a/libavformat/crypto.c
+++ b/libavformat/crypto.c
@@ -41,14 +41,32 @@ typedef struct {
 int keylen;
 uint8_t *iv;
 int ivlen;
-struct AVAES *aes;
+uint8_t *decrypt_key;
+int decrypt_keylen;
+uint8_t *decrypt_iv;
+int decrypt_ivlen;
+uint8_t *encrypt_key;
+int encrypt_keylen;
+uint8_t *encrypt_iv;
+int encrypt_ivlen;
+struct AVAES *aes_decrypt;
+struct AVAES *aes_encrypt;
+
+uint8_t pad[BLOCKSIZE];
+int pad_len;
+
 } CryptoContext;
 
 #define OFFSET(x) offsetof(CryptoContext, x)
 #define D AV_OPT_FLAG_DECODING_PARAM
+#define E AV_OPT_FLAG_ENCODING_PARAM
 static const AVOption options[] = {
-{"key", "AES decryption key", OFFSET(key), AV_OPT_TYPE_BINARY, .flags = D 
},
-{"iv",  "AES decryption initialization vector", OFFSET(iv), 
AV_OPT_TYPE_BINARY, .flags = D },
+{"key", "AES encryption/decryption key",   OFFSET(key),
 AV_OPT_TYPE_BINARY, .flags = D|E },
+{"iv",  "AES encryption/decryption initialization vector", OFFSET(iv), 
 AV_OPT_TYPE_BINARY, .flags = D|E },
+{"decryption_key", "AES decryption key",   
OFFSET(decrypt_key), AV_OPT_TYPE_BINARY, .flags = D },
+{"decryption_iv",  "AES decryption initialization vector", 
OFFSET(decrypt_iv),  AV_OPT_TYPE_BINARY, .flags = D },
+{"encryption_key", "AES encryption key",   
OFFSET(encrypt_key), AV_OPT_TYPE_BINARY, .flags = E },
+{"encryption_iv",  "AES encryption initialization vector", 
OFFSET(encrypt_iv),  AV_OPT_TYPE_BINARY, .flags = E },
 { NULL }
 };
 
@@ -59,6 +77,34 @@ static const AVClass crypto_class = {
 .version= LIBAVUTIL_VERSION_INT,
 };
 
+static int set_aes_arg(CryptoContext *c, uint8_t **buf, int *buf_len,
+   uint8_t *default_buf, int default_buf_len,
+   const char *desc)
+{
+if (!*buf_len) {
+if (!default_buf_len) {
+av_log(c, AV_LOG_ERROR, "%s not set\n", desc);
+return AVERROR(EINVAL);
+} else if (default_buf_len != BLOCKSIZE) {
+av_log(c, AV_LOG_ERROR,
+   "invalid %s size (%d bytes, block size is %d)\n",
+   desc, default_buf_len, BLOCKSIZE);
+return AVERROR(EINVAL);
+}
+*buf = av_malloc(default_buf_len);
+if (!*buf)
+return AVERROR(ENOMEM);
+memcpy(*buf, default_buf, default_buf_len);
+*buf_len = default_buf_len;
+} else if (*buf_len != BLOCKSIZE) {
+av_log(c, AV_LOG_ERROR,
+   "invalid %s size (%d bytes, block size is %d)\n",
+   desc, *buf_len, BLOCKSIZE);
+return AVERROR(EINVAL);
+}
+return 0;
+}
+
 static int crypto_open2(URLContext *h, const char *uri, int flags, 
AVDictionary **options)
 {
 const char *nested_url;
@@ -72,28 +118,54 @@ static int crypto_open2(URLContext *h, const char *uri, 
int flags, AVDictionary
 goto err;
 }
 
-if (c->keylen < BLOCKSIZE || c->ivlen < BLOCKSIZE) {
-av_log(h, AV_LOG_ERROR, "Key or IV not set\n");
-ret = AVERROR(EINVAL);
-goto err;
+if (flags & AVIO_FLAG_READ) {
+if ((ret = set_aes_arg(c, &c->decrypt_key, &c->decrypt_keylen,
+   c->key, c->keylen, "decryption key")) < 0)
+goto err;
+if ((ret = set_aes_arg(c, &c->decrypt_iv, &c->decrypt_ivlen,
+   c->key, c->keylen, "decryption IV")) < 0)
+goto err;
 }
+
 if (flags & AVIO_FLAG_WRITE) {
-av_log(h, AV_LOG_ERROR, "Only decryption is supported currently\n");
-ret = AVERROR(ENOSYS);
-goto err;
+if ((ret = set_aes_arg(c, &c->encrypt_key, &c->encrypt_keylen,
+   c->key, c->keylen, "encryption key")) < 0)
+if (ret < 0)
+goto err;
+if ((ret = set_aes_arg(c, &c->encrypt_iv, &c->encrypt_ivlen,
+   c->key, c->keylen, "encryption IV")) < 0)
+goto err;
 }
-if ((ret = ffurl_open(&c->hd, nested_url, AVIO_FLAG_READ,
+
+if ((ret = ffurl_open(&c->hd, nested_url, flags,
   &h->interrupt_callback, options)) < 0) {
-av_log(h, AV_LOG_ERROR, "Unable to open input\n");
+av_log(h, AV_LOG_ERR

[FFmpeg-devel] [PATCH 4/4] avformat/hlsenc: added HLS encryption

2014-12-01 Thread Christian Suloway
HLS encryption with key URL & key containing file specified with
-hls_key_info_file (key info updates when modified). Option for IV from
segment number or random generation (-hls_random_iv).

Signed-off-by: Christian Suloway 
---
 libavformat/hlsenc.c | 225 +--
 1 file changed, 218 insertions(+), 7 deletions(-)

diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c
index 11817a9..c7bd1be 100644
--- a/libavformat/hlsenc.c
+++ b/libavformat/hlsenc.c
@@ -33,16 +33,23 @@
 #include "libavutil/avstring.h"
 #include "libavutil/opt.h"
 #include "libavutil/log.h"
+#include "libavutil/lfg.h"
+#include "libavutil/random_seed.h"
 
 #include "avformat.h"
 #include "internal.h"
 
+#define BLOCKSIZE 16
+
 typedef struct HLSSegment {
 char *filename;
 double duration; /* in seconds */
 int64_t pos;
 int64_t size;
 
+char *key_uri;
+char *iv_string;
+
 struct HLSSegment *next;
 } HLSSegment;
 
@@ -88,12 +95,25 @@ typedef struct HLSContext {
 
 char *segment_filename;
 
+char *key_info_file;
+int random_iv;
+int encrypt;
+
+char *key_file;
+char *key_uri;
+char *key_string;
+char *iv_string;
+
+AVLFG *lfg;
+
 AVIOContext *pb;
 } HLSContext;
 
 static void hls_free_segment(HLSSegment *en)
 {
 av_freep(&en->filename);
+av_freep(&en->key_uri);
+av_freep(&en->iv_string);
 av_freep(&en);
 }
 
@@ -143,6 +163,137 @@ static int hls_delete_old_segments(HLSContext *hls) {
 return 0;
 }
 
+static int hls_encryption_init(AVFormatContext *s)
+{
+HLSContext *hls = s->priv_data;
+
+hls->key_file = NULL;
+hls->key_uri = NULL;
+hls->key_string = NULL;
+hls->iv_string = NULL;
+
+if (hls->key_info_file) {
+hls->encrypt = 1;
+} else {
+hls->encrypt = 0;
+return 0;
+}
+
+if (hls->random_iv) {
+hls->lfg = av_malloc(sizeof(AVLFG));
+av_lfg_init(hls->lfg, av_get_random_seed());
+} else
+hls->lfg = NULL;
+
+return 0;
+}
+
+static int hls_encryption_start(HLSContext *hls) {
+
+uint8_t *iv = NULL;
+int ret, i, j, rotate_iv = 0;
+unsigned int u;
+AVIOContext *pb = NULL;
+AVIOContext *dyn_buf = NULL;
+uint8_t buf[1024], *tmp;
+char *p, *tstr, *saveptr = NULL;
+char key[BLOCKSIZE], *key_string;
+
+if ((ret = avio_open(&pb, hls->key_info_file, AVIO_FLAG_READ)) < 0) {
+av_log(hls, AV_LOG_ERROR, "error opening key info file %s\n",
+  hls->key_info_file);
+return ret;
+}
+ret = avio_open_dyn_buf(&dyn_buf);
+if (ret < 0) {
+avio_closep(&pb);
+return ret;
+}
+
+while ((ret = avio_read(pb, buf, sizeof(buf))) > 0)
+avio_write(dyn_buf, buf, ret);
+avio_w8(dyn_buf, 0);
+avio_closep(&pb);
+
+if ((ret = avio_close_dyn_buf(dyn_buf, &tmp)) < 0)
+return ret;
+
+p = tmp;
+if (!(tstr = av_strtok(p, "\n", &saveptr)) || !*tstr) {
+av_log(hls, AV_LOG_ERROR, "no key URL specified in key info file %s\n",
+  hls->key_info_file);
+return AVERROR(EINVAL);
+}
+p = NULL;
+av_free(hls->key_uri);
+hls->key_uri = av_strdup(tstr);
+if (!hls->key_uri)
+return AVERROR(ENOMEM);
+if (!(tstr = av_strtok(p, "\n", &saveptr)) || !*tstr) {
+av_log(hls, AV_LOG_ERROR, "no key file specified in key info file 
%s\n",
+  hls->key_info_file);
+return AVERROR(EINVAL);
+}
+av_free(hls->key_file);
+hls->key_file = av_strdup(tstr);
+if (!hls->key_file)
+return AVERROR(ENOMEM);
+av_free(tmp);
+
+if ((ret = avio_open(&pb, hls->key_file, AVIO_FLAG_READ)) < 0) {
+av_log(hls, AV_LOG_ERROR, "error opening key file %s\n",
+  hls->key_file);
+return ret;
+}
+
+ret = avio_read(pb, key, sizeof(key));
+avio_closep(&pb);
+if (ret < sizeof(key)) {
+av_log(hls, AV_LOG_ERROR, "error reading key file %s\n",
+  hls->key_file);
+return ret;
+}
+
+key_string = av_mallocz(BLOCKSIZE*2 + 1);
+if (!key_string)
+return AVERROR(ENOMEM);
+ff_data_to_hex(key_string, key, BLOCKSIZE, 0);
+if (!hls->key_string || strncmp(key_string, hls->key_string, BLOCKSIZE*2)) 
{
+av_free(hls->key_string);
+hls->key_string = key_string;
+rotate_iv = 1;
+} else {
+av_free(key_string);
+}
+
+if (!hls->random_iv) {
+iv = av_mallocz(BLOCKSIZE);
+if (!iv)
+return AVERROR(ENOMEM);
+

[FFmpeg-devel] [PATCH 1/3] avformat/hlsenc: added segment filename template

2014-12-04 Thread Christian Suloway
Signed-off-by: Christian Suloway 
---
 libavformat/hlsenc.c | 87 +---
 1 file changed, 69 insertions(+), 18 deletions(-)

diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c
index e13f438..0a48919 100644
--- a/libavformat/hlsenc.c
+++ b/libavformat/hlsenc.c
@@ -33,7 +33,7 @@
 #include "internal.h"
 
 typedef struct HLSSegment {
-char filename[1024];
+char *filename;
 double duration; /* in seconds */
 int64_t pos;
 int64_t size;
@@ -73,14 +73,23 @@ typedef struct HLSContext {
 HLSSegment *segments;
 HLSSegment *last_segment;
 
+char *dirname;
 char *basename;
 char *baseurl;
 char *format_options_str;
 AVDictionary *format_options;
 
+char *segment_filename;
+
 AVIOContext *pb;
 } HLSContext;
 
+static void hls_free_segment(HLSSegment *en)
+{
+av_freep(&en->filename);
+av_freep(&en);
+}
+
 static int hls_mux_init(AVFormatContext *s)
 {
 HLSContext *hls = s->priv_data;
@@ -119,7 +128,9 @@ static int hls_append_segment(HLSContext *hls, double 
duration, int64_t pos,
 if (!en)
 return AVERROR(ENOMEM);
 
-av_strlcpy(en->filename, av_basename(hls->avf->filename), 
sizeof(en->filename));
+en->filename = av_strdup(hls->avf->filename);
+if (!en->filename)
+return AVERROR(ENOMEM);
 
 en->duration = duration;
 en->pos  = pos;
@@ -136,7 +147,7 @@ static int hls_append_segment(HLSContext *hls, double 
duration, int64_t pos,
 if (hls->max_nb_segments && hls->nb_entries >= hls->max_nb_segments) {
 en = hls->segments;
 hls->segments = en->next;
-av_free(en);
+hls_free_segment(en);
 } else
 hls->nb_entries++;
 
@@ -152,7 +163,7 @@ static void hls_free_segments(HLSContext *hls)
 while(p) {
 en = p;
 p = p->next;
-av_free(en);
+hls_free_segment(en);
 }
 }
 
@@ -186,6 +197,7 @@ static int hls_window(AVFormatContext *s, int last)
sequence);
 
 for (en = hls->segments; en; en = en->next) {
+
 avio_printf(hls->pb, "#EXTINF:%f,\n", en->duration);
 if (hls->flags & HLS_SINGLE_FILE)
  avio_printf(hls->pb, "#EXT-X-BYTERANGE:%"PRIi64"@%"PRIi64"\n",
@@ -208,6 +220,8 @@ static int hls_start(AVFormatContext *s)
 HLSContext *c = s->priv_data;
 AVFormatContext *oc = c->avf;
 int err = 0;
+int filename_size;
+char *filename;
 
 if (c->flags & HLS_SINGLE_FILE)
 av_strlcpy(oc->filename, c->basename,
@@ -220,8 +234,18 @@ static int hls_start(AVFormatContext *s)
 }
 c->number++;
 
-if ((err = avio_open2(&oc->pb, oc->filename, AVIO_FLAG_WRITE,
-  &s->interrupt_callback, NULL)) < 0)
+filename_size = strlen(c->dirname) + strlen(oc->filename) + 1;
+filename = av_malloc(filename_size);
+if (!filename)
+return AVERROR(ENOMEM);
+*filename = '\0';
+av_strlcat(filename, c->dirname, filename_size);
+av_strlcat(filename, oc->filename, filename_size);
+
+err = avio_open2(&oc->pb, filename, AVIO_FLAG_WRITE,
+ &s->interrupt_callback, NULL);
+av_free(filename);
+if (err < 0)
 return err;
 
 if (oc->oformat->priv_class && oc->priv_data)
@@ -237,15 +261,13 @@ static int hls_write_header(AVFormatContext *s)
 char *p;
 const char *pattern = "%d.ts";
 AVDictionary *options = NULL;
-int basename_size = strlen(s->filename) + strlen(pattern) + 1;
+int basename_size;
+char *basename;
 
 hls->sequence   = hls->start_sequence;
 hls->recording_time = hls->time * AV_TIME_BASE;
 hls->start_pts  = AV_NOPTS_VALUE;
 
-if (hls->flags & HLS_SINGLE_FILE)
-pattern = ".ts";
-
 if (hls->format_options_str) {
 ret = av_dict_parse_string(&hls->format_options, 
hls->format_options_str, "=", ":", 0);
 if (ret < 0) {
@@ -270,21 +292,45 @@ static int hls_write_header(AVFormatContext *s)
 goto fail;
 }
 
-hls->basename = av_malloc(basename_size);
-
-if (!hls->basename) {
+hls->dirname = av_strdup(s->filename);
+if (!hls->dirname) {
 ret = AVERROR(ENOMEM);
 goto fail;
 }
 
-strcpy(hls->basename, s->filename);
+basename = (char *)av_basename(hls->dirname);
 
-p = strrchr(hls->basename, '.');
+if (hls->segment_filename) {
+hls->basename = av_strdup(av_basename(hls->segment_filename));
+if (!hls->basename) {
+ret = AVERROR(ENOMEM);
+goto fail;
+}
+if (strlen(hls->basename) != strlen(hl

[FFmpeg-devel] [PATCH 3/3] avformat/hlsenc: added HLS encryption

2014-12-04 Thread Christian Suloway
HLS encryption with key URL & key containing file specified with
-hls_key_info_file (key info updates when modified). Option for IV from
segment number or random generation (-hls_random_iv).

Signed-off-by: Christian Suloway 
---
 libavformat/hlsenc.c | 225 +--
 1 file changed, 218 insertions(+), 7 deletions(-)

diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c
index 11817a9..c7bd1be 100644
--- a/libavformat/hlsenc.c
+++ b/libavformat/hlsenc.c
@@ -33,16 +33,23 @@
 #include "libavutil/avstring.h"
 #include "libavutil/opt.h"
 #include "libavutil/log.h"
+#include "libavutil/lfg.h"
+#include "libavutil/random_seed.h"
 
 #include "avformat.h"
 #include "internal.h"
 
+#define BLOCKSIZE 16
+
 typedef struct HLSSegment {
 char *filename;
 double duration; /* in seconds */
 int64_t pos;
 int64_t size;
 
+char *key_uri;
+char *iv_string;
+
 struct HLSSegment *next;
 } HLSSegment;
 
@@ -88,12 +95,25 @@ typedef struct HLSContext {
 
 char *segment_filename;
 
+char *key_info_file;
+int random_iv;
+int encrypt;
+
+char *key_file;
+char *key_uri;
+char *key_string;
+char *iv_string;
+
+AVLFG *lfg;
+
 AVIOContext *pb;
 } HLSContext;
 
 static void hls_free_segment(HLSSegment *en)
 {
 av_freep(&en->filename);
+av_freep(&en->key_uri);
+av_freep(&en->iv_string);
 av_freep(&en);
 }
 
@@ -143,6 +163,137 @@ static int hls_delete_old_segments(HLSContext *hls) {
 return 0;
 }
 
+static int hls_encryption_init(AVFormatContext *s)
+{
+HLSContext *hls = s->priv_data;
+
+hls->key_file = NULL;
+hls->key_uri = NULL;
+hls->key_string = NULL;
+hls->iv_string = NULL;
+
+if (hls->key_info_file) {
+hls->encrypt = 1;
+} else {
+hls->encrypt = 0;
+return 0;
+}
+
+if (hls->random_iv) {
+hls->lfg = av_malloc(sizeof(AVLFG));
+av_lfg_init(hls->lfg, av_get_random_seed());
+} else
+hls->lfg = NULL;
+
+return 0;
+}
+
+static int hls_encryption_start(HLSContext *hls) {
+
+uint8_t *iv = NULL;
+int ret, i, j, rotate_iv = 0;
+unsigned int u;
+AVIOContext *pb = NULL;
+AVIOContext *dyn_buf = NULL;
+uint8_t buf[1024], *tmp;
+char *p, *tstr, *saveptr = NULL;
+char key[BLOCKSIZE], *key_string;
+
+if ((ret = avio_open(&pb, hls->key_info_file, AVIO_FLAG_READ)) < 0) {
+av_log(hls, AV_LOG_ERROR, "error opening key info file %s\n",
+  hls->key_info_file);
+return ret;
+}
+ret = avio_open_dyn_buf(&dyn_buf);
+if (ret < 0) {
+avio_closep(&pb);
+return ret;
+}
+
+while ((ret = avio_read(pb, buf, sizeof(buf))) > 0)
+avio_write(dyn_buf, buf, ret);
+avio_w8(dyn_buf, 0);
+avio_closep(&pb);
+
+if ((ret = avio_close_dyn_buf(dyn_buf, &tmp)) < 0)
+return ret;
+
+p = tmp;
+if (!(tstr = av_strtok(p, "\n", &saveptr)) || !*tstr) {
+av_log(hls, AV_LOG_ERROR, "no key URL specified in key info file %s\n",
+  hls->key_info_file);
+return AVERROR(EINVAL);
+}
+p = NULL;
+av_free(hls->key_uri);
+hls->key_uri = av_strdup(tstr);
+if (!hls->key_uri)
+return AVERROR(ENOMEM);
+if (!(tstr = av_strtok(p, "\n", &saveptr)) || !*tstr) {
+av_log(hls, AV_LOG_ERROR, "no key file specified in key info file 
%s\n",
+  hls->key_info_file);
+return AVERROR(EINVAL);
+}
+av_free(hls->key_file);
+hls->key_file = av_strdup(tstr);
+if (!hls->key_file)
+return AVERROR(ENOMEM);
+av_free(tmp);
+
+if ((ret = avio_open(&pb, hls->key_file, AVIO_FLAG_READ)) < 0) {
+av_log(hls, AV_LOG_ERROR, "error opening key file %s\n",
+  hls->key_file);
+return ret;
+}
+
+ret = avio_read(pb, key, sizeof(key));
+avio_closep(&pb);
+if (ret < sizeof(key)) {
+av_log(hls, AV_LOG_ERROR, "error reading key file %s\n",
+  hls->key_file);
+return ret;
+}
+
+key_string = av_mallocz(BLOCKSIZE*2 + 1);
+if (!key_string)
+return AVERROR(ENOMEM);
+ff_data_to_hex(key_string, key, BLOCKSIZE, 0);
+if (!hls->key_string || strncmp(key_string, hls->key_string, BLOCKSIZE*2)) 
{
+av_free(hls->key_string);
+hls->key_string = key_string;
+rotate_iv = 1;
+} else {
+av_free(key_string);
+}
+
+if (!hls->random_iv) {
+iv = av_mallocz(BLOCKSIZE);
+if (!iv)
+return AVERROR(ENOMEM);
+

[FFmpeg-devel] [PATCH 2/3] avformat/hlsenc: added segment file deletion

2014-12-04 Thread Christian Suloway
Option removes segments no longer in playlist when older than playlist + 
segment duration

Signed-off-by: Christian Suloway 
---
 libavformat/hlsenc.c | 72 
 1 file changed, 67 insertions(+), 5 deletions(-)

diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c
index 0a48919..11817a9 100644
--- a/libavformat/hlsenc.c
+++ b/libavformat/hlsenc.c
@@ -19,8 +19,13 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
+#include "config.h"
 #include 
 #include 
+#if HAVE_UNISTD_H
+#include 
+#endif
+#include 
 
 #include "libavutil/avassert.h"
 #include "libavutil/mathematics.h"
@@ -58,6 +63,7 @@ typedef struct HLSContext {
 float time;// Set by a private option.
 int max_nb_segments;   // Set by a private option.
 int  wrap; // Set by a private option.
+int delete_segments;
 uint32_t flags;// enum HLSFlags
 
 int allowcache;
@@ -72,6 +78,7 @@ typedef struct HLSContext {
 
 HLSSegment *segments;
 HLSSegment *last_segment;
+HLSSegment *old_segments;
 
 char *dirname;
 char *basename;
@@ -90,6 +97,52 @@ static void hls_free_segment(HLSSegment *en)
 av_freep(&en);
 }
 
+static int hls_delete_old_segments(HLSContext *hls) {
+
+HLSSegment *segment, *previous_segment = NULL;
+float playlist_duration = 0.0f;
+int path_size;
+char *path;
+
+segment = hls->segments;
+while (segment) {
+playlist_duration += segment->duration;
+segment = segment->next;
+}
+
+segment = hls->old_segments;
+while (segment) {
+playlist_duration -= segment->duration;
+previous_segment = segment;
+segment = segment->next;
+if (playlist_duration <= 0.0f) {
+previous_segment->next = NULL;
+break;
+}
+}
+
+while (segment) {
+av_log(hls, AV_LOG_DEBUG, "deleting old segment %s\n",
+  segment->filename);
+path_size = strlen(hls->dirname) + strlen(segment->filename) + 1;
+path = av_malloc(path_size);
+if (!path)
+return AVERROR(ENOMEM);
+av_strlcpy(path, hls->dirname, path_size);
+av_strlcat(path, segment->filename, path_size);
+if (unlink(path) < 0) {
+av_log(hls, AV_LOG_ERROR, "failed to delete old segment %s: %s\n",
+ path, strerror(errno));
+}
+av_free(path);
+previous_segment = segment;
+segment = segment->next;
+hls_free_segment(previous_segment);
+}
+
+return 0;
+}
+
 static int hls_mux_init(AVFormatContext *s)
 {
 HLSContext *hls = s->priv_data;
@@ -124,6 +177,7 @@ static int hls_append_segment(HLSContext *hls, double 
duration, int64_t pos,
   int64_t size)
 {
 HLSSegment *en = av_malloc(sizeof(*en));
+int ret;
 
 if (!en)
 return AVERROR(ENOMEM);
@@ -147,7 +201,14 @@ static int hls_append_segment(HLSContext *hls, double 
duration, int64_t pos,
 if (hls->max_nb_segments && hls->nb_entries >= hls->max_nb_segments) {
 en = hls->segments;
 hls->segments = en->next;
-hls_free_segment(en);
+
+if (en && hls->delete_segments && !hls->wrap) {
+en->next = hls->old_segments;
+hls->old_segments = en;
+if ((ret = hls_delete_old_segments(hls)) < 0)
+return ret;
+} else
+hls_free_segment(en);
 } else
 hls->nb_entries++;
 
@@ -156,9 +217,9 @@ static int hls_append_segment(HLSContext *hls, double 
duration, int64_t pos,
 return 0;
 }
 
-static void hls_free_segments(HLSContext *hls)
+static void hls_free_segments(HLSSegment *p)
 {
-HLSSegment *p = hls->segments, *en;
+HLSSegment *en;
 
 while(p) {
 en = p;
@@ -197,7 +258,6 @@ static int hls_window(AVFormatContext *s, int last)
sequence);
 
 for (en = hls->segments; en; en = en->next) {
-
 avio_printf(hls->pb, "#EXTINF:%f,\n", en->duration);
 if (hls->flags & HLS_SINGLE_FILE)
  avio_printf(hls->pb, "#EXT-X-BYTERANGE:%"PRIi64"@%"PRIi64"\n",
@@ -442,7 +502,8 @@ static int hls_write_trailer(struct AVFormatContext *s)
 hls->avf = NULL;
 hls_window(s, 1);
 
-hls_free_segments(hls);
+hls_free_segments(hls->segments);
+hls_free_segments(hls->old_segments);
 av_free(hls->dirname);
 
 avio_close(hls->pb);
@@ -458,6 +519,7 @@ static const AVOption options[] = {
 {"hls_list_size", "set maximum number of playlist entries",  
OFFSET(max_nb_segments),AV_OPT_TYPE_INT,{.i64 = 5}, 0, INT_MAX, E},
 

[FFmpeg-devel] [PATCH] avformat/hlsenc: added segment filename option

2014-12-05 Thread Christian Suloway
This option allows segment filenames to be specified. Unless -hls_flags
single_file is enabled the filename is used as a string format with the
segment number.

Example:
ffmpeg -f lavfi -i testsrc -c:v h264 -map 0 -hls_segment_filename
bar%03d.ts foo.m3u8

Signed-off-by: Christian Suloway `
---
 libavformat/hlsenc.c | 46 ++
 1 file changed, 30 insertions(+), 16 deletions(-)

diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c
index e13f438..59392c5 100644
--- a/libavformat/hlsenc.c
+++ b/libavformat/hlsenc.c
@@ -59,6 +59,7 @@ typedef struct HLSContext {
 int max_nb_segments;   // Set by a private option.
 int  wrap; // Set by a private option.
 uint32_t flags;// enum HLSFlags
+char *segment_filename;
 
 int allowcache;
 int64_t recording_time;
@@ -237,15 +238,12 @@ static int hls_write_header(AVFormatContext *s)
 char *p;
 const char *pattern = "%d.ts";
 AVDictionary *options = NULL;
-int basename_size = strlen(s->filename) + strlen(pattern) + 1;
+int basename_size;
 
 hls->sequence   = hls->start_sequence;
 hls->recording_time = hls->time * AV_TIME_BASE;
 hls->start_pts  = AV_NOPTS_VALUE;
 
-if (hls->flags & HLS_SINGLE_FILE)
-pattern = ".ts";
-
 if (hls->format_options_str) {
 ret = av_dict_parse_string(&hls->format_options, 
hls->format_options_str, "=", ":", 0);
 if (ret < 0) {
@@ -270,21 +268,36 @@ static int hls_write_header(AVFormatContext *s)
 goto fail;
 }
 
-hls->basename = av_malloc(basename_size);
-
-if (!hls->basename) {
-ret = AVERROR(ENOMEM);
-goto fail;
-}
-
-strcpy(hls->basename, s->filename);
+if (hls->segment_filename) {
+hls->basename = av_strdup(av_basename(hls->segment_filename));
+if (!hls->basename) {
+ret = AVERROR(ENOMEM);
+goto fail;
+}
+if (strlen(hls->basename) != strlen(hls->segment_filename)) {
+av_log(hls, AV_LOG_ERROR, "invalid segment filename %s\n",
+  hls->segment_filename);
+ret = AVERROR(EINVAL);
+goto fail;
+}
+} else {
+if (hls->flags & HLS_SINGLE_FILE)
+pattern = ".ts";
 
-p = strrchr(hls->basename, '.');
+basename_size = strlen(s->filename) + strlen(pattern) + 1;
+hls->basename = av_malloc(basename_size);
+if (!hls->basename) {
+ret = AVERROR(ENOMEM);
+goto fail;
+}
 
-if (p)
-*p = '\0';
+strlcpy(hls->basename, s->filename, basename_size);
 
-av_strlcat(hls->basename, pattern, basename_size);
+p = strrchr(hls->basename, '.');
+if (p)
+*p = '\0';
+av_strlcat(hls->basename, pattern, basename_size);
+}
 
 if ((ret = hls_mux_init(s)) < 0)
 goto fail;
@@ -412,6 +425,7 @@ static const AVOption options[] = {
 {"hls_base_url",  "url to prepend to each playlist entry",   
OFFSET(baseurl), AV_OPT_TYPE_STRING, {.str = NULL},  0, 0,   E},
 {"hls_flags", "set flags affecting HLS playlist and media file 
generation", OFFSET(flags), AV_OPT_TYPE_FLAGS, {.i64 = 0 }, 0, UINT_MAX, E, 
"flags"},
 {"single_file",   "generate a single media file indexed with byte ranges", 
0, AV_OPT_TYPE_CONST, {.i64 = HLS_SINGLE_FILE }, 0, UINT_MAX,   E, "flags"},
+{"hls_segment_filename", "filename template for segment files", 
OFFSET(segment_filename),   AV_OPT_TYPE_STRING, {.str = NULL},0,
   0, E},
 
 { NULL },
 };
-- 
1.9.3 (Apple Git-50)

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


[FFmpeg-devel] [PATCH] avformat/hlsenc: added segment filename option

2014-12-05 Thread Christian Suloway
This option allows segment filenames to be specified. Unless -hls_flags
single_file is set the filename is used as a string format with the
segment number.

Example:
ffmpeg -f lavfi -i testsrc -c:v h264 -map 0 -hls_segment_filename
bar%03d.ts foo.m3u8

Signed-off-by: Christian Suloway 
---
 doc/muxers.texi  |  9 +
 libavformat/hlsenc.c | 40 
 2 files changed, 33 insertions(+), 16 deletions(-)

diff --git a/doc/muxers.texi b/doc/muxers.texi
index c6ba604..34e827c 100644
--- a/doc/muxers.texi
+++ b/doc/muxers.texi
@@ -254,6 +254,15 @@ and it is not to be confused with the segment filename 
sequence number
 which can be cyclic, for example if the @option{wrap} option is
 specified.
 
+@item hls_segment_filename @var{filename}
+Set the segment filename. Unless hls_flags single_file is set @var{filename}
+is used as a string format with the segment number:
+@example
+ffmpeg in.nut -hls_segment_filename 'file%03d.ts' out.m3u8
+@end example
+This example will produce the playlist, @file{out.m3u8}, and segment files:
+@file{file000.ts}, @file{file001.ts}, @file{file002.ts}, etc.
+
 @item hls_flags single_file
 If this flag is set, the muxer will store all segments in a single MPEG-TS
 file, and will use byte ranges in the playlist. HLS playlists generated with
diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c
index e13f438..786c6b4 100644
--- a/libavformat/hlsenc.c
+++ b/libavformat/hlsenc.c
@@ -59,6 +59,7 @@ typedef struct HLSContext {
 int max_nb_segments;   // Set by a private option.
 int  wrap; // Set by a private option.
 uint32_t flags;// enum HLSFlags
+char *segment_filename;
 
 int allowcache;
 int64_t recording_time;
@@ -237,15 +238,12 @@ static int hls_write_header(AVFormatContext *s)
 char *p;
 const char *pattern = "%d.ts";
 AVDictionary *options = NULL;
-int basename_size = strlen(s->filename) + strlen(pattern) + 1;
+int basename_size;
 
 hls->sequence   = hls->start_sequence;
 hls->recording_time = hls->time * AV_TIME_BASE;
 hls->start_pts  = AV_NOPTS_VALUE;
 
-if (hls->flags & HLS_SINGLE_FILE)
-pattern = ".ts";
-
 if (hls->format_options_str) {
 ret = av_dict_parse_string(&hls->format_options, 
hls->format_options_str, "=", ":", 0);
 if (ret < 0) {
@@ -270,21 +268,30 @@ static int hls_write_header(AVFormatContext *s)
 goto fail;
 }
 
-hls->basename = av_malloc(basename_size);
-
-if (!hls->basename) {
-ret = AVERROR(ENOMEM);
-goto fail;
-}
-
-strcpy(hls->basename, s->filename);
+if (hls->segment_filename) {
+hls->basename = av_strdup(av_basename(hls->segment_filename));
+if (!hls->basename) {
+ret = AVERROR(ENOMEM);
+goto fail;
+}
+} else {
+if (hls->flags & HLS_SINGLE_FILE)
+pattern = ".ts";
 
-p = strrchr(hls->basename, '.');
+basename_size = strlen(s->filename) + strlen(pattern) + 1;
+hls->basename = av_malloc(basename_size);
+if (!hls->basename) {
+ret = AVERROR(ENOMEM);
+goto fail;
+}
 
-if (p)
-*p = '\0';
+av_strlcpy(hls->basename, s->filename, basename_size);
 
-av_strlcat(hls->basename, pattern, basename_size);
+p = strrchr(hls->basename, '.');
+if (p)
+*p = '\0';
+av_strlcat(hls->basename, pattern, basename_size);
+}
 
 if ((ret = hls_mux_init(s)) < 0)
 goto fail;
@@ -410,6 +417,7 @@ static const AVOption options[] = {
 {"hls_wrap",  "set number after which the index wraps",  OFFSET(wrap), 
   AV_OPT_TYPE_INT,{.i64 = 0}, 0, INT_MAX, E},
 {"hls_allow_cache", "explicitly set whether the client MAY (1) or MUST NOT 
(0) cache media segments", OFFSET(allowcache), AV_OPT_TYPE_INT, {.i64 = -1}, 
INT_MIN, INT_MAX, E},
 {"hls_base_url",  "url to prepend to each playlist entry",   
OFFSET(baseurl), AV_OPT_TYPE_STRING, {.str = NULL},  0, 0,   E},
+{"hls_segment_filename", "filename template for segment files", 
OFFSET(segment_filename),   AV_OPT_TYPE_STRING, {.str = NULL},0,
   0, E},
 {"hls_flags", "set flags affecting HLS playlist and media file 
generation", OFFSET(flags), AV_OPT_TYPE_FLAGS, {.i64 = 0 }, 0, UINT_MAX, E, 
"flags"},
 {"single_file",   "generate a single media file indexed with byte ranges", 
0, AV_OPT_TYPE_CONST, {.i64 = HLS_SINGLE_FILE }, 0, UINT_MAX,   E, "flags"},
 
-- 
1.9.3 (Apple Git-50)

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


[FFmpeg-devel] [PATCH] avformat/hlsenc: added segment filename option

2014-12-05 Thread Christian Suloway
This option allows segment filenames to be specified. Unless -hls_flags
single_file is set the filename is used as a string format with the
segment number.

Example:
ffmpeg -f lavfi -i testsrc -c:v h264 -map 0 -hls_segment_filename
bar%03d.ts foo.m3u8

Signed-off-by: Christian Suloway 
---
 doc/muxers.texi  |  9 +
 libavformat/hlsenc.c | 40 
 2 files changed, 33 insertions(+), 16 deletions(-)

diff --git a/doc/muxers.texi b/doc/muxers.texi
index c6ba604..34e827c 100644
--- a/doc/muxers.texi
+++ b/doc/muxers.texi
@@ -254,6 +254,15 @@ and it is not to be confused with the segment filename 
sequence number
 which can be cyclic, for example if the @option{wrap} option is
 specified.
 
+@item hls_segment_filename @var{filename}
+Set the segment filename. Unless hls_flags single_file is set @var{filename}
+is used as a string format with the segment number:
+@example
+ffmpeg in.nut -hls_segment_filename 'file%03d.ts' out.m3u8
+@end example
+This example will produce the playlist, @file{out.m3u8}, and segment files:
+@file{file000.ts}, @file{file001.ts}, @file{file002.ts}, etc.
+
 @item hls_flags single_file
 If this flag is set, the muxer will store all segments in a single MPEG-TS
 file, and will use byte ranges in the playlist. HLS playlists generated with
diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c
index e13f438..d5ea990 100644
--- a/libavformat/hlsenc.c
+++ b/libavformat/hlsenc.c
@@ -59,6 +59,7 @@ typedef struct HLSContext {
 int max_nb_segments;   // Set by a private option.
 int  wrap; // Set by a private option.
 uint32_t flags;// enum HLSFlags
+char *segment_filename;
 
 int allowcache;
 int64_t recording_time;
@@ -237,15 +238,12 @@ static int hls_write_header(AVFormatContext *s)
 char *p;
 const char *pattern = "%d.ts";
 AVDictionary *options = NULL;
-int basename_size = strlen(s->filename) + strlen(pattern) + 1;
+int basename_size;
 
 hls->sequence   = hls->start_sequence;
 hls->recording_time = hls->time * AV_TIME_BASE;
 hls->start_pts  = AV_NOPTS_VALUE;
 
-if (hls->flags & HLS_SINGLE_FILE)
-pattern = ".ts";
-
 if (hls->format_options_str) {
 ret = av_dict_parse_string(&hls->format_options, 
hls->format_options_str, "=", ":", 0);
 if (ret < 0) {
@@ -270,21 +268,30 @@ static int hls_write_header(AVFormatContext *s)
 goto fail;
 }
 
-hls->basename = av_malloc(basename_size);
-
-if (!hls->basename) {
-ret = AVERROR(ENOMEM);
-goto fail;
-}
-
-strcpy(hls->basename, s->filename);
+if (hls->segment_filename) {
+hls->basename = av_strdup(hls->segment_filename);
+if (!hls->basename) {
+ret = AVERROR(ENOMEM);
+goto fail;
+}
+} else {
+if (hls->flags & HLS_SINGLE_FILE)
+pattern = ".ts";
 
-p = strrchr(hls->basename, '.');
+basename_size = strlen(s->filename) + strlen(pattern) + 1;
+hls->basename = av_malloc(basename_size);
+if (!hls->basename) {
+ret = AVERROR(ENOMEM);
+goto fail;
+}
 
-if (p)
-*p = '\0';
+av_strlcpy(hls->basename, s->filename, basename_size);
 
-av_strlcat(hls->basename, pattern, basename_size);
+p = strrchr(hls->basename, '.');
+if (p)
+*p = '\0';
+av_strlcat(hls->basename, pattern, basename_size);
+}
 
 if ((ret = hls_mux_init(s)) < 0)
 goto fail;
@@ -410,6 +417,7 @@ static const AVOption options[] = {
 {"hls_wrap",  "set number after which the index wraps",  OFFSET(wrap), 
   AV_OPT_TYPE_INT,{.i64 = 0}, 0, INT_MAX, E},
 {"hls_allow_cache", "explicitly set whether the client MAY (1) or MUST NOT 
(0) cache media segments", OFFSET(allowcache), AV_OPT_TYPE_INT, {.i64 = -1}, 
INT_MIN, INT_MAX, E},
 {"hls_base_url",  "url to prepend to each playlist entry",   
OFFSET(baseurl), AV_OPT_TYPE_STRING, {.str = NULL},  0, 0,   E},
+{"hls_segment_filename", "filename template for segment files", 
OFFSET(segment_filename),   AV_OPT_TYPE_STRING, {.str = NULL},0,
   0, E},
 {"hls_flags", "set flags affecting HLS playlist and media file 
generation", OFFSET(flags), AV_OPT_TYPE_FLAGS, {.i64 = 0 }, 0, UINT_MAX, E, 
"flags"},
 {"single_file",   "generate a single media file indexed with byte ranges", 
0, AV_OPT_TYPE_CONST, {.i64 = HLS_SINGLE_FILE }, 0, UINT_MAX,   E, "flags"},
 
-- 
1.9.3 (Apple Git-50)

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


Re: [FFmpeg-devel] [PATCH] avformat/hlsenc: added segment filename option

2014-12-05 Thread Christian Suloway
Updating from previous message.

From: Christian Suloway 
Sent: Friday, December 5, 2014 3:17 PM
To: ffmpeg-devel@ffmpeg.org
Cc: Christian Suloway
Subject: [PATCH] avformat/hlsenc: added segment filename option

This option allows segment filenames to be specified. Unless -hls_flags
single_file is set the filename is used as a string format with the
segment number.

Example:
ffmpeg -f lavfi -i testsrc -c:v h264 -map 0 -hls_segment_filename
bar%03d.ts foo.m3u8

Signed-off-by: Christian Suloway 
---
 doc/muxers.texi  |  9 +
 libavformat/hlsenc.c | 40 
 2 files changed, 33 insertions(+), 16 deletions(-)

diff --git a/doc/muxers.texi b/doc/muxers.texi
index c6ba604..34e827c 100644
--- a/doc/muxers.texi
+++ b/doc/muxers.texi
@@ -254,6 +254,15 @@ and it is not to be confused with the segment filename 
sequence number
 which can be cyclic, for example if the @option{wrap} option is
 specified.

+@item hls_segment_filename @var{filename}
+Set the segment filename. Unless hls_flags single_file is set @var{filename}
+is used as a string format with the segment number:
+@example
+ffmpeg in.nut -hls_segment_filename 'file%03d.ts' out.m3u8
+@end example
+This example will produce the playlist, @file{out.m3u8}, and segment files:
+@file{file000.ts}, @file{file001.ts}, @file{file002.ts}, etc.
+
 @item hls_flags single_file
 If this flag is set, the muxer will store all segments in a single MPEG-TS
 file, and will use byte ranges in the playlist. HLS playlists generated with
diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c
index e13f438..d5ea990 100644
--- a/libavformat/hlsenc.c
+++ b/libavformat/hlsenc.c
@@ -59,6 +59,7 @@ typedef struct HLSContext {
 int max_nb_segments;   // Set by a private option.
 int  wrap; // Set by a private option.
 uint32_t flags;// enum HLSFlags
+char *segment_filename;

 int allowcache;
 int64_t recording_time;
@@ -237,15 +238,12 @@ static int hls_write_header(AVFormatContext *s)
 char *p;
 const char *pattern = "%d.ts";
 AVDictionary *options = NULL;
-int basename_size = strlen(s->filename) + strlen(pattern) + 1;
+int basename_size;

 hls->sequence   = hls->start_sequence;
 hls->recording_time = hls->time * AV_TIME_BASE;
 hls->start_pts  = AV_NOPTS_VALUE;

-if (hls->flags & HLS_SINGLE_FILE)
-pattern = ".ts";
-
 if (hls->format_options_str) {
 ret = av_dict_parse_string(&hls->format_options, 
hls->format_options_str, "=", ":", 0);
 if (ret < 0) {
@@ -270,21 +268,30 @@ static int hls_write_header(AVFormatContext *s)
 goto fail;
 }

-hls->basename = av_malloc(basename_size);
-
-if (!hls->basename) {
-ret = AVERROR(ENOMEM);
-goto fail;
-}
-
-strcpy(hls->basename, s->filename);
+if (hls->segment_filename) {
+hls->basename = av_strdup(hls->segment_filename);
+if (!hls->basename) {
+ret = AVERROR(ENOMEM);
+goto fail;
+}
+} else {
+if (hls->flags & HLS_SINGLE_FILE)
+pattern = ".ts";

-p = strrchr(hls->basename, '.');
+basename_size = strlen(s->filename) + strlen(pattern) + 1;
+hls->basename = av_malloc(basename_size);
+if (!hls->basename) {
+ret = AVERROR(ENOMEM);
+goto fail;
+}

-if (p)
-*p = '\0';
+av_strlcpy(hls->basename, s->filename, basename_size);

-av_strlcat(hls->basename, pattern, basename_size);
+p = strrchr(hls->basename, '.');
+if (p)
+*p = '\0';
+av_strlcat(hls->basename, pattern, basename_size);
+}

 if ((ret = hls_mux_init(s)) < 0)
 goto fail;
@@ -410,6 +417,7 @@ static const AVOption options[] = {
 {"hls_wrap",  "set number after which the index wraps",  OFFSET(wrap), 
   AV_OPT_TYPE_INT,{.i64 = 0}, 0, INT_MAX, E},
 {"hls_allow_cache", "explicitly set whether the client MAY (1) or MUST NOT 
(0) cache media segments", OFFSET(allowcache), AV_OPT_TYPE_INT, {.i64 = -1}, 
INT_MIN, INT_MAX, E},
 {"hls_base_url",  "url to prepend to each playlist entry",   
OFFSET(baseurl), AV_OPT_TYPE_STRING, {.str = NULL},  0, 0,   E},
+{"hls_segment_filename", "filename template for segment files", 
OFFSET(segment_filename),   AV_OPT_TYPE_STRING, {.str = NULL},0,
   0, E},
 {"hls_flags", "set flags affecting HLS playlist and media file 
generation", OFFSET(flags), AV_OPT_TYPE_FLAGS, {.i64 = 0 }, 0, UINT_MAX, E, 
"flags"},
 {"single_file",   "generate a single media file indexed with byte ranges", 
0, AV_OPT_TYPE_CONST, {.i64 = HLS_SINGLE_FILE }, 0, UINT_MAX,   E, "flags"},

--
1.9.3 (Apple Git-50)

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


[FFmpeg-devel] [PATCH] avformat/hlsenc: added segment file deletion

2014-12-08 Thread Christian Suloway
This option flag deletes segment files removed from the playlist after a
period of time equal to the duration of the segment plus the duration of
the playlist.

Signed-off-by: Christian Suloway 
---
 doc/muxers.texi  |  4 +++
 libavformat/hlsenc.c | 90 +---
 2 files changed, 90 insertions(+), 4 deletions(-)

diff --git a/doc/muxers.texi b/doc/muxers.texi
index 34e827c..a1264d2 100644
--- a/doc/muxers.texi
+++ b/doc/muxers.texi
@@ -273,6 +273,10 @@ ffmpeg -i in.nut -hls_flags single_file out.m3u8
 @end example
 Will produce the playlist, @file{out.m3u8}, and a single segment file,
 @file{out.ts}.
+
+@item hls_flags delete_segments
+Segment files removed from the playlist are deleted after a period of time
+equal to the duration of the segment plus the duration of the playlist.
 @end table
 
 @anchor{ico}
diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c
index d5ea990..79f3a23 100644
--- a/libavformat/hlsenc.c
+++ b/libavformat/hlsenc.c
@@ -19,8 +19,12 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
+#include "config.h"
 #include 
 #include 
+#if HAVE_UNISTD_H
+#include 
+#endif
 
 #include "libavutil/avassert.h"
 #include "libavutil/mathematics.h"
@@ -31,6 +35,7 @@
 
 #include "avformat.h"
 #include "internal.h"
+#include "os_support.h"
 
 typedef struct HLSSegment {
 char filename[1024];
@@ -44,6 +49,7 @@ typedef struct HLSSegment {
 typedef enum HLSFlags {
 // Generate a single media file and use byte ranges in the playlist.
 HLS_SINGLE_FILE = (1 << 0),
+HLS_DELETE_SEGMENTS = (1 << 1),
 } HLSFlags;
 
 typedef struct HLSContext {
@@ -73,6 +79,7 @@ typedef struct HLSContext {
 
 HLSSegment *segments;
 HLSSegment *last_segment;
+HLSSegment *old_segments;
 
 char *basename;
 char *baseurl;
@@ -82,6 +89,71 @@ typedef struct HLSContext {
 AVIOContext *pb;
 } HLSContext;
 
+static int hls_delete_old_segments(HLSContext *hls) {
+
+HLSSegment *segment, *previous_segment = NULL;
+float playlist_duration = 0.0f;
+int ret = 0, path_size;
+char *dirname = NULL, *p, *path;
+
+segment = hls->segments;
+while (segment) {
+playlist_duration += segment->duration;
+segment = segment->next;
+}
+
+segment = hls->old_segments;
+while (segment) {
+playlist_duration -= segment->duration;
+previous_segment = segment;
+segment = previous_segment->next;
+if (playlist_duration <= -previous_segment->duration) {
+previous_segment->next = NULL;
+break;
+}
+}
+
+if (segment) {
+if (hls->segment_filename) {
+dirname = av_strdup(hls->segment_filename);
+} else {
+dirname = av_strdup(hls->avf->filename);
+}
+if (!dirname) {
+ret = AVERROR(ENOMEM);
+goto fail;
+}
+p = (char *)av_basename(dirname);
+*p = '\0';
+}
+
+while (segment) {
+av_log(hls, AV_LOG_DEBUG, "deleting old segment %s\n",
+  segment->filename);
+path_size = strlen(dirname) + strlen(segment->filename) + 1;
+path = av_malloc(path_size);
+if (!path) {
+ret = AVERROR(ENOMEM);
+goto fail;
+}
+av_strlcpy(path, dirname, path_size);
+av_strlcat(path, segment->filename, path_size);
+if (unlink(path) < 0) {
+av_log(hls, AV_LOG_ERROR, "failed to delete old segment %s: %s\n",
+ path, strerror(errno));
+}
+av_free(path);
+previous_segment = segment;
+segment = previous_segment->next;
+av_free(previous_segment);
+}
+
+fail:
+av_free(dirname);
+
+return ret;
+}
+
 static int hls_mux_init(AVFormatContext *s)
 {
 HLSContext *hls = s->priv_data;
@@ -116,6 +188,7 @@ static int hls_append_segment(HLSContext *hls, double 
duration, int64_t pos,
   int64_t size)
 {
 HLSSegment *en = av_malloc(sizeof(*en));
+int ret;
 
 if (!en)
 return AVERROR(ENOMEM);
@@ -137,7 +210,14 @@ static int hls_append_segment(HLSContext *hls, double 
duration, int64_t pos,
 if (hls->max_nb_segments && hls->nb_entries >= hls->max_nb_segments) {
 en = hls->segments;
 hls->segments = en->next;
-av_free(en);
+if (en && hls->flags & HLS_DELETE_SEGMENTS &&
+!(hls->flags & HLS_SINGLE_FILE || hls->wrap)) {
+en->next = hls->old_segments;
+hls->old_segments = en;
+if ((ret = hls_delete_old_segments(hls)) < 0)
+return ret;
+} else
+

Re: [FFmpeg-devel] [PATCH] avformat/hlsenc: added segment file deletion

2014-12-10 Thread Christian Suloway
On 12/9/14, 7:44 PM, "Michael Niedermayer"  wrote:

>On Mon, Dec 08, 2014 at 10:25:05AM -0600, Christian Suloway wrote:
>> This option flag deletes segment files removed from the playlist after a
>> period of time equal to the duration of the segment plus the duration of
>> the playlist.
>
>can you explain the usecase for this ?
>isnt -hls_wrap  already achieving this more or less ?

-hls_wrap  does achieve this more or less, but the option has been
proposed for two reasons:

(1) Simplify compliance with HLS Internet-Draft
(http://tools.ietf.org/html/draft-pantos-http-live-streaming) section
6.2.2., Live Playlists:

   When the server removes a Media Segment URI from the Playlist, the
   corresponding Media Segment MUST remain available to clients for a
   period of time equal to the duration of the segment plus the duration
   of the longest Playlist file distributed by the server containing
   that segment.  Removing a Media Segment earlier than that can
   interrupt in-progress playback.

The playlist length/duration can change without computation and
modification to the -hls_wrap  argument.

(2) Although not required in the HLS Internet-Draft, it can be useful to
have the sequence number in the segment URI for tracking when logging and
making modifications to playlists.

Thank you for your consideration.

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


[FFmpeg-devel] [PATCH] avformat/hlsenc: added HLS encryption

2014-12-11 Thread Christian Suloway
Added HLS encryption with -hls_key_info_file  option. The
first line of key_info_file specifies the key URI for the playlist, and
the second line specifies the path to the file containing the encryption
key. Changes to key_info_file will be reflected in segment encryption
along with an entry in the playlist for the new key URI.

Also added -hls_flags random_iv option flag to use a random IV for
encryption instead of the segment number.

Signed-off-by: Christian Suloway 
---
 doc/muxers.texi  |  11 +++
 libavformat/hlsenc.c | 257 +--
 2 files changed, 262 insertions(+), 6 deletions(-)

diff --git a/doc/muxers.texi b/doc/muxers.texi
index a1264d2..29a5de3 100644
--- a/doc/muxers.texi
+++ b/doc/muxers.texi
@@ -263,6 +263,13 @@ ffmpeg in.nut -hls_segment_filename 'file%03d.ts' out.m3u8
 This example will produce the playlist, @file{out.m3u8}, and segment files:
 @file{file000.ts}, @file{file001.ts}, @file{file002.ts}, etc.
 
+@item hls_key_info_file @var{file}
+Use in the information in @var{file} for segment encryption. The first line of
+@var{file} specifies the key URI for the playlist. The second line specifies
+the path to the file containing the encryption key as a single packed array of
+16 octets in binary format. Changes to @var{file} will result in segment
+encryption with the new key and an entry in the playlist for the new key URI.
+
 @item hls_flags single_file
 If this flag is set, the muxer will store all segments in a single MPEG-TS
 file, and will use byte ranges in the playlist. HLS playlists generated with
@@ -277,6 +284,10 @@ Will produce the playlist, @file{out.m3u8}, and a single 
segment file,
 @item hls_flags delete_segments
 Segment files removed from the playlist are deleted after a period of time
 equal to the duration of the segment plus the duration of the playlist.
+
+@item hls_flags random_iv
+Segment file encryption will use a random initialization vector (IV) instead of
+the segment number.
 @end table
 
 @anchor{ico}
diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c
index 79f3a23..5bde70e 100644
--- a/libavformat/hlsenc.c
+++ b/libavformat/hlsenc.c
@@ -32,17 +32,24 @@
 #include "libavutil/avstring.h"
 #include "libavutil/opt.h"
 #include "libavutil/log.h"
+#include "libavutil/lfg.h"
+#include "libavutil/random_seed.h"
 
 #include "avformat.h"
 #include "internal.h"
 #include "os_support.h"
 
+#define BLOCKSIZE 16
+
 typedef struct HLSSegment {
 char filename[1024];
 double duration; /* in seconds */
 int64_t pos;
 int64_t size;
 
+char *key_uri;
+char *iv_string;
+
 struct HLSSegment *next;
 } HLSSegment;
 
@@ -50,6 +57,7 @@ typedef enum HLSFlags {
 // Generate a single media file and use byte ranges in the playlist.
 HLS_SINGLE_FILE = (1 << 0),
 HLS_DELETE_SEGMENTS = (1 << 1),
+HLS_RANDOM_IV = (1 << 2),
 } HLSFlags;
 
 typedef struct HLSContext {
@@ -86,9 +94,23 @@ typedef struct HLSContext {
 char *format_options_str;
 AVDictionary *format_options;
 
+char *key_info_file;
+char *key_file;
+char *key_uri;
+char *key_string;
+char *iv_string;
+AVLFG *lfg;
+
 AVIOContext *pb;
 } HLSContext;
 
+static void hls_free_segment(HLSSegment *en)
+{
+   av_freep(&en->key_uri);
+   av_freep(&en->iv_string);
+   av_freep(&en);
+}
+
 static int hls_delete_old_segments(HLSContext *hls) {
 
 HLSSegment *segment, *previous_segment = NULL;
@@ -145,7 +167,7 @@ static int hls_delete_old_segments(HLSContext *hls) {
 av_free(path);
 previous_segment = segment;
 segment = previous_segment->next;
-av_free(previous_segment);
+hls_free_segment(previous_segment);
 }
 
 fail:
@@ -154,6 +176,157 @@ fail:
 return ret;
 }
 
+static int hls_encryption_init(AVFormatContext *s)
+{
+HLSContext *hls = s->priv_data;
+
+if (hls->flags & HLS_RANDOM_IV) {
+hls->lfg = av_malloc(sizeof(AVLFG));
+if (!hls->lfg)
+return AVERROR(ENOMEM);
+av_lfg_init(hls->lfg, av_get_random_seed());
+}
+
+return 0;
+}
+
+static int hls_encryption_start(HLSContext *hls)
+{
+
+int ret = 0, i, j, rotate_iv = 0;
+AVIOContext *pb = NULL;
+AVIOContext *dyn_buf = NULL;
+uint8_t buf[1024], *tmp = NULL, *key = NULL, *iv = NULL;
+char *p, *tstr, *saveptr = NULL, *key_string = NULL;
+unsigned int u;
+
+if ((ret = avio_open(&pb, hls->key_info_file, AVIO_FLAG_READ)) < 0) {
+av_log(hls, AV_LOG_ERROR, "error opening key info file %s\n",
+  hls->key_info_file);
+goto fail;
+}
+
+ret = avio_open_dyn_buf(&dyn_buf);
+if (ret < 0) {
+avio_closep(&pb);
+goto fail;
+}
+
+while ((ret = avio_read(pb, buf, sizeof(buf))) > 0)
+

Re: [FFmpeg-devel] [PATCH] avformat/hlsenc: added HLS encryption

2014-12-15 Thread Christian Suloway
On 12/12/14, 9:57 PM, "Michael Niedermayer"  wrote:
>combining the random seed with a LFG seems a bit odd
>i would out of principle use something stronger, though i dont know
>what the exact scenarios are this is intended to prevent, so maybe
>its fine

Yes, this is a good point. I will resubmit the patch with the IV
optionally specified as part of the ³key_info_file² and leave IV
generation outside of ffmpeg. Let me know you would like this done
differently.
Thanks,
Christian

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


[FFmpeg-devel] [PATCH 2/2] avformat/hlsenc: added HLS encryption

2014-12-15 Thread Christian Suloway
Added HLS encryption with -hls_key_info_file  option. The
first line of key_info_file specifies the key URI for the playlist. The
second line specifies the path to the file containing the encryption
key. An optional third line specifies an IV to use instead of the
segment number. Changes to key_info_file will be reflected in segment
encryption along with an entry in the playlist for the new key URI and
IV.

Signed-off-by: Christian Suloway 
---
 doc/muxers.texi  |   9 ++
 libavformat/hlsenc.c | 235 +--
 2 files changed, 238 insertions(+), 6 deletions(-)

diff --git a/doc/muxers.texi b/doc/muxers.texi
index a1264d2..f2ecf8b 100644
--- a/doc/muxers.texi
+++ b/doc/muxers.texi
@@ -263,6 +263,15 @@ ffmpeg in.nut -hls_segment_filename 'file%03d.ts' out.m3u8
 This example will produce the playlist, @file{out.m3u8}, and segment files:
 @file{file000.ts}, @file{file001.ts}, @file{file002.ts}, etc.
 
+@item hls_key_info_file @var{file}
+Use in the information in @var{file} for segment encryption. The first line of
+@var{file} specifies the key URI for the playlist. The second line specifies
+the path to the file containing the encryption key as a single packed array of
+16 octets in binary format. The optional third line specifies a hexidecimal
+string for the initialization vector (IV) to be used instead of the segment
+number. Changes to @var{file} will result in segment encryption with the new
+key/IV and an entry in the playlist for the new key URI/IV.
+
 @item hls_flags single_file
 If this flag is set, the muxer will store all segments in a single MPEG-TS
 file, and will use byte ranges in the playlist. HLS playlists generated with
diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c
index 7645065..f62675e 100644
--- a/libavformat/hlsenc.c
+++ b/libavformat/hlsenc.c
@@ -37,12 +37,18 @@
 #include "internal.h"
 #include "os_support.h"
 
+#define BLOCKSIZE 16
+
 typedef struct HLSSegment {
 char filename[1024];
 double duration; /* in seconds */
 int64_t pos;
 int64_t size;
 
+char *key_uri;
+char *iv_string;
+int attribute_iv;
+
 struct HLSSegment *next;
 } HLSSegment;
 
@@ -86,9 +92,23 @@ typedef struct HLSContext {
 char *format_options_str;
 AVDictionary *format_options;
 
+char *key_info_file;
+char *key_file;
+char *key_uri;
+char *key_string;
+char *iv_string;
+int attribute_iv;
+
 AVIOContext *pb;
 } HLSContext;
 
+static void hls_free_segment(HLSSegment *en)
+{
+   av_freep(&en->key_uri);
+   av_freep(&en->iv_string);
+   av_freep(&en);
+}
+
 static int hls_delete_old_segments(HLSContext *hls) {
 
 HLSSegment *segment, *previous_segment = NULL;
@@ -145,7 +165,7 @@ static int hls_delete_old_segments(HLSContext *hls) {
 av_free(path);
 previous_segment = segment;
 segment = previous_segment->next;
-av_free(previous_segment);
+hls_free_segment(previous_segment);
 }
 
 fail:
@@ -154,6 +174,134 @@ fail:
 return ret;
 }
 
+static int hls_encryption_start(HLSContext *hls)
+{
+
+int ret = 0, i;
+AVIOContext *pb = NULL, *dyn_buf = NULL;
+uint8_t buf[1024], *tmp = NULL, *key = NULL, *iv = NULL;
+char *p, *tstr, *saveptr = NULL, *key_string = NULL, *iv_string = NULL;
+
+if ((ret = avio_open(&pb, hls->key_info_file, AVIO_FLAG_READ)) < 0) {
+av_log(hls, AV_LOG_ERROR, "error opening key info file %s\n",
+  hls->key_info_file);
+goto fail;
+}
+
+ret = avio_open_dyn_buf(&dyn_buf);
+if (ret < 0) {
+avio_closep(&pb);
+goto fail;
+}
+
+while ((ret = avio_read(pb, buf, sizeof(buf))) > 0)
+avio_write(dyn_buf, buf, ret);
+avio_closep(&pb);
+if (ret != AVERROR_EOF && ret < 0) {
+avio_close_dyn_buf(dyn_buf, &tmp);
+goto fail;
+}
+
+avio_w8(dyn_buf, 0);
+if ((ret = avio_close_dyn_buf(dyn_buf, &tmp)) < 0)
+goto fail;
+
+p = tmp;
+if (!(tstr = av_strtok(p, "\n", &saveptr)) || !*tstr) {
+av_log(hls, AV_LOG_ERROR, "no key URI specified in key info file %s\n",
+  hls->key_info_file);
+ret = AVERROR(EINVAL);
+goto fail;
+}
+av_free(hls->key_uri);
+hls->key_uri = av_strdup(tstr);
+if (!hls->key_uri) {
+ret = AVERROR(ENOMEM);
+goto fail;
+}
+
+if (!(tstr = av_strtok(NULL, "\n", &saveptr)) || !*tstr) {
+av_log(hls, AV_LOG_ERROR, "no key file specified in key info file 
%s\n",
+  hls->key_info_file);
+ret = AVERROR(EINVAL);
+goto fail;
+}
+av_free(hls->key_file);
+hls->key_file = av_strdup(tstr);
+if (!hls->key_file) {
+ret = AVERROR(ENOMEM);
+   

[FFmpeg-devel] [PATCH 1/2] avformat/hlsenc: fix hls_write_trailer() on hls_start() failure

2014-12-15 Thread Christian Suloway
Close segment I/O context and append segment in hls_write_trailer() only
when segment I/O context is allocated.

Signed-off-by: Christian Suloway 
---
 libavformat/hlsenc.c | 10 ++
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c
index 79f3a23..7645065 100644
--- a/libavformat/hlsenc.c
+++ b/libavformat/hlsenc.c
@@ -449,7 +449,7 @@ static int hls_write_packet(AVFormatContext *s, AVPacket 
*pkt)
 av_opt_set(hls->avf->priv_data, "mpegts_flags", 
"resend_headers", 0);
 hls->number++;
 } else {
-avio_close(oc->pb);
+avio_closep(&oc->pb);
 
 ret = hls_start(s);
 }
@@ -474,10 +474,12 @@ static int hls_write_trailer(struct AVFormatContext *s)
 AVFormatContext *oc = hls->avf;
 
 av_write_trailer(oc);
-hls->size = avio_tell(hls->avf->pb) - hls->start_pos;
-avio_closep(&oc->pb);
+if (oc->pb) {
+hls->size = avio_tell(hls->avf->pb) - hls->start_pos;
+avio_closep(&oc->pb);
+hls_append_segment(hls, hls->duration, hls->start_pos, hls->size);
+}
 av_free(hls->basename);
-hls_append_segment(hls, hls->duration, hls->start_pos, hls->size);
 avformat_free_context(oc);
 hls->avf = NULL;
 hls_window(s, 1);
-- 
1.9.3 (Apple Git-50)

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


Re: [FFmpeg-devel] [PATCH 1/2] avformat/hlsenc: fix hls_write_trailer() on hls_start() failure

2014-12-16 Thread Christian Suloway
On 12/16/14, 3:23 AM, "Carl Eugen Hoyos"  wrote:

>Christian Suloway  row44.com> writes:
>
>> Close segment I/O context and append segment in
>> hls_write_trailer() only when segment I/O context
>> is allocated.
>
>Was this a regression since 25ccf5df?
>(And should be backported to 2.5?)

This does not appear specific to 25ccf5df and goes back to 2.2. Also, the
patch does not cover the mpegtsenc context accessing the null I/O context
from hls_write_trailer or hls_write_packet. I don¹t know if this should be
covered in hlsenc or mpegtsenc.

Examples:

   177  void avio_write(AVIOContext *s, const unsigned char *buf, int size)
   178  {
-> 179  if (s->direct && !s->update_checksum) {
   180  avio_flush(s);
   181  writeout(s, buf, size);
   182  return;

* thread #1: tid = 0x1548b77, 0x0001002879f7
libavformat.56.dylib`avio_write(s=0x,
buf=0x7fff5fbff690, size=188) + 23 at aviobuf.c:179, queue =
'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=1,
address=0xa0)
  * frame #0: 0x0001002879f7
libavformat.56.dylib`avio_write(s=0x,
buf=0x7fff5fbff690, size=188) + 23 at aviobuf.c:179
frame #1: 0x00010034542b
libavformat.56.dylib`mpegts_write_pes(s=0x000103032200,
st=0x0001021026f0, payload=0x00010303c0a8, payload_size=1256,
pts=1341180, dts=1341180, key=1) + 4347 at mpegtsenc.c:1187
frame #2: 0x000100344303
libavformat.56.dylib`mpegts_write_flush(s=0x000103032200) + 147 at
mpegtsenc.c:1379
frame #3: 0x000100344161
libavformat.56.dylib`mpegts_write_end(s=0x000103032200) + 33 at
mpegtsenc.c:1403
frame #4: 0x00010034d834
libavformat.56.dylib`av_write_trailer(s=0x000103032200) + 276 at
mux.c:949
frame #5: 0x0001002cdf1d
libavformat.56.dylib`hls_write_trailer(s=0x000103030400) + 45 at
hlsenc.c:476
frame #6: 0x00010034d834
libavformat.56.dylib`av_write_trailer(s=0x000103030400) + 276 at
mux.c:949
frame #7: 0x00010001bdb8 ffmpeg`transcode + 568 at ffmpeg.c:3799
frame #8: 0x00010001b3df ffmpeg`main(argc=11,
argv=0x7fff5fbffa28) + 447 at ffmpeg.c:3946

or

* thread #1: tid = 0x1564f17, 0x0001002879f7
libavformat.56.dylib`avio_write(s=0x,
buf=0x7fff5fbff3c0, size=188) + 23 at aviobuf.c:179, queue =
'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=1,
address=0xa0)
  * frame #0: 0x0001002879f7
libavformat.56.dylib`avio_write(s=0x,
buf=0x7fff5fbff3c0, size=188) + 23 at aviobuf.c:179
frame #1: 0x00010034542b
libavformat.56.dylib`mpegts_write_pes(s=0x00010365f600,
st=0x00010210d6d0, payload=0x0001036694a8, payload_size=2619,
pts=396540, dts=396540, key=1) + 4347 at mpegtsenc.c:1187
frame #2: 0x0001003482c4
libavformat.56.dylib`mpegts_write_packet_internal(s=0x00010365f600,
pkt=0x7fff5fbff718) + 2068 at mpegtsenc.c:1341
frame #3: 0x000100344130
libavformat.56.dylib`mpegts_write_packet(s=0x00010365f600,
pkt=0x7fff5fbff718) + 64 at mpegtsenc.c:1393
frame #4: 0x00010034c6ef
libavformat.56.dylib`write_packet(s=0x00010365f600,
pkt=0x7fff5fbff718) + 975 at mux.c:598
frame #5: 0x00010034b7f5
libavformat.56.dylib`av_write_frame(s=0x00010365f600,
pkt=0x7fff5fbff718) + 421 at mux.c:654
frame #6: 0x00010034db6a
libavformat.56.dylib`ff_write_chained(dst=0x00010365f600,
dst_stream=1, pkt=0x7fff5fbff900, src=0x000103030400,
interleave=0) + 394 at mux.c:999
frame #7: 0x0001002cded1
libavformat.56.dylib`hls_write_packet(s=0x000103030400,
pkt=0x7fff5fbff900) + 929 at hlsenc.c:466
frame #8: 0x00010034c6ef
libavformat.56.dylib`write_packet(s=0x000103030400,
pkt=0x7fff5fbff900) + 975 at mux.c:598
frame #9: 0x00010034d77f
libavformat.56.dylib`av_write_trailer(s=0x000103030400) + 95 at
mux.c:934
frame #10: 0x00010001bdb8 ffmpeg`transcode + 568 at ffmpeg.c:3799
frame #11: 0x00010001b3df ffmpeg`main(argc=11,
argv=0x7fff5fbffa30) + 447 at ffmpeg.c:3946

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


[FFmpeg-devel] [PATCH] avformat/hlsenc: added HLS encryption

2014-12-22 Thread Christian Suloway
Added HLS encryption with -hls_key_info_file  option.
The first line of key_info_file specifies the key URI for the playlist.
The second line specifies the path to the file containing the encryption
key. An optional third line specifies an IV to use instead of the
segment number. Changes to key_info_file will be reflected in segment
encryption along with an entry in the playlist for the new key URI and
IV.

Signed-off-by: Christian Suloway 
---
 doc/muxers.texi  |   9 ++
 libavformat/hlsenc.c | 235 +--
 2 files changed, 238 insertions(+), 6 deletions(-)

diff --git a/doc/muxers.texi b/doc/muxers.texi
index a1264d2..f2ecf8b 100644
--- a/doc/muxers.texi
+++ b/doc/muxers.texi
@@ -263,6 +263,15 @@ ffmpeg in.nut -hls_segment_filename 'file%03d.ts' out.m3u8
 This example will produce the playlist, @file{out.m3u8}, and segment files:
 @file{file000.ts}, @file{file001.ts}, @file{file002.ts}, etc.
 
+@item hls_key_info_file @var{file}
+Use in the information in @var{file} for segment encryption. The first line of
+@var{file} specifies the key URI for the playlist. The second line specifies
+the path to the file containing the encryption key as a single packed array of
+16 octets in binary format. The optional third line specifies a hexidecimal
+string for the initialization vector (IV) to be used instead of the segment
+number. Changes to @var{file} will result in segment encryption with the new
+key/IV and an entry in the playlist for the new key URI/IV.
+
 @item hls_flags single_file
 If this flag is set, the muxer will store all segments in a single MPEG-TS
 file, and will use byte ranges in the playlist. HLS playlists generated with
diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c
index f46e8d4..1dba60c 100644
--- a/libavformat/hlsenc.c
+++ b/libavformat/hlsenc.c
@@ -37,12 +37,18 @@
 #include "internal.h"
 #include "os_support.h"
 
+#define BLOCKSIZE 16
+
 typedef struct HLSSegment {
 char filename[1024];
 double duration; /* in seconds */
 int64_t pos;
 int64_t size;
 
+char *key_uri;
+char *iv_string;
+int attribute_iv;
+
 struct HLSSegment *next;
 } HLSSegment;
 
@@ -86,9 +92,23 @@ typedef struct HLSContext {
 char *format_options_str;
 AVDictionary *format_options;
 
+char *key_info_file;
+char *key_file;
+char *key_uri;
+char *key_string;
+char *iv_string;
+int attribute_iv;
+
 AVIOContext *pb;
 } HLSContext;
 
+static void hls_free_segment(HLSSegment *en)
+{
+   av_freep(&en->key_uri);
+   av_freep(&en->iv_string);
+   av_freep(&en);
+}
+
 static int hls_delete_old_segments(HLSContext *hls) {
 
 HLSSegment *segment, *previous_segment = NULL;
@@ -145,7 +165,7 @@ static int hls_delete_old_segments(HLSContext *hls) {
 av_free(path);
 previous_segment = segment;
 segment = previous_segment->next;
-av_free(previous_segment);
+hls_free_segment(previous_segment);
 }
 
 fail:
@@ -154,6 +174,134 @@ fail:
 return ret;
 }
 
+static int hls_encryption_start(HLSContext *hls)
+{
+
+int ret = 0, i;
+AVIOContext *pb = NULL, *dyn_buf = NULL;
+uint8_t buf[1024], *tmp = NULL, *key = NULL, *iv = NULL;
+char *p, *tstr, *saveptr = NULL, *key_string = NULL, *iv_string = NULL;
+
+if ((ret = avio_open(&pb, hls->key_info_file, AVIO_FLAG_READ)) < 0) {
+av_log(hls, AV_LOG_ERROR, "error opening key info file %s\n",
+  hls->key_info_file);
+goto fail;
+}
+
+ret = avio_open_dyn_buf(&dyn_buf);
+if (ret < 0) {
+avio_closep(&pb);
+goto fail;
+}
+
+while ((ret = avio_read(pb, buf, sizeof(buf))) > 0)
+avio_write(dyn_buf, buf, ret);
+avio_closep(&pb);
+if (ret != AVERROR_EOF && ret < 0) {
+avio_close_dyn_buf(dyn_buf, &tmp);
+goto fail;
+}
+
+avio_w8(dyn_buf, 0);
+if ((ret = avio_close_dyn_buf(dyn_buf, &tmp)) < 0)
+goto fail;
+
+p = tmp;
+if (!(tstr = av_strtok(p, "\n", &saveptr)) || !*tstr) {
+av_log(hls, AV_LOG_ERROR, "no key URI specified in key info file %s\n",
+  hls->key_info_file);
+ret = AVERROR(EINVAL);
+goto fail;
+}
+av_free(hls->key_uri);
+hls->key_uri = av_strdup(tstr);
+if (!hls->key_uri) {
+ret = AVERROR(ENOMEM);
+goto fail;
+}
+
+if (!(tstr = av_strtok(NULL, "\n", &saveptr)) || !*tstr) {
+av_log(hls, AV_LOG_ERROR, "no key file specified in key info file 
%s\n",
+  hls->key_info_file);
+ret = AVERROR(EINVAL);
+goto fail;
+}
+av_free(hls->key_file);
+hls->key_file = av_strdup(tstr);
+if (!hls->key_file) {
+ret = AVERROR(ENOMEM);
+   

Re: [FFmpeg-devel] [PATCH] avformat/hlsenc: added HLS encryption

2014-12-23 Thread Christian Suloway
On Dec 22, 2014, at 6:36 PM, Michael Niedermayer  wrote:
> this looks a bit odd,
> see ff_get_line(), it probably allows to simplify this a lot

Resubmitting using ff_get_line().
Thanks,
Christian

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


[FFmpeg-devel] [PATCH] avformat/hlsenc: added HLS encryption

2014-12-23 Thread Christian Suloway
Added HLS encryption with -hls_key_info_file  option. The
first line of key_info_file specifies the key URI for the playlist. The
second line specifies the path to the file containing the encryption
key. An optional third line specifies an IV to use instead of the
segment number. Changes to key_info_file will be reflected in segment
encryption along with an entry in the playlist for the new key URI and
IV.

Signed-off-by: Christian Suloway 
---
 doc/muxers.texi  |   9 ++
 libavformat/hlsenc.c | 242 +--
 2 files changed, 245 insertions(+), 6 deletions(-)

diff --git a/doc/muxers.texi b/doc/muxers.texi
index a1264d2..f2ecf8b 100644
--- a/doc/muxers.texi
+++ b/doc/muxers.texi
@@ -263,6 +263,15 @@ ffmpeg in.nut -hls_segment_filename 'file%03d.ts' out.m3u8
 This example will produce the playlist, @file{out.m3u8}, and segment files:
 @file{file000.ts}, @file{file001.ts}, @file{file002.ts}, etc.
 
+@item hls_key_info_file @var{file}
+Use in the information in @var{file} for segment encryption. The first line of
+@var{file} specifies the key URI for the playlist. The second line specifies
+the path to the file containing the encryption key as a single packed array of
+16 octets in binary format. The optional third line specifies a hexidecimal
+string for the initialization vector (IV) to be used instead of the segment
+number. Changes to @var{file} will result in segment encryption with the new
+key/IV and an entry in the playlist for the new key URI/IV.
+
 @item hls_flags single_file
 If this flag is set, the muxer will store all segments in a single MPEG-TS
 file, and will use byte ranges in the playlist. HLS playlists generated with
diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c
index f46e8d4..6969187 100644
--- a/libavformat/hlsenc.c
+++ b/libavformat/hlsenc.c
@@ -37,12 +37,19 @@
 #include "internal.h"
 #include "os_support.h"
 
+#define BLOCKSIZE 16
+#define LINE_BUFFER_SIZE 1024
+
 typedef struct HLSSegment {
 char filename[1024];
 double duration; /* in seconds */
 int64_t pos;
 int64_t size;
 
+char *key_uri;
+char *iv_string;
+int attribute_iv;
+
 struct HLSSegment *next;
 } HLSSegment;
 
@@ -86,9 +93,23 @@ typedef struct HLSContext {
 char *format_options_str;
 AVDictionary *format_options;
 
+char *key_info_file;
+char *key_file;
+char *key_uri;
+char *key_string;
+char *iv_string;
+int attribute_iv;
+
 AVIOContext *pb;
 } HLSContext;
 
+static void hls_free_segment(HLSSegment *en)
+{
+   av_freep(&en->key_uri);
+   av_freep(&en->iv_string);
+   av_freep(&en);
+}
+
 static int hls_delete_old_segments(HLSContext *hls) {
 
 HLSSegment *segment, *previous_segment = NULL;
@@ -145,7 +166,7 @@ static int hls_delete_old_segments(HLSContext *hls) {
 av_free(path);
 previous_segment = segment;
 segment = previous_segment->next;
-av_free(previous_segment);
+hls_free_segment(previous_segment);
 }
 
 fail:
@@ -154,6 +175,140 @@ fail:
 return ret;
 }
 
+static int hls_get_line(AVIOContext *pb, char *buf, int buf_size) {
+int i = 0;
+
+if (!(i = ff_get_line(pb, buf, buf_size)))
+return 0;
+i = strcspn(buf, "\r\n");
+if (!i || buf[i] == '\0')
+return AVERROR(EINVAL);
+buf[i] = '\0';
+return i + 1;
+}
+
+static int hls_encryption_start(AVFormatContext *s)
+{
+HLSContext *hls = s->priv_data;
+int ret = 0, i;
+AVIOContext *pb = NULL;
+uint8_t *key = NULL, *iv = NULL;
+char buf[LINE_BUFFER_SIZE + 1], *key_string = NULL, *iv_string = NULL;
+
+if ((ret = avio_open2(&pb, hls->key_info_file, AVIO_FLAG_READ,
+   &s->interrupt_callback, NULL)) < 0) {
+av_log(hls, AV_LOG_ERROR,
+"error opening key info file %s\n", hls->key_info_file);
+goto fail;
+}
+
+if ((ret = hls_get_line(pb, buf, sizeof(buf))) <= 0) {
+if (!ret) {
+av_log(hls, AV_LOG_ERROR, "no key URI in key info file\n");
+ret = AVERROR(EINVAL);
+} else
+av_log(hls, AV_LOG_ERROR, "malformed key URI in key info file\n");
+goto fail;
+}
+av_free(hls->key_uri);
+hls->key_uri = av_strdup(buf);
+if (!hls->key_uri)
+return AVERROR(ENOMEM);
+av_log(hls, AV_LOG_DEBUG, "key URI = %s\n", hls->key_uri);
+
+if ((ret = hls_get_line(pb, buf, sizeof(buf))) <= 0) {
+if (!ret) {
+av_log(hls, AV_LOG_ERROR, "no key file in key info file\n");
+ret = AVERROR(EINVAL);
+} else
+av_log(hls, AV_LOG_ERROR, "malformed key file in key info file\n");
+goto fail;
+}
+av_free(hls->key_file);
+hls->key_file = av_strdup(buf);
+if (!hls-&g

[FFmpeg-devel] [PATCH] avformat/hlsenc: added HLS encryption

2014-12-30 Thread Christian Suloway
Added HLS encryption with -hls_key_info_file  option. The
first line of key_info_file specifies the key URI for the playlist. The
second line specifies the path to the file containing the encryption
key. An optional third line specifies an IV to use instead of the
segment number. Changes to key_info_file will be reflected in segment
encryption along with an entry in the playlist for the new key URI and
IV.

Signed-off-by: Christian Suloway 
---
 doc/muxers.texi  |   9 
 libavformat/hlsenc.c | 130 +--
 2 files changed, 136 insertions(+), 3 deletions(-)

diff --git a/doc/muxers.texi b/doc/muxers.texi
index a1264d2..f2ecf8b 100644
--- a/doc/muxers.texi
+++ b/doc/muxers.texi
@@ -263,6 +263,15 @@ ffmpeg in.nut -hls_segment_filename 'file%03d.ts' out.m3u8
 This example will produce the playlist, @file{out.m3u8}, and segment files:
 @file{file000.ts}, @file{file001.ts}, @file{file002.ts}, etc.
 
+@item hls_key_info_file @var{file}
+Use in the information in @var{file} for segment encryption. The first line of
+@var{file} specifies the key URI for the playlist. The second line specifies
+the path to the file containing the encryption key as a single packed array of
+16 octets in binary format. The optional third line specifies a hexidecimal
+string for the initialization vector (IV) to be used instead of the segment
+number. Changes to @var{file} will result in segment encryption with the new
+key/IV and an entry in the playlist for the new key URI/IV.
+
 @item hls_flags single_file
 If this flag is set, the muxer will store all segments in a single MPEG-TS
 file, and will use byte ranges in the playlist. HLS playlists generated with
diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c
index f46e8d4..7f2bc96 100644
--- a/libavformat/hlsenc.c
+++ b/libavformat/hlsenc.c
@@ -37,12 +37,18 @@
 #include "internal.h"
 #include "os_support.h"
 
+#define BLOCKSIZE 16
+#define LINE_BUFFER_SIZE 1024
+
 typedef struct HLSSegment {
 char filename[1024];
 double duration; /* in seconds */
 int64_t pos;
 int64_t size;
 
+char key_uri[LINE_BUFFER_SIZE + 1];
+char iv_string[BLOCKSIZE*2 + 1];
+
 struct HLSSegment *next;
 } HLSSegment;
 
@@ -86,6 +92,12 @@ typedef struct HLSContext {
 char *format_options_str;
 AVDictionary *format_options;
 
+char *key_info_file;
+char key_file[LINE_BUFFER_SIZE + 1];
+char key_uri[LINE_BUFFER_SIZE + 1];
+char key_string[BLOCKSIZE*2 + 1];
+char iv_string[BLOCKSIZE*2 + 1];
+
 AVIOContext *pb;
 } HLSContext;
 
@@ -154,6 +166,62 @@ fail:
 return ret;
 }
 
+static int hls_encryption_start(AVFormatContext *s)
+{
+HLSContext *hls = s->priv_data;
+int ret;
+AVIOContext *pb;
+uint8_t key[BLOCKSIZE];
+
+if ((ret = avio_open2(&pb, hls->key_info_file, AVIO_FLAG_READ,
+   &s->interrupt_callback, NULL)) < 0) {
+av_log(hls, AV_LOG_ERROR,
+"error opening key info file %s\n", hls->key_info_file);
+return ret;
+}
+
+ff_get_line(pb, hls->key_uri, sizeof(hls->key_uri));
+hls->key_uri[strcspn(hls->key_uri, "\r\n")] = '\0';
+
+ff_get_line(pb, hls->key_file, sizeof(hls->key_file));
+hls->key_file[strcspn(hls->key_file, "\r\n")] = '\0';
+
+ff_get_line(pb, hls->iv_string, sizeof(hls->iv_string));
+hls->iv_string[strcspn(hls->iv_string, "\r\n")] = '\0';
+
+avio_close(pb);
+
+if (!*hls->key_uri) {
+av_log(hls, AV_LOG_ERROR, "no key URI specified in key info file\n");
+return AVERROR(EINVAL);
+}
+av_log(hls, AV_LOG_DEBUG, "key URI = %s\n", hls->key_uri);
+
+if (!*hls->key_file) {
+av_log(hls, AV_LOG_ERROR, "no key file specified in key info file\n");
+return AVERROR(EINVAL);
+}
+av_log(hls, AV_LOG_DEBUG, "key file = %s\n", hls->key_file);
+
+if ((ret = avio_open2(&pb, hls->key_file, AVIO_FLAG_READ,
+   &s->interrupt_callback, NULL)) < 0) {
+av_log(hls, AV_LOG_ERROR, "error opening key file %s\n", 
hls->key_file);
+return ret;
+}
+
+ret = avio_read(pb, key, sizeof(key));
+avio_close(pb);
+if (ret != sizeof(key)) {
+av_log(hls, AV_LOG_ERROR, "error reading key file %s\n", 
hls->key_file);
+if (ret >= 0 || ret == AVERROR_EOF)
+ret = AVERROR(EINVAL);
+return ret;
+}
+ff_data_to_hex(hls->key_string, key, sizeof(key), 0);
+
+return 0;
+}
+
 static int hls_mux_init(AVFormatContext *s)
 {
 HLSContext *hls = s->priv_data;
@@ -200,6 +268,11 @@ static int hls_append_segment(HLSContext *hls, double 
duration, int64_t pos,
 en->size = size;
 en->next = NULL

[FFmpeg-devel] [PATCH] avformat/hlsenc: added HLS encryption

2015-01-07 Thread Christian Suloway
Added HLS encryption with -hls_key_info_file  option. The
first line of key_info_file specifies the key URI for the playlist. The
second line specifies the path to the file containing the encryption
key. An optional third line specifies an IV to use instead of the
segment number. Changes to key_info_file will be reflected in segment
encryption along with an entry in the playlist for the new key URI and
IV.

Signed-off-by: Christian Suloway 
---
 doc/muxers.texi  |   9 
 libavformat/hlsenc.c | 130 +--
 2 files changed, 136 insertions(+), 3 deletions(-)

diff --git a/doc/muxers.texi b/doc/muxers.texi
index a1264d2..f2ecf8b 100644
--- a/doc/muxers.texi
+++ b/doc/muxers.texi
@@ -263,6 +263,15 @@ ffmpeg in.nut -hls_segment_filename 'file%03d.ts' out.m3u8
 This example will produce the playlist, @file{out.m3u8}, and segment files:
 @file{file000.ts}, @file{file001.ts}, @file{file002.ts}, etc.
 
+@item hls_key_info_file @var{file}
+Use in the information in @var{file} for segment encryption. The first line of
+@var{file} specifies the key URI for the playlist. The second line specifies
+the path to the file containing the encryption key as a single packed array of
+16 octets in binary format. The optional third line specifies a hexidecimal
+string for the initialization vector (IV) to be used instead of the segment
+number. Changes to @var{file} will result in segment encryption with the new
+key/IV and an entry in the playlist for the new key URI/IV.
+
 @item hls_flags single_file
 If this flag is set, the muxer will store all segments in a single MPEG-TS
 file, and will use byte ranges in the playlist. HLS playlists generated with
diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c
index f46e8d4..7f2bc96 100644
--- a/libavformat/hlsenc.c
+++ b/libavformat/hlsenc.c
@@ -37,12 +37,18 @@
 #include "internal.h"
 #include "os_support.h"
 
+#define BLOCKSIZE 16
+#define LINE_BUFFER_SIZE 1024
+
 typedef struct HLSSegment {
 char filename[1024];
 double duration; /* in seconds */
 int64_t pos;
 int64_t size;
 
+char key_uri[LINE_BUFFER_SIZE + 1];
+char iv_string[BLOCKSIZE*2 + 1];
+
 struct HLSSegment *next;
 } HLSSegment;
 
@@ -86,6 +92,12 @@ typedef struct HLSContext {
 char *format_options_str;
 AVDictionary *format_options;
 
+char *key_info_file;
+char key_file[LINE_BUFFER_SIZE + 1];
+char key_uri[LINE_BUFFER_SIZE + 1];
+char key_string[BLOCKSIZE*2 + 1];
+char iv_string[BLOCKSIZE*2 + 1];
+
 AVIOContext *pb;
 } HLSContext;
 
@@ -154,6 +166,62 @@ fail:
 return ret;
 }
 
+static int hls_encryption_start(AVFormatContext *s)
+{
+HLSContext *hls = s->priv_data;
+int ret;
+AVIOContext *pb;
+uint8_t key[BLOCKSIZE];
+
+if ((ret = avio_open2(&pb, hls->key_info_file, AVIO_FLAG_READ,
+   &s->interrupt_callback, NULL)) < 0) {
+av_log(hls, AV_LOG_ERROR,
+"error opening key info file %s\n", hls->key_info_file);
+return ret;
+}
+
+ff_get_line(pb, hls->key_uri, sizeof(hls->key_uri));
+hls->key_uri[strcspn(hls->key_uri, "\r\n")] = '\0';
+
+ff_get_line(pb, hls->key_file, sizeof(hls->key_file));
+hls->key_file[strcspn(hls->key_file, "\r\n")] = '\0';
+
+ff_get_line(pb, hls->iv_string, sizeof(hls->iv_string));
+hls->iv_string[strcspn(hls->iv_string, "\r\n")] = '\0';
+
+avio_close(pb);
+
+if (!*hls->key_uri) {
+av_log(hls, AV_LOG_ERROR, "no key URI specified in key info file\n");
+return AVERROR(EINVAL);
+}
+av_log(hls, AV_LOG_DEBUG, "key URI = %s\n", hls->key_uri);
+
+if (!*hls->key_file) {
+av_log(hls, AV_LOG_ERROR, "no key file specified in key info file\n");
+return AVERROR(EINVAL);
+}
+av_log(hls, AV_LOG_DEBUG, "key file = %s\n", hls->key_file);
+
+if ((ret = avio_open2(&pb, hls->key_file, AVIO_FLAG_READ,
+   &s->interrupt_callback, NULL)) < 0) {
+av_log(hls, AV_LOG_ERROR, "error opening key file %s\n", 
hls->key_file);
+return ret;
+}
+
+ret = avio_read(pb, key, sizeof(key));
+avio_close(pb);
+if (ret != sizeof(key)) {
+av_log(hls, AV_LOG_ERROR, "error reading key file %s\n", 
hls->key_file);
+if (ret >= 0 || ret == AVERROR_EOF)
+ret = AVERROR(EINVAL);
+return ret;
+}
+ff_data_to_hex(hls->key_string, key, sizeof(key), 0);
+
+return 0;
+}
+
 static int hls_mux_init(AVFormatContext *s)
 {
 HLSContext *hls = s->priv_data;
@@ -200,6 +268,11 @@ static int hls_append_segment(HLSContext *hls, double 
duration, int64_t pos,
 en->size = size;
 en->next = NULL

Re: [FFmpeg-devel] [PATCH] avformat/hlsenc: added HLS encryption

2015-01-09 Thread Christian Suloway
New version of the patch attached to address your comments.
Thanks,
Christian

On Jan 7, 2015, at 2:17 PM, Michael Niedermayer  wrote:

> Please add a testcase/example to either the documentation or
> commit message

Example added to the commit message.

>> +ff_get_line(pb, hls->key_uri, sizeof(hls->key_uri));
>> +hls->key_uri[strcspn(hls->key_uri, "\r\n")] = '\0';
>> +
>> +ff_get_line(pb, hls->key_file, sizeof(hls->key_file));
>> +hls->key_file[strcspn(hls->key_file, "\r\n")] = '\0';
>> +
>> +ff_get_line(pb, hls->iv_string, sizeof(hls->iv_string));
>> +hls->iv_string[strcspn(hls->iv_string, "\r\n")] = '\0';
> 
> in what case are the strcspn() needed ?

Replaced with terminating character check/replace, and combined with error 
check.

>> +if (!err)
>> +snprintf(iv_string, sizeof(iv_string), "%032llx", c->sequence);
> 
> libavformat/hlsenc.c:407:13: warning: format ‘%llx’ expects argument of type 
> ‘long long unsigned int’, but argument 4 has type ‘int64_t’ [-Wformat]
> libavformat/hlsenc.c:407:13: warning: format ‘%llx’ expects argument of type 
> ‘long long unsigned int’, but argument 4 has type ‘int64_t’ [-Wformat]

Replaced with PRIx64 macro.

>> +filename_size = strlen(prefix) + strlen(oc->filename) + 1;
>> +filename = av_malloc(filename_size);
>> +if (!filename) {
>> +av_dict_free(&options);
>> +return AVERROR(ENOMEM);
>> +}
>> +av_strlcpy(filename, prefix, filename_size);
>> +av_strlcat(filename, oc->filename, filename_size);
> 
> this looks like it can be simplified with av_asprintf()

Replaced with av_asprintf().



0001-avformat-hlsenc-added-HLS-encryption.patch
Description: 0001-avformat-hlsenc-added-HLS-encryption.patch



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


Re: [FFmpeg-devel] [PATCH] avformat/hlsenc: added HLS encryption

2015-01-09 Thread Christian Suloway
Resending attachment.


From: ffmpeg-devel-boun...@ffmpeg.org  on 
behalf of Christian Suloway 
Sent: Friday, January 9, 2015 5:02 PM
To: FFmpeg development discussions and patches
Subject: Re: [FFmpeg-devel] [PATCH] avformat/hlsenc: added HLS encryption

New version of the patch attached to address your comments.
Thanks,
Christian

On Jan 7, 2015, at 2:17 PM, Michael Niedermayer  wrote:

> Please add a testcase/example to either the documentation or
> commit message

Example added to the commit message.

>> +ff_get_line(pb, hls->key_uri, sizeof(hls->key_uri));
>> +hls->key_uri[strcspn(hls->key_uri, "\r\n")] = '\0';
>> +
>> +ff_get_line(pb, hls->key_file, sizeof(hls->key_file));
>> +hls->key_file[strcspn(hls->key_file, "\r\n")] = '\0';
>> +
>> +ff_get_line(pb, hls->iv_string, sizeof(hls->iv_string));
>> +hls->iv_string[strcspn(hls->iv_string, "\r\n")] = '\0';
>
> in what case are the strcspn() needed ?

Replaced with terminating character check/replace, and combined with error 
check.

>> +if (!err)
>> +snprintf(iv_string, sizeof(iv_string), "%032llx", c->sequence);
>
> libavformat/hlsenc.c:407:13: warning: format ‘%llx’ expects argument of type 
> ‘long long unsigned int’, but argument 4 has type ‘int64_t’ [-Wformat]
> libavformat/hlsenc.c:407:13: warning: format ‘%llx’ expects argument of type 
> ‘long long unsigned int’, but argument 4 has type ‘int64_t’ [-Wformat]

Replaced with PRIx64 macro.

>> +filename_size = strlen(prefix) + strlen(oc->filename) + 1;
>> +filename = av_malloc(filename_size);
>> +if (!filename) {
>> +av_dict_free(&options);
>> +return AVERROR(ENOMEM);
>> +}
>> +av_strlcpy(filename, prefix, filename_size);
>> +av_strlcat(filename, oc->filename, filename_size);
>
> this looks like it can be simplified with av_asprintf()

Replaced with av_asprintf().



0001-avformat-hlsenc-added-HLS-encryption.patch
Description: 0001-avformat-hlsenc-added-HLS-encryption.patch
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


[FFmpeg-devel] [PATCH 2/2] MAINTAINERS: add myself as hls encryption maintainer

2015-06-16 Thread Christian Suloway
Signed-off-by: Christian Suloway 
---
 MAINTAINERS | 1 +
 1 file changed, 1 insertion(+)

diff --git a/MAINTAINERS b/MAINTAINERS
index 7b239a1..fa9e966 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -416,6 +416,7 @@ Muxers/Demuxers:
   gxf.c Reimar Doeffinger
   gxfenc.c  Baptiste Coudurier
   hls.c Anssi Hannula
+  hls encryption (hlsenc.c) Christian Suloway
   idcin.c   Mike Melanson
   idroqdec.cMike Melanson
   iff.c Jaikrishnan Menon
-- 
2.4.2

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


[FFmpeg-devel] [PATCH 1/2] avformat/hlsenc: removed empty/unused print_encryption_tag function

2015-06-16 Thread Christian Suloway
Signed-off-by: Christian Suloway 
---
 libavformat/hlsenc.c | 4 
 1 file changed, 4 deletions(-)

diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c
index 68c6479..cf29f4f 100644
--- a/libavformat/hlsenc.c
+++ b/libavformat/hlsenc.c
@@ -310,10 +310,6 @@ static void hls_free_segments(HLSSegment *p)
 }
 }
 
-static void print_encryption_tag(HLSContext *hls, HLSSegment *en)
-{
-}
-
 static int hls_window(AVFormatContext *s, int last)
 {
 HLSContext *hls = s->priv_data;
-- 
2.4.2

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


Re: [FFmpeg-devel] [PATCH] avformat/hlsenc: added HLS encryption

2015-02-03 Thread Christian Suloway
Updated patch is attached.

On 1/10/15, 3:06 PM, "Michael Niedermayer"  wrote:
>
>i got it working after a few tries but
>please provide an example that works and documentation that describes
>the feature in a way sufficient to use it without reading the code
>ideally add a example to the documentation too

The documentation and commit message have been updated. Let me know if
further clarification is needed.

>also the parser is fragile it requires to carefully place newlines
>or it will fail, i think the previous strcspn() code was better if it
>avoided that, i didnt realize this

I have reverted this section to the previous strcspn() code.

Thanks,
Christian



0001-avformat-hlsenc-added-HLS-encryption.patch
Description: 0001-avformat-hlsenc-added-HLS-encryption.patch
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH] avformat/hlsenc: added HLS encryption

2015-02-11 Thread Christian Suloway
bumping this thread

On 2/3/15, 9:54 AM, "Christian Suloway" 
wrote:

>Updated patch is attached.
>
>On 1/10/15, 3:06 PM, "Michael Niedermayer"  wrote:
>>
>>i got it working after a few tries but
>>please provide an example that works and documentation that describes
>>the feature in a way sufficient to use it without reading the code
>>ideally add a example to the documentation too
>
>The documentation and commit message have been updated. Let me know if
>further clarification is needed.
>
>>also the parser is fragile it requires to carefully place newlines
>>or it will fail, i think the previous strcspn() code was better if it
>>avoided that, i didnt realize this
>
>I have reverted this section to the previous strcspn() code.
>
>Thanks,
>Christian
>



0001-avformat-hlsenc-added-HLS-encryption.patch
Description: 0001-avformat-hlsenc-added-HLS-encryption.patch
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


[FFmpeg-devel] Anybody already working on VDPAU / HEVC support?

2015-04-30 Thread Christian König

Hi list,

since VDPAU has now officially picked up HEVC support I wonder if 
anybody is already working on integrating it into ffmpeg?


Best regards,
Christian.
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] Anybody already working on VDPAU / HEVC support?

2015-04-30 Thread Christian König

On 30.04.2015 19:09, Philip Langdale wrote:

On 2015-04-30 09:10, Christian König wrote:

Hi list,

since VDPAU has now officially picked up HEVC support I wonder if
anybody is already working on integrating it into ffmpeg?


I was hoping that Stephen Warren from nvidia would pop up again with
the relevant patches, having done the original work for the other 
formats.

For all I know, they might still be working on it.


I already talked to José Hiram Soltren from NVidia and it unfortunately 
doesn't look like they will do it this time.




I'm not aware of anyone else; given the hardware requirements, I wouldn't
be surprised if there's no one who's both qualified to do the work and 
has

the hardware to test it.


Thanks for the info,
Christian.



--phil


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


Re: [FFmpeg-devel] [PATCH] avfilter/vf_xpsnr: remove duplicated DSP infranstructure

2024-10-14 Thread Helmrich, Christian
Hi,


thanks for taking a look, but I don't understand the two "unsigned error = 
main_line[j] - ref_line[j];" you added. Inline:



Fully reuse the existing one from vf_psnr, instead of halfways.

Signed-off-by: James Almer 
---
 libavfilter/Makefile|  4 +--
 libavfilter/psnr.c  | 64 +
 libavfilter/psnr.h  |  1 +
 libavfilter/vf_psnr.c   | 29 +--
 libavfilter/vf_xpsnr.c  | 28 ---
 libavfilter/x86/Makefile|  3 +-
 libavfilter/x86/vf_xpsnr_init.c | 43 --
 libavfilter/xpsnr.h |  5 +--
 8 files changed, 77 insertions(+), 100 deletions(-)
 create mode 100644 libavfilter/psnr.c
 delete mode 100644 libavfilter/x86/vf_xpsnr_init.c

diff --git a/libavfilter/Makefile b/libavfilter/Makefile
index a56c8e8b79..a3a63d326e 100644
--- a/libavfilter/Makefile
+++ b/libavfilter/Makefile
@@ -437,7 +437,7 @@ OBJS-$(CONFIG_PREWITT_OPENCL_FILTER) += 
vf_convolution_opencl.o opencl.o
 OBJS-$(CONFIG_PROCAMP_VAAPI_FILTER)  += vf_procamp_vaapi.o vaapi_vpp.o
 OBJS-$(CONFIG_PROGRAM_OPENCL_FILTER) += vf_program_opencl.o opencl.o 
framesync.o
 OBJS-$(CONFIG_PSEUDOCOLOR_FILTER)+= vf_pseudocolor.o
-OBJS-$(CONFIG_PSNR_FILTER)   += vf_psnr.o framesync.o
+OBJS-$(CONFIG_PSNR_FILTER)   += vf_psnr.o framesync.o psnr.o
 OBJS-$(CONFIG_PULLUP_FILTER) += vf_pullup.o
 OBJS-$(CONFIG_QP_FILTER) += vf_qp.o
 OBJS-$(CONFIG_QUIRC_FILTER)  += vf_quirc.o
@@ -566,7 +566,7 @@ OBJS-$(CONFIG_XFADE_FILTER)  += vf_xfade.o
 OBJS-$(CONFIG_XFADE_OPENCL_FILTER)   += vf_xfade_opencl.o opencl.o 
opencl/xfade.o
 OBJS-$(CONFIG_XFADE_VULKAN_FILTER)   += vf_xfade_vulkan.o vulkan.o 
vulkan_filter.o
 OBJS-$(CONFIG_XMEDIAN_FILTER)+= vf_xmedian.o framesync.o
-OBJS-$(CONFIG_XPSNR_FILTER)  += vf_xpsnr.o framesync.o
+OBJS-$(CONFIG_XPSNR_FILTER)  += vf_xpsnr.o framesync.o psnr.o
 OBJS-$(CONFIG_XSTACK_FILTER) += vf_stack.o framesync.o
 OBJS-$(CONFIG_YADIF_FILTER)  += vf_yadif.o yadif_common.o
 OBJS-$(CONFIG_YADIF_CUDA_FILTER) += vf_yadif_cuda.o 
vf_yadif_cuda.ptx.o \
diff --git a/libavfilter/psnr.c b/libavfilter/psnr.c
new file mode 100644
index 00..a6b7f5969c
--- /dev/null
+++ b/libavfilter/psnr.c
@@ -0,0 +1,64 @@
+/*
+ * Copyright (c) 2015 Ronald S. Bultje 
+ *
+ * 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 "config.h"
+
+#include 
+#include 
+
+#include "psnr.h"
+
+static uint64_t sse_line_8bit(const uint8_t *main_line,  const uint8_t 
*ref_line, int outw)
+{
+int j;
+unsigned m2 = 0;
+
+for (j = 0; j < outw; j++) {
+unsigned error = main_line[j] - ref_line[j];

Why is error unsigned? The difference could be negative. In our code we had:
const int... error = (int...) blk_org[x] - (int...) blk_rec[x];
and the PSNR code had: m2 += pow_2(main_line[j] - ref_line[j]);
Is this equivalent, and I don't see it? Could this be a general issue even with 
the pow_2 variant?

+
+m2 += error * error;
+}
+
+return m2;
+}
+
+static uint64_t sse_line_16bit(const uint8_t *_main_line, const uint8_t 
*_ref_line, int outw)
+{
+int j;
+uint64_t m2 = 0;
+const uint16_t *main_line = (const uint16_t *) _main_line;
+const uint16_t *ref_line = (const uint16_t *) _ref_line;
+
+for (j = 0; j < outw; j++) {
+unsigned error = main_line[j] - ref_line[j];

Same as above.

Best,

Christian

+
+m2 += error * error;
+}
+
+return m2;
+}
+
+void ff_psnr_init(PSNRDSPContext *dsp, int bpp)
+{
+dsp->sse_line = bpp > 8 ? sse_line_16bit : sse_line_8bit;
+#if ARCH_X86
+ff_psnr_init_x86(dsp, bpp);
+#endif
+}
diff --git a/libavfilter/psnr.h b/libavfilter/psnr.h
index bbc4541135..2664aa5255 100644
--- a/libavfilter/psnr.h
+++ b/libavfilter/psnr.h
@@ -28,6 +28,7 @@ typedef struct PSNRDSPContext {
 uint64_t (*sse_line)(const uint8_t *buf, const uint8_t *ref, int w);
 } PSNRDSPContext;

+void ff_psnr_init(PSNRDSPContext *dsp, int bpp);
 void ff_psnr_init_x86(PSNRDS

[FFmpeg-devel] [PATCH 1/1] avformat/gopher: Add audio and video itemtypes

2024-03-04 Thread Christian Lee Seibold
The 's', ';', and '<' itemtypes are used for audio and video by
Gophernicus and Gopher+.

Signed-off-by: Christian Lee Seibold 
---
 libavformat/gopher.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/libavformat/gopher.c b/libavformat/gopher.c
index 9497ffacf2..97ac9028a1 100644
--- a/libavformat/gopher.c
+++ b/libavformat/gopher.c
@@ -49,6 +49,9 @@ static int gopher_connect(URLContext *h, const char *path)
 if (!*path) return AVERROR(EINVAL);
 switch (*++path) {
 case '5':
+case 's':
+case '<':
+case ';':
 case '9':
 path = strchr(path, '/');
 if (!path) return AVERROR(EINVAL);
-- 
2.41.0.windows.2

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