Go to file
Andreas Rheinhardt c602deb138 avformat/mux: Preserve sync even if later packet has negative ts
write_packet() has code to shift the packets timestamps
to make them nonnegative or even make them start at ts zero;
this code inspects every packet that is written and if a packet
with negative timestamp (whether this is dts or pts depends upon
another flag; basically: Matroska uses pts, everyone else dts)
is encountered, this is offset to make the timestamp zero.
All further packets will be offset accordingly (with the offset
converted according to the streams' timebases).

This is based around an assumption, namely that the timestamps
are indeed non-decreasing, so that the first packet with negative
timestamps is the first packet with timestamps. This assumption
is often fulfilled given that the default interleavement function
by default interleaves per dts; yet there are scenarios in which
it may not be fulfilled:
a) av_write_frame() instead of av_interleaved_write_frame() is used.
b) The audio_preload option is used.
c) When the timestamps that are made nonnegative/zero are pts
(i.e. with Matroska), because the packet with the smallest dts
is not necessarily the packet with the smallest pts.
d) Possibly with custom interleavement functions.
In these cases the relative sync of the first few packet(s) is offset
relative to the later packets. This contradicts the documentation
("When shifting is enabled, all output timestamps are shifted by
the same amount").

Therefore this commit changes this: As soon as the first packet
with valid timestamps is output, it is checked and recorded whether
the timestamps need to be shifted. Further packets are no longer
checked for needing to be offset; instead they are simply offset.
In the cases above this leads to packets with negative timestamps
(and the appropriate warnings) instead of desync. This will mostly
be fixed in the next commit.

This commit also factors handling the avoid_negative_ts stuff out
of write_packet() in order to be able to return immediately.

Tickets #4536 and #5784 as well as the matroska-avoid-negative-ts-test
are examples of c); as has been said, some timestamps are now negative,
yet the ref file update does not show it because ffmpeg.c sanitizes
the timestamps (-copyts disables it; ffprobe and mkvinfo also show
the original timestamps).

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2022-01-21 16:47:38 +01:00
compat Replace all occurences of av_mallocz_array() by av_calloc() 2021-09-20 01:03:52 +02:00
doc libavcodec/qsvenc: Add transform skip to hevc_qsv 2022-01-21 12:56:30 +08:00
ffbuild Makefile: Redo duplicating object files in shared builds 2022-01-04 05:01:04 +01:00
fftools fftools/cmdutils: Fix undefined 1 << 31 2022-01-11 00:20:35 +01:00
libavcodec libavcodec/qsvenc: Add transform skip to hevc_qsv 2022-01-21 12:56:30 +08:00
libavdevice avdevice/iec61883: #if unused code away, fix -O0 compilation 2022-01-08 18:15:18 +01:00
libavfilter avfilter/tonemap_vaapi: set va parameters filters and numbers 2022-01-17 16:32:17 +08:00
libavformat avformat/mux: Preserve sync even if later packet has negative ts 2022-01-21 16:47:38 +01:00
libavutil avutil/pixfmt.h: typo 2022-01-21 11:58:23 +01:00
libpostproc lib*/version.h: Bump Versions after release/5.0 branch 2022-01-04 14:29:06 +01:00
libswresample lib*/version.h: Bump Versions after release/5.0 branch 2022-01-04 14:29:06 +01:00
libswscale swscale/x86/input.asm: add x86-optimized planer rgb2yuv functions 2022-01-11 16:34:33 -03:00
presets
tests avformat/mux: Preserve sync even if later packet has negative ts 2022-01-21 16:47:38 +01:00
tools tools/target_dec_fuzzer: Adjust threshold for prores 2021-12-16 21:06:47 +01:00
.gitattributes
.gitignore build: detect Metal.framework and build .metal files 2021-12-18 11:55:47 -08:00
.mailmap
.travis.yml
Changelog Changelog: Add new <next> line after 5.0 2022-01-05 08:37:55 -03:00
configure configure: link to libatomic when it's present 2022-01-21 09:28:59 +01:00
CONTRIBUTING.md
COPYING.GPLv2
COPYING.GPLv3
COPYING.LGPLv2.1
COPYING.LGPLv3
CREDITS
INSTALL.md
LICENSE.md
MAINTAINERS MAINTAINERS: add my gpg fingerprint 2021-12-23 09:25:16 +08:00
Makefile Makefile: Redo duplicating object files in shared builds 2022-01-04 05:01:04 +01:00
README.md README: fix typo and description of libavfilter 2021-10-08 09:44:34 +05:30
RELEASE

FFmpeg README

FFmpeg is a collection of libraries and tools to process multimedia content such as audio, video, subtitles and related metadata.

Libraries

  • libavcodec provides implementation of a wider range of codecs.
  • libavformat implements streaming protocols, container formats and basic I/O access.
  • libavutil includes hashers, decompressors and miscellaneous utility functions.
  • libavfilter provides means to alter decoded audio and video through a directed graph of connected filters.
  • libavdevice provides an abstraction to access capture and playback devices.
  • libswresample implements audio mixing and resampling routines.
  • libswscale implements color conversion and scaling routines.

Tools

  • ffmpeg is a command line toolbox to manipulate, convert and stream multimedia content.
  • ffplay is a minimalistic multimedia player.
  • ffprobe is a simple analysis tool to inspect multimedia content.
  • Additional small tools such as aviocat, ismindex and qt-faststart.

Documentation

The offline documentation is available in the doc/ directory.

The online documentation is available in the main website and in the wiki.

Examples

Coding examples are available in the doc/examples directory.

License

FFmpeg codebase is mainly LGPL-licensed with optional components licensed under GPL. Please refer to the LICENSE file for detailed information.

Contributing

Patches should be submitted to the ffmpeg-devel mailing list using git format-patch or git send-email. Github pull requests should be avoided because they are not part of our review process and will be ignored.