youtube-dl: Youtube-dl can't merge VP9+Opus youtube videos

Checklist

  • I’m reporting a broken site support
  • I’ve verified that I’m running youtube-dl version 2021.01.24.1
  • I’ve checked that all provided URLs are alive and playable in a browser
  • I’ve checked that all URLs and arguments with special characters are properly quoted or escaped
  • I’ve searched the bugtracker for similar issues including closed ones

Verbose log

youtube-dl -v --abort-on-unavailable-fragment -f (bestvideo[vcodec=vp9])+(bestaudio[acodec=opus]) https://youtu.be/g6zva0stnOY --no-continue

[debug] System config: []                                                          
[debug] User config: []                                                            
[debug] Custom config: []                                                          
[debug] Command-line args: ['-v', '--abort-on-unavailable-fragment', '-f', '(bestvideo[vcodec=vp9])+(bestaudio[acodec=opus])', 'https://youtu.be/g6zva0stnOY', '--no-continue']   
                                                                       
[debug] Encodings: locale UTF-8, fs utf-8, out utf-8, pref UTF-8  
                 
[debug] youtube-dl version 2021.01.24.1          
                                  
[debug] Python version 3.8.7 (CPython) - Linux-5.10.11-0-lts-x86_64-with           

[debug] exe versions: ffmpeg 4.3.1, ffprobe 4.3.1                                  

[debug] Proxy map: {}                                                              
[youtube] g6zva0stnOY: Downloading webpage                                         
[youtube] g6zva0stnOY: Downloading MPD manifest                                    
[debug] Invoking downloader on [REDACTED]

[dashsegments] Total fragments: 280                                                
[download] Destination: المحاضرة الثانية _ الثرموداينمك _ الجزء الثاني 2021-g6zva0stnOY.f302.webm                                                                     
[download] 100% of 417.83MiB in 24:16                                              
[debug] Invoking downloader on [REDACTED]
[dashsegments] Total fragments: 157
[download] Destination: المحاضرة الثانية _ الثرموداينمك _ الجزء الثاني 2021-g6zva0stnOY.f251.webm
[download] 100% of 22.60MiB in 00:36
[ffmpeg] Merging formats into "المحاضرة الثانية _ الثرموداينمك _ الجزء الثاني 2021-g6zva0stnOY.webm"
[debug] ffmpeg command line: ffmpeg -y -loglevel repeat+info -i 'file:المحاضرة الثانية _ الثرموداينمك _ الجزء الثاني 2021-g6zva0stnOY.f302.webm' -i 'file:المحاضرة الثانية _ الثرموداينمك _ الجزء الثاني 2021-g6zva0stnOY.f251.webm' -c copy -map 0:v:0 -map 1:a:0 'file:المحاضرة الثانية _ الثرموداينمك _ الجزء الثاني 2021-g6zva0stnOY.temp.webm'
ERROR: Conversion failed!
Traceback (most recent call last):
  File "/usr/lib/python3.8/site-packages/youtube_dl/YoutubeDL.py", line 2102, in post_process
    files_to_delete, info = pp.run(info)
  File "/usr/lib/python3.8/site-packages/youtube_dl/postprocessor/ffmpeg.py", line 523, in run
    self.run_ffmpeg_multiple_files(info['__files_to_merge'], temp_filename, args)
  File "/usr/lib/python3.8/site-packages/youtube_dl/postprocessor/ffmpeg.py", line 235, in run_ffmpeg_multiple_files
    raise FFmpegPostProcessorError(msg)
youtube_dl.postprocessor.ffmpeg.FFmpegPostProcessorError: Conversion failed!

FFmpeg gives me the following error when I run the command mentioned in the above output manually:

[webm @ 0x7fe94ccf40c0] Application provided invalid, non monotonically increasing dts to muxer in stream 0: 5620 >= 5600 av_interleaved_write_frame(): Invalid argument

I’ve tried to re-download it multiple times and the issue persists. Other videos can be merged fine, so it seems like this is a problem with this particular video.

About this issue

  • Original URL
  • State: open
  • Created 3 years ago
  • Reactions: 2
  • Comments: 54 (10 by maintainers)

Most upvoted comments

@Vangelis66

FWIW, as a Windows Vista SP2 32-bit user, I have no access to the patched ffmpeg builds mentioned earlier in this thread (those, as well as the ones recently offered by yt-dlp devs, target Win7+ …).

You have bigger shit to worry about if you’re on Windows Vista. You do realize you’re on an operating system with no security from Microsoft? There should be no reason for you to be on there other than pure incompetence.

Hello 😃

We have narrowed down the problematic ffmpeg commit to https://github.com/FFmpeg/FFmpeg/commit/2e6636aa87303d37b112e79f093ca39500f92364

This commit disabled the ability for ffmpeg to correct DTS errors when the encoding is VP9, and the mode is a simple copy.

We are testing some patches right now to see if we can restore DTS correction for VP9 without re-introducing 4313.

Talked to FFmpeg developers on #ffmpeg-devel IRC. They stopped publishing IRC logs in June 2020 (https://lists.ffmpeg.org/pipermail/ffmpeg-devel-irc/), so here is the short summary:

  1. Nobody remembers whether disabling DTS correction was necessary to fix https://trac.ffmpeg.org/ticket/4313.
  2. They merged @danny-wu patch into FFmpeg master: https://github.com/FFmpeg/FFmpeg/commit/68595b46cb374658432fff998e82e5ff434557ac.

https://trac.ffmpeg.org/ticket/9086 is now closed.

If someone is tired waiting for FFmpeg devs to fix this issue, FFmpeg builds with a patch by @danny-wu can be found here: https://github.com/nihil-admirari/FFmpeg-With-VP9-Timestamp-Fix/releases. Builds are based on https://github.com/BtbN/FFmpeg-Builds.

When it comes to setts filter, looks like bitstream filter parser is based on a simple tokenizer, which completely ignores escape sequences. Most likely it’s a bug, but until it is fixed, setts cannot be used to correct timestamps.

A Googler has filed an issue about their malformed VP9 encoding in their internal bug tracker.

Patch submitted to ffmpeg-devel mailing list 😄

Video playback is perfect on VLC.

image

https://github.com/FFmpeg/FFmpeg/commit/301d275301d72387732ccdc526babaf984ddafe5 has not been backported to 4.4 release branch. Problem with commas is still reproducible there.

Turns out that eval doesn’t support conditional operators, only functions. Correct syntax is:

-bsf:v 'setts=pts=if(lt(DTS\, PREV_OUTDTS) * gte(PTS\, DTS)\, max(PTS\, PREV_OUTDTS)\, PTS):dts=max(DTS\, PREV_OUTDTS)'

With PTS part present, Invalid DTS warning goes away. It should reproduce the C code, assuming that PREV_OUTDTS is ost->last_mux_dts, DTS is pkt->dts, PTS is pkt->pts, and that VP9 holding containers are non-strict.

Hi @Vangelis66, I will continue working on the patch with the goals of incorporating it into ffmpeg.

optimally, compile win32 FFmpeg builds for us Windows people (preferably ones that would launch on Vista, too, as that is the minimum ffmpeg supports currently) ?

Unfortunately I do not develop on Windows, and have no clue how to compile for Windows. Sorry! But someone else is of course welcome to compile (although I cannot endorse the security of any binaries, and do not encourage running untrusted binaries).

this gets added in the ffmpeg command after the input files and mux fails…

I think this is a valid case that calls for introducing a postprocessor-args-prepend flag to youtube-dl.

@Vangelis66 I have relayed that to them, in addition to the results of your testing to track down the error in past builds. I don’t know that it’ll matter due to the stipulation of using the current git head (which I surmise is the most recent version) but I figured it wouldn’t hurt to try.

Thanks again.

I have opened an issue: https://trac.ffmpeg.org/ticket/9187#ticket Lets see what happens

Please try setts bitstream filter.

Doesn’t work atleast without any parameters and I have no idea what params to use

$ ffmpeg -y -i "file:303.webm" -i "file:251.webm" -c copy -bsf:v setts "file:out.mkv"
ffmpeg version 2021-04-11-git-309e3cc15c-full_build-www.gyan.dev Copyright (c) 2000-2021 the FFmpeg developers
  built with gcc 10.2.0 (Rev6, Built by MSYS2 project)
  configuration: --enable-gpl --enable-version3 --enable-static --disable-w32threads --disable-autodetect --enable-fontconfig --enable-iconv --enable-gnutls --enable-libxml2 --enable-gmp --enable-lzma --enable-libsnappy --enable-zlib --enable-librist --enable-libsrt --enable-libssh --enable-libzmq --enable-avisynth --enable-libbluray --enable-libcaca --enable-sdl2 --enable-libdav1d --enable-libzvbi --enable-librav1e --enable-libsvtav1 --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxvid --enable-libaom --enable-libopenjpeg --enable-libvpx --enable-libass --enable-frei0r --enable-libfreetype --enable-libfribidi --enable-libvidstab --enable-libvmaf --enable-libzimg --enable-amf --enable-cuda-llvm --enable-cuvid --enable-ffnvcodec --enable-nvdec --enable-nvenc --enable-d3d11va --enable-dxva2 --enable-libmfx --enable-libglslang --enable-vulkan --enable-opencl --enable-libcdio --enable-libgme --enable-libmodplug --enable-libopenmpt --enable-libopencore-amrwb --enable-libmp3lame --enable-libshine --enable-libtheora --enable-libtwolame --enable-libvo-amrwbenc --enable-libilbc --enable-libgsm --enable-libopencore-amrnb --enable-libopus --enable-libspeex --enable-libvorbis --enable-ladspa --enable-libbs2b --enable-libflite --enable-libmysofa --enable-librubberband --enable-libsoxr --enable-chromaprint
  libavutil      56. 72.100 / 56. 72.100
  libavcodec     58.136.101 / 58.136.101
  libavformat    58. 78.100 / 58. 78.100
  libavdevice    58. 14.100 / 58. 14.100
  libavfilter     7.111.100 /  7.111.100
  libswscale      5. 10.100 /  5. 10.100
  libswresample   3. 10.100 /  3. 10.100
  libpostproc    55. 10.100 / 55. 10.100
Input #0, matroska,webm, from 'file:303.webm':
  Metadata:
    encoder         : google/video-file
    http://youtube.com/streaming/otf/durations/112015: Segment-Count: 54
                    : Segment-Durations-Ms: 5339,5338,5339(r=1),5338,5339(r=1),5338,5339(r=1),5338,5339(r=1),5338,5339(r=1),5338,5339(r=1),5338,5339(r=1),5338,5339(r=1),5338,5339(r=1),5338,5339(r=1),5338,5339(r=1),5338,5339(r=1),5338,5339(r=1),5338,5339(r=1),5338,5339(r=1),533
                    :
                    :
  Duration: N/A, start: 0.000000, bitrate: N/A
  Stream #0:0(eng): Video: vp9 (Profile 0), yuv420p(tv, bt709/unknown/unknown), 1920x1010, SAR 1:1 DAR 192:101, 59.94 fps, 59.94 tbr, 1k tbn, 1k tbc (default)
Input #1, matroska,webm, from 'file:251.webm':
  Metadata:
    encoder         : google/video-file
  Duration: 00:04:46.56, start: -0.007000, bitrate: 92 kb/s
  Stream #1:0(eng): Audio: opus, 48000 Hz, stereo, fltp (default)
Output #0, matroska, to 'file:out.mkv':
  Metadata:
    http://youtube.com/streaming/otf/durations/112015: Segment-Count: 54
                    : Segment-Durations-Ms: 5339,5338,5339(r=1),5338,5339(r=1),5338,5339(r=1),5338,5339(r=1),5338,5339(r=1),5338,5339(r=1),5338,5339(r=1),5338,5339(r=1),5338,5339(r=1),5338,5339(r=1),5338,5339(r=1),5338,5339(r=1),5338,5339(r=1),5338,5339(r=1),5338,5339(r=1),533
                    :
                    :
    encoder         : Lavf58.78.100
  Stream #0:0(eng): Video: vp9 (Profile 0) (VP90 / 0x30395056), yuv420p(tv, bt709/unknown/unknown), 1920x1010 [SAR 1:1 DAR 192:101], q=2-31, 59.94 fps, 59.94 tbr, 1k tbn, 1k tbc (default)
  Stream #0:1(eng): Audio: opus ([255][255][255][255] / 0xFFFFFFFF), 48000 Hz, stereo, fltp (default)
Stream mapping:
  Stream #0:0 -> #0:0 (copy)
  Stream #1:0 -> #0:1 (copy)
Press [q] to stop, [?] for help
[matroska @ 000001e9e68b3440] Application provided invalid, non monotonically increasing dts to muxer in stream 0: 5355 >= 5339
av_interleaved_write_frame(): Invalid argument
frame=  323 fps=0.0 q=-1.0 Lsize=     472kB time=00:00:05.36 bitrate= 721.1kbits/s speed= 759x
video:459kB audio:63kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: unknown
Conversion failed!

Continuing the investigation. One merge was done with vanilla FFmpeg using setts filter:

/opt/ffmpeg-N-103588-g0b4d009587-linux64-gpl/bin/ffmpeg -i 'file:Blender Help - Dust Impact - Animated puff or cloud of dust from an object impact. [W9mNLFseTT4].f303.webm' -i 'file:Blender Help - Dust Impact - Animated puff or cloud of dust from an object impact. [W9mNLFseTT4].f251.webm' -c copy -map 0:v:0 -map 1:a:0 -bsf:v 'setts=pts=if(lt(DTS\, PREV_OUTDTS) * gte(PTS\, DTS)\, max(PTS\, PREV_OUTDTS)\, PTS):dts=max(DTS\, PREV_OUTDTS)' 'file:setts.webm'

A second merge was done with patched FFmpeg without using any filters:

/opt/ffmpeg-N-103588-g0b4d009587-linux64-nonfree/bin/ffmpeg -i 'file:Blender Help - Dust Impact - Animated puff or cloud of dust from an object impact. [W9mNLFseTT4].f303.webm' -i 'file:Blender Help - Dust Impact - Animated puff or cloud of dust from an object impact. [W9mNLFseTT4].f251.webm' -c copy -map 0:v:0 -map 1:a:0 'file:patched.webm'

FFprobe was used to show the packet structure:

/opt/ffmpeg-N-103588-g0b4d009587-linux64-gpl/bin/ffprobe -show_packets setts.webm > setts.pkts
/opt/ffmpeg-N-103588-g0b4d009587-linux64-gpl/bin/ffprobe -show_packets patched.webm > patched.pkts

Diff is empty. (If you know a better way to diff videos, please let me know.)

diff setts.pkts patched.pkts

Looks like setts filter expression is in fact identical to what the patch does. For example, replacing PREV_OUTDTS with PREV_OUTDTS + 1 produces a non-empty diff.

Once -bsf fix is propagated to FFmpeg releases, setts may become a viable solution to this problem. Currently it works only on master builds of FFmpeg.

Your information about setts filter is incorrect and misleading. Also you provided no proofs for your claims. Here is one possible example how to use setts filter:

-bsf:v setts=ts='N*(1001/60000)/TB

If you were to read what is written above carefully, you would’ve found the following:

However, nonsensical stuff like ‘setts=dts=sin(DTS + PREV_OUTDTS)’ at least parses. Looks like the problem in the presence of comma, but I haven’t found a way to escape it: no amount of backslashes works, and single quotes don’t work either (“setts=dts=‘max(DTS, PREV_OUTDTS)’”).

I wasn’t claiming that any TS filter expression results in an error, I was claiming that expressions containing commas do not parse. The error message was also presented, I don’t quite understand how that isn’t a proof:

Error parsing bitstream filter sequence 'setts=dts=max(DTS\, PREV_OUTDTS)': Bitstream filter not found

That said, I’ve retested everything again with latest FFmpeg from BtbN. Looks like a problem with commas has been fixed since June (now it’s a problem with parentheses, see below).

Video downloaded with

yt-dlp --keep-video --ffmpeg-location /opt/ffmpeg-N-103585-gbb9141cc13-linux64-gpl/bin/ -f bv*[ext=webm]+ba[ext=webm]' -S +size W9mNLFseTT4

does merge with an additional -bsf:v 'setts=dts=max(DTS\, PREV_OUTDTS)', producing a warning:

[webm @ 0x557a20394dc0] Invalid DTS: 5355 PTS: 5339 in output stream 0:0, replacing by guess

Full FFmpeg command line:

/opt/ffmpeg-N-103585-gbb9141cc13-linux64-gpl/bin/ffmpeg -y -i 'file:Blender Help - Dust Impact - Animated puff or cloud of dust from an object impact. [W9mNLFseTT4].f303.webm' -i 'file:Blender Help - Dust Impact - Animated puff or cloud of dust from an object impact. [W9mNLFseTT4].f251.webm' -c copy -map 0:v:0 -map 1:a:0 -bsf:v 'setts=dts=max(DTS\, PREV_OUTDTS)' 'file:Blender Help - Dust Impact - Animated puff or cloud of dust from an object impact. [W9mNLFseTT4].temp.webm'

However, an attempt to set PTS in addition to DTS with -bsf:v 'setts=pts=if((DTS < PREV_OUTDTS) * (PTS >= DTS)\, max(PTS\, PREV_OUTDTS)\, PTS):dts=max(DTS\, PREV_OUTDTS)' fails with:

[setts @ 0x55dd6ed1efc0] [Eval @ 0x7ffe4eaaa0f0] Missing ')' in '(DTS<PREV_OUTDTS)*(PTS>=DTS),max(PTS,PREV_OUTDTS),PTS)'
[setts @ 0x55dd6ed1efc0] Error while parsing pts expression 'if((DTS < PREV_OUTDTS) * (PTS >= DTS), max(PTS, PREV_OUTDTS), PTS)'
Error initializing bitstream filter: setts
Error initializing output stream 0:0 --

I’m sure if you know how to properly overwrite non-monotonic PTS/DTS in stream that if you provide working formula

Quoting myself:

Looking at ffmpeg.c, it seems to me that

int64_t max = ost->last_mux_dts + !(s->oformat->flags & AVFMT_TS_NONSTRICT);
...
if (pkt->dts < max) {
    if (pkt->pts >= pkt->dts)
        pkt->pts = FFMAX(pkt->pts, max);
    pkt->dts = max;
}

should be equivalent to (PREV_OUTDTS may need to be replaced with PREV_OUTDTS + 1, I’ve no idea whether VP9 is strict or not):

-bsf:v 'setts=pts=if((DTS < PREV_OUTDTS) * (PTS >= DTS)\, max(PTS\, PREV_OUTDTS)\, PTS):dts=max(DTS\, PREV_OUTDTS)'

Looks like WebM & Matroska are both non-strict: https://github.com/FFmpeg/FFmpeg/blob/master/libavformat/webm_chunk.c#L298, https://github.com/FFmpeg/FFmpeg/blob/master/libavformat/matroskaenc.c#L2842 (correct me if I’m wrong, or if VP9 could be merged into a container that is strict).

I can write expression for you to be used in setts filter.

The task is to convert the C code above into FFmpeg eval expression. My attempt:

setts=pts=if((DTS < PREV_OUTDTS) * (PTS >= DTS)\, max(PTS\, PREV_OUTDTS)\, PTS):dts=max(DTS\, PREV_OUTDTS)

partially worked. I’d be happy to hear how to write a conditional that doesn’t result in

Missing ')' in '(DTS<PREV_OUTDTS)*(PTS>=DTS),max(PTS,PREV_OUTDTS),PTS)'

Your information about setts filter is incorrect and misleading. Also you provided no proofs for your claims. Here is one possible example how to use setts filter:

-bsf:v setts=ts=‘N*(1001/60000)/TB’

I’m sure if you know how to properly overwrite non-monotonic PTS/DTS in stream that if you provide working formula I can write expression for you to be used in setts filter.

@danny-wu wrote:

We have narrowed down the problematic ffmpeg commit to FFmpeg/FFmpeg@2e6636a

That is actually ffmpeg-n3.1-dev-541-N-79004-git-20160311-g2e6636a so just 15 commits away from the last win32 build (I found to be the one) in which the remux works: ffmpeg-n3.1-dev-526-N-78989-git-20160310-gcaeed04 So glad I was able to help pinpoint a regression window!

Patch submitted to ffmpeg-devel mailing list

Many thanks, indeed! 👍 This is the actual mailing list thread:

http://ffmpeg.org/pipermail/ffmpeg-devel/2021-May/280189.html

The one dev that replied as of now appears to be yet unconvinced… 😞

Knowing how evil Google are 😠 👎 , I wouldn’t rule out them “fixing” their HFR encodes on purpose, just to spoil it for “downloaders”…

Knowing the ffmpeg devs, it’ll probably take eons to review/approve/merge submitted patch; @danny-wu, are you willing to post your patch here, too, and, optimally, compile win32 FFmpeg builds for us Windows people (preferably ones that would launch on Vista, too, as that is the minimum ffmpeg supports currently) ?

I haven’t been idle myself on this, despite not posting here… 😜 I have been going through FFmpeg’s vast documentation in search of an interim “workaround”, until this is addressed in FFmpeg code…

-fflags "+noparse +nofillin"

https://ffmpeg.org/ffmpeg-formats.html:

> fflags flags
>   Set format flags. Some are implemented for a limited number of formats.
>   Possible values for input files: 
> (snipped)
>  ‘noparse’
>      Disable AVParsers, this needs +nofillin too. 

supposedly will make FFmpeg disregard the non-monotonus DTS inside the VP9 video stream (rather than correct it, as with FFmpeg-3.0.1) and proceed with the mux; thus, the “issue” is then delegated to the player asked to play back the muxed streams…

However, that switch has to be specified before the “invalid” VP9 file, e.g.

ffmpeg44 -hide_banner -y -fflags "+noparse +nofillin" -i "VP9_674p60.webm" -i "opus96k.webm" -c copy "VP9+opus.webm"

works

Input #0, matroska,webm, from 'VP9_674p60.webm':
  Metadata:
    encoder         : google/video-file
    http://youtube.com/streaming/otf/durations/112015: Segment-Count: 54
                    : Segment-Durations-Ms: 5339,5338,5339(r=1),5338,5339(r=1),5
338,5339(r=1),5338,5339(r=1),5338,5339(r=1),5338,5339(r=1),5338,5339(r=1),5338,5
339(r=1),5338,5339(r=1),5338,5339(r=1),5338,5339(r=1),5338,5339(r=1),5338,5339(r
=1),5338,5339(r=1),5338,5339(r=1),533
                    :
                    :
  Duration: N/A, bitrate: N/A
  Stream #0:0(eng): Video: vp9 (Profile 0), yuv420p(tv, bt709/unknown/unknown),
1280x674, SAR 1:1 DAR 640:337, 59.94 fps, 59.94 tbr, 1k tbn, 1k tbc (default)
Input #1, matroska,webm, from 'opus96k.webm':
  Metadata:
    encoder         : google/video-file
  Duration: 00:04:46.56, start: -0.007000, bitrate: 92 kb/s
  Stream #1:0(eng): Audio: opus, 48000 Hz, stereo, fltp (default)
Output #0, webm, to 'VP9+opus.webm':
  Metadata:
    http://youtube.com/streaming/otf/durations/112015: Segment-Count: 54
                    : Segment-Durations-Ms: 5339,5338,5339(r=1),5338,5339(r=1),5
338,5339(r=1),5338,5339(r=1),5338,5339(r=1),5338,5339(r=1),5338,5339(r=1),5338,5
339(r=1),5338,5339(r=1),5338,5339(r=1),5338,5339(r=1),5338,5339(r=1),5338,5339(r
=1),5338,5339(r=1),5338,5339(r=1),533
                    :
                    :
    encoder         : Lavf58.76.100
  Stream #0:0(eng): Video: vp9 (Profile 0), yuv420p(tv, bt709/unknown/unknown),
1280x674 [SAR 1:1 DAR 640:337], q=2-31, 59.94 fps, 59.94 tbr, 1k tbn, 1k tbc (de
fault)
  Stream #0:1(eng): Audio: opus, 48000 Hz, stereo, fltp (default)
Stream mapping:
  Stream #0:0 -> #0:0 (copy)
  Stream #1:0 -> #0:1 (copy)
Press [q] to stop, [?] for help
frame=    1 fps=0.0 q=-1.0 size=       1kB time=00:00:00.00 bitrate=8032.0kbits/
frame=17177 fps=0.0 q=-1.0 Lsize=    9735kB time=00:04:46.54 bitrate= 278.3kbits
/s speed= 645x
video:6403kB audio:3122kB subtitle:0kB other streams:0kB global headers:0kB muxi
ng overhead: 2.200533%

but

ffmpeg44 -hide_banner -y -i "VP9_674p60.webm" -i "opus96k.webm" -c copy -fflags "+noparse +nofillin" "VP9+opus.webm"

fails 😭 (ffmpeg44 a renamed ffmpeg.exe v4.4) …

Where I am currently stuck is that when I supply the switch to yt-dl via, e.g. --postprocessor-args "-fflags +noparse -fflags +nofillin", this gets added in the ffmpeg command after the input files and mux fails… 😞

[ffmpeg] Merging formats into "VP9_674p60+opus96k.webm"
[debug] ffmpeg command line: ffmpeg -y -loglevel "repeat+info" -i "file:VP9_674p
60+opus96k.f302.webm" -i "file:VP9_674p60+opus96k.f251.webm" -c copy -map "0:v:0
" -map "1:a:0" -fflags "+noparse" -fflags "+nofillin" "file:VP9_674p60+opus96k.t
emp.webm"
ERROR: Conversion failed!
Traceback (most recent call last):
  File "youtube_dl\YoutubeDL.py", line 2115, in post_process
  File "youtube_dl\postprocessor\ffmpeg.py", line 523, in run
  File "youtube_dl\postprocessor\ffmpeg.py", line 235, in run_ffmpeg_multiple_fi
les
youtube_dl.postprocessor.ffmpeg.FFmpegPostProcessorError: Conversion failed!

@Vangelis66 and @pukkandan, I just want to thank you for the investigation. I’ve been troubleshooting and I believe the root cause is that there was a regression in this specific function that aims to correct DTS non-linearity:

https://github.com/FFmpeg/FFmpeg/blob/fd5f4ac0813c27c34c387f00044905a859e29e37/fftools/ffmpeg.c#L757

Reading the code, it seems clear the intention is not to exit/abort when there is a DTS non-linearity, but rather correct it. Unfortunately, this correction logic broke after ffmpeg3, and is no longer working correctly.

I’ve passed this information to the ffmpeg developers, and I hope they are able to fix it, but as this is an open source project, to anyone with C knowledge, it would be amazing if anyone could investigate this specific function and see why this stopped properly correcting around ffmpeg-n3.1-dev-1443-N-79906-git-20160510-gc8c14d0.

Hopefully we can get to the bottom of this and finally fix it 😃

OK, I think I may have made some progress, the findings of which, sadly, won’t apply to the vast majority of yt-dl users… 😢 FTR, I am on Windows Vista SP2 32-bit, it is currently extremely hard for me to find 1: recent 32-bit ffmpeg compiles, as all of the ffmpeg Windows-binary repos (linked to in the official ffmpeg site) now offer 64-bit compiles exclusively… 💢 2: recent 32-bit ffmpeg builds that have been compiled with appropriate compiler flags to target Vista (NT 6.0) as the minimum WinOS; FTR, the ffmpeg source still supports fully NT 6.0 (but some third party libs don’t - others [e.g. libx265] need special compatibility flags to be set at build time) … Many thanks to @AnimMouse for his Vista-compatible 32-bit ffmpeg builds - my “progress” in this issue wouldn’t be possible without his builds 👍 .

Now, to the point:

@mechalincoln wrote:

Another developer added this:

Please try setts bitstream filter. It is specifically designed for such videos.

@pukkandan wrote:

Please try setts bitstream filter.

Doesn’t work, at least without any parameters and I have no idea what params to use

The first thing is, that the “setts bitstream filter” is a very recent addition to FFmpeg code; I first conducted my experiments with a ffmpeg build version n4.3.2, and that filter was missing there! But, it is present in latest stable n4.4 release:

ffmpeg -hide_banner -bsfs =>

Bitstream filters:
aac_adtstoasc
av1_frame_merge
av1_frame_split
av1_metadata
chomp
dump_extra
dca_core
eac3_core
extract_extradata
filter_units
h264_metadata
h264_mp4toannexb
h264_redundant_pps
hapqa_extract
hevc_metadata
hevc_mp4toannexb
imxdump
mjpeg2jpeg
mjpegadump
mp3decomp
mpeg2_metadata
mpeg4_unpack_bframes
mov2textsub
noise
null
opus_metadata
pcm_rechunk
prores_metadata
remove_extra
setts
text2movsub
trace_headers
truehd_core
vp9_metadata
vp9_raw_reorder
vp9_superframe
vp9_superframe_split

Documentation for that new bsf is provided in

https://ffmpeg.org/ffmpeg-bitstream-filters.html#setts

The syntax for bsfs is documented in

https://ffmpeg.org/ffmpeg-bitstream-filters.html#Description

In previous logs of this thread, muxing fails because of discrepancies in the DTS of the input video file (formats -f=302|303) ; I first fetched the two elementary streams by issuing:

youtube-dl --console-title -c --no-part --fixup never -f 302 "W9mNLFseTT4" -o VP9_674p60.webm

youtube-dl --console-title -c --no-part --fixup never -f 251 "W9mNLFseTT4" -o opus96k.webm

… and after some brief experimentation, I achieved successful muxing to a WEBM container, with FFmpeg-n4.4, by issuing:

ffmpeg -i "VP9_674p60.webm" -i "opus96k.webm" -c copy -bsf:v setts=dts=0 "VP9+opus.webm" =>

ffmpeg version n4.4-ffmpeg-windows-build-helpers Copyright (c) 2000-2021 the FFm
peg developers
  built with gcc 10.2.0 (GCC)
(configuration redacted, for brevity)
  libavutil      56. 70.100 / 56. 70.100
  libavcodec     58.134.100 / 58.134.100
  libavformat    58. 76.100 / 58. 76.100
  libavdevice    58. 13.100 / 58. 13.100
  libavfilter     7.110.100 /  7.110.100
  libavresample   4.  0.  0 /  4.  0.  0
  libswscale      5.  9.100 /  5.  9.100
  libswresample   3.  9.100 /  3.  9.100
  libpostproc    55.  9.100 / 55.  9.100
Input #0, matroska,webm, from 'VP9_674p60.webm':
  Metadata:
    encoder         : google/video-file
    http://youtube.com/streaming/otf/durations/112015: Segment-Count: 54
                    : Segment-Durations-Ms: 5339,5338,5339(r=1),5338,5339(r=1),5
338,5339(r=1),5338,5339(r=1),5338,5339(r=1),5338,5339(r=1),5338,5339(r=1),5338,5
339(r=1),5338,5339(r=1),5338,5339(r=1),5338,5339(r=1),5338,5339(r=1),5338,5339(r
=1),5338,5339(r=1),5338,5339(r=1),533
                    :
                    :
  Duration: N/A, start: 0.000000, bitrate: N/A
  Stream #0:0(eng): Video: vp9 (Profile 0), yuv420p(tv, bt709/unknown/unknown),
1280x674, SAR 1:1 DAR 640:337, 59.94 fps, 59.94 tbr, 1k tbn, 1k tbc (default)
Input #1, matroska,webm, from 'opus96k.webm':
  Metadata:
    encoder         : google/video-file
  Duration: 00:04:46.56, start: -0.007000, bitrate: 92 kb/s
  Stream #1:0(eng): Audio: opus, 48000 Hz, stereo, fltp (default)
Output #0, webm, to 'VP9+opus.webm':
  Metadata:
    http://youtube.com/streaming/otf/durations/112015: Segment-Count: 54
                    : Segment-Durations-Ms: 5339,5338,5339(r=1),5338,5339(r=1),5
338,5339(r=1),5338,5339(r=1),5338,5339(r=1),5338,5339(r=1),5338,5339(r=1),5338,5
339(r=1),5338,5339(r=1),5338,5339(r=1),5338,5339(r=1),5338,5339(r=1),5338,5339(r
=1),5338,5339(r=1),5338,5339(r=1),533
                    :
                    :
    encoder         : Lavf58.76.100
  Stream #0:0(eng): Video: vp9 (Profile 0), yuv420p(tv, bt709/unknown/unknown),
1280x674 [SAR 1:1 DAR 640:337], q=2-31, 59.94 fps, 59.94 tbr, 1k tbn, 1k tbc (de
fault)
  Stream #0:1(eng): Audio: opus, 48000 Hz, stereo, fltp (default)
Stream mapping:
  Stream #0:0 -> #0:0 (copy)
  Stream #1:0 -> #0:1 (copy)
Press [q] to stop, [?] for help
frame=    1 fps=0.0 q=-1.0 size=       1kB time=00:00:00.00 bitrate=8032.0kbits/
frame=17177 fps=0.0 q=-1.0 size=    6400kB time=00:03:01.30 bitrate= 289.2kbits/
[webm @ 08905680] Starting new cluster due to timestamp
frame=17177 fps=0.0 q=-1.0 Lsize=    9734kB time=00:04:46.54 bitrate= 278.3kbits
/s speed= 472x
video:6403kB audio:3122kB subtitle:0kB other streams:0kB global headers:0kB muxi
ng overhead: 2.192095%

MediaInfo Log of produced file: VP9+opus.webm.txt

However, the only software player on my system that produces a trouble-free playback of the resultant webm file is the mpv-based SMPlayer:

smp

YMMV, of course, especially on systems (Win10) with VP9 hardware decoding… So, we’re getting there, but not currently THERE…

@pukkandan : I don’t think the FFmpeg people would engage further in this… @mechalincoln: Could you revisit the ffmpeg-user mailing list and kindly ask for more clarification towards “fine-tuning” the bsf:v setts syntax/arguments? I have little experience in filter syntax, less so with this very new one, for which no working examples can be currently found on-line… 😢

Of course, migrating every yt-dl user to FFmpeg 4.4+ isn’t very practical currently, plus the fact the issue at hand manifests itself at random youtube video IDs discourages, probably, the devs from writing code exclusive to ffmpeg 4.4+… Additionally, a lot more testing is needed on how the muxed file (with using the setts bsf) behaves on popular media players… ❓

Addition: The webm file produced by OLD ffmpeg (N-78989-gcaeed04 in my tests) plays absolutely fine in ALL players available in my machine (MPC-HC, MPC-BE, PotPlayer, VLC 3 and SMPlayer), thus I still consider using an ol’n’good ffmpeg build to be the definitive cure for this… 😉