Commit Graph

499 Commits

Author SHA1 Message Date
James Almer 8c1342e631 avformat/matroskaenc: write updated STREAMINFO metadata for FLAC streams if available
FLAC streams originating from the FLAC encoder send updated and more
complete STREAMINFO metadata as part of the last packet, so write that
to CodecPrivate instead of the incomplete one available in extradata
during init.

Signed-off-by: James Almer <jamrial@gmail.com>
2016-11-20 19:31:32 -03:00
James Almer ee888cfbe7 avformat/matroskaenc: postpone writing the Tracks master
This will allow us to write updated stream information not available
during write_header().

Signed-off-by: James Almer <jamrial@gmail.com>
2016-11-20 19:31:32 -03:00
James Almer 5cb57131d3 avformat/matroskaenc: use display aspect ratio for DisplayWidth and DisplayHeight when possible
This avoids potential rounding errors and guarantees the source aspect
ratio is preserved.
Keep writing pixel values when Stereo 3D Mode is enabled and for WebM,
as the format doesn't support anything else.

This fixes ticket #5743, implementing the suggestion from ticket #5903.

Signed-off-by: James Almer <jamrial@gmail.com>
2016-11-02 17:08:38 -03:00
James Almer bab6b60675 avformat/matroskaenc: support writing Chroma Location elements
Signed-off-by: James Almer <jamrial@gmail.com>
2016-11-02 17:07:04 -03:00
Rodger Combs 1a958f4eb0
lavf/matroskaenc: don't try to modify the header when live-streaming 2016-11-02 01:16:26 -05:00
Rodger Combs be28ce210d
lavf/matroskaenc: fix uninitialized read 2016-11-02 01:16:26 -05:00
Adriano Pallavicino 6089c44a2a Fix build warnings due to misleading indentation
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2016-11-01 17:44:10 +01:00
James Almer eabbc64728 avformat/matroskaenc: fix cue relative position values when CRC32 is enabled
The dynamic buffer does not contain the CRC32 element so calls to avio_tell()
don't take it into account. This resulted in CueRelativePosition values being
six bytes short.
This is a regression since 6724525a15

Instead of adding yet another custom check for CRC32 to fix a size or an offset,
remove the existing ones and reserve the six bytes in the dynamic buffer.

Signed-off-by: James Almer <jamrial@gmail.com>
2016-10-26 16:28:59 -03:00
James Almer cc71fa319f avformat/matroskaenc: write DisplayWidth and DisplayHeight elements only if they differ from PixelWidth and PixelHeight
Signed-off-by: James Almer <jamrial@gmail.com>
2016-10-22 15:00:15 -03:00
James Almer 90826031a2 avformat/matroskaenc: write a DisplayUnit element when aspect ratio is unknown
We don't currently support values 1 (centimeters), 2 (inches) or 3 (DAR),
only the default value 0 (pixels) which doesn't need to be written.

The fate refs are updated as unknown SAR is now signaled in the output
files with the addition of the new element.

Reviewed-by: Carl Eugen Hoyos <ceffmpeg@gmail.com>
Signed-off-by: James Almer <jamrial@gmail.com>
2016-10-15 20:48:03 -03:00
James Almer 8063978bfc avformat/matroskaenc: don't write a FlagInterlaced element if it would write the default value
The spec says:
"Mandatory elements with a default value may be left out of the file. In the absence
of a mandatory element, the element's default value is used."

Reviewed-by: Hendrik Leppkes <h.leppkes@gmail.com>
Signed-off-by: James Almer <jamrial@gmail.com>
2016-10-11 19:49:19 -03:00
Carl Eugen Hoyos 5781256c01 lavf/matroskaenc: Always write V_QUICKTIME extradata.
Fixes ticket #5872.
2016-10-11 10:07:18 +02:00
James Almer c44eae157f avformat/matroskaenc: fix targets for attachment tags
Attachment tags were being written targeting non-existent streams in the
output file.
Also filter filename and mimetype entries, as they are standard elements
in the Attachment master.

Signed-off-by: James Almer <jamrial@gmail.com>
2016-10-10 23:18:36 -03:00
James Almer c45ba265fc avformat/matroskaenc: fix Tags master on seekable output if there are tags after the last stream duration
The dynamic AVIOContext would get closed pointing to the wrong position
in the buffer.
This is a regression since 650e17d88b.

Reviewed-by: Dave Rice <dave@dericed.com>
Signed-off-by: James Almer <jamrial@gmail.com>
2016-10-07 16:46:45 -03:00
Michael Niedermayer 572f16e100 avformat/matroskaenc: Fix () error
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2016-10-07 14:56:53 +02:00
James Almer 711bfb33df avformat/matroskaenc: add an option to disable writting CRC32 elements
Also add missing Changelog entry.

Signed-off-by: James Almer <jamrial@gmail.com>
2016-10-06 18:42:10 -03:00
James Almer 3bcadf8227 avformat/matroskaenc: write a CRC32 element on Info
Finishes implementing ticket #4347

Tested-by: Dave Rice <dave@dericed.com>
Tested-by: Jerome Martinez <jerome@mediaarea.net>
Reviewed-by: Michael Niedermayer <michael@niedermayer.cc>
Signed-off-by: James Almer <jamrial@gmail.com>
2016-10-06 17:16:12 -03:00
James Almer 650e17d88b avformat/matroskaenc: write a CRC32 element on Tags
Implements part of ticket #4347

Tested-by: Dave Rice <dave@dericed.com>
Tested-by: Jerome Martinez <jerome@mediaarea.net>
Reviewed-by: Michael Niedermayer <michael@niedermayer.cc>
Signed-off-by: James Almer <jamrial@gmail.com>
2016-10-06 17:13:59 -03:00
James Almer 4687240d52 avformat/matroskaenc: write a CRC32 element on Attachments
Implements part of ticket #4347

Tested-by: Dave Rice <dave@dericed.com>
Tested-by: Jerome Martinez <jerome@mediaarea.net>
Reviewed-by: Michael Niedermayer <michael@niedermayer.cc>
Signed-off-by: James Almer <jamrial@gmail.com>
2016-10-06 17:10:51 -03:00
James Almer eccefece61 avformat/matroskaenc: write a CRC32 element on Chapters
Implements part of ticket #4347

Tested-by: Dave Rice <dave@dericed.com>
Tested-by: Jerome Martinez <jerome@mediaarea.net>
Reviewed-by: Michael Niedermayer <michael@niedermayer.cc>
Signed-off-by: James Almer <jamrial@gmail.com>
2016-10-06 17:08:14 -03:00
James Almer 87ce2595de avformat/matroskaenc: write a CRC32 element on Tracks
Implements part of ticket #4347

Tested-by: Dave Rice <dave@dericed.com>
Tested-by: Jerome Martinez <jerome@mediaarea.net>
Reviewed-by: Michael Niedermayer <michael@niedermayer.cc>
Signed-off-by: James Almer <jamrial@gmail.com>
2016-10-06 17:05:03 -03:00
James Almer 79248795d4 avformat/matroskaenc: write a CRC32 element on Cues
Implements part of ticket #4347

Tested-by: Dave Rice <dave@dericed.com>
Tested-by: Jerome Martinez <jerome@mediaarea.net>
Reviewed-by: Michael Niedermayer <michael@niedermayer.cc>
Signed-off-by: James Almer <jamrial@gmail.com>
2016-10-06 17:01:20 -03:00
James Almer 3b189fae73 avformat/matroskaenc: write a CRC32 element on SeekHead
Implements part of ticket #4347

Tested-by: Dave Rice <dave@dericed.com>
Tested-by: Jerome Martinez <jerome@mediaarea.net>
Reviewed-by: Michael Niedermayer <michael@niedermayer.cc>
Signed-off-by: James Almer <jamrial@gmail.com>
2016-10-06 16:59:09 -03:00
James Almer 6724525a15 avformat/matroskaenc: write a CRC32 element on each Cluster
Implements part of ticket #4347

Tested-by: Dave Rice <dave@dericed.com>
Tested-by: Jerome Martinez <jerome@mediaarea.net>
Reviewed-by: Michael Niedermayer <michael@niedermayer.cc>
Signed-off-by: James Almer <jamrial@gmail.com>
2016-10-06 16:54:07 -03:00
James Almer 4e3bdf729a avformat/matroskaenc: always use a dynamic buffer when writting clusters
Tested-by: Dave Rice <dave@dericed.com>
Tested-by: Jerome Martinez <jerome@mediaarea.net>
Reviewed-by: Michael Niedermayer <michael@niedermayer.cc>
Signed-off-by: James Almer <jamrial@gmail.com>
2016-10-06 16:30:56 -03:00
James Almer d41aeea8a6 avformat/matroskaenc: print debug message with cluster offsets only if the output is seekable
Printing the dynamic buffer offset is useless.

Reviewed-by: Michael Niedermayer <michael@niedermayer.cc>
Signed-off-by: James Almer <jamrial@gmail.com>
2016-10-06 16:30:56 -03:00
James Almer 9b8ac526f6 avformat/matroskaenc: don't write an empty Colour master element
Signed-off-by: James Almer <jamrial@gmail.com>
2016-10-06 13:49:10 -03:00
James Almer b33369b612 avformat/matroskaenc: don't reserve space for stream duration tags if the output is not seekable
The durations are never written in that situation.

Reviewed-by: Michael Niedermayer <michael@niedermayer.cc>
Signed-off-by: James Almer <jamrial@gmail.com>
2016-10-04 21:19:58 -03:00
James Almer 3cc9d6d382 avformat/matroska: write FlagInterlaced element in WebM
It's listed as supported in both https://www.webmproject.org/docs/container/
and https://matroska.org/technical/specs/index.html

Reviewed-by: Dave Rice <dave@dericed.com>
Signed-off-by: James Almer <jamrial@gmail.com>
2016-10-04 19:42:55 -03:00
Rodger Combs 843e72ea55
lavf/matroskaenc: use mkv_check_tag_name consistently
Previously, we used a different list of checks when deciding whether to
write a set of tags at all than we did when deciding whether to write an
individual tag in the set. This resulted in sometimes writing an empty
tag master and seekhead. Now we use mkv_check_tag_name everywhere, so
if a dictionary is entirely composed of tags we skip, we don't write a
tag master at all.

This affected the test file, since "language" was on one list but not
the other, so we were writing an empty tag master there. The test hash
is updated to reflect that change.
2016-09-06 17:25:37 -05:00
Rodger Combs 3829a02738
lavf/matroskaenc: skip writing "duration" tags 2016-09-06 17:25:36 -05:00
Rodger Combs 6ede4e93ca
lavf/matroskaenc: move skipped metadata keys to separate function 2016-09-06 17:25:36 -05:00
Michael Bradshaw c9ae8be5a8 avformat/matroskaenc: fix Voids with size < 10
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2016-07-31 16:59:49 +02:00
softworkz 70c1647a35 avformat/matroskaenc: Write duration early during mkv_write_header (Rev #3)
Rev #2: Fixes doubled header writing, checked FATE running without errors
Rev #3: Fixed coding style

This commit addresses the following scenario:

we are using ffmpeg to transcode or remux mkv (or something else) to mkv. The result is being streamed on-the-fly to an HTML5 client (streaming starts while ffmpeg is still running). The problem here is that the client is unable to detect the duration because the duration is only written to the mkv at the end of the transcoding/remoxing process. In matroskaenc.c, the duration is only written during mkv_write_trailer but not during mkv_write_header.

The approach:

FFMPEG is currently putting quite some effort to estimate the durations of source streams, but in many cases the source stream durations are still left at 0 and these durations are nowhere mapped to or used for output streams. As much as I would have liked to deduct or estimate output durations based on input stream durations - I realized that this is a hard task (as Nicolas already mentioned in a previous conversation). It would involve changes to the duration calculation/estimation/deduction for input streams and propagating these durations to output streams or the output context in a correct way.
So I looked for a simple and small solution with better chances to get accepted. In webmdashenc.c I found that a duration is written during write_header and this duration is taken from the streams' metadata, so I decided for a similar approach.

And here's what it does:

At first it is checking the duration of the AVFormatContext. In typical cases this value is not set, but: It is set in cases where the user has specified a recording_time or an end_time via the -t or -to parameters.
Then it is looking for a DURATION metadata field in the metadata of the output context (AVFormatContext::metadata). This would only exist in case the user has explicitly specified a metadata DURATION value from the command line.
Then it is iterating all streams looking for a "DURATION" metadata (this works unless the option "-map_metadata -1" has been specified) and determines the maximum value.
The precendence is as follows: 1. Use duration of AVFormatContext - 2. Use explicitly specified metadata duration value - 3. Use maximum (mapped) metadata duration over all streams.

To test this:

1. With explicit recording time:
ffmpeg -i file:"src.mkv" -loglevel debug -t 01:38:36.000 -y "dest.mkv"

2. Take duration from metadata specified via command line parameters:
ffmpeg -i file:"src.mkv" -loglevel debug -map_metadata -1 -metadata Duration="01:14:33.00" -y "dest.mkv"

3. Take duration from mapped input metadata:
ffmpeg -i file:"src.mkv" -loglevel debug -y "dest.mkv"

Regression risk:

Very low IMO because it only affects the header while ffmpeg is still running. When ffmpeg completes the process, the duration is rewritten to the header with the usual value (same like without this commit).

Signed-off-by: SoftWorkz <softworkz@hotmail.com>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2016-07-28 02:06:55 +02:00
James Almer be04c4aa00 avformt/matroskaenc: undo an accidental revert by commit 5d48e4ea
Commit 5d48e4eafa accidentally reverted changes
made to matroskaenc by commit 989a614b70.

Signed-off-by: James Almer <jamrial@gmail.com>
2016-07-26 15:22:32 -03:00
James Almer 1582e306a4 avformat/avlanguage: make av_convert_lang_to() internal
The header was never installed and the function is only used in libavformat

Reviewed-by: Paul B Mahol <onemda@gmail.com>
Signed-off-by: James Almer <jamrial@gmail.com>
2016-07-19 21:43:14 -03:00
Matthieu Bouron dc62016c4b Merge commit '71852a1ba89abc8749e309d9d662c49d47e19531'
* commit '71852a1ba89abc8749e309d9d662c49d47e19531':
  matroskaenc: Provide output bytestream markers

Merged-by: Matthieu Bouron <matthieu.bouron@stupeflix.com>
2016-06-23 17:57:34 +02:00
Clément Bœsch 5d48e4eafa Merge commit 'a6a750c7ef240b72ce01e9653343a0ddf247d196'
* commit 'a6a750c7ef240b72ce01e9653343a0ddf247d196':
  tests: Move all test programs to a subdirectory

Merged-by: Clément Bœsch <clement@stupeflix.com>
2016-06-22 13:44:34 +02:00
Michael Bradshaw 989a614b70 libavformat/matroskaenc: omit segment UID for webm
SegmentUID is not a supported element in WebM. See:
http://www.webmproject.org/docs/container/#SegmentUID

Reviewed-by: Dave Rice <dave@dericed.com>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2016-06-22 12:12:46 +02:00
Michael Niedermayer 566be4f9e8 avformat/matroskaenc: reindent after last commit
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2016-05-22 03:22:16 +02:00
Michael Niedermayer 2062d51275 avformat/matroskaenc: wrap par->format use as sample format under codec_type == AVMEDIA_TYPE_AUDI
Fixes CID1361946

Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2016-05-22 03:22:09 +02:00
Martin Storsjö 71852a1ba8 matroskaenc: Provide output bytestream markers
Signed-off-by: Martin Storsjö <martin@martin.st>
2016-05-18 10:36:58 +03:00
Derek Buitenhuis ee865e9780 Merge commit 'e3453fd44480d903338c663238bf280215dd9a07'
* commit 'e3453fd44480d903338c663238bf280215dd9a07':
  matroska: Write the field order information

Merged-by: Derek Buitenhuis <derek.buitenhuis@gmail.com>
2016-05-08 23:25:58 +01:00
Michael Niedermayer c4fad02779 avformat/matroskaenc: Undo bits_per_coded_sample change as bits_per_raw_sample is available again
Reminded-by: James Almer
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2016-04-16 02:01:10 +02:00
Derek Buitenhuis 6f69f7a8bf Merge commit '9200514ad8717c63f82101dc394f4378854325bf'
* commit '9200514ad8717c63f82101dc394f4378854325bf':
  lavf: replace AVStream.codec with AVStream.codecpar

This has been a HUGE effort from:
    - Derek Buitenhuis <derek.buitenhuis@gmail.com>
    - Hendrik Leppkes <h.leppkes@gmail.com>
    - wm4 <nfxjfg@googlemail.com>
    - Clément Bœsch <clement@stupeflix.com>
    - James Almer <jamrial@gmail.com>
    - Michael Niedermayer <michael@niedermayer.cc>
    - Rostislav Pehlivanov <atomnuker@gmail.com>

Merged-by: Derek Buitenhuis <derek.buitenhuis@gmail.com>
2016-04-10 20:59:55 +01:00
Luca Barbato e3453fd444 matroska: Write the field order information
And bump the document version to 4.
2016-04-03 19:36:57 +02:00
Neil Birkbeck e7e5c5e6c4 lavf/matroskaenc.c: add early support for colour elements
Adding early support for a subset of the proposed colour elements
according to the latest version of spec:
https://mailarchive.ietf.org/arch/search/?email_list=cellar&gbt=1&index=hIKLhMdgTMTEwUTeA4ct38h0tmE

Like matroskadec, I've left out elements for pix_fmt related things
 as there still seems to be some discussion around these.

The new elements are exposed under strict experimental mode.

Signed-off-by: Neil Birkbeck <neil.birkbeck@gmail.com>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2016-03-21 00:10:18 +01:00
Hendrik Leppkes c43d485811 matroskaenc: set the actual PCM bitdepth in the header
The actual bitdepth can be different to the storage format (ie. sample format).
Fixes the stored bitdepth for 24-bit formats like FLAC.
2016-03-16 12:52:35 +01:00
Ronald S. Bultje 2e6636aa87 vp9: add superframe merging bitstream filter.
Fixes ticket 4313.
2016-03-11 11:19:14 -05:00
Anton Khirnov 9200514ad8 lavf: replace AVStream.codec with AVStream.codecpar
Currently, AVStream contains an embedded AVCodecContext instance, which
is used by demuxers to export stream parameters to the caller and by
muxers to receive stream parameters from the caller. It is also used
internally as the codec context that is passed to parsers.

In addition, it is also widely used by the callers as the decoding (when
demuxer) or encoding (when muxing) context, though this has been
officially discouraged since Libav 11.

There are multiple important problems with this approach:
    - the fields in AVCodecContext are in general one of
        * stream parameters
        * codec options
        * codec state
      However, it's not clear which ones are which. It is consequently
      unclear which fields are a demuxer allowed to set or a muxer allowed to
      read. This leads to erratic behaviour depending on whether decoding or
      encoding is being performed or not (and whether it uses the AVStream
      embedded codec context).
    - various synchronization issues arising from the fact that the same
      context is used by several different APIs (muxers/demuxers,
      parsers, bitstream filters and encoders/decoders) simultaneously, with
      there being no clear rules for who can modify what and the different
      processes being typically delayed with respect to each other.
    - avformat_find_stream_info() making it necessary to support opening
      and closing a single codec context multiple times, thus
      complicating the semantics of freeing various allocated objects in the
      codec context.

Those problems are resolved by replacing the AVStream embedded codec
context with a newly added AVCodecParameters instance, which stores only
the stream parameters exported by the demuxers or read by the muxers.
2016-02-23 17:01:58 +01:00