PySceneDetect icon indicating copy to clipboard operation
PySceneDetect copied to clipboard

Final Cut Pro X - XML File

Open cbitterfield opened this issue 4 years ago • 14 comments

Description of Problem & Solution

Request the ability export scene cut information directly to a FInal Cut Pro XML file.

Media Examples:

Guide to XML https://support.apple.com/guide/final-cut-pro/use-xml-to-transfer-projects-verdbd66ae/mac.

Proposed Implementation:

From what I understand it is the same information as the CSV file but in "FCPX" XML format

Alternative Solutions: Writing a python converter between the CSV output and the XML format.

cbitterfield avatar Mar 27 '20 04:03 cbitterfield

I found this on the developer documentation about the XML format itself, but could definitely use some pointers for where to start. The XML looks a lot more involved than just the CSV though at a first glance. If you could provide an example XML that would be helpful for me to judge the effort required to implement this.

Thank you!

Breakthrough avatar Mar 30 '20 01:03 Breakthrough

Marking as on-hold until further information can be gleaned as to the scope of this feature. Closing issue to cleanup backlog, feel free to re-open in future if desired.

Breakthrough avatar Jul 29 '20 18:07 Breakthrough

I am very interested in a feature like this. Having it could save a lot of time with my workflow and also hopefully fix a few quirks with the current one (like with colorspace conversion or disk space required for lossless conversions)

camjac251 avatar Mar 21 '22 11:03 camjac251

I tried to find if someone else might've made something like this before but could only find https://github.com/Mirellanmawl/PySceneDetect-CSV-to-Vegas-EDL and https://github.com/duolanda/scene-detect-to-xml The second one I believe takes the final clip video files generated by PySceneDetect and creates an FCP XML from that, instead of using the CSV output as an input

camjac251 avatar Mar 21 '22 11:03 camjac251

If you can provide an example of what this XML should look like I can certainly look into adding support for it. I don't have Final Cut Pro so I will need some assistance with testing as well.

Could add a few new commands to the CLI like save-csv, save-xml, and save-edl - just need a library of samples for the output format.

Breakthrough avatar Mar 22 '22 00:03 Breakthrough

I can work on that, to get one to you. I use Premiere Pro and Davinci Resolve. FCP XML is pretty much supported with all major NLEs luckily and has been better for me than EDL. You could save one out or import one in both programs. It might take me a little while to create a test example but maybe this might be more helpful https://developer.apple.com/documentation/professional_video_applications/fcpxml_reference https://github.com/Cubxity/ResolveParser or the work that this user has done https://github.com/duolanda/scene-detect-to-xml/blob/main/xml_creator.py or https://github.com/ldsxp/fcpxml/blob/master/fcpxml/fcp.py

camjac251 avatar Mar 22 '22 00:03 camjac251

Awesome, yeah if we can just get the most simplest "ground truth" XML so to speak I can use that as the test case for validation purposes. Ideally it would just be a short clip with 3 or more cuts, can just be manually placed. I'm also curious if you can specify a shorter start/duration if for example the time command was used.

If this XML could be validated on all of the programs you mentioned as well then it should be no problem at that point in adding a new command. One open question I have that might need some testing is how robust these parameters need to be:

    <format id="r1" name="FFVideoFormat1080p30"/>
    <asset id="r2" start="0s" duration="10s" hasVideo="1" hasAudio="1" format="r1" audioSources="1" audioChannels="2" audioRate="48000">
        <media-rep kind="original-media" src="file:///Volumes/media/MyMovie1.mov"/>
    </asset>

I'm assuming some of that information can be simply omitted (edit: looks like that may be the case indeed), so hoping we can come up with the smallest example that works with all of those programs you listed. Thanks!

The smallest thing I think is something like (with some of my own comments inline for things that need to be determined):


<fcpxml version="1.10">
    <resources>
        <!-- can format be omitted? -->
        <format id="r1" name="FFVideoFormat1080p30"/>
        <!-- can start/duration be omitted?  can they be overriden?  if so how does it affect start/duration in the clips below? -->
        <asset id="r2" start="0s" duration="10s">
            <media-rep kind="original-media" src="file:///Volumes/media/MyMovie1.mov"/>
        </asset>
    </resources>
    <event name="Scenes">
        <!-- can format be omitted? can audio_role be omitted? -->
        <!-- what does setting offset (e.g. offset="5s") do? -->
        <asset-clip name="scene1" ref="r2" format="r1" start="0s" duration="10s" audioRole="dialogue"/>
        <asset-clip name="scene2" ref="r2" format="r1" start="0s" offset="5s" duration="20s" audioRole="dialogue"/>
        <asset-clip name="scene3" ref="r2" format="r1" start="10s" duration="40s" audioRole="dialogue"/>
    </event>
</fcpxml>

Breakthrough avatar Mar 22 '22 01:03 Breakthrough

I've created a few test files in Davinci Resolve and Premiere Pro. I hope they might be useful. I took this video from http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4, imported it into Davinci Resolve, onto a timeline, and ran the cut detection in the app which went through and added splices for each cut. That is the base for all of these files. I then exported it out of Resolve with the FCP 7 XML V5 Files option which creates an XML file. There were other options like FCPXML 1.9 which might've been what I linked above but the extension .fcpxml isn't detected when I go to import in Premiere, even after renaming to XML. FCP 7 XML V5 works though. I exported this from Davinci and imported it into Premiere and re-exported it with the Final Cut XML option. I did this for a timeline with audio and without. I can't upload an XML file directly on GitHub, but was able to zip them up and upload that. AllFCPXMLs.zip

According to this https://helpx.adobe.com/premiere-pro/how-to/migrate-from-final-cut-pro.html Final Cut Pro X generated files aren't compatible with Premiere, but older FCP7 files would be.

camjac251 avatar Mar 23 '22 10:03 camjac251

Here's the documentation for the FCP 7 XML format https://developer.apple.com/library/archive/documentation/AppleApplications/Reference/FinalCutPro_XML/AboutThisDoc/AboutThisDoc.html#//apple_ref/doc/uid/TP30001152-TPXREF101

I saw this as well which might be cool as a library to use in PySceneDetect https://opentimelineio.readthedocs.io/en/latest/tutorials/adapters.html https://github.com/PixarAnimationStudios/OpenTimelineIO

camjac251 avatar Mar 23 '22 10:03 camjac251

Awesome, thank you so much. One last thing that would be super helpful is, if you could repeat what you did with those XMLs, but using just the first 30 seconds of that clip, as well as the same thing but at 23.976 FPS and at 30 FPS (re-encoding is fine). I need to work out how the timing values are calculated and that would help work out any edge cases. (No need for more than the first 30 seconds)

Really appreciate these samples. I can't commit to any definite timelines just yet, but will likely target this for v0.6.1 (right after the upcoming release). I may need some help testing some hand-crafted XMLs once this is being worked on just to verify that everything will work, but what you provided should be perfect for getting that started.

Thank you!

Edit: Found one more implementation that might help as a reference: https://github.com/antiboredom/videogrep/blob/master/videogrep/fcpxml.py

I didn't realize Davinci Resolve is free, so I'll see how far I can get using that for some testing while developing this out.

Breakthrough avatar Mar 24 '22 23:03 Breakthrough

Just a quick update, have scheduled this for v0.7, but right now I don't have many cycles to tackle this. If anyone else wants to step in and submit a PR for this though, would be happy to accept that. Thanks for your patience.

Breakthrough avatar Aug 25 '22 22:08 Breakthrough

First of all, sorry for my English. It is not my native language. I hope I can explain myself well.

In Davinci Resolve, the scene cut detection window allows us to export the timecodes to EDL or SceneCut file format. For import it is the same, but EDL has some issues related to mismatched frame rates between the original file and the project when importing directly from the media page. For example, if you have this security footage at 15fps and the project in davinci is at 24fps, importing that video into davinci, it will converts those 15fps timecodes to 24fps. So the original marked frame will never be the same in davinci. I found a user with a similar problem: https://forum.blackmagicdesign.com/viewtopic.php?f=21&t=80962

Instead, the SceneCut format is very simple at that. It only counts the total frames and marks the frame that has differences from the previous frame. PySceneDetect or DVR-Scan just needs to put some value where it detects a scene change or in the case of DVR-Scan, in the start motion frame and then in the end motion frame. The data that is saved in that format is also simple. I'm just not sure what some values ​​mean but trying different videos with different frames per second, it seems that they don't influence the final result that PySceneDetect or DVR-Scan would offer.

In the BlackMagic Desing forum I have asked but nobody has answered me yet the following:

I have this data in a SceneCut file 0 <-- intial frame? 509 <-- end frame? total frames? 0 <-- playhead position 0 <-- in point range? 509 <-- end point range? 100 <-- threshold position (magenta line, filter sensitivity) 0 <-- first frame 0 <-- second frame etc...

The value of the line from the first frame to the last can vary in relation to the sensitivity with which the tool detects differences with previous frames.

washinoboku avatar Oct 08 '22 20:10 washinoboku

I also found this project: https://github.com/ThomasWeckenmann/PyVfxShotDetect/tree/master/scenedetect

May be useful when revisiting this.

Breakthrough avatar Nov 21 '22 03:11 Breakthrough

+1 for FCP XML support

According to Apple, there were more than 2.5 million users of FCP as of 2018. Enlyft reports that they have data on 36,427 companies that use FCP.

slavakurilyak avatar Mar 11 '23 17:03 slavakurilyak