Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve support for external post-process programs #974

Open
Yoooi0 opened this issue Jan 10, 2022 · 12 comments
Open

Improve support for external post-process programs #974

Yoooi0 opened this issue Jan 10, 2022 · 12 comments

Comments

@Yoooi0
Copy link

Yoooi0 commented Jan 10, 2022

This is a loose feature request but I recently had a project in mind recently that required me to cut/merge video files and I didnt want to reinvent the wheel with video processing so I wanted to use LosslessCut for that, and write a simple "post-process" application that would do the stuff I need on the exported files.
While writing I noticed that it is actually somewhat tricky to use .llc project files from external programs.

For example there is no way to know what files were actually exported. The external program could try to create the file names if it knows the segment export format that the user configured, and the .llc project file, but due to float inaccuracies I actually encountered a case where the segment time in the filename was off by 1ms.
I think the project file could contain information on the last export, something like this:

{
  ...
  "lastExport": {
    "type": "merge+separate",
    "path": "C:\\Videos",
    "segmentFormat": "${FILENAME}-${CUT_FROM}-${CUT_TO}${SEG_SUFFIX}${EXT}",
    "output": [
      "video-00.01.17.230-00.02.12.465-seg1.mp4",
      "video-00.03.36.232-00.05.17.917-seg2.mp4",
      "13793562_720p-cut-merged-1641853512921.mp4"
    ]
  }
}

As a bonus, LosslessCut could allow users to specify an executable to run after each export that would pass the .llc project file path as argument. This way advanced users could create small post-process plugins/applications and rely on LosslessCut on the actual cutting/merging.

@mifi
Copy link
Owner

mifi commented Jan 11, 2022

Thanks for your feature request

  • I think it's the first time I've heard a request for running an external program after the export, but we can leave this open in case it is something that more people would want to do.
  • I'm not sure if lastExport is something that belongs in the project file, but maybe we could improve the output file format so you can more easily correlate the project file's content with the output file names. Doesn't cutSegments array index equal to the template variable ${SEG_NUM}?

@Yoooi0
Copy link
Author

Yoooi0 commented Jan 11, 2022

I'm not sure if lastExport is something that belongs in the project file, but maybe we could improve the output file format so you can more easily correlate the project file's content with the output file names.

True, but it would make sense if the project would include all/most of the options you can configure when exporting, maybe not the actual file names but stuff like segment format, export type, and the path. Those would be then auto set when loading a project in LosslessCut.

But one issue would remain with start/end segment times being saved as floats, like i mentioned there are cases where converting the float value to time string can result in 1ms differences.
Ideally I think they should be saved in some specific string time format like "hh.mm.ss.fff".

I think it's the first time I've heard a request for running an external program after the export, but we can leave this open in case it is something that more people would want to do.

Yea I figured that this would be an super edge case request.
But it could be used to make tools or python scripts to for example automatically cut subtitles (i think i saw a request for that), metadata or other additional tracks. Maybe automatically move exported files to some archive, batch open each segment in some video processing software.
Just spit balling some stuff that can be automated but which doesnt belong to be added as a feature to LosslessCut.

@mifi
Copy link
Owner

mifi commented Jan 11, 2022

True, but it would make sense if the project would include all/most of the options you can configure when exporting, maybe not the actual file names but stuff like segment format, export type, and the path. Those would be then auto set when loading a project in LosslessCut.

Yes I agree that some of these options could be saved in the project file, that is something I have to consider.

Ideally I think they should be saved in some specific string time format like "hh.mm.ss.fff".

I'm not sure why you need the time to be exact, but I agree that such a format makes sense. Or just the calculated frame number (which we are already showing inside the UI)

But it could be used to make tools or python scripts to for example automatically cut subtitles (i think i saw a request for that), metadata or other additional tracks. Maybe automatically move exported files to some archive, batch open each segment in some video processing software.

That's true, and also why I want to leave the feature request open

@Yoooi0
Copy link
Author

Yoooi0 commented Jan 11, 2022

I'm not sure why you need the time to be exact, but I agree that such a format makes sense. Or just the calculated frame number (which we are already showing inside the UI)

I assumed you don't like the idea of saving the list of latest exported files to the project file itself, so for the tool/script to reconstruct the exported file names based on the project file and do the stuff it does, it needs the "segment format" and segment time/start times.
But there also cant be a mismatch between the start/end times in the file names saved by LosslessCut and times that the tool will be able to create from the float value.
For example:

project file:

{
  ...
  cutSegments: [
    {
      start: 1023.023,
      end: 1123.023,
      name: '',
    },
  ]
}

exported file: video-00.17.03.023-00.18.43.022.mp4
C# tool:

//outputs 00.17.03.023
TimeSpan.FromSeconds(1023.023).ToString(@"hh\.mm\.ss\.fff");

//outputs 00.18.43.023
TimeSpan.FromSeconds(1123.023).ToString(@"hh\.mm\.ss\.fff");

As you can see there is a 1ms mismatch.
So I think the float value is fine for precision, but can be unreliable when trying to create the correct file names.

@mifi
Copy link
Owner

mifi commented Jan 14, 2022

Could you instead use the ${SEG_NUM} in your output file format as suggested above, and then I believe SEG_NUM should correspond with the index inside the cutSegments array

@Yoooi0
Copy link
Author

Yoooi0 commented Jan 14, 2022

Yes that will work fine but requires me to use some special format. Or I could use the default format to get the seg1, seg2 etc. suffix but then you can't label your segments.
If the tool was just for me then there would be no problem with me using some custom format in LosslessCut, but if I were to share it then I can't really assume what the user settings are.

This feature request was so that the tools/scripts could be more generic and not rely on assumptions, just parse the project file to get all the info they need. There is no problem in getting this to work if I hardcode some stuff.

@mifi
Copy link
Owner

mifi commented Jan 14, 2022

Ah, so you want to kknd of build an application or tool around losslesscut and distribute it as one working unit? Then yea i agree it would be better to have a programmatic api. I have created an issue for gathering these kinds of programmatic requests #980

@Yoooi0
Copy link
Author

Yoooi0 commented Jan 14, 2022

More or less yes, it doesn't have to be distributed as one, it would use output from losslesscut to do its thing on the exported segments files and/or merged file. The output I suggested that could be used would the the project file since it is always created, and just needs a few tweaks.

I didn't even think to suggest an api because I knew that it will be a bigger task, but for sure it will be more flexible and could provide even more data/events that would not be fit for the project file.
Thanks!

@mifi
Copy link
Owner

mifi commented Jan 14, 2022

How does your program know that the export is finished if there is no API?

@Yoooi0
Copy link
Author

Yoooi0 commented Jan 14, 2022

It doesn't, I just drag drop the project file manually after the export is done.

@Pierrounator
Copy link

Hi, I'm hopping something like this will happen.
I personnaly use LosslessCut just to have time codes based on keyframes, then I export those time codes in txt and I use MKVtoolnix to split.
Unfortunately, those .txt files are not “other programs” friendly so I have to edit them manually which is a pain when you have a lot of files to process. I would love to be able to export those timestamps with {start1}-{end1},{start2}-{end2} format.

@mifi mifi mentioned this issue Aug 23, 2024
4 tasks
@bverkron
Copy link

Would love this feature as well. I am using LC to cut larger video files from my Canon R6 MK II into clips. It works great overall but a bunch of the metadata like Exposure, Aperture, etc are missing in the clips that LC produces, even when using the Preserve all MP4/MOV metadata option during export. I think this is due to the non-standard metadata fields in the source file or the limited fields available in the resulting file formats. Not sure.

Point being that I use exiftool to copy all the metadata from the original file to the clips but currently this has to be done manually afterwards. Would be amazing if I could just trigger my exiftool script automatically after exporting the file(s) from LC!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants