Sagnac / streamsave

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

Clips sometime longer than expected #8

Closed doesn123 closed 1 year ago

doesn123 commented 1 year ago

Sometimes the extracted clip will contain around 6 seconds more of video then expected (but for these extra seconds there is no audio). This also can happen before the expected starting time of the clip (each time this has happened it's been including audio).

I'm using mp4 local video and I'm using A-B Loops to determine the length of the extract. Sorry if this is all rather vague, but I can't quite figure out a pattern.

Sagnac commented 1 year ago

Sometimes the clip points will differ from the chosen loop points because what's actually extracted is done so at keyframes so if you choose loop points which are far from one of these keyframes you will get a clip with a slightly different length (in your case it seems there's a difference of about 3 seconds on average from the start and end points).

I believe this is also the case if you use ffmpeg to cut the video without encoding using the -ss, -t, and -c copy switches as it likewise depends on keyframes, but you can compare and see if that's more accurate.

You can also use the Alt+x keybind to align the points before writing out the cache in order to confirm that this is the issue. In this case you should see a shift in the chosen length of about 6 seconds for the same video and segment you're referring to and the extracted clip should then match the new adjusted points and your previous clips.

Also you're using cache=yes for local videos, right?

DrDillis commented 10 months ago

I have the exact same problem when using loop mode, which would be my primary way of using the script, its awesome but this is a major issue, cache is enabled and used 2 different versions of MPV were used. The output file starts a few seconds too early when and ends too late when it ends too late it has no audio from then on afterwards.

EDIT: Rather than rely on the cache and stream info, I made 3 scripts that export the ab loop with ffmpeg and give a little more control to the ab loop (extend / reduce time) and return to loop if you're outside of the range.

https://github.com/DrDillis/MPV-FFMPEG-LOOPBUDDY

Sagnac commented 10 months ago

Unfortunately this is simply a limitation of cutting streams without encoding, at least as far as I understand; from my experience ffmpeg will produce similar output if you simply copy the codecs because of the aforementioned keyframe requisite. If you need exact cuts you'll usually have to encode, I don't see an easy workaround for that.