mifi / lossless-cut

The swiss army knife of lossless video/audio editing
GNU General Public License v2.0
24.01k stars 1.19k forks source link

M3U VLC Export #2051

Open dreamflasher opened 1 week ago

dreamflasher commented 1 week ago

The fewer issues I have to read, the more new features I will have time to implement, so I ask that you please try these things first

Description

I'd like to be able to export projects as M3U playlist files, including vlc start-stop info:

#EXTVLCOPT:start-time=28.3
#EXTVLCOPT:stop-time=36.7
video.mp4

This would allow me to play cut videos without storing the cut segments (and thus saving disk space) and allows lossless cutting on a frame level.

mifi commented 1 week ago

Interesting use case. So you want to be able to store an m3u playlist which has a bunch of start-stop times for the same video file, thus when a player plays it back, the player effectively just seeks back and forth in the same video?

Is it m3u or m3u8?

dreamflasher commented 1 week ago

Yeah, meanwhile I actually implemented a python script to convert LLC to M3U, maybe it's helpful for others or could be used as an inspiration:

import urllib.parse
from pathlib import Path

import demjson3
from fire import Fire

def main(llc: Path):
    llc = Path(llc)
    l = demjson3.decode(llc.read_text())
    segments = l["cutSegments"]

    for i, segment in enumerate(segments):
        out = ["#EXTM3U"]
        out.append(f"#EXTVLCOPT:start-time={segment['start']}")
        out.append(f"#EXTVLCOPT:stop-time={segment['end']}")
        out.append(urllib.parse.quote(l["mediaFileName"]))
        Path(llc.parent / f"{llc.stem}-{i}-{segment['name']}.m3u").write_text("\n".join(out))

if __name__ == '__main__':
    Fire(main)

I'm using this with M3U, but it also works with M3U8, I am not attached to the file extension.

And it works like a charm. VLC is fast enough in opening and jumping to the file position. I implemented it the way that it creates an m3u file for each split segment, because I want to reorder the segments or only use specific segments each time – but in lossless cut it could just output it to one file with all segments.

mifi commented 1 week ago

thanks. i agree it's a cool feature so i'll consider implementing it