[FFmpeg-cvslog] qt-faststart: add validation on ftyp atom size

2018-06-13 Thread erankor
ffmpeg | branch: master | erankor  | Wed Jun 13 
11:48:20 2018 +0300| [ee09ffbfd2f744e796d6289523f396d830c025a3] | committer: 
Michael Niedermayer

qt-faststart: add validation on ftyp atom size

avoid trying to allocate an unreasonably sized buffer on corrupt files

Signed-off-by: Michael Niedermayer 

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

 tools/qt-faststart.c | 6 ++
 1 file changed, 6 insertions(+)

diff --git a/tools/qt-faststart.c b/tools/qt-faststart.c
index d0ae7245f3..9446c11f80 100644
--- a/tools/qt-faststart.c
+++ b/tools/qt-faststart.c
@@ -84,6 +84,7 @@
 
 #define ATOM_PREAMBLE_SIZE8
 #define COPY_BUFFER_SIZE   33554432
+#define MAX_FTYP_ATOM_SIZE 1048576
 
 int main(int argc, char *argv[])
 {
@@ -133,6 +134,11 @@ int main(int argc, char *argv[])
 
 /* keep ftyp atom */
 if (atom_type == FTYP_ATOM) {
+if (atom_size > MAX_FTYP_ATOM_SIZE) {
+printf("ftyp atom size %"PRIu64" too big\n",
+   atom_size);
+goto error_out;
+}
 ftyp_atom_size = atom_size;
 free(ftyp_atom);
 ftyp_atom = malloc(ftyp_atom_size);

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


[FFmpeg-cvslog] qt-faststart: add fate test for stco overflow

2018-06-13 Thread erankor
ffmpeg | branch: master | erankor  | Mon Jun 11 
14:45:11 2018 +0300| [c5e6c0b5f680bbcaa7a172b6b241f5a920df983a] | committer: 
Michael Niedermayer

qt-faststart: add fate test for stco overflow

verify that the stco atom is upgraded to co64 when the addition of moov
size to the offsets results in an overflow

Signed-off-by: Michael Niedermayer 

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

 tests/Makefile | 4 +++-
 tests/fate/mov.mak | 9 -
 2 files changed, 11 insertions(+), 2 deletions(-)

diff --git a/tests/Makefile b/tests/Makefile
index 98d7b6d608..409d88a9f1 100644
--- a/tests/Makefile
+++ b/tests/Makefile
@@ -182,7 +182,7 @@ FATE-$(CONFIG_FFPROBE) += $(FATE_FFPROBE)
 
 FATE_SAMPLES_AVCONV   += $(FATE_SAMPLES_AVCONV-yes)
 FATE_SAMPLES_FFMPEG   += $(FATE_SAMPLES_FFMPEG-yes)
-FATE_EXTERN-$(CONFIG_FFMPEG)  += $(FATE_SAMPLES_AVCONV) $(FATE_SAMPLES_FFMPEG) 
$(FATE_SAMPLES_FFPROBE)
+FATE_EXTERN-$(CONFIG_FFMPEG)  += $(FATE_SAMPLES_AVCONV) $(FATE_SAMPLES_FFMPEG) 
$(FATE_SAMPLES_FFPROBE) $(FATE_SAMPLES_FASTSTART)
 FATE_EXTERN += $(FATE_EXTERN-yes)
 
 FATE += $(FATE-yes)
@@ -194,6 +194,8 @@ $(FATE_FFMPEG) $(FATE_SAMPLES_AVCONV) 
$(FATE_SAMPLES_FFMPEG): ffmpeg$(PROGSSUF)$
 
 $(FATE_FFPROBE) $(FATE_SAMPLES_FFPROBE): ffprobe$(PROGSSUF)$(EXESUF)
 
+$(FATE_SAMPLES_FASTSTART): tools/qt-faststart$(PROGSSUF)$(EXESUF)
+
 ifdef SAMPLES
 FATE += $(FATE_FULL) $(FATE_FULL-yes)
 FATE += $(FATE_EXTERN)
diff --git a/tests/fate/mov.mak b/tests/fate/mov.mak
index 960b1867dd..b9c1ad9d3a 100644
--- a/tests/fate/mov.mak
+++ b/tests/fate/mov.mak
@@ -28,10 +28,13 @@ FATE_MOV_FFPROBE = fate-mov-neg-firstpts-discard \
fate-mov-guess-delay-2 \
fate-mov-guess-delay-3 \
 
+FATE_MOV_FASTSTART = fate-mov-faststart-4gb-overflow \
+
 FATE_SAMPLES_AVCONV += $(FATE_MOV)
 FATE_SAMPLES_FFPROBE += $(FATE_MOV_FFPROBE)
+FATE_SAMPLES_FASTSTART += $(FATE_MOV_FASTSTART)
 
-fate-mov: $(FATE_MOV) $(FATE_MOV_FFPROBE)
+fate-mov: $(FATE_MOV) $(FATE_MOV_FFPROBE) $(FATE_MOV_FASTSTART)
 
 # Make sure we handle edit lists correctly in normal cases.
 fate-mov-1elist-noctts: CMD = framemd5 -i 
$(TARGET_SAMPLES)/mov/mov-1elist-noctts.mov
@@ -109,3 +112,7 @@ fate-mov-gpmf-remux: REF = 8f48e435ee1f6b7e173ea756141eabf3
 fate-mov-guess-delay-1: CMD = run ffprobe$(PROGSSUF)$(EXESUF) -show_entries 
stream=has_b_frames -select_streams v 
$(TARGET_SAMPLES)/h264/h264_3bf_nopyramid_nobsrestriction.mp4
 fate-mov-guess-delay-2: CMD = run ffprobe$(PROGSSUF)$(EXESUF) -show_entries 
stream=has_b_frames -select_streams v 
$(TARGET_SAMPLES)/h264/h264_3bf_pyramid_nobsrestriction.mp4
 fate-mov-guess-delay-3: CMD = run ffprobe$(PROGSSUF)$(EXESUF) -show_entries 
stream=has_b_frames -select_streams v 
$(TARGET_SAMPLES)/h264/h264_4bf_pyramid_nobsrestriction.mp4
+
+fate-mov-faststart-4gb-overflow: CMD = run 
tools/qt-faststart$(PROGSSUF)$(EXESUF) 
$(TARGET_SAMPLES)/mov/faststart-4gb-overflow.mov 
faststart-4gb-overflow-output.mov > /dev/null ; md5sum 
faststart-4gb-overflow-output.mov | cut -d " " -f1 ; rm 
faststart-4gb-overflow-output.mov
+fate-mov-faststart-4gb-overflow: CMP = oneline
+fate-mov-faststart-4gb-overflow: REF = bc875921f151871e787c4b4023269b29

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


[FFmpeg-cvslog] qt-faststart - stco offset bug fix

2018-06-13 Thread erankor
ffmpeg | branch: master | erankor  | Fri Jun  1 
09:55:45 2018 +0300| [dc16c9dd90593ffc3642d4a531b73ae6ea836a97] | committer: 
Michael Niedermayer

qt-faststart - stco offset bug fix

when the last offsets in the stco atom are close to 4GB, the addition of
the moov atom size can overflow, causing corruption near the end of the
mp4 file.
this patch upgrades all stco atoms to co64 when such an edge case is
detected. in order to accomplish this, the implementation was changed to
walk the atom tree, instead of searching for the strings 'stco'/'co64'.
this was required since when an stco atom is changed to co64, its size
changes, and the sizes of all containing atoms (moov, trak, etc.) have
to be updated as well.

Signed-off-by: Michael Niedermayer 

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

 tools/qt-faststart.c | 400 ---
 1 file changed, 345 insertions(+), 55 deletions(-)

diff --git a/tools/qt-faststart.c b/tools/qt-faststart.c
index 9446c11f80..07813ae35c 100644
--- a/tools/qt-faststart.c
+++ b/tools/qt-faststart.c
@@ -28,6 +28,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #ifdef __MINGW32__
 #undef fseeko
@@ -43,8 +44,6 @@
 
 #define MIN(a,b) ((a) > (b) ? (b) : (a))
 
-#define BE_16(x) uint8_t*)(x))[0] <<  8) | ((uint8_t*)(x))[1])
-
 #define BE_32(x) (((uint32_t)(((uint8_t*)(x))[0]) << 24) |  \
  (((uint8_t*)(x))[1]  << 16) |  \
  (((uint8_t*)(x))[2]  <<  8) |  \
@@ -59,6 +58,18 @@
   ((uint64_t)(((uint8_t*)(x))[6]) <<  8) |  \
   ((uint64_t)( (uint8_t*)(x))[7]))
 
+#define AV_WB32(p, val){\
+((uint8_t*)(p))[0] = ((val) >> 24) & 0xff;  \
+((uint8_t*)(p))[1] = ((val) >> 16) & 0xff;  \
+((uint8_t*)(p))[2] = ((val) >> 8) & 0xff;   \
+((uint8_t*)(p))[3] = (val) & 0xff;  \
+}
+
+#define AV_WB64(p, val){\
+AV_WB32(p, (val) >> 32) \
+AV_WB32(p + 4, val) \
+}
+
 #define BE_FOURCC(ch0, ch1, ch2, ch3)   \
 ( (uint32_t)(unsigned char)(ch3)|   \
  ((uint32_t)(unsigned char)(ch2) <<  8) |   \
@@ -79,6 +90,10 @@
 #define UUID_ATOM QT_ATOM('u', 'u', 'i', 'd')
 
 #define CMOV_ATOM QT_ATOM('c', 'm', 'o', 'v')
+#define TRAK_ATOM QT_ATOM('t', 'r', 'a', 'k')
+#define MDIA_ATOM QT_ATOM('m', 'd', 'i', 'a')
+#define MINF_ATOM QT_ATOM('m', 'i', 'n', 'f')
+#define STBL_ATOM QT_ATOM('s', 't', 'b', 'l')
 #define STCO_ATOM QT_ATOM('s', 't', 'c', 'o')
 #define CO64_ATOM QT_ATOM('c', 'o', '6', '4')
 
@@ -86,6 +101,332 @@
 #define COPY_BUFFER_SIZE   33554432
 #define MAX_FTYP_ATOM_SIZE 1048576
 
+typedef struct {
+uint32_t type;
+uint32_t header_size;
+uint64_t size;
+unsigned char *data;
+} atom_t;
+
+typedef struct {
+uint64_t moov_atom_size;
+uint64_t stco_offset_count;
+uint64_t stco_data_size;
+int stco_overflow;
+uint32_t depth;
+} update_chunk_offsets_context_t;
+
+typedef struct {
+unsigned char *dest;
+uint64_t original_moov_size;
+uint64_t new_moov_size;
+} upgrade_stco_context_t;
+
+typedef int (*parse_atoms_callback_t)(void *context, atom_t *atom);
+
+static int parse_atoms(
+unsigned char *buf,
+uint64_t size,
+parse_atoms_callback_t callback,
+void *context)
+{
+unsigned char *pos = buf;
+unsigned char *end = pos + size;
+atom_t atom;
+int ret;
+
+while (end - pos >= ATOM_PREAMBLE_SIZE) {
+atom.size = BE_32(pos);
+atom.type = BE_32(pos + 4);
+pos += ATOM_PREAMBLE_SIZE;
+atom.header_size = ATOM_PREAMBLE_SIZE;
+
+switch (atom.size) {
+case 1:
+if (end - pos < 8) {
+printf("not enough room for 64 bit atom size\n");
+return -1;
+}
+
+atom.size = BE_64(pos);
+pos += 8;
+atom.header_size = ATOM_PREAMBLE_SIZE + 8;
+break;
+
+case 0:
+atom.size = ATOM_PREAMBLE_SIZE + end - pos;
+break;
+}
+
+if (atom.size < atom.header_size) {
+printf("atom size %"PRIu64" too small\n", atom.size);
+return -1;
+}
+
+atom.size -= atom.header_size;
+
+if (atom.size > end - pos) {
+printf("atom size %"PRIu64" too big\n", atom.size);
+return -1;
+}
+
+atom.data = pos;
+ret = callback(context, );
+if (ret < 0) {
+return ret;
+}
+
+pos += atom.size;
+}
+
+return 0;
+}
+
+static int update_stco_offsets(update_chunk_offsets_context_t *context, atom_t 
*atom)
+{
+uint32_t current_offset;
+uint32_t offset_count;
+unsigned char *pos;
+unsigned char *end;
+
+printf(" patching stco atom...\n");
+if (atom->size < 8) {
+printf("stco atom size %"PRIu64" too 

[FFmpeg-cvslog] avcodec/mpeg4videodec: Clear bits_per_raw_sample if it has originated from a previous instance

2018-06-13 Thread Michael Niedermayer
ffmpeg | branch: master | Michael Niedermayer  | Sat 
Jun  9 22:25:38 2018 +0200| [2fc108f60f98cd00813418a8754a46476b404a3c] | 
committer: Michael Niedermayer

avcodec/mpeg4videodec: Clear bits_per_raw_sample if it has originated from a 
previous instance

Fixes: assertion failure
Fixes: ffmpeg_crash_5.avi

Found-by: Thuan Pham , Marcel Böhme, Andrew Santosa 
and Alexandru Razvan Caciulescu with AFLSmart
Signed-off-by: Michael Niedermayer 

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

 libavcodec/mpeg4videodec.c | 6 ++
 1 file changed, 6 insertions(+)

diff --git a/libavcodec/mpeg4videodec.c b/libavcodec/mpeg4videodec.c
index 51b58fac02..d0ebaac6e8 100644
--- a/libavcodec/mpeg4videodec.c
+++ b/libavcodec/mpeg4videodec.c
@@ -3109,6 +3109,12 @@ int ff_mpeg4_decode_picture_header(Mpeg4DecContext *ctx, 
GetBitContext *gb)
 /* search next start code */
 align_get_bits(gb);
 
+// If we have not switched to studio profile than we also did not switch 
bps
+// that means something else (like a previous instance) outside set bps 
which
+// would be inconsistant with the currect state, thus reset it
+if (!s->studio_profile && s->avctx->bits_per_raw_sample != 8)
+s->avctx->bits_per_raw_sample = 0;
+
 if (s->codec_tag == AV_RL32("WV1F") && show_bits(gb, 24) == 0x575630) {
 skip_bits(gb, 24);
 if (get_bits(gb, 8) == 0xF0)

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


[FFmpeg-cvslog] doc/devices: order alphabetically and add missing v4l2 outdev

2018-06-13 Thread Lou Logan
ffmpeg | branch: master | Lou Logan  | Wed Jun 13 11:21:12 2018 
-0800| [30af29a712b820e8e28c4963fab0160128c23d3d] | committer: Lou Logan

doc/devices: order alphabetically and add missing v4l2 outdev

Signed-off-by: Lou Logan 

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

 doc/indevs.texi  | 221 +++
 doc/outdevs.texi |  62 
 2 files changed, 143 insertions(+), 140 deletions(-)

diff --git a/doc/indevs.texi b/doc/indevs.texi
index 632d1e4743..5d4c02c597 100644
--- a/doc/indevs.texi
+++ b/doc/indevs.texi
@@ -408,116 +408,6 @@ ffmpeg -channels 16 -format_code Hi50 -f decklink -i 
'UltraStudio Mini Recorder'
 
 @end itemize
 
-@section kmsgrab
-
-KMS video input device.
-
-Captures the KMS scanout framebuffer associated with a specified CRTC or plane 
as a
-DRM object that can be passed to other hardware functions.
-
-Requires either DRM master or CAP_SYS_ADMIN to run.
-
-If you don't understand what all of that means, you probably don't want this.  
Look at
-@option{x11grab} instead.
-
-@subsection Options
-
-@table @option
-
-@item device
-DRM device to capture on.  Defaults to @option{/dev/dri/card0}.
-
-@item format
-Pixel format of the framebuffer.  Defaults to @option{bgr0}.
-
-@item format_modifier
-Format modifier to signal on output frames.  This is necessary to import 
correctly into
-some APIs, but can't be autodetected.  See the libdrm documentation for 
possible values.
-
-@item crtc_id
-KMS CRTC ID to define the capture source.  The first active plane on the given 
CRTC
-will be used.
-
-@item plane_id
-KMS plane ID to define the capture source.  Defaults to the first active plane 
found if
-neither @option{crtc_id} nor @option{plane_id} are specified.
-
-@item framerate
-Framerate to capture at.  This is not synchronised to any page flipping or 
framebuffer
-changes - it just defines the interval at which the framebuffer is sampled.  
Sampling
-faster than the framebuffer update rate will generate independent frames with 
the same
-content.  Defaults to @code{30}.
-
-@end table
-
-@subsection Examples
-
-@itemize
-
-@item
-Capture from the first active plane, download the result to normal frames and 
encode.
-This will only work if the framebuffer is both linear and mappable - if not, 
the result
-may be scrambled or fail to download.
-@example
-ffmpeg -f kmsgrab -i - -vf 'hwdownload,format=bgr0' output.mp4
-@end example
-
-@item
-Capture from CRTC ID 42 at 60fps, map the result to VAAPI, convert to NV12 and 
encode as H.264.
-@example
-ffmpeg -crtc_id 42 -framerate 60 -f kmsgrab -i - -vf 
'hwmap=derive_device=vaapi,scale_vaapi=w=1920:h=1080:format=nv12' -c:v 
h264_vaapi output.mp4
-@end example
-
-@end itemize
-
-@section libndi_newtek
-
-The libndi_newtek input device provides capture capabilities for using NDI 
(Network
-Device Interface, standard created by NewTek).
-
-Input filename is a NDI source name that could be found by sending 
-find_sources 1
-to command line - it has no specific syntax but human-readable formatted.
-
-To enable this input device, you need the NDI SDK and you
-need to configure with the appropriate @code{--extra-cflags}
-and @code{--extra-ldflags}.
-
-@subsection Options
-
-@table @option
-
-@item find_sources
-If set to @option{true}, print a list of found/available NDI sources and exit.
-Defaults to @option{false}.
-
-@item wait_sources
-Override time to wait until the number of online sources have changed.
-Defaults to @option{0.5}.
-
-@item allow_video_fields
-When this flag is @option{false}, all video that you receive will be 
progressive.
-Defaults to @option{true}.
-
-@end table
-
-@subsection Examples
-
-@itemize
-
-@item
-List input devices:
-@example
-ffmpeg -f libndi_newtek -find_sources 1 -i dummy
-@end example
-
-@item
-Restream to NDI:
-@example
-ffmpeg -f libndi_newtek -i "DEV-5.INTERNAL.M1STEREO.TV (NDI_SOURCE_NAME_1)" -f 
libndi_newtek -y NDI_SOURCE_NAME_2
-@end example
-
-@end itemize
-
 @section dshow
 
 Windows DirectShow input device.
@@ -945,6 +835,68 @@ Set the number of channels. Default is 2.
 
 @end table
 
+@section kmsgrab
+
+KMS video input device.
+
+Captures the KMS scanout framebuffer associated with a specified CRTC or plane 
as a
+DRM object that can be passed to other hardware functions.
+
+Requires either DRM master or CAP_SYS_ADMIN to run.
+
+If you don't understand what all of that means, you probably don't want this.  
Look at
+@option{x11grab} instead.
+
+@subsection Options
+
+@table @option
+
+@item device
+DRM device to capture on.  Defaults to @option{/dev/dri/card0}.
+
+@item format
+Pixel format of the framebuffer.  Defaults to @option{bgr0}.
+
+@item format_modifier
+Format modifier to signal on output frames.  This is necessary to import 
correctly into
+some APIs, but can't be autodetected.  See the libdrm documentation for 
possible values.
+
+@item crtc_id
+KMS CRTC ID to define the 

[FFmpeg-cvslog] avformat/movenc: properly handle cover image codecs

2018-06-13 Thread Timo Teräs
ffmpeg | branch: master | Timo Teräs  | Fri Jun  1 02:24:39 
2018 +0300| [12205d2c896b7edbc929d4886e7bfda4b53538e5] | committer: Michael 
Niedermayer

avformat/movenc: properly handle cover image codecs

Find codec tag for attached images using appropriate list of
supported image formats.

This fixes writing the cover image to m4v/m4a and other container
formats that do not allow these codecs as a track.

Signed-off-by: Timo Teräs 
Signed-off-by: Michael Niedermayer 

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

 libavformat/movenc.c | 30 --
 1 file changed, 12 insertions(+), 18 deletions(-)

diff --git a/libavformat/movenc.c b/libavformat/movenc.c
index 7e616e866f..4ba90135df 100644
--- a/libavformat/movenc.c
+++ b/libavformat/movenc.c
@@ -1557,10 +1557,20 @@ static int mov_get_codec_tag(AVFormatContext *s, 
MOVTrack *track)
 return tag;
 }
 
+static const AVCodecTag codec_cover_image_tags[] = {
+{ AV_CODEC_ID_MJPEG,  0xD },
+{ AV_CODEC_ID_PNG,0xE },
+{ AV_CODEC_ID_BMP,0x1B },
+{ AV_CODEC_ID_NONE, 0 },
+};
+
 static int mov_find_codec_tag(AVFormatContext *s, MOVTrack *track)
 {
 int tag;
 
+if (track->st->disposition & AV_DISPOSITION_ATTACHED_PIC)
+return ff_codec_get_tag(codec_cover_image_tags, track->par->codec_id);
+
 if (track->mode == MODE_MP4 || track->mode == MODE_PSP)
 tag = track->par->codec_tag;
 else if (track->mode == MODE_ISM)
@@ -3429,7 +3439,7 @@ static int mov_write_covr(AVIOContext *pb, 
AVFormatContext *s)
 {
 MOVMuxContext *mov = s->priv_data;
 int64_t pos = 0;
-int i, type;
+int i;
 
 for (i = 0; i < s->nb_streams; i++) {
 MOVTrack *trk = >tracks[i];
@@ -3439,22 +3449,6 @@ static int mov_write_covr(AVIOContext *pb, 
AVFormatContext *s)
 trk->cover_image.size <= 0)
 continue;
 
-switch (st->codecpar->codec_id) {
-case AV_CODEC_ID_MJPEG:
-type = 0xD;
-break;
-case AV_CODEC_ID_PNG:
-type = 0xE;
-break;
-case AV_CODEC_ID_BMP:
-type = 0x1B;
-break;
-default:
-av_log(s, AV_LOG_ERROR, "unsupported codec_id (0x%x) for cover",
-   st->codecpar->codec_id);
-continue;
-}
-
 if (!pos) {
 pos = avio_tell(pb);
 avio_wb32(pb, 0);
@@ -3462,7 +3456,7 @@ static int mov_write_covr(AVIOContext *pb, 
AVFormatContext *s)
 }
 avio_wb32(pb, 16 + trk->cover_image.size);
 ffio_wfourcc(pb, "data");
-avio_wb32(pb, type);
+avio_wb32(pb, trk->tag);
 avio_wb32(pb , 0);
 avio_write(pb, trk->cover_image.data, trk->cover_image.size);
 }

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


[FFmpeg-cvslog] avformat/movenc: fix recognization of cover image streams

2018-06-13 Thread Timo Teräs
ffmpeg | branch: master | Timo Teräs  | Mon Jun  4 17:36:19 
2018 +0300| [2223811b015926fec68473a08016d40cea0989b2] | committer: Michael 
Niedermayer

avformat/movenc: fix recognization of cover image streams

For chapter images, the mov demux produces streams with disposition set
to attached_pic+timed_thumbnails. This patch fixes to properly recognize
streams that should be encoded as cover image (ones with only and only
attached_pic disposition set).

Signed-off-by: Timo Teräs 
Signed-off-by: Michael Niedermayer 

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

 libavformat/movenc.c | 36 ++--
 1 file changed, 18 insertions(+), 18 deletions(-)

diff --git a/libavformat/movenc.c b/libavformat/movenc.c
index 4ba90135df..db266b7765 100644
--- a/libavformat/movenc.c
+++ b/libavformat/movenc.c
@@ -143,10 +143,17 @@ static int co64_required(const MOVTrack *track)
 return 0;
 }
 
+static int is_cover_image(const AVStream *st)
+{
+/* Eg. AV_DISPOSITION_ATTACHED_PIC | AV_DISPOSITION_TIMED_THUMBNAILS
+ * is encoded as sparse video track */
+return st && st->disposition == AV_DISPOSITION_ATTACHED_PIC;
+}
+
 static int rtp_hinting_needed(const AVStream *st)
 {
 /* Add hint tracks for each real audio and video stream */
-if (st->disposition & AV_DISPOSITION_ATTACHED_PIC)
+if (is_cover_image(st))
 return 0;
 return st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO ||
st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO;
@@ -1568,7 +1575,7 @@ static int mov_find_codec_tag(AVFormatContext *s, 
MOVTrack *track)
 {
 int tag;
 
-if (track->st->disposition & AV_DISPOSITION_ATTACHED_PIC)
+if (is_cover_image(track->st))
 return ff_codec_get_tag(codec_cover_image_tags, track->par->codec_id);
 
 if (track->mode == MODE_MP4 || track->mode == MODE_PSP)
@@ -3443,10 +3450,8 @@ static int mov_write_covr(AVIOContext *pb, 
AVFormatContext *s)
 
 for (i = 0; i < s->nb_streams; i++) {
 MOVTrack *trk = >tracks[i];
-AVStream *st = s->streams[i];
 
-if (!(st->disposition & AV_DISPOSITION_ATTACHED_PIC) ||
-trk->cover_image.size <= 0)
+if (!is_cover_image(trk->st) || trk->cover_image.size <= 0)
 continue;
 
 if (!pos) {
@@ -3989,15 +3994,13 @@ static int mov_write_isml_manifest(AVIOContext *pb, 
MOVMuxContext *mov, AVFormat
 AVStream *st = track->st;
 AVDictionaryEntry *lang = av_dict_get(st->metadata, "language", 
NULL,0);
 
-if (track->par->codec_type == AVMEDIA_TYPE_VIDEO) {
+if (track->par->codec_type == AVMEDIA_TYPE_VIDEO && 
!is_cover_image(st)) {
 type = "video";
 } else if (track->par->codec_type == AVMEDIA_TYPE_AUDIO) {
 type = "audio";
 } else {
 continue;
 }
-if (st->disposition & AV_DISPOSITION_ATTACHED_PIC)
-continue;
 
 props = (AVCPBProperties*)av_stream_get_side_data(track->st, 
AV_PKT_DATA_CPB_PROPERTIES, NULL);
 
@@ -4657,7 +4660,7 @@ static int mov_write_ftyp_tag(AVIOContext *pb, 
AVFormatContext *s)
 
 for (i = 0; i < s->nb_streams; i++) {
 AVStream *st = s->streams[i];
-if (st->disposition & AV_DISPOSITION_ATTACHED_PIC)
+if (is_cover_image(st))
 continue;
 if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO)
 has_video = 1;
@@ -4807,7 +4810,7 @@ static int mov_write_identification(AVIOContext *pb, 
AVFormatContext *s)
 int video_streams_nb = 0, audio_streams_nb = 0, other_streams_nb = 0;
 for (i = 0; i < s->nb_streams; i++) {
 AVStream *st = s->streams[i];
-if (st->disposition & AV_DISPOSITION_ATTACHED_PIC)
+if (is_cover_image(st))
 continue;
 if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO)
 video_streams_nb++;
@@ -4998,8 +5001,7 @@ static int mov_flush_fragment(AVFormatContext *s, int 
force)
 int buf_size, moov_size;
 
 for (i = 0; i < mov->nb_streams; i++)
-if (!mov->tracks[i].entry &&
-(i >= s->nb_streams || !(s->streams[i]->disposition & 
AV_DISPOSITION_ATTACHED_PIC)))
+if (!mov->tracks[i].entry && !is_cover_image(mov->tracks[i].st))
 break;
 /* Don't write the initial moov unless all tracks have data */
 if (i < mov->nb_streams && !force)
@@ -5581,21 +5583,19 @@ static int mov_write_packet(AVFormatContext *s, 
AVPacket *pkt)
 {
 MOVMuxContext *mov = s->priv_data;
 MOVTrack *trk;
-AVStream *st;
 
 if (!pkt) {
 mov_flush_fragment(s, 1);
 return 1;
 }
 
-st = s->streams[pkt->stream_index];
 trk = >tracks[pkt->stream_index];
 
-if (st->disposition & AV_DISPOSITION_ATTACHED_PIC) {
+if (is_cover_image(trk->st)) {
 int ret;
 
-if (st->nb_frames >= 1) {
-if 

[FFmpeg-cvslog] avformat/mov: Add check for per-sample IV size.

2018-06-13 Thread Jacob Trimble
ffmpeg | branch: master | Jacob Trimble  | 
Tue Jun 12 14:26:20 2018 -0700| [4aba45ca1fece6be425d168c05aa3a7f9f05da36] | 
committer: Michael Niedermayer

avformat/mov: Add check for per-sample IV size.

Found by Chrome's ClusterFuzz: http://crbug.com/849062.

Signed-off-by: Jacob Trimble 
Signed-off-by: Michael Niedermayer 

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

 libavformat/mov.c | 9 +++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/libavformat/mov.c b/libavformat/mov.c
index 2fca025889..5d9ffa69a3 100644
--- a/libavformat/mov.c
+++ b/libavformat/mov.c
@@ -6273,8 +6273,13 @@ static int mov_read_tenc(MOVContext *c, AVIOContext *pb, 
MOVAtom atom)
 return AVERROR(ENOMEM);
 }
 sc->cenc.per_sample_iv_size = avio_r8(pb);
+if (sc->cenc.per_sample_iv_size != 0 && sc->cenc.per_sample_iv_size != 8 &&
+sc->cenc.per_sample_iv_size != 16) {
+av_log(c->fc, AV_LOG_ERROR, "invalid per-sample IV size value\n");
+return AVERROR_INVALIDDATA;
+}
 if (avio_read(pb, sc->cenc.default_encrypted_sample->key_id, 16) != 16) {
-av_log(c->fc, AV_LOG_ERROR, "failed to read the default key ID");
+av_log(c->fc, AV_LOG_ERROR, "failed to read the default key ID\n");
 return AVERROR_INVALIDDATA;
 }
 
@@ -6286,7 +6291,7 @@ static int mov_read_tenc(MOVContext *c, AVIOContext *pb, 
MOVAtom atom)
 }
 
 if (avio_read(pb, sc->cenc.default_encrypted_sample->iv, iv_size) != 
iv_size) {
-av_log(c->fc, AV_LOG_ERROR, "failed to read the default IV");
+av_log(c->fc, AV_LOG_ERROR, "failed to read the default IV\n");
 return AVERROR_INVALIDDATA;
 }
 }

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


[FFmpeg-cvslog] configure: The eac3_core bitstream filter needs the ac3 parser.

2018-06-13 Thread Carl Eugen Hoyos
ffmpeg | branch: master | Carl Eugen Hoyos  | Tue Jun 12 
10:02:44 2018 +0200| [9461e7d3a598e78811146b730db68d3a5b2532b0] | committer: 
Carl Eugen Hoyos

configure: The eac3_core bitstream filter needs the ac3 parser.

Fixes linking with "--disable-everything --enable-bsf=eac3_core".

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

 configure | 1 +
 1 file changed, 1 insertion(+)

diff --git a/configure b/configure
index 473be31d7f..994d8006e0 100755
--- a/configure
+++ b/configure
@@ -2992,6 +2992,7 @@ vc1_parser_select="vc1dsp"
 
 # bitstream_filters
 aac_adtstoasc_bsf_select="adts_header"
+eac3_core_bsf_select="ac3_parser"
 filter_units_bsf_select="cbs"
 h264_metadata_bsf_deps="const_nan"
 h264_metadata_bsf_select="cbs_h264"

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