[FFmpeg-cvslog] avcodec: add a subcharenc mode that disables UTF-8 check

2018-03-25 Thread wm4
ffmpeg | branch: master | wm4  | Sat Mar 24 13:37:00 
2018 +0100| [b7d0d912ef9b60eae962e4622d72860af31a8b00] | committer: wm4

avcodec: add a subcharenc mode that disables UTF-8 check

This is for applications which want to explicitly check for invalid
UTF-8 manually, and take actions that are better than dropping invalid
subtitles silently. (It's pretty much silent because sporadic avcodec
error messages are so common that you can't reasonably display them in a
prominent and meaningful way in a application GUI.)

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=b7d0d912ef9b60eae962e4622d72860af31a8b00
---

 doc/APIchanges | 3 +++
 libavcodec/avcodec.h   | 1 +
 libavcodec/decode.c| 3 ++-
 libavcodec/options_table.h | 1 +
 libavcodec/version.h   | 2 +-
 5 files changed, 8 insertions(+), 2 deletions(-)

diff --git a/doc/APIchanges b/doc/APIchanges
index a099afd9bc..95b5cd772f 100644
--- a/doc/APIchanges
+++ b/doc/APIchanges
@@ -15,6 +15,9 @@ libavutil: 2017-10-21
 
 API changes, most recent first:
 
+2018-03-xx - xxx - lavc 58.16.100 - avcodec.h
+  Add FF_SUB_CHARENC_MODE_IGNORE.
+
 2018-xx-xx - xxx - lavu 56.8.100 - encryption_info.h
   Add AVEncryptionInitInfo and AVEncryptionInfo structures to hold new 
side-data
   for encryption info.
diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h
index 495242faf0..50c34dbff9 100644
--- a/libavcodec/avcodec.h
+++ b/libavcodec/avcodec.h
@@ -3092,6 +3092,7 @@ typedef struct AVCodecContext {
 #define FF_SUB_CHARENC_MODE_DO_NOTHING  -1  ///< do nothing (demuxer outputs a 
stream supposed to be already in UTF-8, or the codec is bitmap for instance)
 #define FF_SUB_CHARENC_MODE_AUTOMATIC0  ///< libavcodec will select the 
mode itself
 #define FF_SUB_CHARENC_MODE_PRE_DECODER  1  ///< the AVPacket data needs to be 
recoded to UTF-8 before being fed to the decoder, requires iconv
+#define FF_SUB_CHARENC_MODE_IGNORE   2  ///< neither convert the 
subtitles, nor check them for valid UTF-8
 
 /**
  * Skip processing alpha if supported by codec.
diff --git a/libavcodec/decode.c b/libavcodec/decode.c
index ea2168ad0c..40c8a8855c 100644
--- a/libavcodec/decode.c
+++ b/libavcodec/decode.c
@@ -1057,7 +1057,8 @@ int avcodec_decode_subtitle2(AVCodecContext *avctx, 
AVSubtitle *sub,
 sub->format = 1;
 
 for (i = 0; i < sub->num_rects; i++) {
-if (sub->rects[i]->ass && !utf8_check(sub->rects[i]->ass)) {
+if (avctx->sub_charenc_mode != FF_SUB_CHARENC_MODE_IGNORE &&
+sub->rects[i]->ass && !utf8_check(sub->rects[i]->ass)) {
 av_log(avctx, AV_LOG_ERROR,
"Invalid UTF-8 in decoded subtitles text; "
"maybe missing -sub_charenc option\n");
diff --git a/libavcodec/options_table.h b/libavcodec/options_table.h
index 5a5eae65fb..099261e168 100644
--- a/libavcodec/options_table.h
+++ b/libavcodec/options_table.h
@@ -447,6 +447,7 @@ static const AVOption avcodec_options[] = {
 {"do_nothing",  NULL, 0, AV_OPT_TYPE_CONST, {.i64 = 
FF_SUB_CHARENC_MODE_DO_NOTHING},  INT_MIN, INT_MAX, S|D, "sub_charenc_mode"},
 {"auto",NULL, 0, AV_OPT_TYPE_CONST, {.i64 = 
FF_SUB_CHARENC_MODE_AUTOMATIC},   INT_MIN, INT_MAX, S|D, "sub_charenc_mode"},
 {"pre_decoder", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = 
FF_SUB_CHARENC_MODE_PRE_DECODER}, INT_MIN, INT_MAX, S|D, "sub_charenc_mode"},
+{"ignore",  NULL, 0, AV_OPT_TYPE_CONST, {.i64 = 
FF_SUB_CHARENC_MODE_IGNORE},  INT_MIN, INT_MAX, S|D, "sub_charenc_mode"},
 #if FF_API_ASS_TIMING
 {"sub_text_format", "set decoded text subtitle format", 
OFFSET(sub_text_format), AV_OPT_TYPE_INT, {.i64 = 
FF_SUB_TEXT_FMT_ASS_WITH_TIMINGS}, 0, 1, S|D, "sub_text_format"},
 #else
diff --git a/libavcodec/version.h b/libavcodec/version.h
index a5b7f752d1..8ac4626da7 100644
--- a/libavcodec/version.h
+++ b/libavcodec/version.h
@@ -28,7 +28,7 @@
 #include "libavutil/version.h"
 
 #define LIBAVCODEC_VERSION_MAJOR  58
-#define LIBAVCODEC_VERSION_MINOR  15
+#define LIBAVCODEC_VERSION_MINOR  16
 #define LIBAVCODEC_VERSION_MICRO 100
 
 #define LIBAVCODEC_VERSION_INT  AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \

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


[FFmpeg-cvslog] movtextdec: fix handling of UTF-8 subtitles

2018-03-25 Thread wm4
ffmpeg | branch: master | wm4  | Sat Mar 24 15:41:54 
2018 +0100| [b0644c3e1a96397ee5e2448c542fa4c3bc319537] | committer: wm4

movtextdec: fix handling of UTF-8 subtitles

Subtitles which contained styled UTF-8 subtitles (i.e. not just 7 bit
ASCII characters) were not handled correctly. The spec mandates that
styling start/end ranges are in "characters". It's not quite clear what
a "character" is supposed to be, but maybe they mean unicode codepoints.

FFmpeg's decoder treated the style ranges as byte idexes, which could
lead to UTF-8 sequences being broken, and the common code dropping the
whole subtitle line.

Change this and count the codepoint instead. This also means that even
if this is somehow wrong, the decoder won't break UTF-8 sequences
anymore. The sample which led me to investigate this now appears to work
correctly.

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=b0644c3e1a96397ee5e2448c542fa4c3bc319537
---

 libavcodec/movtextdec.c | 50 -
 1 file changed, 37 insertions(+), 13 deletions(-)

diff --git a/libavcodec/movtextdec.c b/libavcodec/movtextdec.c
index bd19577724..89ac791602 100644
--- a/libavcodec/movtextdec.c
+++ b/libavcodec/movtextdec.c
@@ -326,9 +326,24 @@ static const Box box_types[] = {
 
 const static size_t box_count = FF_ARRAY_ELEMS(box_types);
 
+// Return byte length of the UTF-8 sequence starting at text[0]. 0 on error.
+static int get_utf8_length_at(const char *text, const char *text_end)
+{
+const char *start = text;
+int err = 0;
+uint32_t c;
+GET_UTF8(c, text < text_end ? (uint8_t)*text++ : (err = 1, 0), goto 
error;);
+if (err)
+goto error;
+return text - start;
+error:
+return 0;
+}
+
 static int text_to_ass(AVBPrint *buf, const char *text, const char *text_end,
-MovTextContext *m)
+   AVCodecContext *avctx)
 {
+MovTextContext *m = avctx->priv_data;
 int i = 0;
 int j = 0;
 int text_pos = 0;
@@ -342,6 +357,8 @@ static int text_to_ass(AVBPrint *buf, const char *text, 
const char *text_end,
 }
 
 while (text < text_end) {
+int len;
+
 if (m->box_flags & STYL_BOX) {
 for (i = 0; i < m->style_entries; i++) {
 if (m->s[i]->style_flag && text_pos == m->s[i]->style_end) {
@@ -388,17 +405,24 @@ static int text_to_ass(AVBPrint *buf, const char *text, 
const char *text_end,
 }
 }
 
-switch (*text) {
-case '\r':
-break;
-case '\n':
-av_bprintf(buf, "\\N");
-break;
-default:
-av_bprint_chars(buf, *text, 1);
-break;
+len = get_utf8_length_at(text, text_end);
+if (len < 1) {
+av_log(avctx, AV_LOG_ERROR, "invalid UTF-8 byte in subtitle\n");
+len = 1;
+}
+for (i = 0; i < len; i++) {
+switch (*text) {
+case '\r':
+break;
+case '\n':
+av_bprintf(buf, "\\N");
+break;
+default:
+av_bprint_chars(buf, *text, 1);
+break;
+}
+text++;
 }
-text++;
 text_pos++;
 }
 
@@ -507,10 +531,10 @@ static int mov_text_decode_frame(AVCodecContext *avctx,
 }
 m->tracksize = m->tracksize + tsmb_size;
 }
-text_to_ass(&buf, ptr, end, m);
+text_to_ass(&buf, ptr, end, avctx);
 mov_text_cleanup(m);
 } else
-text_to_ass(&buf, ptr, end, m);
+text_to_ass(&buf, ptr, end, avctx);
 
 ret = ff_ass_add_rect(sub, buf.str, m->readorder++, 0, NULL, NULL);
 av_bprint_finalize(&buf, NULL);

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


[FFmpeg-cvslog] doc/filter.texi: fix some spotted typos

2018-03-25 Thread Paul B Mahol
ffmpeg | branch: master | Paul B Mahol  | Sun Mar 25 23:10:59 
2018 +0200| [261171d084bc89313c1fb9ace643243959aeef9f] | committer: Paul B Mahol

doc/filter.texi: fix some spotted typos

Signed-off-by: Paul B Mahol 

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=261171d084bc89313c1fb9ace643243959aeef9f
---

 doc/filters.texi | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/doc/filters.texi b/doc/filters.texi
index 1620ae1cfa..5c119c0151 100644
--- a/doc/filters.texi
+++ b/doc/filters.texi
@@ -509,7 +509,7 @@ An Anti-Aliasing setting is able to produce "softer" 
crushing sounds.
 Another feature of this filter is the logarithmic mode.
 This setting switches from linear distances between bits to logarithmic ones.
 The result is a much more "natural" sounding crusher which doesn't gate low
-signals for example. The human ear has a logarithmic perception, too
+signals for example. The human ear has a logarithmic perception,
 so this kind of crushing is much more pleasant.
 Logarithmic crushing is also able to get anti-aliased.
 
@@ -3606,7 +3606,7 @@ 
lv2=p=http://calf.sourceforge.net/plugins/BassEnhancer:c=amount=2
 @end example
 
 @item
-Apply bass vinyl plugin from Calf:
+Apply vinyl plugin from Calf:
 @example
 lv2=p=http://calf.sourceforge.net/plugins/Vinyl:c=drone=0.2|aging=0.5
 @end example
@@ -20056,7 +20056,7 @@ Scale pixel values for each drawn sample.
 Draw every sample directly.
 @end table
 
-Default vlaue is @code{scale}.
+Default value is @code{scale}.
 @end table
 
 @subsection Examples

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


[FFmpeg-cvslog] avfilter/af_mcompand: make error message more helpful

2018-03-25 Thread Paul B Mahol
ffmpeg | branch: master | Paul B Mahol  | Sun Mar 25 23:26:26 
2018 +0200| [78f8036c9c1f7375a0ff8aefe2030f160dbedf36] | committer: Paul B Mahol

avfilter/af_mcompand: make error message more helpful

Signed-off-by: Paul B Mahol 

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=78f8036c9c1f7375a0ff8aefe2030f160dbedf36
---

 libavfilter/af_mcompand.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libavfilter/af_mcompand.c b/libavfilter/af_mcompand.c
index 02f987a6a8..f142573bea 100644
--- a/libavfilter/af_mcompand.c
+++ b/libavfilter/af_mcompand.c
@@ -456,7 +456,7 @@ static int config_output(AVFilterLink *outlink)
 
 new_nb_items += sscanf(tstr2, "%lf", &s->bands[i].topfreq) == 1;
 if (s->bands[i].topfreq < 0 || s->bands[i].topfreq >= 
outlink->sample_rate / 2) {
-av_log(ctx, AV_LOG_ERROR, "crossover_frequency should be >=0 and 
lower than half of sample rate\n");
+av_log(ctx, AV_LOG_ERROR, "crossover_frequency: %f, should be >=0 
and lower than half of sample rate: %d.\n", s->bands[i].topfreq, 
outlink->sample_rate / 2);
 uninit(ctx);
 return AVERROR(EINVAL);
 }

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


[FFmpeg-cvslog] avformat/mov: Move +1 in check to avoid hypothetical overflow in add_ctts_entry()

2018-03-25 Thread Michael Niedermayer
ffmpeg | branch: master | Michael Niedermayer  | Sat 
Feb  3 21:36:22 2018 +0100| [eb60b9d342265fb1960be6fff6383cfdbf37] | 
committer: Michael Niedermayer

avformat/mov: Move +1 in check to avoid hypothetical overflow in 
add_ctts_entry()

Signed-off-by: Michael Niedermayer 

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=eb60b9d342265fb1960be6fff6383cfdbf37
---

 libavformat/mov.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libavformat/mov.c b/libavformat/mov.c
index 33126781a0..cb6f3a45de 100644
--- a/libavformat/mov.c
+++ b/libavformat/mov.c
@@ -3256,7 +3256,7 @@ static int64_t add_ctts_entry(MOVStts** ctts_data, 
unsigned int* ctts_count, uns
 FFMAX(min_size_needed, 2 * (*allocated_size)) :
 min_size_needed;
 
-if((unsigned)(*ctts_count) + 1 >= UINT_MAX / sizeof(MOVStts))
+if((unsigned)(*ctts_count) >= UINT_MAX / sizeof(MOVStts) - 1)
 return -1;
 
 ctts_buf_new = av_fast_realloc(*ctts_data, allocated_size, requested_size);

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


[FFmpeg-cvslog] avcodec/mpeg4videodec: Use more specific error codes

2018-03-25 Thread Michael Niedermayer
ffmpeg | branch: master | Michael Niedermayer  | Sat 
Mar 10 18:03:09 2018 +0100| [db772308941a2a338c7809f90d347219a6a93074] | 
committer: Michael Niedermayer

avcodec/mpeg4videodec: Use more specific error codes

Forward error codes where possible.

Signed-off-by: Michael Niedermayer 

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=db772308941a2a338c7809f90d347219a6a93074
---

 libavcodec/mpeg4video.h|   4 +-
 libavcodec/mpeg4videodec.c | 100 +++--
 2 files changed, 53 insertions(+), 51 deletions(-)

diff --git a/libavcodec/mpeg4video.h b/libavcodec/mpeg4video.h
index 0ba502d50b..6672c6dd66 100644
--- a/libavcodec/mpeg4video.h
+++ b/libavcodec/mpeg4video.h
@@ -239,12 +239,12 @@ static inline int ff_mpeg4_pred_dc(MpegEncContext *s, int 
n, int level,
 if (level < 0) {
 av_log(s->avctx, AV_LOG_ERROR,
"dc<0 at %dx%d\n", s->mb_x, s->mb_y);
-return -1;
+return AVERROR_INVALIDDATA;
 }
 if (level > 2048 + scale) {
 av_log(s->avctx, AV_LOG_ERROR,
"dc overflow at %dx%d\n", s->mb_x, s->mb_y);
-return -1;
+return AVERROR_INVALIDDATA;
 }
 }
 if (level < 0)
diff --git a/libavcodec/mpeg4videodec.c b/libavcodec/mpeg4videodec.c
index 19210d97fe..a1117dc272 100644
--- a/libavcodec/mpeg4videodec.c
+++ b/libavcodec/mpeg4videodec.c
@@ -448,7 +448,7 @@ int ff_mpeg4_decode_video_packet_header(Mpeg4DecContext 
*ctx)
 
 /* is there enough space left for a video packet + header */
 if (get_bits_count(&s->gb) > s->gb.size_in_bits - 20)
-return -1;
+return AVERROR_INVALIDDATA;
 
 for (len = 0; len < 32; len++)
 if (get_bits1(&s->gb))
@@ -456,7 +456,7 @@ int ff_mpeg4_decode_video_packet_header(Mpeg4DecContext 
*ctx)
 
 if (len != ff_mpeg4_get_video_packet_prefix_length(s)) {
 av_log(s->avctx, AV_LOG_ERROR, "marker does not match f_code\n");
-return -1;
+return AVERROR_INVALIDDATA;
 }
 
 if (ctx->shape != RECT_SHAPE) {
@@ -468,7 +468,7 @@ int ff_mpeg4_decode_video_packet_header(Mpeg4DecContext 
*ctx)
 if (mb_num >= s->mb_num || !mb_num) {
 av_log(s->avctx, AV_LOG_ERROR,
"illegal mb_num in video packet (%d %d) \n", mb_num, s->mb_num);
-return -1;
+return AVERROR_INVALIDDATA;
 }
 
 s->mb_x = mb_num % s->mb_width;
@@ -597,7 +597,7 @@ static inline int mpeg4_decode_dc(MpegEncContext *s, int n, 
int *dir_ptr)
 
 if (code < 0 || code > 9 /* && s->nbit < 9 */) {
 av_log(s->avctx, AV_LOG_ERROR, "illegal dc vlc\n");
-return -1;
+return AVERROR_INVALIDDATA;
 }
 
 if (code == 0) {
@@ -620,7 +620,7 @@ static inline int mpeg4_decode_dc(MpegEncContext *s, int n, 
int *dir_ptr)
 if (get_bits1(&s->gb) == 0) { /* marker */
 if (s->avctx->err_recognition & 
(AV_EF_BITSTREAM|AV_EF_COMPLIANT)) {
 av_log(s->avctx, AV_LOG_ERROR, "dc marker bit missing\n");
-return -1;
+return AVERROR_INVALIDDATA;
 }
 }
 }
@@ -664,7 +664,7 @@ static int mpeg4_decode_partition_a(Mpeg4DecContext *ctx)
 if (cbpc < 0) {
 av_log(s->avctx, AV_LOG_ERROR,
"mcbpc corrupted at %d %d\n", s->mb_x, s->mb_y);
-return -1;
+return AVERROR_INVALIDDATA;
 }
 } while (cbpc == 8);
 
@@ -684,7 +684,7 @@ static int mpeg4_decode_partition_a(Mpeg4DecContext *ctx)
 if (dc < 0) {
 av_log(s->avctx, AV_LOG_ERROR,
"DC corrupted at %d %d\n", s->mb_x, s->mb_y);
-return -1;
+return dc;
 }
 dir <<= 1;
 if (dc_pred_dir)
@@ -736,7 +736,7 @@ try_again:
 if (cbpc < 0) {
 av_log(s->avctx, AV_LOG_ERROR,
"mcbpc corrupted at %d %d\n", s->mb_x, s->mb_y);
-return -1;
+return AVERROR_INVALIDDATA;
 }
 if (cbpc == 20)
 goto try_again;
@@ -774,11 +774,11 @@ try_again:
 if (!s->mcsel) {
 mx = ff_h263_decode_motion(s, pred_x, s->f_code);
 if (mx >= 0x)
-return -1;
+return AVERROR_INVALIDDATA;
 
 my = ff_h263_decode_motion(s, pred_y, s->f_code);
 if (my >= 0x)
-return -1;
+return AVERROR_INVALIDDATA;
   

[FFmpeg-cvslog] avcodec/get_bits: Make sure the input bitstream with padding can be addressed

2018-03-25 Thread Michael Niedermayer
ffmpeg | branch: master | Michael Niedermayer  | Sat 
Mar 24 01:38:53 2018 +0100| [e529fe7633762cb26a665fb6dee3be29b15285cc] | 
committer: Michael Niedermayer

avcodec/get_bits: Make sure the input bitstream with padding can be addressed

Signed-off-by: Michael Niedermayer 

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=e529fe7633762cb26a665fb6dee3be29b15285cc
---

 libavcodec/get_bits.h | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/libavcodec/get_bits.h b/libavcodec/get_bits.h
index 0c7f5ff0c6..d7cf286378 100644
--- a/libavcodec/get_bits.h
+++ b/libavcodec/get_bits.h
@@ -32,6 +32,7 @@
 #include "libavutil/intreadwrite.h"
 #include "libavutil/log.h"
 #include "libavutil/avassert.h"
+#include "avcodec.h"
 #include "mathops.h"
 #include "vlc.h"
 
@@ -428,7 +429,7 @@ static inline int init_get_bits(GetBitContext *s, const 
uint8_t *buffer,
 int buffer_size;
 int ret = 0;
 
-if (bit_size >= INT_MAX - 7 || bit_size < 0 || !buffer) {
+if (bit_size >= INT_MAX - FFMAX(7, AV_INPUT_BUFFER_PADDING_SIZE*8) || 
bit_size < 0 || !buffer) {
 bit_size= 0;
 buffer  = NULL;
 ret = AVERROR_INVALIDDATA;

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


[FFmpeg-cvslog] avformat/rtpenc_chain: use the proper function to free AVFormatContext

2018-03-25 Thread James Almer
ffmpeg | branch: master | James Almer  | Mon Mar 26 00:52:39 
2018 -0300| [3eff98c9278804b4b664bad3853e5e60184c6a54] | committer: James Almer

avformat/rtpenc_chain: use the proper function to free AVFormatContext

Fixes ticket #7075

Signed-off-by: James Almer 

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=3eff98c9278804b4b664bad3853e5e60184c6a54
---

 libavformat/rtpenc_chain.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libavformat/rtpenc_chain.c b/libavformat/rtpenc_chain.c
index f768fb002e..e69fdc27cf 100644
--- a/libavformat/rtpenc_chain.c
+++ b/libavformat/rtpenc_chain.c
@@ -101,7 +101,7 @@ int ff_rtp_chain_mux_open(AVFormatContext **out, 
AVFormatContext *s,
 return 0;
 
 fail:
-av_free(rtpctx);
+avformat_free_context(rtpctx);
 if (handle)
 ffurl_close(handle);
 return ret;

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