1. 02 Apr, 2020 14 commits
    • Andreas Rheinhardt's avatar
      avformat/hnm: Only keep and parse what is needed later · d2037837
      Andreas Rheinhardt authored
      The hnm demuxer's context struct contained lots of fields that are
      write-only variables or that are not used outside of parsing the header
      and that can therefore be replaced by local variables of hnm_read_header().
      This commit removes all of these from the context; the second type has
      been replaced by local variables.
      
      An AVPacket (that was initialized when reading the header and for which
      dead code to unreference it existed in hnm_read_close()) is among the
      removed things. Removing it allowed to remove hnm_read_close()
      altogether and also removes another instance of usage of sizeof(AVPacket).
      Reviewed-by: 's avatarPaul B Mahol <onemda@gmail.com>
      Signed-off-by: 's avatarAndreas Rheinhardt <andreas.rheinhardt@gmail.com>
      d2037837
    • Andreas Rheinhardt's avatar
      avformat/matroskaenc: Don't implicitly mark WebVTT in WebM as English · da4ba243
      Andreas Rheinhardt authored
      Writing the language of WebVTT in WebM proceeded differently than the
      language of all other tracks: In case no language was given, it does not
      write anything instead of "und" (for undefined). Because the default
      value of the Language element in WebM (that inherited it from Matroska)
      is "eng" (for English), any such track will actually be flagged as
      English.
      
      Doing it this way goes back to commit 509642b4 (the commit adding
      support for WebVTT) and no reason for this has been given in the commit
      message or in the discussion about this patch on the mailing list; the
      best I can think of is this: the WebM wiki contains "The srclang attribute
      is stored as the Language sub-element." Someone unfamiliar with default
      values in Matroska/WebM could interpret this as meaning that no Language
      element should be written if the language is unknown. And this is wrong
      and this commit changes it.
      Signed-off-by: 's avatarAndreas Rheinhardt <andreas.rheinhardt@gmail.com>
      da4ba243
    • Andreas Rheinhardt's avatar
      avformat/matroskaenc: Reindent after previous commit · bc52ce30
      Andreas Rheinhardt authored
      Also remove { } after an if if there is only one statement inside { }.
      Signed-off-by: 's avatarAndreas Rheinhardt <andreas.rheinhardt@gmail.com>
      bc52ce30
    • Andreas Rheinhardt's avatar
      avformat/matroskaenc: Combine checks for audio · 0d4b3b4c
      Andreas Rheinhardt authored
      mkv_write_track() currently has three places where it checks for whether
      the current codec type is audio: One in a switch and two outside of it.
      These checks can be combined by moving the code after the other two checks
      inside the audio-related part of the switch.
      Signed-off-by: 's avatarAndreas Rheinhardt <andreas.rheinhardt@gmail.com>
      0d4b3b4c
    • Andreas Rheinhardt's avatar
      avformat/matroskaenc: Simplify writing Void elements · 98a6c6ec
      Andreas Rheinhardt authored
      Reserving space in Matroska works by writing a Void element. And until
      now this worked as follows: The current position was recorded and the
      EBML ID as well as the length field written; then the new position was
      recorded to know how much more to write. Afterwards the actual writing
      has been performed via ffio_fill().
      
      But it is unnecessary to explicitly use the positions (obtained via
      avio_tell()) to find out how much still needs to be written, because the
      length of the ID and the length field are known. So rewrite the function
      to no longer use them.
      
      Also, given that ffio_fill() uses an int parameter and given that no
      current caller (and no sane future caller) will want to reserve several
      GB of space, make the size parameter of put_ebml_void() itself an int.
      Signed-off-by: 's avatarAndreas Rheinhardt <andreas.rheinhardt@gmail.com>
      98a6c6ec
    • Andreas Rheinhardt's avatar
      avformat/matroskaenc: Avoid seek when writing Cues at the front · 8e4c8711
      Andreas Rheinhardt authored
      When the Cues are written in front of the Cluster, the muxer would seek
      to the beginning (to where the Cues ought to be written) and write the
      Cues; afterwards it would seek back to the end of the file only to seek
      to the beginning once again to update several elements there. This
      commit removes the seek to the end.
      Signed-off-by: 's avatarAndreas Rheinhardt <andreas.rheinhardt@gmail.com>
      8e4c8711
    • Andreas Rheinhardt's avatar
      avformat/matroskaenc: Fix edge case of writing Cues at the beginning · b7883434
      Andreas Rheinhardt authored
      The Matroska muxer has the ability to write the Cues (the index) at the
      beginning of the file (in front of the Cluster): The user inputs the
      amount of space that should be reserved at the beginning of the file and
      if this is sufficient, the Cues will be written there and the part of the
      reserved space not used up by the Cues will be filled with a "Void"
      element.
      
      There is just one problem with this: One can not fill a single byte this
      way, because said Void element is minimally two bytes long (one byte ID,
      one byte length field). Up until now, if one reserved one byte more than
      needed, one would run into an assert when writing the Void element.
      
      There are two solutions for this: Error out if it happens. Or adjust the
      length field of the Cues in order to ensure that the above situation
      can't happen (i.e. write the length on one byte more than necessary).
      The first solution is very unsatisfactory, as enough space has been
      reserved. Therefore this commit implements the second solution.
      Signed-off-by: 's avatarAndreas Rheinhardt <andreas.rheinhardt@gmail.com>
      b7883434
    • Andreas Rheinhardt's avatar
      avformat/matroskaenc: Don't fail if reserved Cues space doesn't suffice · 06f10890
      Andreas Rheinhardt authored
      When the user opted to write the Cues at the beginning, the Cues were
      simply written without checking in advance whether enough space has been
      reserved for them. If it wasn't enough, the data following the space
      reserved for the Cues was simply overwritten, corrupting the file.
      
      This commit changes this by checking whether enough space has been
      reserved for the Cues before outputting anything. If it isn't enough,
      no Cues will be output at all and the file will be finalized normally,
      yet writing the trailer will nevertheless return an error to notify
      the user that his wish of having Cues at the front of the file hasn't
      been fulfilled.
      
      This change opens new usecases for this option: It is now safe to use
      this option to e.g. record live streams or to use it when muxing the
      output of an expensive encoding, because when the reserved space turns
      out to be insufficient, one ends up with a file that just lacks Cues
      but is otherwise fine.
      Signed-off-by: 's avatarAndreas Rheinhardt <andreas.rheinhardt@gmail.com>
      06f10890
    • Paul B Mahol's avatar
      8e1354c9
    • Paul B Mahol's avatar
      e4809e12
    • Paul B Mahol's avatar
      b00b935d
    • Andreas Rheinhardt's avatar
      avformat/matroskaenc: Update the default version of WavPack · 7039045c
      Andreas Rheinhardt authored
      The Matroska muxer currently assumed WavPack version 4.03 in case it was
      not explicitly signalled via extradata; but following a recommendation
      from David Bryant, the WavPack creator, this is changed to 4.10.
      Reviewed-by: 's avatarDavid Bryant <david@wavpack.com>
      Signed-off-by: 's avatarAndreas Rheinhardt <andreas.rheinhardt@gmail.com>
      7039045c
    • Andreas Rheinhardt's avatar
      avformat/wvdec: Export version as extradata · 96bf6d61
      Andreas Rheinhardt authored
      It might be used by the Matroska muxer. This is also the reason why the
      FATE-tests for muxing WavPack into Matroska needed to be updated: They
      now write the correct version 4.07 and not 4.03 as before.
      Reviewed-by: 's avatarDavid Bryant <david@wavpack.com>
      Signed-off-by: 's avatarAndreas Rheinhardt <andreas.rheinhardt@gmail.com>
      96bf6d61
    • Andreas Rheinhardt's avatar
      avformat/matroskadec: Add a workaround for missing WavPack extradata · 048bc3fe
      Andreas Rheinhardt authored
      mkvmerge versions 6.2 to 40.0 had a bug that made it not propagate the
      WavPack extradata (containing the WavPack version) during remuxing from
      a Matroska file; currently our demuxer would treat every WavPack block
      encountered as invalid data (unless the WavPack stream is to be
      discarded (i.e. the streams discard is >= AVDISCARD_ALL)) and try to
      resync to the next level 1 element.
      
      Luckily, the WavPack version is currently not really important; so we
      fix this problem by assuming a version. David Bryant, the creator of
      WavPack, recommended using version 0x410 (the most recent version) for
      this. And this is what this commit does.
      
      A FATE-test for this has been added.
      Reviewed-by: 's avatarDavid Bryant <david@wavpack.com>
      Signed-off-by: 's avatarAndreas Rheinhardt <andreas.rheinhardt@gmail.com>
      048bc3fe
  2. 01 Apr, 2020 9 commits
  3. 31 Mar, 2020 3 commits
  4. 30 Mar, 2020 12 commits
    • Carl Eugen Hoyos's avatar
      ffmpeg: Print an error instead of a debug message on exit. · b5a8ad56
      Carl Eugen Hoyos authored
      Reported-by: Forum user NewPlaza
      b5a8ad56
    • Andreas Rheinhardt's avatar
      avformat/mxfdec: Correct confusing struct tag · 8d019dbc
      Andreas Rheinhardt authored
      Don't use typedef struct MXFTrack {...} MXFTimecodeComponent, in
      particular given the fact that MXFTrack is a type of its own.
      Reviewed-by: 's avatarTomas Härdin <tjoppen@acc.umu.se>
      Signed-off-by: 's avatarAndreas Rheinhardt <andreas.rheinhardt@gmail.com>
      8d019dbc
    • Andreas Rheinhardt's avatar
      avformat/matroskaenc: Check that Cluster has been opened · 5d24b684
      Andreas Rheinhardt authored
      before setting the field indicating that a Cluster has been opened.
      Signed-off-by: 's avatarAndreas Rheinhardt <andreas.rheinhardt@gmail.com>
      5d24b684
    • Andreas Rheinhardt's avatar
      avformat/matroskaenc: Remove unused function parameter · 907b7f88
      Andreas Rheinhardt authored
      end_ebml_master_crc32_preliminary() has a MatroskaMuxContext as
      parameter that isn't used at all. So remove it.
      Furthermore it doesn't close its dynamic buffer; it just uses the
      underlying buffer and therefore it only needs a pointer to the
      dynamic buffer, not a pointer to a pointer.
      Signed-off-by: 's avatarAndreas Rheinhardt <andreas.rheinhardt@gmail.com>
      907b7f88
    • Andreas Rheinhardt's avatar
      avformat/matroskaenc: Write level 1 elements in one go · d9c21ec6
      Andreas Rheinhardt authored
      Up until now, writing level 1 elements proceeded as follows: First, the
      element id was written to the ordinary output AVIOContext and a dynamic
      buffer was opened for the content of the level 1 element in
      start_ebml_master_crc32(). Then this buffer was actually used and after it
      was closed (in end_ebml_master_crc32()), the size field corresponding to
      the buffer's size was written, after which the actual data was written.
      
      This commit changes this: Nothing is written to the main AVIOContext any
      more in start_ebml_master_crc32(). end_ebml_master_crc32() now writes
      both the id, the length field as well as the data. This implies that
      one can start a level 1 element in memory without outputting anything.
      This is done to enable to test whether enough space has been reserved
      for the Cues (if space has been reserved for them) before writing them.
      A large duration between outputting the header and outputting the rest
      could also break certain streaming usecases like the one from #8578
      (which this commit fixes).
      Signed-off-by: 's avatarAndreas Rheinhardt <andreas.rheinhardt@gmail.com>
      d9c21ec6
    • Andreas Rheinhardt's avatar
      avformat/matroskaenc: Simplify writing Cues · 5e3b7bd5
      Andreas Rheinhardt authored
      When the Matroska muxer writes the Cues (the index), it groups index
      entries with the same timestamp into the same CuePoint to save space.
      But given Matroska's variable-length length fields, it either needs
      to have an upper bound of the final size of the CuePoint before writing it
      or the CuePoint has to be assembled in a different buffer, so that after
      having assembled the CuePoint (when the real size is known), the CuePoint's
      header can be written and its data copied after it.
      
      The first of these approaches is the currently used one. This entails
      finding out the number of entries in a CuePoint before starting the
      CuePoint and therefore means that the list is read at least twice.
      Furthermore, a worst-case upper-bound for the length of a single entry
      was used, so that sometimes bytes are wasted on length fields.
      
      This commit switches to the second approach. This is no longer more
      expensive than the current approach if one only resets the dynamic
      buffer used to write the CuePoint's content instead of opening a new
      buffer for every CuePoint: Writing the trailer of a file with 540.000
      CuePoints improved actually from 219054414 decicycles to 2164379394
      decicycles (based upon 50 iterations).
      Signed-off-by: 's avatarAndreas Rheinhardt <andreas.rheinhardt@gmail.com>
      5e3b7bd5
    • Andreas Rheinhardt's avatar
      avformat/aviobuf: Add function to reset dynamic buffer · 639728f5
      Andreas Rheinhardt authored
      Resetting a dynamic buffer means to keep the AVIOContext and the
      internal buffer used by the dynamic buffer. This is done in order to
      save (re)allocations when one has a workflow where one opens and closes
      dynamic buffers in sequence.
      Signed-off-by: 's avatarAndreas Rheinhardt <andreas.rheinhardt@gmail.com>
      639728f5
    • Andreas Rheinhardt's avatar
      avformat/matroskaenc: Avoid allocation for Cues · 5cdd2ebb
      Andreas Rheinhardt authored
      Up until now, the Matroska muxer would allocate a structure containing
      three members: The segment offset, a pointer to an array containing Cue
      (index) entries and a counter for said array. It is unnecessary to
      allocate it separately and it is unnecessary to contain the segment
      offset in said structure, as it duplicates another field contained in
      the MatroskaMuxContext. This commit implements the corresponding
      changes.
      Signed-off-by: 's avatarAndreas Rheinhardt <andreas.rheinhardt@gmail.com>
      5cdd2ebb
    • Andreas Rheinhardt's avatar
      6cf69f0e
    • Andreas Rheinhardt's avatar
      avformat/matroskaenc: Avoid unnecessary seek · b1c3d711
      Andreas Rheinhardt authored
      When writing the SeekHead (a form of index) at the end of the muxing
      process, mkv_write_seekhead() would first seek to the position where the
      SeekHead ought to be written, then write it there and seek back to the
      original position afterwards. Which means: To the end of the file.
      Afterwards, a seek to the beginning of the file is performed to update
      further values. This of course means that the second seek in
      mkv_write_seekhead() was unnecessary.
      
      This has been changed: A new parameter was added to mkv_write_seekhead()
      containing the destination for the second seek, effectively eliminating
      the seek to the end of the file after writing the SeekHead.
      Signed-off-by: 's avatarAndreas Rheinhardt <andreas.rheinhardt@gmail.com>
      b1c3d711
    • Andreas Rheinhardt's avatar
      avformat/matroskaenc: Check for failure when writing SeekHead · 8c89fc18
      Andreas Rheinhardt authored
      mkv_write_seekhead() would up until now try to seek to the position where
      the SeekHead ought to be written, write the SeekHead and seek back. The
      first of these seeks was checked as was writing, yet the seek back was
      unchecked. Moreover the return value of mkv_write_seekhead() was unchecked
      (the ordinary return value was the position where the SeekHead was written).
      
      This commit changes this: Everything is checked. In the unseekable case
      (where the first seek may nevertheless work when it happens in the buffer)
      a failure at the first seek is not considered an error. In any case,
      failure to seek back is an error.
      Signed-off-by: 's avatarAndreas Rheinhardt <andreas.rheinhardt@gmail.com>
      8c89fc18
    • Andreas Rheinhardt's avatar
      avformat/matroskaenc: Improve calculating EBML ID size · e6ea75a3
      Andreas Rheinhardt authored
      When the Matroska muxer writes an EBML ID, it calculates the length of
      said ID before; and it does this as if this were a number that needs to
      be encoded as EBML number: The formula used is (av_log2(id + 1) - 1) / 7
      + 1. But the constants used already contain the VINT_MARKER (the leading
      bit indicating the length of the EBML number) and therefore the algorithm
      used makes no sense. Instead the position of the most significant byte
      set gives the desired length.
      
      The algorithm used until now worked because EBML numbers are subject to
      restrictions: If the EBML number takes up k bytes, then the bit 1 << (7
      * k) is set and av_log2(id) is 7 * k. So the current algorithm produces
      the correct result unless the EBML ID is of the form 7 * k - 1 because
      of the "id + 1". But contrary to encoding lengths as EBML number (where
      the + 1 exists to avoid the encodings reserved for unknown length),
      such EBML numbers are simply forbidden as EBML IDs and as such none of
      them were ever written.
      Signed-off-by: 's avatarAndreas Rheinhardt <andreas.rheinhardt@gmail.com>
      e6ea75a3
  5. 29 Mar, 2020 2 commits