Go to file
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
compat
doc Add an OpenH264 decoder wrapper 2016-07-27 10:19:40 +03:00
libavcodec avcodec/h264_slice: Make setup_finished check cover more cases 2016-07-27 19:29:55 +02:00
libavdevice avdev/jack: remove duplicated dispatch macros 2016-07-26 23:10:47 +01:00
libavfilter af_hdcd: Add counter for cdt expirations 2016-07-27 23:09:45 +02:00
libavformat avformat/matroskaenc: Write duration early during mkv_write_header (Rev #3) 2016-07-28 02:06:55 +02:00
libavresample
libavutil avutil/frame: access avframe fields directly in get_frame_defaults() 2016-07-25 17:37:18 -03:00
libpostproc
libswresample
libswscale Revert "PPC64: Add versions of functions in libswscale/input.c optimized for POWER8 VSX SIMD." 2016-07-11 10:15:05 -04:00
presets
tests fate: Add HDCD filter tests for false positive and error detection 2016-07-27 22:21:43 +02:00
tools tools/patcheck: add a couple more common typos 2016-07-17 18:38:14 -03:00
.gitattributes
.gitignore
.travis.yml
arch.mak
Changelog Add an OpenH264 decoder wrapper 2016-07-27 10:19:40 +03:00
cmdutils_common_opts.h
cmdutils_opencl.c
cmdutils.c
cmdutils.h
common.mak
configure Add an OpenH264 decoder wrapper 2016-07-27 10:19:40 +03:00
COPYING.GPLv2
COPYING.GPLv3
COPYING.LGPLv2.1
COPYING.LGPLv3
CREDITS
ffmpeg_cuvid.c
ffmpeg_dxva2.c
ffmpeg_filter.c
ffmpeg_opt.c ffmpeg_opt: Delete duplicate “hwaccel_output_format” option. 2016-07-20 12:07:38 +02:00
ffmpeg_qsv.c
ffmpeg_vaapi.c
ffmpeg_vdpau.c
ffmpeg_videotoolbox.c
ffmpeg.c ffmpeg.c: copy video profile when using stream_copy 2016-07-23 03:52:38 +02:00
ffmpeg.h
ffplay.c ffplay: Fix usage of private lavfi API 2016-06-29 12:53:01 +02:00
ffprobe.c ffprobe: add missing PROGRAM_STREAM_TAGS case 2016-07-26 19:22:47 +02:00
ffserver_config.c
ffserver_config.h
ffserver.c
INSTALL.md
library.mak
LICENSE.md
MAINTAINERS MAINTAINERS: add myself to the project server 2016-07-23 11:13:06 +02:00
Makefile
README.md
RELEASE
version.sh

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 a mean to alter decoded Audio and Video through chain of 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.
  • ffserver is a multimedia streaming server for live broadcasts.
  • 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. Few developers follow pull requests so they will likely be ignored.