Sagnac / streamsave

mpv script aimed at saving live streams and clipping online videos without encoding.
94 stars 4 forks source link

Issue with making clips of local mkv files #17

Closed raziel711 closed 3 months ago

raziel711 commented 3 months ago

System information: mpv version: mpv v0.38.0-622-g58f3009b mpv source: https://github.com/zhongfly/mpv-winbuild/releases OS: Windows 11 Pro 23H2 22631.3880 streamsave version: v0.27.4 with default settings

I'm having an issue when using streamsave to make clips of local mkv files. It seems like if the input format is an mkv, the script's automatic detection function for the output format is choosing mp4 instead of mkv for local files.

If I play an mkv file using mpv --vo=gpu-next --cache=yes file.mkv, set the a-b loop, and use align-cache, instead of generating an mkv clip, an mp4 clip is created with noticeable video artifacts in the first couple of seconds:

https://github.com/user-attachments/assets/34c2db7b-b8e2-421a-b238-804f7c1a22e0

Also, the console shows multiple instances of the following errors:

[ffmpeg] mp4: Application provided invalid, non monotonically increasing dts to muxer in stream 0: 5900 >= 5900
[recorder] Failed writing packet.

Log file: log.txt

If I use script-message streamsave-extension .mkv force before making the clip, then there is no issue. There are no artifacts in the video or any errors generated in the log.

Sagnac commented 3 months ago

This happens when the codecs are compatible with MP4, and in this case you have h264 + aac which is a combination the script uses to decide whether to write to MP4, regardless of container. For online streams, I think it's generally preferred to output MP4 due to compatibility even if for some reason MKV is detected, but this leads to the unintuitive behaviour with local files you outlined.

Even though some people may prefer to automatically clip the MKV into MP4 if it's compatible, others expect the opposite, and since there do seem to be issues with corruption I think a better solution here would be to check if it's a local MKV file, and if so then just use MKV; preserving the container in these cases makes more sense since Matroska is a more flexible / compatible format in this regard and the user can just force MP4 if they desire in cases where it works.

I've thrown a quick fix up at the dev branch, does it work for you?

raziel711 commented 3 months ago

I tested the 0.28 version on the dev branch and the automatic detection works perfectly for me for both streaming and local files. Thanks for the quick fix.