WyattBlue / auto-editor

Auto-Editor: Efficient media analysis and rendering
https://auto-editor.com
The Unlicense
2.71k stars 402 forks source link

Cut segements without re-encoding #426

Closed sasa closed 3 months ago

sasa commented 5 months ago

Hi WyattBlue,

love, love, love auto-editor. Thanks for the mention on the contributors page. I was wondering how I could contribute more. Maybe I can do so short tutorials or work a little on the docs.

So here is what has been bugging me the last weeks. I auto-edit a lot a videos. Usually tutorials by myself. Some of them are very long. I would like to know if there is a way to cut the parts without re-encoding them. Or get a list of timestamps with which I could "extract" the parts myself. For example this 3 minute 4k clip took almost 5 minutes to finish:

PS C:\home\Videos\Trading> auto-editor clip.mkv --no_open --ffmpeg-location C:\bin\ffmpeg.exe --export clip-sequence -vcodec copy --margin 1sec --show-ffmpeg-commands
C:\bin\ffmpeg.exe -hide_banner -y -i clip.mkv -map 0:a:0 -ac 2 -ar 48000 -rf64 always C:\Users\ebach\AppData\Local\Temp\tmpfwlhxrzp\0.wav -nostats -loglevel error

C:\bin\ffmpeg.exe -hide_banner -y -f rawvideo -c:v rawvideo -pix_fmt yuv420p -s 3840*2160 -framerate 60 -i - -pix_fmt yuv420p -b:v 10M -c:v hevc -movflags faststart -vf setsar=1 C:\Users\ebach\AppData\Local\Temp\tmpfwlhxrzp\spedup0.mp4

# TRUNCATED OUTPUT

C:\bin\ffmpeg.exe -hide_banner -y -i clip.mkv -i C:\Users\ebach\AppData\Local\Temp\tmpfwlhxrzp\spedup0.mp4 -i C:\Users\ebach\AppData\Local\Temp\tmpfwlhxrzp\new0.wav -map 1:0 -map  -color_trc unknown -strict -2 -map 0:t? clip_ALTERED-8.mkvc:a aac -color_range tv

Finished. took 290.59 seconds (0:04:51)

What else can I do expect -vcodec copy to ensure that it doesn't get re-encoded? I was thinking of taking the output of --export shotcut and trying to create a script and use ffmpeg myself. But maybe this is not necessary.

I actually tried using the shotcut timestamps to slice the original file:

C:\bin\ffmpeg -copyts -i clip.mkv -c copy -ss 00:00:11.283 -to 00:00:14.850 output1.mkv
...
C:\bin\ffmpeg -copyts -i clip.mkv -c copy -ss 00:02:54.817 -to 00:02:59.633 output9.mkv

The results were not good. I think this has to do with the keyframes, but I am not sure.

Any ideas?

Greetings Saša

WyattBlue commented 3 months ago

Your suggestion is very reasonable.

I don't think using the ffmpeg cli is a reasonable approach for implementation. A better approach would be to use PyAV and copy the video packet if no modification is needed. This is pretty involved on my end, however, so I'll circle back on this eventually.