Re: [libav-devel] [PATCH 09/15] lavc: Add h264_metadata bitstream filter
On 2017/6/24 7:39, Mark Thompson wrote: > This is able to modify some header metadata found in the SPS/VUI, > and can also add/remove AUDs and insert user data in SEI NAL units. > --- > doc/bitstream_filters.texi | 47 + > libavcodec/Makefile| 2 + > libavcodec/bitstream_filters.c | 1 + > libavcodec/h264_metadata_bsf.c | 462 > + > 4 files changed, 512 insertions(+) > create mode 100644 libavcodec/h264_metadata_bsf.c > > diff --git a/doc/bitstream_filters.texi b/doc/bitstream_filters.texi > index af14b67ad..474a9d5c1 100644 > --- a/doc/bitstream_filters.texi > +++ b/doc/bitstream_filters.texi > @@ -39,6 +39,53 @@ When this option is enabled, the long-term headers are > removed from the > bitstream after extraction. > @end table > > +@section h264_metadata > + > +Modify metadata attached to the H.264 stream. > + > +@table @option > +@item aud > +Insert or remove AUD NAL units in all access units of the stream. > + > +@table @samp > +@item insert > +@item remove > +@end table > + > +@item sample_aspect_ratio > +Set the sample aspect ratio in the stream in the VUI parameters. > + > +@item video_format > +@item video_full_range_flag > +Set the video format in the stream (see H.264 section E.2.1 and > +table E-2). > + > +@item colour_primaries > +@item transfer_characteristics > +@item matrix_coefficients > +Set the colour description in the stream (see H.264 section E.2.1 > +and tables E-3, E-4 and E-5). > + > +@item chroma_sample_loc_type > +Set the chroma sample location in the stream (see H.264 section > +E.2.1 and figure E-1). > + > +@item frame_rate > +@item fixed_frame_rate_flag > +Set the frame rate in the VUI parameters (num_units_in_tick / > +time_scale). Note that this is likely to be overridden by container > +parameters when the stream is in a container. > + > +@item sei_user_data > +Insert a string as SEI unregistered user data. The argument must > +be of the form @emph{UUID+string}, where the UUID is as hex digits > +possibly separated by hyphens, and the string can be anything. > + > +For example, @samp{086f3693-b7b3-4f2c-9653-21492feee5b8+hello} will > +insert the string ``hello'' associated with the given UUID. > + > +@end table > + > @section h264_mp4toannexb > > @section imx_dump_header > diff --git a/libavcodec/Makefile b/libavcodec/Makefile > index b6c3d..10a05adf2 100644 > --- a/libavcodec/Makefile > +++ b/libavcodec/Makefile > @@ -768,6 +768,8 @@ OBJS-$(CONFIG_CHOMP_BSF) += chomp_bsf.o > OBJS-$(CONFIG_DUMP_EXTRADATA_BSF) += dump_extradata_bsf.o > OBJS-$(CONFIG_EXTRACT_EXTRADATA_BSF) += extract_extradata_bsf.o\ > h2645_parse.o > +OBJS-$(CONFIG_H264_METADATA_BSF) += h264_metadata_bsf.o \ > + cbs.o cbs_h2645.o > OBJS-$(CONFIG_H264_MP4TOANNEXB_BSF) += h264_mp4toannexb_bsf.o > OBJS-$(CONFIG_HEVC_MP4TOANNEXB_BSF) += hevc_mp4toannexb_bsf.o > OBJS-$(CONFIG_IMX_DUMP_HEADER_BSF)+= imx_dump_header_bsf.o > diff --git a/libavcodec/bitstream_filters.c b/libavcodec/bitstream_filters.c > index 2e423acaf..4ad50508c 100644 > --- a/libavcodec/bitstream_filters.c > +++ b/libavcodec/bitstream_filters.c > @@ -28,6 +28,7 @@ extern const AVBitStreamFilter ff_aac_adtstoasc_bsf; > extern const AVBitStreamFilter ff_chomp_bsf; > extern const AVBitStreamFilter ff_dump_extradata_bsf; > extern const AVBitStreamFilter ff_extract_extradata_bsf; > +extern const AVBitStreamFilter ff_h264_metadata_bsf; > extern const AVBitStreamFilter ff_h264_mp4toannexb_bsf; > extern const AVBitStreamFilter ff_hevc_mp4toannexb_bsf; > extern const AVBitStreamFilter ff_imx_dump_header_bsf; > diff --git a/libavcodec/h264_metadata_bsf.c b/libavcodec/h264_metadata_bsf.c > new file mode 100644 > index 0..4eb58ce45 > --- /dev/null > +++ b/libavcodec/h264_metadata_bsf.c > @@ -0,0 +1,462 @@ > +/* > + * This file is part of Libav. > + * > + * Libav 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. > + * > + * Libav 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 Libav; if not, write to the Free Software > + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 > USA > + */ > + > +#include "libavutil/common.h" > +#include "libavutil/opt.h" > + > +#include "bsf.h" > +#include "cbs.h" > +#include "cbs_h264.h" > +#include "h264.h" > +#include "h264_sei.h" > + > +enum { > +PASS,
Re: [libav-devel] [PATCH 09/15] lavc: Add h264_metadata bitstream filter
Quoting Mark Thompson (2017-06-24 01:39:15) > This is able to modify some header metadata found in the SPS/VUI, > and can also add/remove AUDs and insert user data in SEI NAL units. > --- > doc/bitstream_filters.texi | 47 + > libavcodec/Makefile| 2 + > libavcodec/bitstream_filters.c | 1 + > libavcodec/h264_metadata_bsf.c | 462 > + > 4 files changed, 512 insertions(+) > create mode 100644 libavcodec/h264_metadata_bsf.c > Looks ok -- Anton Khirnov ___ libav-devel mailing list libav-devel@libav.org https://lists.libav.org/mailman/listinfo/libav-devel
[libav-devel] [PATCH 09/15] lavc: Add h264_metadata bitstream filter
This is able to modify some header metadata found in the SPS/VUI, and can also add/remove AUDs and insert user data in SEI NAL units. --- doc/bitstream_filters.texi | 47 + libavcodec/Makefile| 2 + libavcodec/bitstream_filters.c | 1 + libavcodec/h264_metadata_bsf.c | 462 + 4 files changed, 512 insertions(+) create mode 100644 libavcodec/h264_metadata_bsf.c diff --git a/doc/bitstream_filters.texi b/doc/bitstream_filters.texi index af14b67ad..474a9d5c1 100644 --- a/doc/bitstream_filters.texi +++ b/doc/bitstream_filters.texi @@ -39,6 +39,53 @@ When this option is enabled, the long-term headers are removed from the bitstream after extraction. @end table +@section h264_metadata + +Modify metadata attached to the H.264 stream. + +@table @option +@item aud +Insert or remove AUD NAL units in all access units of the stream. + +@table @samp +@item insert +@item remove +@end table + +@item sample_aspect_ratio +Set the sample aspect ratio in the stream in the VUI parameters. + +@item video_format +@item video_full_range_flag +Set the video format in the stream (see H.264 section E.2.1 and +table E-2). + +@item colour_primaries +@item transfer_characteristics +@item matrix_coefficients +Set the colour description in the stream (see H.264 section E.2.1 +and tables E-3, E-4 and E-5). + +@item chroma_sample_loc_type +Set the chroma sample location in the stream (see H.264 section +E.2.1 and figure E-1). + +@item frame_rate +@item fixed_frame_rate_flag +Set the frame rate in the VUI parameters (num_units_in_tick / +time_scale). Note that this is likely to be overridden by container +parameters when the stream is in a container. + +@item sei_user_data +Insert a string as SEI unregistered user data. The argument must +be of the form @emph{UUID+string}, where the UUID is as hex digits +possibly separated by hyphens, and the string can be anything. + +For example, @samp{086f3693-b7b3-4f2c-9653-21492feee5b8+hello} will +insert the string ``hello'' associated with the given UUID. + +@end table + @section h264_mp4toannexb @section imx_dump_header diff --git a/libavcodec/Makefile b/libavcodec/Makefile index b6c3d..10a05adf2 100644 --- a/libavcodec/Makefile +++ b/libavcodec/Makefile @@ -768,6 +768,8 @@ OBJS-$(CONFIG_CHOMP_BSF) += chomp_bsf.o OBJS-$(CONFIG_DUMP_EXTRADATA_BSF) += dump_extradata_bsf.o OBJS-$(CONFIG_EXTRACT_EXTRADATA_BSF) += extract_extradata_bsf.o\ h2645_parse.o +OBJS-$(CONFIG_H264_METADATA_BSF) += h264_metadata_bsf.o \ + cbs.o cbs_h2645.o OBJS-$(CONFIG_H264_MP4TOANNEXB_BSF) += h264_mp4toannexb_bsf.o OBJS-$(CONFIG_HEVC_MP4TOANNEXB_BSF) += hevc_mp4toannexb_bsf.o OBJS-$(CONFIG_IMX_DUMP_HEADER_BSF)+= imx_dump_header_bsf.o diff --git a/libavcodec/bitstream_filters.c b/libavcodec/bitstream_filters.c index 2e423acaf..4ad50508c 100644 --- a/libavcodec/bitstream_filters.c +++ b/libavcodec/bitstream_filters.c @@ -28,6 +28,7 @@ extern const AVBitStreamFilter ff_aac_adtstoasc_bsf; extern const AVBitStreamFilter ff_chomp_bsf; extern const AVBitStreamFilter ff_dump_extradata_bsf; extern const AVBitStreamFilter ff_extract_extradata_bsf; +extern const AVBitStreamFilter ff_h264_metadata_bsf; extern const AVBitStreamFilter ff_h264_mp4toannexb_bsf; extern const AVBitStreamFilter ff_hevc_mp4toannexb_bsf; extern const AVBitStreamFilter ff_imx_dump_header_bsf; diff --git a/libavcodec/h264_metadata_bsf.c b/libavcodec/h264_metadata_bsf.c new file mode 100644 index 0..4eb58ce45 --- /dev/null +++ b/libavcodec/h264_metadata_bsf.c @@ -0,0 +1,462 @@ +/* + * This file is part of Libav. + * + * Libav 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. + * + * Libav 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 Libav; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include "libavutil/common.h" +#include "libavutil/opt.h" + +#include "bsf.h" +#include "cbs.h" +#include "cbs_h264.h" +#include "h264.h" +#include "h264_sei.h" + +enum { +PASS, +INSERT, +REMOVE, +}; + +typedef struct H264MetadataContext { +const AVClass *class; + +CodedBitstreamContext cbc; +CodedBitstreamFragment access_unit; + +H264RawAUD aud_nal; +H264RawSEI sei_nal; + +int aud; + +AVRational sample_aspect_ratio; + +int video_format; +