summaryrefslogtreecommitdiffstats
path: root/demux
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2016-08-19 14:19:46 +0200
committerwm4 <wm4@nowhere>2016-08-19 14:59:30 +0200
commit05e4df3f0c7679e8ac3b32a1a414be751b6b6b37 (patch)
tree82341aaaf7d4e82800d0555b3e39dfd2ddb6a77f /demux
parent4aaa83339ca9515113e936af79bc3d860d67cb4b (diff)
downloadmpv-05e4df3f0c7679e8ac3b32a1a414be751b6b6b37.tar.bz2
mpv-05e4df3f0c7679e8ac3b32a1a414be751b6b6b37.tar.xz
video/audio: always provide "proper" timestamps to libavcodec
Instead of passing through double float timestamps opaquely, pass real timestamps. Do so by always setting a valid timebase on the AVCodecContext for audio and video decoding. Specifically try not to round timestamps to a too coarse timebase, which could round off small adjustments to timestamps (such as for start time rebasing or demux_timeline). If the timebase is considered too coarse, make it finer. This gets rid of the need to do this specifically for some hardware decoding wrapper. The old method of passing through double timestamps was also a bit questionable. While libavcodec is not supposed to interpret timestamps at all if no timebase is provided, it was needlessly tricky. Also, it actually does compare them with AV_NOPTS_VALUE. This change will probably also reduce confusion in the future.
Diffstat (limited to 'demux')
-rw-r--r--demux/demux_lavf.c2
-rw-r--r--demux/demux_mf.c1
-rw-r--r--demux/demux_raw.c4
-rw-r--r--demux/stheader.h4
4 files changed, 11 insertions, 0 deletions
diff --git a/demux/demux_lavf.c b/demux/demux_lavf.c
index ef0a8583d5..4b236ee2be 100644
--- a/demux/demux_lavf.c
+++ b/demux/demux_lavf.c
@@ -670,6 +670,8 @@ static void handle_new_stream(demuxer_t *demuxer, int i)
if (sh->codec->lav_headers)
mp_copy_lav_codec_headers(sh->codec->lav_headers, codec);
#endif
+ sh->codec->native_tb_num = st->time_base.num;
+ sh->codec->native_tb_den = st->time_base.den;
if (st->disposition & AV_DISPOSITION_DEFAULT)
sh->default_track = true;
diff --git a/demux/demux_mf.c b/demux/demux_mf.c
index c0b159e4ea..20b948630c 100644
--- a/demux/demux_mf.c
+++ b/demux/demux_mf.c
@@ -321,6 +321,7 @@ static int demux_open_mf(demuxer_t *demuxer, enum demux_check check)
c->disp_w = 0;
c->disp_h = 0;
c->fps = demuxer->opts->mf_fps;
+ c->reliable_fps = true;
demux_add_sh_stream(demuxer, sh);
diff --git a/demux/demux_raw.c b/demux/demux_raw.c
index bd8e11306d..51378e7031 100644
--- a/demux/demux_raw.c
+++ b/demux/demux_raw.c
@@ -145,6 +145,9 @@ static int demux_rawaudio_open(demuxer_t *demuxer, enum demux_check check)
c->force_channels = true;
c->samplerate = opts->samplerate;
+ c->native_tb_num = 1;
+ c->native_tb_den = c->samplerate;
+
int f = opts->aformat;
// See PCM(): sign float bits endian
mp_set_pcm_codec(sh->codec, f & 1, f & 2, f >> 3, f & 4);
@@ -233,6 +236,7 @@ static int demux_rawvideo_open(demuxer_t *demuxer, enum demux_check check)
c->codec = decoder;
c->codec_tag = imgfmt;
c->fps = opts->fps;
+ c->reliable_fps = true;
c->disp_w = width;
c->disp_h = height;
demux_add_sh_stream(demuxer, sh);
diff --git a/demux/stheader.h b/demux/stheader.h
index f9d564c230..78e86a47ee 100644
--- a/demux/stheader.h
+++ b/demux/stheader.h
@@ -74,6 +74,9 @@ struct mp_codec_params {
struct AVCodecContext *lav_headers;
struct AVCodecParameters *lav_codecpar;
+ // Timestamp granularity for converting double<->rational timestamps.
+ int native_tb_num, native_tb_den;
+
// STREAM_AUDIO
int samplerate;
struct mp_chmap channels;
@@ -85,6 +88,7 @@ struct mp_codec_params {
// STREAM_VIDEO
bool avi_dts; // use DTS timing; first frame and DTS is 0
float fps; // frames per second (set only if constant fps)
+ bool reliable_fps; // the fps field is definitely not broken
int par_w, par_h; // pixel aspect ratio (0 if unknown/square)
int disp_w, disp_h; // display size
int rotate; // intended display rotation, in degrees, [0, 359]