Re: [FFmpeg-devel] [PATCH] lavc: Add filter_units bitstream filter

2018-03-25 Thread Mark Thompson
On 25/03/18 13:40, Eran Kornblau wrote:
>> -Original Message-
>> From: ffmpeg-devel [mailto:ffmpeg-devel-boun...@ffmpeg.org] On Behalf Of 
>> Mark Thompson
>> Sent: Sunday, March 11, 2018 8:38 PM
>> To: ffmpeg-devel@ffmpeg.org
>> Subject: Re: [FFmpeg-devel] [PATCH] lavc: Add filter_units bitstream filter
>>
>> On 08/03/18 04:01, James Almer wrote:
>>> On 3/6/2018 3:49 PM, Mark Thompson wrote:
>>>> This can remove units with types in or not in a given set from a stream.
>>>> For example, it can be used to remove all non-VCL NAL units from an 
>>>> H.264 or
>>>> H.265 stream.
>>>> ---
>>>> On 06/03/18 17:27, Hendrik Leppkes wrote:
>>>>> On Tue, Mar 6, 2018 at 3:51 PM, Eran Kornblau <eran.kornb...@kaltura.com> 
>>>>> wrote:
>>>>>> Hi all,
>>>>>>
>>>>>> The attached patch adds a parameter that enables the user to choose 
>>>>>> which AVC/HEVC NAL units to include in the output.
>>>>>> The parameter is supplied as a bitmask in order to keep things simple.
>>>>>>
>>>>>> A short background on why we need it - in our transcoding process, 
>>>>>> we partition the video in chunks, the chunks are transcoded in 
>>>>>> parallel and packaged in MPEG-TS container. The transcoded TS 
>>>>>> chunks are then concatenated and packaged in MP4. These MP4 files are 
>>>>>> later repackaged on-the-fly to various protocols (HLS/DASH etc.) using 
>>>>>> our JIT packager.
>>>>>> For performance reasons (can get into more detail if anyone's 
>>>>>> interested...), when packaging the MP4 to DASH/CENC, we configure the 
>>>>>> packager to assume that each AVC frame contains exactly one NAL unit.
>>>>>> The problem is that the transition through MPEG-TS adds additional 
>>>>>> NAL units (NAL AUD before each frame + SPS/PPS before each key frame), 
>>>>>> and this assumption fails.
>>>>>> Using the attached patch we can pass '-nal_types_mask 0x3e' which will 
>>>>>> make ffmpeg output only VCL NALs in the stream.
>>>>>>
>>>>>
>>>>> Having such logic in one single muxer is not something we really 
>>>>> like around here. Next time someone needs something similar for 
>>>>> another codec, you're stuck re-implementing it.
>>>>>
>>>>> To achieve the same effect, Mark Thompson quickly wipped up a 
>>>>> Bitstream Filter using his CBS framework which achieves the same 
>>>>> result. He'll be sending that patch to the mailing list in a while.
>>>> The suggested use-case would be '-bsf:v filter_units=pass_types=1-5' for 
>>>> H.264 or '-bsf:v filter_units=pass_types=0-31' for H.265.
>>>>
>>>> (Also note that filters already exist for some individual parts of 
>>>> this: h264_metadata can remove AUDs, extract_extradata can remove 
>>>> parameter sets.)
>>>>
>>>> - Mark
>>>>
>>>>
>>>>  libavcodec/Makefile|   1 +
>>>>  libavcodec/bitstream_filters.c |   1 +
>>>>  libavcodec/filter_units_bsf.c  | 250 
>>>> +
>>>>  3 files changed, 252 insertions(+)
>>>>  create mode 100644 libavcodec/filter_units_bsf.c
>>>>
>>>
>>> Can you write some minimal documentation with the two above examples?
>>
>> Done.
>>
>>>> diff --git a/libavcodec/Makefile b/libavcodec/Makefile index 
>>>> b496f0d..b99bdce 100644
>>>> --- a/libavcodec/Makefile
>>>> +++ b/libavcodec/Makefile
>>>> @@ -1037,6 +1037,7 @@ OBJS-$(CONFIG_DUMP_EXTRADATA_BSF) += 
>>>> dump_extradata_bsf.o
>>>>  OBJS-$(CONFIG_DCA_CORE_BSF)   += dca_core_bsf.o
>>>>  OBJS-$(CONFIG_EXTRACT_EXTRADATA_BSF)  += extract_extradata_bsf.o\
>>>>   h2645_parse.o
>>>> +OBJS-$(CONFIG_FILTER_UNITS_BSF)   += filter_units_bsf.o
>>>>  OBJS-$(CONFIG_H264_METADATA_BSF)  += h264_metadata_bsf.o
>>>>  OBJS-$(CONFIG_H264_MP4TOANNEXB_BSF)   += h264_mp4toannexb_bsf.o
>>>>  OBJS-$(CONFIG_H264_REDUNDANT_PPS_BSF) += h264_redundant_pps_bsf.o
>>>> diff --git a/libavcodec/bitstream_filters.c 
>>>> b/libavcodec/bitstream_filter

Re: [FFmpeg-devel] [PATCH] lavc: Add filter_units bitstream filter

2018-03-25 Thread Eran Kornblau
> -Original Message-
> From: ffmpeg-devel [mailto:ffmpeg-devel-boun...@ffmpeg.org] On Behalf Of Mark 
> Thompson
> Sent: Sunday, March 11, 2018 8:38 PM
> To: ffmpeg-devel@ffmpeg.org
> Subject: Re: [FFmpeg-devel] [PATCH] lavc: Add filter_units bitstream filter
> 
> On 08/03/18 04:01, James Almer wrote:
> > On 3/6/2018 3:49 PM, Mark Thompson wrote:
> >> This can remove units with types in or not in a given set from a stream.
> >> For example, it can be used to remove all non-VCL NAL units from an 
> >> H.264 or
> >> H.265 stream.
> >> ---
> >> On 06/03/18 17:27, Hendrik Leppkes wrote:
> >>> On Tue, Mar 6, 2018 at 3:51 PM, Eran Kornblau <eran.kornb...@kaltura.com> 
> >>> wrote:
> >>>> Hi all,
> >>>>
> >>>> The attached patch adds a parameter that enables the user to choose 
> >>>> which AVC/HEVC NAL units to include in the output.
> >>>> The parameter is supplied as a bitmask in order to keep things simple.
> >>>>
> >>>> A short background on why we need it - in our transcoding process, 
> >>>> we partition the video in chunks, the chunks are transcoded in 
> >>>> parallel and packaged in MPEG-TS container. The transcoded TS 
> >>>> chunks are then concatenated and packaged in MP4. These MP4 files are 
> >>>> later repackaged on-the-fly to various protocols (HLS/DASH etc.) using 
> >>>> our JIT packager.
> >>>> For performance reasons (can get into more detail if anyone's 
> >>>> interested...), when packaging the MP4 to DASH/CENC, we configure the 
> >>>> packager to assume that each AVC frame contains exactly one NAL unit.
> >>>> The problem is that the transition through MPEG-TS adds additional 
> >>>> NAL units (NAL AUD before each frame + SPS/PPS before each key frame), 
> >>>> and this assumption fails.
> >>>> Using the attached patch we can pass '-nal_types_mask 0x3e' which will 
> >>>> make ffmpeg output only VCL NALs in the stream.
> >>>>
> >>>
> >>> Having such logic in one single muxer is not something we really 
> >>> like around here. Next time someone needs something similar for 
> >>> another codec, you're stuck re-implementing it.
> >>>
> >>> To achieve the same effect, Mark Thompson quickly wipped up a 
> >>> Bitstream Filter using his CBS framework which achieves the same 
> >>> result. He'll be sending that patch to the mailing list in a while.
> >> The suggested use-case would be '-bsf:v filter_units=pass_types=1-5' for 
> >> H.264 or '-bsf:v filter_units=pass_types=0-31' for H.265.
> >>
> >> (Also note that filters already exist for some individual parts of 
> >> this: h264_metadata can remove AUDs, extract_extradata can remove 
> >> parameter sets.)
> >>
> >> - Mark
> >>
> >>
> >>  libavcodec/Makefile|   1 +
> >>  libavcodec/bitstream_filters.c |   1 +
> >>  libavcodec/filter_units_bsf.c  | 250 
> >> +
> >>  3 files changed, 252 insertions(+)
> >>  create mode 100644 libavcodec/filter_units_bsf.c
> >>
> > 
> > Can you write some minimal documentation with the two above examples?
> 
> Done.
> 
> >> diff --git a/libavcodec/Makefile b/libavcodec/Makefile index 
> >> b496f0d..b99bdce 100644
> >> --- a/libavcodec/Makefile
> >> +++ b/libavcodec/Makefile
> >> @@ -1037,6 +1037,7 @@ OBJS-$(CONFIG_DUMP_EXTRADATA_BSF) += 
> >> dump_extradata_bsf.o
> >>  OBJS-$(CONFIG_DCA_CORE_BSF)   += dca_core_bsf.o
> >>  OBJS-$(CONFIG_EXTRACT_EXTRADATA_BSF)  += extract_extradata_bsf.o\
> >>   h2645_parse.o
> >> +OBJS-$(CONFIG_FILTER_UNITS_BSF)   += filter_units_bsf.o
> >>  OBJS-$(CONFIG_H264_METADATA_BSF)  += h264_metadata_bsf.o
> >>  OBJS-$(CONFIG_H264_MP4TOANNEXB_BSF)   += h264_mp4toannexb_bsf.o
> >>  OBJS-$(CONFIG_H264_REDUNDANT_PPS_BSF) += h264_redundant_pps_bsf.o
> >> diff --git a/libavcodec/bitstream_filters.c 
> >> b/libavcodec/bitstream_filters.c index 338ef82..e1dc198 100644
> >> --- a/libavcodec/bitstream_filters.c
> >> +++ b/libavcodec/bitstream_filters.c
> >> @@ -29,6 +29,7 @@ extern const AVBitStreamFilter ff_chomp_bsf;  
> >> extern const AVBitStreamFilter ff_dump_extradata_bsf;  e

Re: [FFmpeg-devel] [PATCH] lavc: Add filter_units bitstream filter

2018-03-11 Thread Mark Thompson
On 08/03/18 04:01, James Almer wrote:
> On 3/6/2018 3:49 PM, Mark Thompson wrote:
>> This can remove units with types in or not in a given set from a stream.
>> For example, it can be used to remove all non-VCL NAL units from an H.264 or
>> H.265 stream.
>> ---
>> On 06/03/18 17:27, Hendrik Leppkes wrote:
>>> On Tue, Mar 6, 2018 at 3:51 PM, Eran Kornblau  
>>> wrote:
 Hi all,

 The attached patch adds a parameter that enables the user to choose which 
 AVC/HEVC NAL units to include in the output.
 The parameter is supplied as a bitmask in order to keep things simple.

 A short background on why we need it - in our transcoding process, we 
 partition the video in chunks, the chunks are
 transcoded in parallel and packaged in MPEG-TS container. The transcoded 
 TS chunks are then concatenated and
 packaged in MP4. These MP4 files are later repackaged on-the-fly to 
 various protocols (HLS/DASH etc.) using our
 JIT packager.
 For performance reasons (can get into more detail if anyone's 
 interested...), when packaging the MP4 to DASH/CENC,
 we configure the packager to assume that each AVC frame contains exactly 
 one NAL unit.
 The problem is that the transition through MPEG-TS adds additional NAL 
 units (NAL AUD before each frame + SPS/PPS
 before each key frame), and this assumption fails.
 Using the attached patch we can pass '-nal_types_mask 0x3e' which will 
 make ffmpeg output only VCL NALs in the stream.

>>>
>>> Having such logic in one single muxer is not something we really like
>>> around here. Next time someone needs something similar for another
>>> codec, you're stuck re-implementing it.
>>>
>>> To achieve the same effect, Mark Thompson quickly wipped up a
>>> Bitstream Filter using his CBS framework which achieves the same
>>> result. He'll be sending that patch to the mailing list in a while.
>> The suggested use-case would be '-bsf:v filter_units=pass_types=1-5' for 
>> H.264 or '-bsf:v filter_units=pass_types=0-31' for H.265.
>>
>> (Also note that filters already exist for some individual parts of this: 
>> h264_metadata can remove AUDs, extract_extradata can remove parameter sets.)
>>
>> - Mark
>>
>>
>>  libavcodec/Makefile|   1 +
>>  libavcodec/bitstream_filters.c |   1 +
>>  libavcodec/filter_units_bsf.c  | 250 
>> +
>>  3 files changed, 252 insertions(+)
>>  create mode 100644 libavcodec/filter_units_bsf.c
>>
> 
> Can you write some minimal documentation with the two above examples?

Done.

>> diff --git a/libavcodec/Makefile b/libavcodec/Makefile
>> index b496f0d..b99bdce 100644
>> --- a/libavcodec/Makefile
>> +++ b/libavcodec/Makefile
>> @@ -1037,6 +1037,7 @@ OBJS-$(CONFIG_DUMP_EXTRADATA_BSF) += 
>> dump_extradata_bsf.o
>>  OBJS-$(CONFIG_DCA_CORE_BSF)   += dca_core_bsf.o
>>  OBJS-$(CONFIG_EXTRACT_EXTRADATA_BSF)  += extract_extradata_bsf.o\
>>   h2645_parse.o
>> +OBJS-$(CONFIG_FILTER_UNITS_BSF)   += filter_units_bsf.o
>>  OBJS-$(CONFIG_H264_METADATA_BSF)  += h264_metadata_bsf.o
>>  OBJS-$(CONFIG_H264_MP4TOANNEXB_BSF)   += h264_mp4toannexb_bsf.o
>>  OBJS-$(CONFIG_H264_REDUNDANT_PPS_BSF) += h264_redundant_pps_bsf.o
>> diff --git a/libavcodec/bitstream_filters.c b/libavcodec/bitstream_filters.c
>> index 338ef82..e1dc198 100644
>> --- a/libavcodec/bitstream_filters.c
>> +++ b/libavcodec/bitstream_filters.c
>> @@ -29,6 +29,7 @@ extern const AVBitStreamFilter ff_chomp_bsf;
>>  extern const AVBitStreamFilter ff_dump_extradata_bsf;
>>  extern const AVBitStreamFilter ff_dca_core_bsf;
>>  extern const AVBitStreamFilter ff_extract_extradata_bsf;
>> +extern const AVBitStreamFilter ff_filter_units_bsf;
>>  extern const AVBitStreamFilter ff_h264_metadata_bsf;
>>  extern const AVBitStreamFilter ff_h264_mp4toannexb_bsf;
>>  extern const AVBitStreamFilter ff_h264_redundant_pps_bsf;
>> diff --git a/libavcodec/filter_units_bsf.c b/libavcodec/filter_units_bsf.c
>> new file mode 100644
>> index 000..3126f17
>> --- /dev/null
>> +++ b/libavcodec/filter_units_bsf.c
>> @@ -0,0 +1,250 @@
>> +/*
>> + * 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 

Re: [FFmpeg-devel] [PATCH] lavc: Add filter_units bitstream filter

2018-03-07 Thread James Almer
On 3/6/2018 3:49 PM, Mark Thompson wrote:
> This can remove units with types in or not in a given set from a stream.
> For example, it can be used to remove all non-VCL NAL units from an H.264 or
> H.265 stream.
> ---
> On 06/03/18 17:27, Hendrik Leppkes wrote:
>> On Tue, Mar 6, 2018 at 3:51 PM, Eran Kornblau  
>> wrote:
>>> Hi all,
>>>
>>> The attached patch adds a parameter that enables the user to choose which 
>>> AVC/HEVC NAL units to include in the output.
>>> The parameter is supplied as a bitmask in order to keep things simple.
>>>
>>> A short background on why we need it - in our transcoding process, we 
>>> partition the video in chunks, the chunks are
>>> transcoded in parallel and packaged in MPEG-TS container. The transcoded TS 
>>> chunks are then concatenated and
>>> packaged in MP4. These MP4 files are later repackaged on-the-fly to various 
>>> protocols (HLS/DASH etc.) using our
>>> JIT packager.
>>> For performance reasons (can get into more detail if anyone's 
>>> interested...), when packaging the MP4 to DASH/CENC,
>>> we configure the packager to assume that each AVC frame contains exactly 
>>> one NAL unit.
>>> The problem is that the transition through MPEG-TS adds additional NAL 
>>> units (NAL AUD before each frame + SPS/PPS
>>> before each key frame), and this assumption fails.
>>> Using the attached patch we can pass '-nal_types_mask 0x3e' which will make 
>>> ffmpeg output only VCL NALs in the stream.
>>>
>>
>> Having such logic in one single muxer is not something we really like
>> around here. Next time someone needs something similar for another
>> codec, you're stuck re-implementing it.
>>
>> To achieve the same effect, Mark Thompson quickly wipped up a
>> Bitstream Filter using his CBS framework which achieves the same
>> result. He'll be sending that patch to the mailing list in a while.
> The suggested use-case would be '-bsf:v filter_units=pass_types=1-5' for 
> H.264 or '-bsf:v filter_units=pass_types=0-31' for H.265.
> 
> (Also note that filters already exist for some individual parts of this: 
> h264_metadata can remove AUDs, extract_extradata can remove parameter sets.)
> 
> - Mark
> 
> 
>  libavcodec/Makefile|   1 +
>  libavcodec/bitstream_filters.c |   1 +
>  libavcodec/filter_units_bsf.c  | 250 
> +
>  3 files changed, 252 insertions(+)
>  create mode 100644 libavcodec/filter_units_bsf.c
> 

Can you write some minimal documentation with the two above examples?

> diff --git a/libavcodec/Makefile b/libavcodec/Makefile
> index b496f0d..b99bdce 100644
> --- a/libavcodec/Makefile
> +++ b/libavcodec/Makefile
> @@ -1037,6 +1037,7 @@ OBJS-$(CONFIG_DUMP_EXTRADATA_BSF) += 
> dump_extradata_bsf.o
>  OBJS-$(CONFIG_DCA_CORE_BSF)   += dca_core_bsf.o
>  OBJS-$(CONFIG_EXTRACT_EXTRADATA_BSF)  += extract_extradata_bsf.o\
>   h2645_parse.o
> +OBJS-$(CONFIG_FILTER_UNITS_BSF)   += filter_units_bsf.o
>  OBJS-$(CONFIG_H264_METADATA_BSF)  += h264_metadata_bsf.o
>  OBJS-$(CONFIG_H264_MP4TOANNEXB_BSF)   += h264_mp4toannexb_bsf.o
>  OBJS-$(CONFIG_H264_REDUNDANT_PPS_BSF) += h264_redundant_pps_bsf.o
> diff --git a/libavcodec/bitstream_filters.c b/libavcodec/bitstream_filters.c
> index 338ef82..e1dc198 100644
> --- a/libavcodec/bitstream_filters.c
> +++ b/libavcodec/bitstream_filters.c
> @@ -29,6 +29,7 @@ extern const AVBitStreamFilter ff_chomp_bsf;
>  extern const AVBitStreamFilter ff_dump_extradata_bsf;
>  extern const AVBitStreamFilter ff_dca_core_bsf;
>  extern const AVBitStreamFilter ff_extract_extradata_bsf;
> +extern const AVBitStreamFilter ff_filter_units_bsf;
>  extern const AVBitStreamFilter ff_h264_metadata_bsf;
>  extern const AVBitStreamFilter ff_h264_mp4toannexb_bsf;
>  extern const AVBitStreamFilter ff_h264_redundant_pps_bsf;
> diff --git a/libavcodec/filter_units_bsf.c b/libavcodec/filter_units_bsf.c
> new file mode 100644
> index 000..3126f17
> --- /dev/null
> +++ b/libavcodec/filter_units_bsf.c
> @@ -0,0 +1,250 @@
> +/*
> + * 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 
> +
> +#include "libavutil/common.h"
> +#include "libavutil/opt.h"

[FFmpeg-devel] [PATCH] lavc: Add filter_units bitstream filter

2018-03-06 Thread Mark Thompson
This can remove units with types in or not in a given set from a stream.
For example, it can be used to remove all non-VCL NAL units from an H.264 or
H.265 stream.
---
On 06/03/18 17:27, Hendrik Leppkes wrote:
> On Tue, Mar 6, 2018 at 3:51 PM, Eran Kornblau  
> wrote:
>> Hi all,
>>
>> The attached patch adds a parameter that enables the user to choose which 
>> AVC/HEVC NAL units to include in the output.
>> The parameter is supplied as a bitmask in order to keep things simple.
>>
>> A short background on why we need it - in our transcoding process, we 
>> partition the video in chunks, the chunks are
>> transcoded in parallel and packaged in MPEG-TS container. The transcoded TS 
>> chunks are then concatenated and
>> packaged in MP4. These MP4 files are later repackaged on-the-fly to various 
>> protocols (HLS/DASH etc.) using our
>> JIT packager.
>> For performance reasons (can get into more detail if anyone's 
>> interested...), when packaging the MP4 to DASH/CENC,
>> we configure the packager to assume that each AVC frame contains exactly one 
>> NAL unit.
>> The problem is that the transition through MPEG-TS adds additional NAL units 
>> (NAL AUD before each frame + SPS/PPS
>> before each key frame), and this assumption fails.
>> Using the attached patch we can pass '-nal_types_mask 0x3e' which will make 
>> ffmpeg output only VCL NALs in the stream.
>>
> 
> Having such logic in one single muxer is not something we really like
> around here. Next time someone needs something similar for another
> codec, you're stuck re-implementing it.
> 
> To achieve the same effect, Mark Thompson quickly wipped up a
> Bitstream Filter using his CBS framework which achieves the same
> result. He'll be sending that patch to the mailing list in a while.
The suggested use-case would be '-bsf:v filter_units=pass_types=1-5' for H.264 
or '-bsf:v filter_units=pass_types=0-31' for H.265.

(Also note that filters already exist for some individual parts of this: 
h264_metadata can remove AUDs, extract_extradata can remove parameter sets.)

- Mark


 libavcodec/Makefile|   1 +
 libavcodec/bitstream_filters.c |   1 +
 libavcodec/filter_units_bsf.c  | 250 +
 3 files changed, 252 insertions(+)
 create mode 100644 libavcodec/filter_units_bsf.c

diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index b496f0d..b99bdce 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -1037,6 +1037,7 @@ OBJS-$(CONFIG_DUMP_EXTRADATA_BSF) += 
dump_extradata_bsf.o
 OBJS-$(CONFIG_DCA_CORE_BSF)   += dca_core_bsf.o
 OBJS-$(CONFIG_EXTRACT_EXTRADATA_BSF)  += extract_extradata_bsf.o\
  h2645_parse.o
+OBJS-$(CONFIG_FILTER_UNITS_BSF)   += filter_units_bsf.o
 OBJS-$(CONFIG_H264_METADATA_BSF)  += h264_metadata_bsf.o
 OBJS-$(CONFIG_H264_MP4TOANNEXB_BSF)   += h264_mp4toannexb_bsf.o
 OBJS-$(CONFIG_H264_REDUNDANT_PPS_BSF) += h264_redundant_pps_bsf.o
diff --git a/libavcodec/bitstream_filters.c b/libavcodec/bitstream_filters.c
index 338ef82..e1dc198 100644
--- a/libavcodec/bitstream_filters.c
+++ b/libavcodec/bitstream_filters.c
@@ -29,6 +29,7 @@ extern const AVBitStreamFilter ff_chomp_bsf;
 extern const AVBitStreamFilter ff_dump_extradata_bsf;
 extern const AVBitStreamFilter ff_dca_core_bsf;
 extern const AVBitStreamFilter ff_extract_extradata_bsf;
+extern const AVBitStreamFilter ff_filter_units_bsf;
 extern const AVBitStreamFilter ff_h264_metadata_bsf;
 extern const AVBitStreamFilter ff_h264_mp4toannexb_bsf;
 extern const AVBitStreamFilter ff_h264_redundant_pps_bsf;
diff --git a/libavcodec/filter_units_bsf.c b/libavcodec/filter_units_bsf.c
new file mode 100644
index 000..3126f17
--- /dev/null
+++ b/libavcodec/filter_units_bsf.c
@@ -0,0 +1,250 @@
+/*
+ * 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 
+
+#include "libavutil/common.h"
+#include "libavutil/opt.h"
+
+#include "bsf.h"
+#include "cbs.h"
+
+
+typedef struct FilterUnitsContext {
+const AVClass *class;
+
+CodedBitstreamContext *cbc;
+
+const char *pass_types;
+const char *remove_types;
+
+int remove;
+CodedBitstreamUnitType *type_list;
+int nb_types;
+}