From 0b47983aa200f52f152b3bb7b751ef78833e2bc9 Mon Sep 17 00:00:00 2001 From: Chris Cunningham Date: Fri, 23 Jun 2017 15:12:06 -0700 Subject: [PATCH] Workaround for negative PTS values in video files. In some videos uploaded from cameras, the first frame in presentation order is not the first frame in decode order. The metadata correctly records this. However, FFmpeg is adjusting timestamps so that the first frame in decode order is at time 0. As a result, the first frame in presentation order has a negative timestamp, which produces an error. The workaround is to pass "advanced_editlist=0" in the demuxer options. This avoids the problem until FFmpeg fixes it properly. BUG=723537 TEST=tested locally with example from comment #6 in the bug (cherry picked from commit 916a8290de5e9e41873282f01e11ffa7606c1531) TBR=jrummell@chromium.org Change-Id: I2b515dff06da2930339592ff4e84ec69da635c91 Reviewed-on: https://chromium-review.googlesource.com/526752 Commit-Queue: John Rummell Reviewed-by: Dale Curtis Cr-Original-Commit-Position: refs/heads/master@{#477887} Reviewed-on: https://chromium-review.googlesource.com/546916 Reviewed-by: Chrome Cunningham Cr-Commit-Position: refs/branch-heads/3112@{#457} Cr-Branched-From: b6460e24cf59f429d69de255538d0fc7a425ccf9-refs/heads/master@{#474897} --- media/filters/ffmpeg_glue.cc | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/media/filters/ffmpeg_glue.cc b/media/filters/ffmpeg_glue.cc index 86091c30da436..8b1909b2f1c7e 100644 --- a/media/filters/ffmpeg_glue.cc +++ b/media/filters/ffmpeg_glue.cc @@ -136,10 +136,17 @@ bool FFmpegGlue::OpenContext() { // destruction path to avoid double frees. open_called_ = true; + // Pass "advanced_editlist=0" in the demuxer options. + // TODO(jrummell): Remove this when we support post-decode discard. + // https://crbug.com/723537. + AVDictionary* dict = nullptr; + av_dict_set(&dict, "advanced_editlist", "0", 0); + // By passing nullptr for the filename (second parameter) we are telling // FFmpeg to use the AVIO context we setup from the AVFormatContext structure. const int ret = - avformat_open_input(&format_context_, nullptr, nullptr, nullptr); + avformat_open_input(&format_context_, nullptr, nullptr, &dict); + av_dict_free(&dict); // If FFmpeg can't identify the file, read the first 8k and attempt to guess // at the container type ourselves. This way we can track emergent formats.