diff mbox series

[FFmpeg-devel,v2] avcodec: Add dv marker bsf

Message ID 20220309181819.22709-1-michael@niedermayer.cc
State New
Headers show
Series [FFmpeg-devel,v2] avcodec: Add dv marker bsf | expand

Checks

Context Check Description
yinshiyou/make_loongarch64 success Make finished
yinshiyou/make_fate_loongarch64 success Make fate finished
andriy/make_armv7_RPi4 success Make finished
andriy/make_fate_armv7_RPi4 success Make fate finished
andriy/make_aarch64_jetson success Make finished
andriy/make_fate_aarch64_jetson success Make fate finished

Commit Message

Michael Niedermayer March 9, 2022, 6:18 p.m. UTC
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
---
 doc/bitstream_filters.texi       |  30 ++++++++
 libavcodec/Makefile              |   1 +
 libavcodec/bitstream_filters.c   |   1 +
 libavcodec/dv_error_marker_bsf.c | 127 +++++++++++++++++++++++++++++++
 4 files changed, 159 insertions(+)
 create mode 100644 libavcodec/dv_error_marker_bsf.c

Comments

Tobias Rapp March 10, 2022, 9:41 a.m. UTC | #1
On 09/03/2022 19:18, Michael Niedermayer wrote:
> Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
> ---
>   doc/bitstream_filters.texi       |  30 ++++++++
>   libavcodec/Makefile              |   1 +
>   libavcodec/bitstream_filters.c   |   1 +
>   libavcodec/dv_error_marker_bsf.c | 127 +++++++++++++++++++++++++++++++
>   4 files changed, 159 insertions(+)
>   create mode 100644 libavcodec/dv_error_marker_bsf.c
> 
> diff --git a/doc/bitstream_filters.texi b/doc/bitstream_filters.texi
> index a0092878c8..8c5d84dceb 100644
> --- a/doc/bitstream_filters.texi
> +++ b/doc/bitstream_filters.texi
> @@ -132,6 +132,36 @@ the header stored in extradata to the key packets:
>   ffmpeg -i INPUT -map 0 -flags:v +global_header -c:v libx264 -bsf:v dump_extra out.ts
>   @end example
>   
> +@section dv_error_marker
> +
> +Blocks in DV which are marked as damaged are replaced by blocks of the specified color.
> +
> +@table @option
> +@item color
> +The color to replace damaged blocks by
> +@item sta
> +A 16 bit mask which specifies which of the 16 possible error status values are
> +to be replaced by colored blocks. 0xFFFE is the default which replaces all non 0
> +error status values.
> +@table @samp
> +@item ok
> +No error, no concealment
> +@item err
> +Error, No concealment
> +@item res
> +Reserved
> +@item notok
> +Error or concealment
> +@item notres
> +Not reserved
> +@item Aa, Ba, Ca, Ab, Bb, Cb, A, B, C, a, b, erri, erru
> +The specific error status code
> +@end table
> +see page 44-46 or section 5.5 of
> +@url{http://web.archive.org/web/20060927044735/http://www.smpte.org/smpte_store/standards/pdf/s314m.pdf}
> +
> +@end table
> +
>   @section eac3_core
> [...]
The filter options look nice to me now. Have not actually tested the 
bitstream filter on DV files, though.

Regards,
Tobias
Dave Rice March 12, 2022, 3:11 p.m. UTC | #2
> On Mar 10, 2022, at 4:41 AM, Tobias Rapp <t.rapp@noa-archive.com> wrote:
> 
> On 09/03/2022 19:18, Michael Niedermayer wrote:
>> Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
>> ---
>>  doc/bitstream_filters.texi       |  30 ++++++++
>>  libavcodec/Makefile              |   1 +
>>  libavcodec/bitstream_filters.c   |   1 +
>>  libavcodec/dv_error_marker_bsf.c | 127 +++++++++++++++++++++++++++++++
>>  4 files changed, 159 insertions(+)
>>  create mode 100644 libavcodec/dv_error_marker_bsf.c
>> diff --git a/doc/bitstream_filters.texi b/doc/bitstream_filters.texi
>> index a0092878c8..8c5d84dceb 100644
>> --- a/doc/bitstream_filters.texi
>> +++ b/doc/bitstream_filters.texi
>> @@ -132,6 +132,36 @@ the header stored in extradata to the key packets:
>>  ffmpeg -i INPUT -map 0 -flags:v +global_header -c:v libx264 -bsf:v dump_extra out.ts
>>  @end example
>>  +@section dv_error_marker
>> +
>> +Blocks in DV which are marked as damaged are replaced by blocks of the specified color.
>> +
>> +@table @option
>> +@item color
>> +The color to replace damaged blocks by
>> +@item sta
>> +A 16 bit mask which specifies which of the 16 possible error status values are
>> +to be replaced by colored blocks. 0xFFFE is the default which replaces all non 0
>> +error status values.
>> +@table @samp
>> +@item ok
>> +No error, no concealment
>> +@item err
>> +Error, No concealment
>> +@item res
>> +Reserved
>> +@item notok
>> +Error or concealment
>> +@item notres
>> +Not reserved
>> +@item Aa, Ba, Ca, Ab, Bb, Cb, A, B, C, a, b, erri, erru
>> +The specific error status code
>> +@end table
>> +see page 44-46 or section 5.5 of
>> +@url{http://web.archive.org/web/20060927044735/http://www.smpte.org/smpte_store/standards/pdf/s314m.pdf}
>> +
>> +@end table
>> +
>>  @section eac3_core
>> [...]
> The filter options look nice to me now. Have not actually tested the bitstream filter on DV files, though.

I tested this and this works well for me. Here's a few samples that demonstrate the filter:

./ffmpeg -i https://samples.ffmpeg.org/archive/audio/pcm_s16le/dv+dvvideo+pcm_s16le++dropout.dv  -bsf dv_error_marker=sta=b -f rawvideo -c:v copy - | ffplay -
./ffmpeg -i https://archive.org/download/DvAnalyzerSampleDvVideoErrorConcealment/DV_Analyzer_Sample_Video_Error_Concealment_original.dv -bsf dv_error_marker=sta=b -f rawvideo -c:v copy - | ffplay -

Dave Rice
Michael Niedermayer March 12, 2022, 6:09 p.m. UTC | #3
On Sat, Mar 12, 2022 at 10:11:52AM -0500, Dave Rice wrote:
> 
> 
> > On Mar 10, 2022, at 4:41 AM, Tobias Rapp <t.rapp@noa-archive.com> wrote:
> > 
> > On 09/03/2022 19:18, Michael Niedermayer wrote:
> >> Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
> >> ---
> >>  doc/bitstream_filters.texi       |  30 ++++++++
> >>  libavcodec/Makefile              |   1 +
> >>  libavcodec/bitstream_filters.c   |   1 +
> >>  libavcodec/dv_error_marker_bsf.c | 127 +++++++++++++++++++++++++++++++
> >>  4 files changed, 159 insertions(+)
> >>  create mode 100644 libavcodec/dv_error_marker_bsf.c
> >> diff --git a/doc/bitstream_filters.texi b/doc/bitstream_filters.texi
> >> index a0092878c8..8c5d84dceb 100644
> >> --- a/doc/bitstream_filters.texi
> >> +++ b/doc/bitstream_filters.texi
> >> @@ -132,6 +132,36 @@ the header stored in extradata to the key packets:
> >>  ffmpeg -i INPUT -map 0 -flags:v +global_header -c:v libx264 -bsf:v dump_extra out.ts
> >>  @end example
> >>  +@section dv_error_marker
> >> +
> >> +Blocks in DV which are marked as damaged are replaced by blocks of the specified color.
> >> +
> >> +@table @option
> >> +@item color
> >> +The color to replace damaged blocks by
> >> +@item sta
> >> +A 16 bit mask which specifies which of the 16 possible error status values are
> >> +to be replaced by colored blocks. 0xFFFE is the default which replaces all non 0
> >> +error status values.
> >> +@table @samp
> >> +@item ok
> >> +No error, no concealment
> >> +@item err
> >> +Error, No concealment
> >> +@item res
> >> +Reserved
> >> +@item notok
> >> +Error or concealment
> >> +@item notres
> >> +Not reserved
> >> +@item Aa, Ba, Ca, Ab, Bb, Cb, A, B, C, a, b, erri, erru
> >> +The specific error status code
> >> +@end table
> >> +see page 44-46 or section 5.5 of
> >> +@url{http://web.archive.org/web/20060927044735/http://www.smpte.org/smpte_store/standards/pdf/s314m.pdf}
> >> +
> >> +@end table
> >> +
> >>  @section eac3_core
> >> [...]
> > The filter options look nice to me now. Have not actually tested the bitstream filter on DV files, though.
> 
> I tested this and this works well for me. Here's a few samples that demonstrate the filter:
> 
> ./ffmpeg -i https://samples.ffmpeg.org/archive/audio/pcm_s16le/dv+dvvideo+pcm_s16le++dropout.dv  -bsf dv_error_marker=sta=b -f rawvideo -c:v copy - | ffplay -
> ./ffmpeg -i https://archive.org/download/DvAnalyzerSampleDvVideoErrorConcealment/DV_Analyzer_Sample_Video_Error_Concealment_original.dv -bsf dv_error_marker=sta=b -f rawvideo -c:v copy - | ffplay -

I tested a bit more and it failed with dvcprohd, i have fixed it and will in a
moment post a version that seems to work with both
please retest

PS: i used some artificially damaged files from fate/dv/

thx

[...]
Dave Rice March 14, 2022, 4:04 p.m. UTC | #4
> On Mar 12, 2022, at 1:09 PM, Michael Niedermayer <michael@niedermayer.cc> wrote:
> 
> On Sat, Mar 12, 2022 at 10:11:52AM -0500, Dave Rice wrote:
>> 
>> 
>>> On Mar 10, 2022, at 4:41 AM, Tobias Rapp <t.rapp@noa-archive.com> wrote:
>>> 
>>> On 09/03/2022 19:18, Michael Niedermayer wrote:
>>>> Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
>>>> ---
>>>> doc/bitstream_filters.texi       |  30 ++++++++
>>>> libavcodec/Makefile              |   1 +
>>>> libavcodec/bitstream_filters.c   |   1 +
>>>> libavcodec/dv_error_marker_bsf.c | 127 +++++++++++++++++++++++++++++++
>>>> 4 files changed, 159 insertions(+)
>>>> create mode 100644 libavcodec/dv_error_marker_bsf.c
>>>> diff --git a/doc/bitstream_filters.texi b/doc/bitstream_filters.texi
>>>> index a0092878c8..8c5d84dceb 100644
>>>> --- a/doc/bitstream_filters.texi
>>>> +++ b/doc/bitstream_filters.texi
>>>> @@ -132,6 +132,36 @@ the header stored in extradata to the key packets:
>>>> ffmpeg -i INPUT -map 0 -flags:v +global_header -c:v libx264 -bsf:v dump_extra out.ts
>>>> @end example
>>>> +@section dv_error_marker
>>>> +
>>>> +Blocks in DV which are marked as damaged are replaced by blocks of the specified color.
>>>> +
>>>> +@table @option
>>>> +@item color
>>>> +The color to replace damaged blocks by
>>>> +@item sta
>>>> +A 16 bit mask which specifies which of the 16 possible error status values are
>>>> +to be replaced by colored blocks. 0xFFFE is the default which replaces all non 0
>>>> +error status values.
>>>> +@table @samp
>>>> +@item ok
>>>> +No error, no concealment
>>>> +@item err
>>>> +Error, No concealment
>>>> +@item res
>>>> +Reserved
>>>> +@item notok
>>>> +Error or concealment
>>>> +@item notres
>>>> +Not reserved
>>>> +@item Aa, Ba, Ca, Ab, Bb, Cb, A, B, C, a, b, erri, erru
>>>> +The specific error status code
>>>> +@end table
>>>> +see page 44-46 or section 5.5 of
>>>> +@url{http://web.archive.org/web/20060927044735/http://www.smpte.org/smpte_store/standards/pdf/s314m.pdf}
>>>> +
>>>> +@end table
>>>> +
>>>> @section eac3_core
>>>> [...]
>>> The filter options look nice to me now. Have not actually tested the bitstream filter on DV files, though.
>> 
>> I tested this and this works well for me. Here's a few samples that demonstrate the filter:
>> 
>> ./ffmpeg -i https://samples.ffmpeg.org/archive/audio/pcm_s16le/dv+dvvideo+pcm_s16le++dropout.dv  -bsf dv_error_marker=sta=b -f rawvideo -c:v copy - | ffplay -
>> ./ffmpeg -i https://archive.org/download/DvAnalyzerSampleDvVideoErrorConcealment/DV_Analyzer_Sample_Video_Error_Concealment_original.dv -bsf dv_error_marker=sta=b -f rawvideo -c:v copy - | ffplay -
> 
> I tested a bit more and it failed with dvcprohd, i have fixed it and will in a
> moment post a version that seems to work with both
> please retest

I retested the new version on variety of DV25 and DV50 content. Looks good to me.

> PS: i used some artificially damaged files from fate/dv/
> 
> thx
> 
> [...]
> -- 
> Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
> 
> Good people do not need laws to tell them to act responsibly, while bad
> people will find a way around the laws. -- Plato
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org <mailto:ffmpeg-devel@ffmpeg.org>
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel <https://ffmpeg.org/mailman/listinfo/ffmpeg-devel>
> 
> To unsubscribe, visit link above, or email
> ffmpeg-devel-request@ffmpeg.org <mailto:ffmpeg-devel-request@ffmpeg.org> with subject "unsubscribe".
Michael Niedermayer March 14, 2022, 6:53 p.m. UTC | #5
On Mon, Mar 14, 2022 at 12:04:46PM -0400, Dave Rice wrote:
> 
> 
> > On Mar 12, 2022, at 1:09 PM, Michael Niedermayer <michael@niedermayer.cc> wrote:
> > 
> > On Sat, Mar 12, 2022 at 10:11:52AM -0500, Dave Rice wrote:
> >> 
> >> 
> >>> On Mar 10, 2022, at 4:41 AM, Tobias Rapp <t.rapp@noa-archive.com> wrote:
> >>> 
> >>> On 09/03/2022 19:18, Michael Niedermayer wrote:
> >>>> Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
> >>>> ---
> >>>> doc/bitstream_filters.texi       |  30 ++++++++
> >>>> libavcodec/Makefile              |   1 +
> >>>> libavcodec/bitstream_filters.c   |   1 +
> >>>> libavcodec/dv_error_marker_bsf.c | 127 +++++++++++++++++++++++++++++++
> >>>> 4 files changed, 159 insertions(+)
> >>>> create mode 100644 libavcodec/dv_error_marker_bsf.c
> >>>> diff --git a/doc/bitstream_filters.texi b/doc/bitstream_filters.texi
> >>>> index a0092878c8..8c5d84dceb 100644
> >>>> --- a/doc/bitstream_filters.texi
> >>>> +++ b/doc/bitstream_filters.texi
> >>>> @@ -132,6 +132,36 @@ the header stored in extradata to the key packets:
> >>>> ffmpeg -i INPUT -map 0 -flags:v +global_header -c:v libx264 -bsf:v dump_extra out.ts
> >>>> @end example
> >>>> +@section dv_error_marker
> >>>> +
> >>>> +Blocks in DV which are marked as damaged are replaced by blocks of the specified color.
> >>>> +
> >>>> +@table @option
> >>>> +@item color
> >>>> +The color to replace damaged blocks by
> >>>> +@item sta
> >>>> +A 16 bit mask which specifies which of the 16 possible error status values are
> >>>> +to be replaced by colored blocks. 0xFFFE is the default which replaces all non 0
> >>>> +error status values.
> >>>> +@table @samp
> >>>> +@item ok
> >>>> +No error, no concealment
> >>>> +@item err
> >>>> +Error, No concealment
> >>>> +@item res
> >>>> +Reserved
> >>>> +@item notok
> >>>> +Error or concealment
> >>>> +@item notres
> >>>> +Not reserved
> >>>> +@item Aa, Ba, Ca, Ab, Bb, Cb, A, B, C, a, b, erri, erru
> >>>> +The specific error status code
> >>>> +@end table
> >>>> +see page 44-46 or section 5.5 of
> >>>> +@url{http://web.archive.org/web/20060927044735/http://www.smpte.org/smpte_store/standards/pdf/s314m.pdf}
> >>>> +
> >>>> +@end table
> >>>> +
> >>>> @section eac3_core
> >>>> [...]
> >>> The filter options look nice to me now. Have not actually tested the bitstream filter on DV files, though.
> >> 
> >> I tested this and this works well for me. Here's a few samples that demonstrate the filter:
> >> 
> >> ./ffmpeg -i https://samples.ffmpeg.org/archive/audio/pcm_s16le/dv+dvvideo+pcm_s16le++dropout.dv  -bsf dv_error_marker=sta=b -f rawvideo -c:v copy - | ffplay -
> >> ./ffmpeg -i https://archive.org/download/DvAnalyzerSampleDvVideoErrorConcealment/DV_Analyzer_Sample_Video_Error_Concealment_original.dv -bsf dv_error_marker=sta=b -f rawvideo -c:v copy - | ffplay -
> > 
> > I tested a bit more and it failed with dvcprohd, i have fixed it and will in a
> > moment post a version that seems to work with both
> > please retest
> 
> I retested the new version on variety of DV25 and DV50 content. Looks good to me.

will apply

thx

[...]
Anton Khirnov March 15, 2022, 8:54 a.m. UTC | #6
Could you please add a test?
Michael Niedermayer March 15, 2022, 2:20 p.m. UTC | #7
On Tue, Mar 15, 2022 at 09:54:26AM +0100, Anton Khirnov wrote:
> Could you please add a test?

that was my plan
somehow i forgot after the sample files from fate didnt work with it and
i fixed that (in fact adding a test was why i tried it with files from
fate :)

thx for reminding me

[...]
diff mbox series

Patch

diff --git a/doc/bitstream_filters.texi b/doc/bitstream_filters.texi
index a0092878c8..8c5d84dceb 100644
--- a/doc/bitstream_filters.texi
+++ b/doc/bitstream_filters.texi
@@ -132,6 +132,36 @@  the header stored in extradata to the key packets:
 ffmpeg -i INPUT -map 0 -flags:v +global_header -c:v libx264 -bsf:v dump_extra out.ts
 @end example
 
+@section dv_error_marker
+
+Blocks in DV which are marked as damaged are replaced by blocks of the specified color.
+
+@table @option
+@item color
+The color to replace damaged blocks by
+@item sta
+A 16 bit mask which specifies which of the 16 possible error status values are
+to be replaced by colored blocks. 0xFFFE is the default which replaces all non 0
+error status values.
+@table @samp
+@item ok
+No error, no concealment
+@item err
+Error, No concealment
+@item res
+Reserved
+@item notok
+Error or concealment
+@item notres
+Not reserved
+@item Aa, Ba, Ca, Ab, Bb, Cb, A, B, C, a, b, erri, erru
+The specific error status code
+@end table
+see page 44-46 or section 5.5 of
+@url{http://web.archive.org/web/20060927044735/http://www.smpte.org/smpte_store/standards/pdf/s314m.pdf}
+
+@end table
+
 @section eac3_core
 
 Extract the core from a E-AC-3 stream, dropping extra channels.
diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index bfc31bacd4..c5ed46f121 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -1161,6 +1161,7 @@  OBJS-$(CONFIG_AV1_FRAME_SPLIT_BSF)        += av1_frame_split_bsf.o
 OBJS-$(CONFIG_CHOMP_BSF)                  += chomp_bsf.o
 OBJS-$(CONFIG_DUMP_EXTRADATA_BSF)         += dump_extradata_bsf.o
 OBJS-$(CONFIG_DCA_CORE_BSF)               += dca_core_bsf.o
+OBJS-$(CONFIG_DV_ERROR_MARKER_BSF)        += dv_error_marker_bsf.o
 OBJS-$(CONFIG_EAC3_CORE_BSF)              += eac3_core_bsf.o
 OBJS-$(CONFIG_EXTRACT_EXTRADATA_BSF)      += extract_extradata_bsf.o    \
                                              av1_parse.o h2645_parse.o
diff --git a/libavcodec/bitstream_filters.c b/libavcodec/bitstream_filters.c
index d565286397..ab27972a88 100644
--- a/libavcodec/bitstream_filters.c
+++ b/libavcodec/bitstream_filters.c
@@ -31,6 +31,7 @@  extern const AVBitStreamFilter ff_av1_metadata_bsf;
 extern const AVBitStreamFilter ff_chomp_bsf;
 extern const AVBitStreamFilter ff_dump_extradata_bsf;
 extern const AVBitStreamFilter ff_dca_core_bsf;
+extern const AVBitStreamFilter ff_dv_error_marker_bsf;
 extern const AVBitStreamFilter ff_eac3_core_bsf;
 extern const AVBitStreamFilter ff_extract_extradata_bsf;
 extern const AVBitStreamFilter ff_filter_units_bsf;
diff --git a/libavcodec/dv_error_marker_bsf.c b/libavcodec/dv_error_marker_bsf.c
new file mode 100644
index 0000000000..c43bc01c6b
--- /dev/null
+++ b/libavcodec/dv_error_marker_bsf.c
@@ -0,0 +1,127 @@ 
+/*
+ * Copyright (c) 2022 Michael Niedermayer
+ *
+ * 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 "bsf.h"
+#include "bsf_internal.h"
+#include "libavutil/colorspace.h"
+#include "libavutil/intreadwrite.h"
+#include "libavutil/opt.h"
+
+typedef struct DVErrorMarkerContext {
+    const AVClass *class;
+    uint8_t color_rgba[4];
+    int sta;
+    uint8_t marked_block[76];
+} DVErrorMarkerContext;
+
+static int dv_error_marker_init(AVBSFContext *ctx)
+{
+    DVErrorMarkerContext *s = ctx->priv_data;
+    int i;
+
+    memset(s->marked_block, -1, 76);
+    for (i=0; i<4; i++) {
+        s->marked_block[14*i  ] = RGB_TO_Y_JPEG(s->color_rgba[0], s->color_rgba[1],s->color_rgba[2]) + 128;
+        s->marked_block[14*i+1] = 0x06;
+    }
+    s->marked_block[4*14 + 10*0  ] = RGB_TO_V_JPEG(s->color_rgba[0], s->color_rgba[1],s->color_rgba[2]) - 128;
+    s->marked_block[4*14 + 10*0+1] = 0x16;
+    s->marked_block[4*14 + 10*1  ] = RGB_TO_U_JPEG(s->color_rgba[0], s->color_rgba[1],s->color_rgba[2]) - 128;
+    s->marked_block[4*14 + 10*1+1] = 0x16;
+
+    return 0;
+}
+
+static int dv_error_marker_filter(AVBSFContext *ctx, AVPacket *pkt)
+{
+    DVErrorMarkerContext *s = ctx->priv_data;
+    int ret = ff_bsf_get_packet_ref(ctx, pkt);
+    uint8_t *p;
+    int writable = 0;
+    int stamask = s->sta;
+    int match_count = 0;
+
+    if (ret < 0)
+        return ret;
+
+    p = pkt->data;
+    for(int i = 0; i < pkt->size - 79; i+=80) {
+        // see page 44-46 or section 5.5 of http://web.archive.org/web/20060927044735/http://www.smpte.org/smpte_store/standards/pdf/s314m.pdf.
+        if ((p[i] >> 4) == 9 && ((stamask >> (p[i+3] >> 4))&1)) {
+            if (!writable) {
+                ret = av_packet_make_writable(pkt);
+                if (ret < 0) {
+                    av_packet_unref(pkt);
+                    return ret;
+                }
+                writable = 1;
+                p = pkt->data;
+            }
+            memcpy(p+i+4, s->marked_block, 76);
+            match_count ++;
+        }
+    }
+    av_log(ctx, AV_LOG_DEBUG, "%8"PRId64": Replaced %5d blocks by color %X\n", pkt->pts, match_count, AV_RB32(s->color_rgba));
+
+    return 0;
+}
+
+#define OFFSET(x) offsetof(DVErrorMarkerContext, x)
+#define FLAGS (AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_BSF_PARAM)
+static const AVOption options[] = {
+    { "color"  , "set color", OFFSET(color_rgba), AV_OPT_TYPE_COLOR, {.str = "yellow"}, 0,      0, FLAGS },
+    { "sta"    , "specify which error status value to match"
+                            , OFFSET(sta       ), AV_OPT_TYPE_FLAGS, {.i64 =   0xFFFE}, 0, 0xFFFF, FLAGS, "sta" },
+    { "ok"     , "No error, no concealment",                        0, AV_OPT_TYPE_CONST, {.i64 =   0x0001}, 0, 0xFFFF, FLAGS, "sta"},
+    { "Aa"     , "No error, concealment from previous frame type a",0, AV_OPT_TYPE_CONST, {.i64 =   0x0004}, 0, 0xFFFF, FLAGS, "sta"},
+    { "Ba"     , "No error, concealment from next frame type a",    0, AV_OPT_TYPE_CONST, {.i64 =   0x0010}, 0, 0xFFFF, FLAGS, "sta"},
+    { "Ca"     , "No error, unspecified concealment type a",        0, AV_OPT_TYPE_CONST, {.i64 =   0x0040}, 0, 0xFFFF, FLAGS, "sta"},
+    { "erri"   , "Error with inserted code, No concealment",        0, AV_OPT_TYPE_CONST, {.i64 =   0x0080}, 0, 0xFFFF, FLAGS, "sta"},
+    { "erru"   , "Error with unidentified pos, No concealment",     0, AV_OPT_TYPE_CONST, {.i64 =   0x8000}, 0, 0xFFFF, FLAGS, "sta"},
+    { "err"    , "Error, No concealment",                           0, AV_OPT_TYPE_CONST, {.i64 =   0x8080}, 0, 0xFFFF, FLAGS, "sta"},
+    { "Ab"     , "No error, concealment from previous frame type b",0, AV_OPT_TYPE_CONST, {.i64 =   0x0400}, 0, 0xFFFF, FLAGS, "sta"},
+    { "Bb"     , "No error, concealment from next frame type b",    0, AV_OPT_TYPE_CONST, {.i64 =   0x1000}, 0, 0xFFFF, FLAGS, "sta"},
+    { "Cb"     , "No error, unspecified concealment type b",        0, AV_OPT_TYPE_CONST, {.i64 =   0x4000}, 0, 0xFFFF, FLAGS, "sta"},
+    { "A"      , "No error, concealment from previous frame",       0, AV_OPT_TYPE_CONST, {.i64 =   0x0404}, 0, 0xFFFF, FLAGS, "sta"},
+    { "B"      , "No error, concealment from next frame",           0, AV_OPT_TYPE_CONST, {.i64 =   0x1010}, 0, 0xFFFF, FLAGS, "sta"},
+    { "C"      , "No error, unspecified concealment",               0, AV_OPT_TYPE_CONST, {.i64 =   0x4040}, 0, 0xFFFF, FLAGS, "sta"},
+    { "a"      , "No error, concealment type a",                    0, AV_OPT_TYPE_CONST, {.i64 =   0x0054}, 0, 0xFFFF, FLAGS, "sta"},
+    { "b"      , "No error, concealment type b",                    0, AV_OPT_TYPE_CONST, {.i64 =   0x5400}, 0, 0xFFFF, FLAGS, "sta"},
+    { "res"    , "Reserved",                                        0, AV_OPT_TYPE_CONST, {.i64 =   0x2B2A}, 0, 0xFFFF, FLAGS, "sta"},
+    { "notok"  , "Error or concealment",                            0, AV_OPT_TYPE_CONST, {.i64 =   0xD4D4}, 0, 0xFFFF, FLAGS, "sta"},
+    { "notres" , "Not reserved",                                    0, AV_OPT_TYPE_CONST, {.i64 =   0xD4D5}, 0, 0xFFFF, FLAGS, "sta"},
+    { NULL },
+};
+
+static const AVClass dv_error_marker_class = {
+    .class_name = "dv_error_marker",
+    .item_name  = av_default_item_name,
+    .option     = options,
+    .version    = LIBAVUTIL_VERSION_INT,
+};
+
+const AVBitStreamFilter ff_dv_error_marker_bsf = {
+    .name           = "dv_error_marker",
+    .priv_data_size = sizeof(DVErrorMarkerContext),
+    .priv_class     = &dv_error_marker_class,
+    .init           = dv_error_marker_init,
+    .filter         = dv_error_marker_filter,
+    .codec_ids      =  (const enum AVCodecID []){ AV_CODEC_ID_DVVIDEO, AV_CODEC_ID_NONE },
+};