[FFmpeg-devel] [PATCH V4] Add a filter implementing HDR image generation from a single exposure using deep CNNs
see the algorithm's paper and code below. the filter's parameter looks like: sdr2hdr=model_filename=/path_to_tensorflow_graph.pb:out_fmt=gbrp10le The input of the deep CNN model is RGB24 while the output is float for each color channel. This is the filter's default behavior to output format with gbrpf32le. And gbrp10le is also supported as the output, so we can see the rendering result in a player, as a reference. To generate the model file, we need modify the original script a little. - set name='y' for y_final within script at https://github.com/gabrieleilertsen/hdrcnn/blob/master/network.py - add the following code to the script at https://github.com/gabrieleilertsen/hdrcnn/blob/master/hdrcnn_predict.py graph = tf.graph_util.convert_variables_to_constants(sess, sess.graph_def, ["y"]) tf.train.write_graph(graph, '.', 'graph.pb', as_text=False) The filter only works when tensorflow C api is supported in the system, native backend is not supported since there are some different types of layers in the deep CNN model, besides CONV and DEPTH_TO_SPACE. https://arxiv.org/pdf/1710.07480.pdf: author = "Eilertsen, Gabriel and Kronander, Joel, and Denes, Gyorgy and Mantiuk, Rafał and Unger, Jonas", title= "HDR image reconstruction from a single exposure using deep CNNs", journal = "ACM Transactions on Graphics (TOG)", number = "6", volume = "36", articleno= "178", year = "2017" https://github.com/gabrieleilertsen/hdrcnn btw, as a whole solution, metadata should also be generated from the sdr video, so to be encoded as a HDR video. Not supported yet. This patch just focuses on this paper. Signed-off-by: Guo, Yejun --- configure| 1 + doc/filters.texi | 35 +++ libavfilter/Makefile | 1 + libavfilter/allfilters.c | 1 + libavfilter/vf_sdr2hdr.c | 268 +++ 5 files changed, 306 insertions(+) create mode 100644 libavfilter/vf_sdr2hdr.c diff --git a/configure b/configure index 85d5dd5..5e2efba 100755 --- a/configure +++ b/configure @@ -3438,6 +3438,7 @@ scale2ref_filter_deps="swscale" scale_filter_deps="swscale" scale_qsv_filter_deps="libmfx" select_filter_select="pixelutils" +sdr2hdr_filter_deps="libtensorflow" sharpness_vaapi_filter_deps="vaapi" showcqt_filter_deps="avcodec avformat swscale" showcqt_filter_suggest="libfontconfig libfreetype" diff --git a/doc/filters.texi b/doc/filters.texi index 17e2549..bba9f87 100644 --- a/doc/filters.texi +++ b/doc/filters.texi @@ -14672,6 +14672,41 @@ Scale a subtitle stream (b) to match the main video (a) in size before overlayin @end example @end itemize +@section sdr2hdr + +HDR image generation from a single exposure using deep CNNs with TensorFlow C library. + +@itemize +@item +paper: see @url{https://arxiv.org/pdf/1710.07480.pdf} + +@item +code with model and trained parameters: see @url{https://github.com/gabrieleilertsen/hdrcnn} +@end itemize + +The filter accepts the following options: + +@table @option + +@item model_filename +Set path to model file specifying network architecture and its parameters. + +@item out_fmt +the data format of the filter's output. + +It accepts the following values: +@table @samp +@item gbrpf32le +force gbrpf32le output + +@item gbrp10le +force gbrp10le output +@end table + +Default value is @samp{gbrpf32le}. + +@end table + @anchor{selectivecolor} @section selectivecolor diff --git a/libavfilter/Makefile b/libavfilter/Makefile index 62cc2f5..88e7da6 100644 --- a/libavfilter/Makefile +++ b/libavfilter/Makefile @@ -360,6 +360,7 @@ OBJS-$(CONFIG_SOBEL_OPENCL_FILTER) += vf_convolution_opencl.o opencl.o OBJS-$(CONFIG_SPLIT_FILTER) += split.o OBJS-$(CONFIG_SPP_FILTER)+= vf_spp.o OBJS-$(CONFIG_SR_FILTER) += vf_sr.o +OBJS-$(CONFIG_SDR2HDR_FILTER)+= vf_sdr2hdr.o OBJS-$(CONFIG_SSIM_FILTER) += vf_ssim.o framesync.o OBJS-$(CONFIG_STEREO3D_FILTER) += vf_stereo3d.o OBJS-$(CONFIG_STREAMSELECT_FILTER) += f_streamselect.o framesync.o diff --git a/libavfilter/allfilters.c b/libavfilter/allfilters.c index 5e72803..1645c0f 100644 --- a/libavfilter/allfilters.c +++ b/libavfilter/allfilters.c @@ -319,6 +319,7 @@ extern AVFilter ff_vf_scale_npp; extern AVFilter ff_vf_scale_qsv; extern AVFilter ff_vf_scale_vaapi; extern AVFilter ff_vf_scale2ref; +extern AVFilter ff_vf_sdr2hdr; extern AVFilter ff_vf_select; extern AVFilter ff_vf_selectivecolor; extern AVFilter ff_vf_sendcmd; diff --git a/libavfilter/vf_sdr2hdr.c b/libavfilter/vf_sdr2hdr.c new file mode 100644 index 000..109b907 --- /dev/null +++ b/libavfilter/vf_sdr2hdr.c @@ -0,0 +1,268 @@ +/* + * Copyright (c) 2018 Guo Yejun + * + * 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 publishe
Re: [FFmpeg-devel] [PATCH V4] Add a filter implementing HDR image generation from a single exposure using deep CNNs
any more comment? thanks. > -Original Message- > From: Guo, Yejun > Sent: Tuesday, October 23, 2018 6:46 AM > To: ffmpeg-devel@ffmpeg.org > Cc: Guo, Yejun ; Guo > Subject: [PATCH V4] Add a filter implementing HDR image generation from a > single exposure using deep CNNs > > see the algorithm's paper and code below. > > the filter's parameter looks like: > sdr2hdr=model_filename=/path_to_tensorflow_graph.pb:out_fmt=gbrp10l > e > > The input of the deep CNN model is RGB24 while the output is float for each > color channel. This is the filter's default behavior to output format with > gbrpf32le. And gbrp10le is also supported as the output, so we can see the > rendering result in a player, as a reference. > > To generate the model file, we need modify the original script a little. > - set name='y' for y_final within script at > https://github.com/gabrieleilertsen/hdrcnn/blob/master/network.py > - add the following code to the script at > https://github.com/gabrieleilertsen/hdrcnn/blob/master/hdrcnn_predict.py > > graph = tf.graph_util.convert_variables_to_constants(sess, sess.graph_def, > ["y"]) tf.train.write_graph(graph, '.', 'graph.pb', as_text=False) > > The filter only works when tensorflow C api is supported in the system, > native backend is not supported since there are some different types of > layers in the deep CNN model, besides CONV and DEPTH_TO_SPACE. > > https://arxiv.org/pdf/1710.07480.pdf: > author = "Eilertsen, Gabriel and Kronander, Joel, and Denes, Gyorgy > and > Mantiuk, Rafał and Unger, Jonas", > title= "HDR image reconstruction from a single exposure using deep > CNNs", > journal = "ACM Transactions on Graphics (TOG)", > number = "6", > volume = "36", > articleno= "178", > year = "2017" > > https://github.com/gabrieleilertsen/hdrcnn > > btw, as a whole solution, metadata should also be generated from the sdr > video, so to be encoded as a HDR video. Not supported yet. > This patch just focuses on this paper. > > Signed-off-by: Guo, Yejun > --- > configure| 1 + > doc/filters.texi | 35 +++ > libavfilter/Makefile | 1 + > libavfilter/allfilters.c | 1 + > libavfilter/vf_sdr2hdr.c | 268 > +++ > 5 files changed, 306 insertions(+) > create mode 100644 libavfilter/vf_sdr2hdr.c > > diff --git a/configure b/configure > index 85d5dd5..5e2efba 100755 > --- a/configure > +++ b/configure > @@ -3438,6 +3438,7 @@ scale2ref_filter_deps="swscale" > scale_filter_deps="swscale" > scale_qsv_filter_deps="libmfx" > select_filter_select="pixelutils" > +sdr2hdr_filter_deps="libtensorflow" > sharpness_vaapi_filter_deps="vaapi" > showcqt_filter_deps="avcodec avformat swscale" > showcqt_filter_suggest="libfontconfig libfreetype" > diff --git a/doc/filters.texi b/doc/filters.texi index 17e2549..bba9f87 100644 > --- a/doc/filters.texi > +++ b/doc/filters.texi > @@ -14672,6 +14672,41 @@ Scale a subtitle stream (b) to match the main > video (a) in size before overlayin @end example @end itemize > > +@section sdr2hdr > + > +HDR image generation from a single exposure using deep CNNs with > TensorFlow C library. > + > +@itemize > +@item > +paper: see @url{https://arxiv.org/pdf/1710.07480.pdf} > + > +@item > +code with model and trained parameters: see > +@url{https://github.com/gabrieleilertsen/hdrcnn} > +@end itemize > + > +The filter accepts the following options: > + > +@table @option > + > +@item model_filename > +Set path to model file specifying network architecture and its parameters. > + > +@item out_fmt > +the data format of the filter's output. > + > +It accepts the following values: > +@table @samp > +@item gbrpf32le > +force gbrpf32le output > + > +@item gbrp10le > +force gbrp10le output > +@end table > + > +Default value is @samp{gbrpf32le}. > + > +@end table > + > @anchor{selectivecolor} > @section selectivecolor > > diff --git a/libavfilter/Makefile b/libavfilter/Makefile index > 62cc2f5..88e7da6 > 100644 > --- a/libavfilter/Makefile > +++ b/libavfilter/Makefile > @@ -360,6 +360,7 @@ OBJS-$(CONFIG_SOBEL_OPENCL_FILTER) += > vf_convolution_opencl.o opencl.o > OBJS-$(CONFIG_SPLIT_FILTER) += split.o > OBJS-$(CONFIG_SPP_FILTER)+= vf_spp.o > OBJS-$(CONFIG_SR_FILTER) += vf_sr.o > +OBJS-$(CONFIG_SDR2HDR_FILTER)+= vf_sdr2hdr.o > OBJS-$(CONFIG_SSIM_FILTER) += vf_ssim.o framesync.o > OBJS-$(CONFIG_STEREO3D_FILTER) += vf_stereo3d.o > OBJS-$(CONFIG_STREAMSELECT_FILTER) += f_streamselect.o > framesync.o > diff --git a/libavfilter/allfilters.c b/libavfilter/allfilters.c index > 5e72803..1645c0f > 100644 > --- a/libavfilter/allfilters.c > +++ b/libavfilter/allfilters.c > @@ -319,6 +319,7 @@ extern AVFilter ff_vf_scale_npp; extern AVFilter > ff_vf_scale_qsv; extern AVFilter ff_vf_scale_vaapi; extern AVFilter >
Re: [FFmpeg-devel] [PATCH V4] Add a filter implementing HDR image generation from a single exposure using deep CNNs
ask for comment or merge, thanks. > -Original Message- > From: ffmpeg-devel [mailto:ffmpeg-devel-boun...@ffmpeg.org] On Behalf > Of Guo, Yejun > Sent: Monday, October 29, 2018 11:19 AM > To: ffmpeg-devel@ffmpeg.org > Subject: Re: [FFmpeg-devel] [PATCH V4] Add a filter implementing HDR > image generation from a single exposure using deep CNNs > > any more comment? thanks. > > > -Original Message- > > From: Guo, Yejun > > Sent: Tuesday, October 23, 2018 6:46 AM > > To: ffmpeg-devel@ffmpeg.org > > Cc: Guo, Yejun ; Guo > > Subject: [PATCH V4] Add a filter implementing HDR image generation > > from a single exposure using deep CNNs > > > > see the algorithm's paper and code below. > > > > the filter's parameter looks like: > > > sdr2hdr=model_filename=/path_to_tensorflow_graph.pb:out_fmt=gbrp10l > > e > > > > The input of the deep CNN model is RGB24 while the output is float for > > each color channel. This is the filter's default behavior to output > > format with gbrpf32le. And gbrp10le is also supported as the output, > > so we can see the rendering result in a player, as a reference. > > > > To generate the model file, we need modify the original script a little. > > - set name='y' for y_final within script at > > https://github.com/gabrieleilertsen/hdrcnn/blob/master/network.py > > - add the following code to the script at > > https://github.com/gabrieleilertsen/hdrcnn/blob/master/hdrcnn_predict. > > py > > > > graph = tf.graph_util.convert_variables_to_constants(sess, > > sess.graph_def, > > ["y"]) tf.train.write_graph(graph, '.', 'graph.pb', as_text=False) > > > > The filter only works when tensorflow C api is supported in the > > system, native backend is not supported since there are some different > > types of layers in the deep CNN model, besides CONV and > DEPTH_TO_SPACE. > > > > https://arxiv.org/pdf/1710.07480.pdf: > > author = "Eilertsen, Gabriel and Kronander, Joel, and Denes, Gyorgy > and > > Mantiuk, Rafał and Unger, Jonas", > > title= "HDR image reconstruction from a single exposure using deep > > CNNs", > > journal = "ACM Transactions on Graphics (TOG)", > > number = "6", > > volume = "36", > > articleno= "178", > > year = "2017" > > > > https://github.com/gabrieleilertsen/hdrcnn > > > > btw, as a whole solution, metadata should also be generated from the > > sdr video, so to be encoded as a HDR video. Not supported yet. > > This patch just focuses on this paper. > > > > Signed-off-by: Guo, Yejun > > --- > > configure| 1 + > > doc/filters.texi | 35 +++ > > libavfilter/Makefile | 1 + > > libavfilter/allfilters.c | 1 + > > libavfilter/vf_sdr2hdr.c | 268 > > +++ > > 5 files changed, 306 insertions(+) > > create mode 100644 libavfilter/vf_sdr2hdr.c > > > > diff --git a/configure b/configure > > index 85d5dd5..5e2efba 100755 > > --- a/configure > > +++ b/configure > > @@ -3438,6 +3438,7 @@ scale2ref_filter_deps="swscale" > > scale_filter_deps="swscale" > > scale_qsv_filter_deps="libmfx" > > select_filter_select="pixelutils" > > +sdr2hdr_filter_deps="libtensorflow" > > sharpness_vaapi_filter_deps="vaapi" > > showcqt_filter_deps="avcodec avformat swscale" > > showcqt_filter_suggest="libfontconfig libfreetype" > > diff --git a/doc/filters.texi b/doc/filters.texi index > > 17e2549..bba9f87 100644 > > --- a/doc/filters.texi > > +++ b/doc/filters.texi > > @@ -14672,6 +14672,41 @@ Scale a subtitle stream (b) to match the main > > video (a) in size before overlayin @end example @end itemize > > > > +@section sdr2hdr > > + > > +HDR image generation from a single exposure using deep CNNs with > > TensorFlow C library. > > + > > +@itemize > > +@item > > +paper: see @url{https://arxiv.org/pdf/1710.07480.pdf} > > + > > +@item > > +code with model and trained parameters: see > > +@url{https://github.com/gabrieleilertsen/hdrcnn} > > +@end itemize > > + > > +The filter accepts the following options: > > + > > +@table @option > > + > > +@item model_filename > > +Set path to model file specifyin
Re: [FFmpeg-devel] [PATCH V4] Add a filter implementing HDR image generation from a single exposure using deep CNNs
> 在 2018年11月5日,下午3:42,Guo, Yejun 写道: > > ask for comment or merge, thanks. Will push after 24 hours if there have no objections. > >> -Original Message- >> From: ffmpeg-devel [mailto:ffmpeg-devel-boun...@ffmpeg.org] On Behalf >> Of Guo, Yejun >> Sent: Monday, October 29, 2018 11:19 AM >> To: ffmpeg-devel@ffmpeg.org >> Subject: Re: [FFmpeg-devel] [PATCH V4] Add a filter implementing HDR >> image generation from a single exposure using deep CNNs >> >> any more comment? thanks. >> >>> -Original Message- >>> From: Guo, Yejun >>> Sent: Tuesday, October 23, 2018 6:46 AM >>> To: ffmpeg-devel@ffmpeg.org >>> Cc: Guo, Yejun ; Guo >>> Subject: [PATCH V4] Add a filter implementing HDR image generation >>> from a single exposure using deep CNNs >>> >>> see the algorithm's paper and code below. >>> >>> the filter's parameter looks like: >>> >> sdr2hdr=model_filename=/path_to_tensorflow_graph.pb:out_fmt=gbrp10l >>> e >>> >>> The input of the deep CNN model is RGB24 while the output is float for >>> each color channel. This is the filter's default behavior to output >>> format with gbrpf32le. And gbrp10le is also supported as the output, >>> so we can see the rendering result in a player, as a reference. >>> >>> To generate the model file, we need modify the original script a little. >>> - set name='y' for y_final within script at >>> https://github.com/gabrieleilertsen/hdrcnn/blob/master/network.py >>> - add the following code to the script at >>> https://github.com/gabrieleilertsen/hdrcnn/blob/master/hdrcnn_predict. >>> py >>> >>> graph = tf.graph_util.convert_variables_to_constants(sess, >>> sess.graph_def, >>> ["y"]) tf.train.write_graph(graph, '.', 'graph.pb', as_text=False) >>> >>> The filter only works when tensorflow C api is supported in the >>> system, native backend is not supported since there are some different >>> types of layers in the deep CNN model, besides CONV and >> DEPTH_TO_SPACE. >>> >>> https://arxiv.org/pdf/1710.07480.pdf: >>> author = "Eilertsen, Gabriel and Kronander, Joel, and Denes, Gyorgy >> and >>> Mantiuk, Rafał and Unger, Jonas", >>> title= "HDR image reconstruction from a single exposure using deep >>> CNNs", >>> journal = "ACM Transactions on Graphics (TOG)", >>> number = "6", >>> volume = "36", >>> articleno= "178", >>> year = "2017" >>> >>> https://github.com/gabrieleilertsen/hdrcnn >>> >>> btw, as a whole solution, metadata should also be generated from the >>> sdr video, so to be encoded as a HDR video. Not supported yet. >>> This patch just focuses on this paper. >>> >>> Signed-off-by: Guo, Yejun >>> --- >>> configure| 1 + >>> doc/filters.texi | 35 +++ >>> libavfilter/Makefile | 1 + >>> libavfilter/allfilters.c | 1 + >>> libavfilter/vf_sdr2hdr.c | 268 >>> +++ >>> 5 files changed, 306 insertions(+) >>> create mode 100644 libavfilter/vf_sdr2hdr.c >>> >>> diff --git a/configure b/configure >>> index 85d5dd5..5e2efba 100755 >>> --- a/configure >>> +++ b/configure >>> @@ -3438,6 +3438,7 @@ scale2ref_filter_deps="swscale" >>> scale_filter_deps="swscale" >>> scale_qsv_filter_deps="libmfx" >>> select_filter_select="pixelutils" >>> +sdr2hdr_filter_deps="libtensorflow" >>> sharpness_vaapi_filter_deps="vaapi" >>> showcqt_filter_deps="avcodec avformat swscale" >>> showcqt_filter_suggest="libfontconfig libfreetype" >>> diff --git a/doc/filters.texi b/doc/filters.texi index >>> 17e2549..bba9f87 100644 >>> --- a/doc/filters.texi >>> +++ b/doc/filters.texi >>> @@ -14672,6 +14672,41 @@ Scale a subtitle stream (b) to match the main >>> video (a) in size before overlayin @end example @end itemize >>> >>> +@section sdr2hdr >>> + >>> +HDR image generation from a single exposure using deep CNNs with >>> TensorFlow C library. >>> + >>> +@itemize >>
Re: [FFmpeg-devel] [PATCH V4] Add a filter implementing HDR image generation from a single exposure using deep CNNs
this filter accepts 8bit frame (RGB24) and outputs 10bit/float frame, and there's no reference image, so it is not feasible to use criteria such as PNSR, SSIM. I choose the same method described in the paper to demo the filter effect, that means the frames before/after the filter are reduced by 3 stops. The native video (test.native.mp4) is created from 7 png files @ https://github.com/gabrieleilertsen/hdrcnn/tree/master/data (the size of the image is enlarged to 1920*1080 with extra area filled with white) with command line: ffmpeg -f image2 -i ./img_%03d.png -c:v libx264 -preset veryslow -crf 1 test.native.mp4. And two rgb24 videos are generated before/after the filter with -3 stops by modifying the code a little, see in the video folder at https://drive.google.com/drive/folders/1URsRY5g-VdE-kHlP5vQoLoimMIZ-SX00?usp=sharing for your convenient, I also dump png files from generated videos and combine the before/after pngs into one file, see in png folder at the google drive. > -Original Message- > From: ffmpeg-devel [mailto:ffmpeg-devel-boun...@ffmpeg.org] On Behalf > Of Liu Steven > Sent: Monday, November 05, 2018 3:57 PM > To: FFmpeg development discussions and patches de...@ffmpeg.org> > Cc: Liu Steven > Subject: Re: [FFmpeg-devel] [PATCH V4] Add a filter implementing HDR > image generation from a single exposure using deep CNNs > > > > > 在 2018年11月5日,下午3:42,Guo, Yejun 写 > 道: > > > > ask for comment or merge, thanks. > Will push after 24 hours if there have no objections. > > > >> -Original Message- > >> From: ffmpeg-devel [mailto:ffmpeg-devel-boun...@ffmpeg.org] On > Behalf > >> Of Guo, Yejun > >> Sent: Monday, October 29, 2018 11:19 AM > >> To: ffmpeg-devel@ffmpeg.org > >> Subject: Re: [FFmpeg-devel] [PATCH V4] Add a filter implementing HDR > >> image generation from a single exposure using deep CNNs > >> > >> any more comment? thanks. > >> > >>> -Original Message- > >>> From: Guo, Yejun > >>> Sent: Tuesday, October 23, 2018 6:46 AM > >>> To: ffmpeg-devel@ffmpeg.org > >>> Cc: Guo, Yejun ; Guo > >>> Subject: [PATCH V4] Add a filter implementing HDR image generation > >>> from a single exposure using deep CNNs > >>> > >>> see the algorithm's paper and code below. > >>> > >>> the filter's parameter looks like: > >>> > >> > sdr2hdr=model_filename=/path_to_tensorflow_graph.pb:out_fmt=gbrp10l > >>> e > >>> > >>> The input of the deep CNN model is RGB24 while the output is float > >>> for each color channel. This is the filter's default behavior to > >>> output format with gbrpf32le. And gbrp10le is also supported as the > >>> output, so we can see the rendering result in a player, as a reference. > >>> > >>> To generate the model file, we need modify the original script a little. > >>> - set name='y' for y_final within script at > >>> https://github.com/gabrieleilertsen/hdrcnn/blob/master/network.py > >>> - add the following code to the script at > >>> > https://github.com/gabrieleilertsen/hdrcnn/blob/master/hdrcnn_predict. > >>> py > >>> > >>> graph = tf.graph_util.convert_variables_to_constants(sess, > >>> sess.graph_def, > >>> ["y"]) tf.train.write_graph(graph, '.', 'graph.pb', as_text=False) > >>> > >>> The filter only works when tensorflow C api is supported in the > >>> system, native backend is not supported since there are some > >>> different types of layers in the deep CNN model, besides CONV and > >> DEPTH_TO_SPACE. > >>> > >>> https://arxiv.org/pdf/1710.07480.pdf: > >>> author = "Eilertsen, Gabriel and Kronander, Joel, and Denes, Gyorgy > >> and > >>> Mantiuk, Rafał and Unger, Jonas", > >>> title= "HDR image reconstruction from a single exposure using > >>> deep > >>> CNNs", > >>> journal = "ACM Transactions on Graphics (TOG)", > >>> number = "6", > >>> volume = "36", > >>> articleno= "178", > >>> year = "2017" > >>> > >>> https://github.com/gabrieleilertsen/hdrcnn > >>> > >>> btw, as a whole solution, metadata should also be generated from the > >>> sdr video, so