Commit Graph

487 Commits

Author SHA1 Message Date
Matthew Heaney 818ebe930f avformat/matroskadec: add WebVTT support
WebM files now support inband text tracks, as described in the
following specification:

http://wiki.webmproject.org/webm-metadata/temporal-metadata/webvtt-in-webm

The Matroska demuxer now detects the presence of WebVTT tracks,
synthesizing WebVTT packets (having codec id AV_CODEC_ID_WEBVTT) and
pushing them downstream in the normal way.

Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
2013-08-19 22:34:57 +02:00
Michael Niedermayer 338f8b2eaf avformat/matroskadec: check out_samplerate before using it in av_rescale()
Prevent assertion failure with damaged input

Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
2013-08-18 02:34:48 +02:00
James Almer af248fa117 matroskadec: Improve TTA duration calculation
Calculate the duration as accurately as possible to improve decoding of samples
where the last frame is smaller than the rest.

Example:
Take lossless-audio/luckynight-partial.tak from the FATE suit and convert it
to TTA muxed into matroska:

ffmpeg -i $(SAMPLES)/lossless-audio/luckynight-partial.tak -c:a tta lucky.mka

The framemd5 output for lucky.mka without this patch:

0,          0,          0,    46080,   184320, 7c3751ddd571d2903c3cf0ab4b3e3d0a
0,      46080,      46080,    46080,   184320, 6b70c782ba1da3f933fde2daa4f96b73
0,      92160,      92160,    46080,   184320, dcf70d89c54b9a4f0b302d4ec4fb302d
0,     138240,     138240,    46080,   184320, 48713ca38b388d2ea4abf5b86ed1226f
0,     184320,     184320,    46080,   184320, 12188a23648e7ebfb07cd6fe9197b2ea
0,     230400,     230400,    46080,   184320, 49653ab8186a5d4a044ed284671a26e0
0,     276480,     276480,    46080,   184320, 5e82c6a7fe58c7ea612c03a0a2927dd4
0,     322560,     322560,    46080,   184320, 83dc449dbd9eab5f2e8ad2b4403d6a21
0,     368640,     368640,    46080,   184320, bdd6b92c23d30978d4e802d305b0fc49

With this patch:

0,          0,          0,    46080,   184320, 7c3751ddd571d2903c3cf0ab4b3e3d0a
0,      46080,      46080,    46080,   184320, 6b70c782ba1da3f933fde2daa4f96b73
0,      92160,      92160,    46080,   184320, dcf70d89c54b9a4f0b302d4ec4fb302d
0,     138240,     138240,    46080,   184320, 48713ca38b388d2ea4abf5b86ed1226f
0,     184320,     184320,    46080,   184320, 12188a23648e7ebfb07cd6fe9197b2ea
0,     230400,     230400,    46080,   184320, 49653ab8186a5d4a044ed284671a26e0
0,     276480,     276480,    46080,   184320, 5e82c6a7fe58c7ea612c03a0a2927dd4
0,     322560,     322560,    46080,   184320, 83dc449dbd9eab5f2e8ad2b4403d6a21
0,     368640,     368640,    46080,   184320, bdd6b92c23d30978d4e802d305b0fc49
0,     414720,     414720,     4230,    16920, b50b440c5bbcecb8e9fbece643447593

The duration without this patch was calculated as 418950000000, which is bigger
than uint32_t and as such stored as 2338172288.
With this patch the duration is correctly calculated as 418950.

Signed-off-by: James Almer <jamrial@gmail.com>
Approved-by: Paul B Mahol <onemda@gmail.com>
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
2013-08-18 02:34:39 +02:00
Michael Niedermayer 62cf5c114a avformat/matroskadec: make sipr_bit_rate static const
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
2013-08-04 21:18:49 +02:00
Michael Niedermayer 6158a3bcdf avformat/matroskadec: Detect conflicting sample rate/default_duration
Fixes Ticket2508

Thanks-to: Moritz Bunkus
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
2013-07-15 17:13:45 +02:00
Michael Niedermayer 045e371cf1 Merge commit '8835c554ff506992c47f6e347c74216ae073f0fa'
* commit '8835c554ff506992c47f6e347c74216ae073f0fa':
  matroskadec: introduce resync function.

Conflicts:
	libavformat/matroskadec.c

Merged-by: Michael Niedermayer <michaelni@gmx.at>
2013-06-11 09:16:13 +02:00
Sean McGovern 8835c554ff matroskadec: introduce resync function.
This allows handling matroska files with errors.
Fixes test4.mkv and test7.mkv from the official Matroska test suite,
and by extension Bugzilla #62.

Based on a patch by Reimar Doffinger <Reimar.Doeffinger@gmx.de>

Signed-off-by: Anton Khirnov <anton@khirnov.net>
2013-06-10 20:51:35 +02:00
Paul B Mahol 9644fc95be matroskadec: move ALAC extradata creation bellow AAC one
Signed-off-by: Paul B Mahol <onemda@gmail.com>
2013-06-08 17:39:51 +00:00
Michael Niedermayer 2fe4b6210c matroskadec: fix memleak of pkt_data
Fixes: CID1026767
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
2013-06-03 16:08:38 +02:00
Michael Niedermayer 0722b4d08c matroskadec: favor av_freep()
av_freep() is safer as it zeros the pointer

Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
2013-06-03 16:05:09 +02:00
Michael Niedermayer 3ed3aaab32 Merge remote-tracking branch 'qatar/master'
* qatar/master:
  smacker: assign video frame PTS
  matroskadec: export full wavpack blocks.

Conflicts:
	libavcodec/wavpack.c

Merged-by: Michael Niedermayer <michaelni@gmx.at>
2013-05-28 11:58:46 +02:00
Anton Khirnov 9b6f47c448 matroskadec: export full wavpack blocks.
This allows us to get rid of demuxer-specific hacks in the decoder and
will allow streamcopy from matroska once we have a wavpack muxer.
2013-05-28 08:14:35 +02:00
Michael Niedermayer 91db8ff203 Merge commit '564b7e0c0095768cd20001b28154d69462be54e7'
* commit '564b7e0c0095768cd20001b28154d69462be54e7':
  matroskadec: silently skip CodecState element.
  smacker: fix off-by-one error in palette expanding code

Conflicts:
	libavformat/smacker.c

Merged-by: Michael Niedermayer <michaelni@gmx.at>
2013-05-28 08:04:02 +02:00
Anton Khirnov 564b7e0c00 matroskadec: silently skip CodecState element.
mkvmerge apparrently uses it for mpeg1/2 video, but it contains the same
information as CodecPrivate, so it can be ignored.
2013-05-27 21:25:53 +02:00
Michael Niedermayer 4758e32a6c matroska_read_seek: Fix used streams for subtitle index compensation
Might fix Ticket1907 (I have no testcase so i cant test)

Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
2013-05-26 13:14:01 +02:00
Michael Niedermayer 729fa55b8f avformat/matroskadec: fix integer overflow
Fixes fate-mkv with ekopath 4

Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
2013-05-19 23:38:01 +02:00
Reimar Döffinger 762d4335ae matroska: set "done" only during resync fail.
Fixes playback of test7.mkv validation test file.

Signed-off-by: Reimar Döffinger <Reimar.Doeffinger@gmx.de>
2013-05-07 05:30:19 +02:00
Michael Niedermayer f083b4c338 Merge commit 'e0f8be6413b6a8d334d6052e610af32935c310af'
* commit 'e0f8be6413b6a8d334d6052e610af32935c310af':
  avformat: Add AVPROBE_SCORE_EXTENSION define and use where appropriate

Conflicts:
	libavformat/ac3dec.c
	libavformat/avformat.h
	libavformat/avs.c
	libavformat/m4vdec.c
	libavformat/mov.c
	libavformat/mp3dec.c
	libavformat/mpeg.c
	libavformat/mpegvideodec.c
	libavformat/psxstr.c
	libavformat/pva.c
	libavformat/utils.c

Merged-by: Michael Niedermayer <michaelni@gmx.at>
2013-05-05 12:31:03 +02:00
Diego Biurrun e0f8be6413 avformat: Add AVPROBE_SCORE_EXTENSION define and use where appropriate 2013-05-04 21:43:06 +02:00
Clément Bœsch 7c1a002c78 subtitles: introduce ASS codec id and use it.
Currently, we have a AV_CODEC_ID_SSA, which matches the way the ASS/SSA
markup is muxed in a standalone .ass/.ssa file. This means the AVPacket
data starts with a "Dialogue:" string, followed by a timing information
(start and end of the event as string) and a trailing CRLF after each
line. One packet can contain several lines. We'll refer to this layout
as "SSA" or "SSA lines".

In matroska, this markup is not stored as such: it has no "Dialogue:"
prefix, it contains a ReadOrder field, the timing information is not in
the payload, and it doesn't contain the trailing CRLF. See [1] for more
info. We'll refer to this layout as "ASS".

Since we have only one common codec for both formats, the matroska
demuxer is constructing an AVPacket following the "SSA lines" format.
This causes several problems, so it was decided to change this into
clean ASS packets.

Some insight about what is changed or unchanged in this commit:

  CODECS
  ------

  - the decoding process still writes "SSA lines" markup inside the ass
    fields of the subtitles rectangles (sub->rects[n]->ass), which is
    still the current common way of representing decoded subtitles
    markup. It is meant to change later.

  - new ASS codec id: AV_CODEC_ID_ASS (which is different from the
    legacy AV_CODEC_ID_SSA)

  - lavc/assdec: the "ass" decoder is renamed into "ssa" (instead of
    "ass") for consistency with the codec id and allows to add a real
    ass decoder. This ass decoder receives clean ASS lines (so it starts
    with a ReadOrder, is followed by the Layer, etc). We make sure this
    is decoded properly in a new ass-line rectangle of the decoded
    subtitles (the ssa decoder OTOH is doing a simple straightforward
    copy). Using the packet timing instead of data string makes sure the
    ass-line now contains the appropriate timing.

  - lavc/assenc: just like the ass decoder, the "ssa" encoder is renamed
    into "ssa" (instead of "ass") for consistency with the codec id, and
    allows to add a real "ass" encoder.

    One important thing about this encoder is that it only supports one
    ass rectangle: we could have put several dialogue events in the
    AVPacket (separated by a \0 for instance) but this would have cause
    trouble for the muxer which needs not only the start time, but also
    the duration: typically, you have merged events with the same start
    time (stored in the AVPacket->pts) but a different duration. At the
    moment, only the matroska do the merge with the SSA-line codec.

    We will need to make sure all the decoders in the future can't add
    more than one rectangle (and only one Dialogue line in it
    obviously).

  FORMATS
  -------

  - lavf/assenc: the .ass/.ssa muxer can take both SSA and ASS packets.
    In the case of ASS packets as input, it adds the timing based on the
    AVPacket pts and duration, and mux it with "Dialogue:", trailing
    CRLF, etc.

  - lavf/assdec: unchanged; it currently still only outputs SSA-lines
    packets.

  - lavf/mkv: the demuxer can now output ASS packets without the need of
    any "SSA-lines" reconstruction hack. It will become the default at
    next libavformat bump, and the SSA support will be dropped from the
    demuxer. The muxer can take ASS packets since it's muxed normally,
    and still supports the old SSA packets. All the SSA support and
    hacks in Matroska code will be dropped at next lavf bump.

[1]: http://www.matroska.org/technical/specs/subtitles/ssa.html
2013-04-18 23:23:59 +02:00
Michael Niedermayer 3b93bea9e3 matroskadec: Check EBML lace sizes.
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
2013-04-04 15:51:04 +02:00
Michael Niedermayer 115c3bc41f matroskadec: Check for overflows in xiph lace decoding
This also detects errors earlier

Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
2013-04-04 15:17:57 +02:00
Michael Niedermayer 14de77d677 matroskadec: fix return code for too long xiph laces
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
2013-04-04 15:13:53 +02:00
Michael Niedermayer e7389ed5d0 Merge commit 'bcc94328980e6c56546792ab08b0756abdce310b'
* commit 'bcc94328980e6c56546792ab08b0756abdce310b':
  opt: check the return values of av_get_token for ENOMEM.
  doc: Fix best_nb_channells typo
  matroska: pass the lace size to the matroska_parse_rm_audio

Conflicts:
	libavformat/matroskadec.c

Merged-by: Michael Niedermayer <michaelni@gmx.at>
2013-04-04 13:00:59 +02:00
Michael Niedermayer 534b292102 Merge commit '8a96df7b70be509dae9ceec82d2c10a20361356d'
* commit '8a96df7b70be509dae9ceec82d2c10a20361356d':
  matroska: fix a corner case in ebml-lace parsing

Merged-by: Michael Niedermayer <michaelni@gmx.at>
2013-04-04 12:46:47 +02:00
Michael Niedermayer f51ce34e5e matroskadec: fix display_width/height = 0 handling
Fixes Ticket2424

Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
2013-04-03 23:45:32 +02:00
Luca Barbato 25a80a931a matroska: pass the lace size to the matroska_parse_rm_audio
Each lace must be independent according to the specification.

Fix heap-buffer-overflow in matroska_parse_block for
corrupted real media in mkv files.

Stricter check than fc43c19a56

CC: libav-stable@libav.org
2013-04-03 12:34:38 +02:00
Luca Barbato 8a96df7b70 matroska: fix a corner case in ebml-lace parsing
Make sure we notice when the lace_size[n] is a negative value.

CC: libav-stable@libav.org
2013-04-03 12:33:15 +02:00
Dale Curtis fc43c19a56 matroska: Update the available size after lace parsing
Fix heap-buffer-overflow in matroska_parse_block for
corrupted real media in mkv files.

CC: libav-stable@libav.org

Signed-off-by: Luca Barbato <lu_zero@gentoo.org>
2013-04-03 12:33:01 +02:00
Dale Curtis 81e85bc95c Fix heap-buffer-overflow in matroska_parse_block
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
2013-03-27 23:51:44 +01:00
Michael Niedermayer ac75e0c755 matroskadec: switch to av_assert
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
2013-03-22 18:04:17 +01:00
Frank Galligan b853103fe0 matroskadec: Add support for parsing Matroska ContentEncKeyID
This patch adds the enums for the ContentEncryption elements.
This patch also adds support for parsing the ContentEncKeyID. The
ContentEncKeyID is then base64 encoded and stored in the stream's
metadata.

Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
2013-03-20 21:29:55 +01:00
Michael Niedermayer fdda9b440c matroska_parse_frame: fix memleak
Fixes CID991856
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
2013-03-19 14:33:47 +01:00
Michael Niedermayer 70c0ae915d matroskadec: avoid integer overflow
Found-by: wm4
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
2013-03-15 13:48:04 +01:00
Luca Barbato 37cb3b180a matroskadec: request a read buffer for the wav header
Solve an infiniloop.

CC: libav-stable@libav.org
2013-03-12 18:58:06 +01:00
Anton Khirnov 85a5bc054c lavf: remove disabled FF_API_R_FRAME_RATE cruft 2013-03-11 18:23:50 +01:00
Michael Niedermayer 2653e12520 Merge commit '1afddbe59e96af75f1c07605afc95615569f388f'
* commit '1afddbe59e96af75f1c07605afc95615569f388f':
  avpacket: use AVBuffer to allow refcounting the packets.

Conflicts:
	libavcodec/avpacket.c
	libavcodec/utils.c
	libavdevice/v4l2.c
	libavformat/avidec.c
	libavformat/flacdec.c
	libavformat/id3v2.c
	libavformat/matroskaenc.c
	libavformat/mux.c
	libavformat/utils.c

Merged-by: Michael Niedermayer <michaelni@gmx.at>
2013-03-08 19:12:03 +01:00
Anton Khirnov 1afddbe59e avpacket: use AVBuffer to allow refcounting the packets.
This will allow us to avoid copying the packets in many cases.

This breaks ABI.
2013-03-08 07:33:45 +01:00
Vignesh Venkatasubramanian 003be0a9c3 Removing network.h from matroskadec.c
Removing accidentally added include file.

Signed-off-by: Vignesh Venkatasubramanian <vigneshv@google.com>
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
2013-02-14 23:59:41 +01:00
Vignesh Venkatasubramanian ce6a8e5947 Adding AlphaMode element to Matroska Parser
Adding support for parsing AlphaMode element in the Track header
and export that information as a metadata tag. This flag indicates
presence of alpha channel data in BlockAdditional element.

Signed-off-by: Vignesh Venkatasubramanian <vigneshv@google.com>
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
2013-02-14 21:34:47 +01:00
Michael Niedermayer a08ebf04b1 matroskadec: simplify additional_id writing code
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
2013-02-14 00:55:25 +01:00
Vignesh Venkatasubramanian 30c5c45b12 Adding support for parsing BlockAdditional
Matroska specification lists support for BlockAdditional element
which is not supported by ffmpeg's matroska parser. This patch
adds grammar definitions for parsing that element (and few other
related elements) and then puts the data in AVPacket.side_data
with new AVPacketSideDataType AV_PKT_DATA_MATROSKA_BLOCKADDITIONAL.

Signed-off-by: Vignesh Venkatasubramanian <vigneshv@google.com>
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
2013-02-14 00:46:28 +01:00
Michael Niedermayer 7c00d853a6 matroskadec: support seek to non keyframes
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
2013-02-07 21:48:48 +01:00
Paul B Mahol dd5689a3bd matroskadec: export codec bits_per_coded_sample
Fixes -codec copy with TTA from matroska to matroska.

Signed-off-by: Paul B Mahol <onemda@gmail.com>
2013-01-24 12:15:12 +00:00
Michael Niedermayer 6fc0648932 Merge commit '7b8c5b263bc680eff5710bee5994de39d47fc15e'
* commit '7b8c5b263bc680eff5710bee5994de39d47fc15e':
  vc1dec: prevent a crash due missing pred_flag parameter
  matroska: Fix use after free

Merged-by: Michael Niedermayer <michaelni@gmx.at>
2013-01-11 13:01:07 +01:00
Dale Curtis ae3d416369 matroska: Fix use after free
Signed-off-by: Dale Curtis <dalecurtis@chromium.org>
Signed-off-by: Luca Barbato <lu_zero@gentoo.org>
2013-01-11 00:12:08 +01:00
Michael Niedermayer d0b450457b matroskadec: fix ffio_init_context() usage
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
2013-01-04 13:01:30 +01:00
Michael Niedermayer 5e1bacf2d4 matroskadec: reset size when freeing data.
Fixes null pointer dereference

Found-by: Mateusz "j00ru" Jurczyk and Gynvael Coldwind
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
2012-12-04 03:50:09 +01:00
Michael Niedermayer 0efcf16a3e replace av_log(0, by av_log(NULL,
The first parameter is a pointer and NULL is more correct

Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
2012-11-23 18:10:02 +01:00
Michael Niedermayer c2ca0163af matroskadec: check h in generic rm packet shuffler
Fixes crash

Found-by: Mateusz "j00ru" Jurczyk and Gynvael Coldwind
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
2012-11-11 01:19:44 +01:00