You can make a difference in the Apple Support Community!

When you sign up with your Apple ID, you can provide valuable feedback to other community members by upvoting helpful replies and User Tips.

FCPXML File creation using script

In xml i need to provide offset and duration:

<asset-clip ref="video16" offset="52505124717/1000000000s" name="34 x2.mov" duration="2581473922/1000000000s">
<asset-clip ref="video17" offset="55086598640/1000000000s" name="36 x.mov" duration="5096621314/1000000000s">


So offset of first clip (video16) 52505124717 + duration 2581473922 = 55086598639 - that should be offset of second clip +1 (to avoid overlapping)


But when i open Final cut i see this:


And other small parts of other clips at the end...

Any solution for that?


https://drive.google.com/file/d/1dhOWxx-KPwjR4HxyMLySGkYSiFop3PAG/view?usp=sharing

Posted on Jul 15, 2024 4:57 AM

Reply
15 replies

Jul 16, 2024 5:31 PM in response to DangerD512

I'm certainly no fcpxml expert but are you sure you can use floats for duration? The docs for XML 1.10 say either a rational number or a whole number. Maybe it's changed for 1.11, but I can't find those docs.


From Document Type Definition | Apple Developer Documentation


<!-- FCP XML Interchange Format, Version 1.10 -->
<!-- Copyright (c) 2011-2021 Apple Inc. All rights reserved. -->

<!-- COMMON ENTITIES -->
<!-- 'time' attributes are expressed as a rational number of seconds (e.g., "1001/30000s") -->
<!-- with a 64-bit numerator and 32-bit denominator. -->
<!-- Integer 'time' values, such as 5 seconds, may be expressed as whole numbers (e.g., '5s'). -->
<!ENTITY % time "CDATA">


Your fcpxml has a decimal time:

    <asset id="video0" format="r1" name="10 x(25).mov" ... duration="121.74s">


Importing your fcpxml into FCP 10.7.1 and then re-exporting it, the duration for this asset is converted to:

    <asset id="r2" name="10 x(25).mov" ... duration="73044/600s"

which is 121.74. But since your fcpxml does actually import maybe this is not the problem.


Importing this re-exported fcpxml comes in with no complaints about edit boundaries but 4 new complaints about edits.

Info.fcpxml	Invalid edit with no respective media. (/fcpxml[1]/library[1]/event[1]/project[1]/sequence[1]/spine[1]/asset-clip[20])
Info.fcpxml	Invalid edit with no respective media. (/fcpxml[1]/library[1]/event[1]/project[1]/sequence[1]/spine[1]/video[3])
Info.fcpxml	Invalid edit with no respective media. (/fcpxml[1]/library[1]/event[1]/project[1]/sequence[1]/spine[1]/asset-clip[23])
Info.fcpxml	Invalid edit with no respective media. (/fcpxml[1]/library[1]/event[1]/project[1]/sequence[1]/spine[1]/asset-clip[24])


The ends of both the original fcpxml and re-exported-then-imported fcpxml timelines look odd and to me could be duration or offset calculation problems. If it were me, I'd start with simple, whole second durations to make sure duration and/or offset calculations are correct.


Original fcpxml


Re-exported fcpxml

Jul 21, 2024 5:32 PM in response to DangerD512

Here's a Swift library for reading and writing time and timecodes to and from FCPXML, among other formats. Even if your app is not written with Swift perhaps you can glean some info from it. github dot com/orchetect/TimecodeKit


For example, here's a snippet to convert real-world wall clock time to timecode.

// elapsed real-world wall time → timecode
try Timecode(.realTime(seconds: 3603.6), at: .fps23_976)


There's also some discussion in the developer discussions at fcp dot cafe/developers/fcpxml/

Jul 15, 2024 8:24 AM in response to DangerD512

I am not being able to test because FCP determines that there is an error when importing your fcpxml:



I opened the xml using TextMate, and I cannot find which item is causing this error.


I do see that the items you listed above also have a <timeMap> tag associated with them, though I am not sure if that has anything to do with the present problem.


Would it be possible to provide a minimal example, with say two clips?

Jul 15, 2024 10:07 AM in response to DangerD512

DangerD512 wrote:

Added format, please check:
https://drive.google.com/file/d/1ZEnd-1CP2Nj13s6ocWAwKohjFnKkPgPa/view?usp=sharing

Take a look at the end, there're small parts of clips, as i understood due to overlapping somehow...


This time, I first got a similar error about an asset missing a duration.

It was an audio clip and I added a bogus value for duration.


I was then able to import the xml.

There were many warnings saying that the clips were not placed at a frame boundary, but the import went through. Obviously all the clips are missing. Besides that, does this look like the timeline you would expect?


Jul 16, 2024 4:22 AM in response to DangerD512

I did zoom where you indicated. I don't know what I am supposed to see, though.


The message about frame boundaries has to do with the values in the xml: you can in principle put any numbers in the xml, but video has to be on frame boundaries.


For example,

.... offset="38799/2997s"


this would correspond to frame 387.99 on a 29.97fps timeline - probably rounded up to 388.


Your initial example included something like this:


52505124717/1000000000s


Now this is about 52.5 seconds, but I am not sure how it will align with a frame boundary.



I assume this is in a 29.97fps project, and maybe this ends up being frame number 387.99 - so frame 388, probably...



Jul 16, 2024 7:52 AM in response to DangerD512

DangerD512 wrote:

Automated video creation is the goal.

I would suggest taking the desired frame rate into account.

And, by the way, avoid fractional frame rates unless you have to use them, for some reason.


For example, if your video is going to be at 30fps, you could use things like 7895/30s and never get an out of frame border - basically if you use the frame rate as the denominator, the frame number will be the numerator.


And if you start with a time in seconds, say 1.23s multiply by 30 (assuming that is the frame rate) and round it to the nearest integer, e.g. 1.23*30=36.9 and you'd use 37/30 for frame 37.

Jul 21, 2024 7:15 AM in response to DangerD512

I *think* the problem is that 16.02 (for example) does not exactly match with a whole number of frames.

TBH, the fact that we are dealing with nefarious fractional frame rates only makes it harder to figure out (plus: we did not even got to deal with drop frame vs non-drop frame).


But even with a decent frame rate like 25 or 30, there are difficulties. For example, the same 16.02 would not correspond to a whole number of frames, anyway: .02 is /1/50 of a second, and that would be half a frame in 25fps, or 3/5 of a frame at 30fps.


As I understand this, what is needed is a calculation to figure out the nearest frame boundary given any time duration.

Here again using a nonfractional frame rate would make it rather easy: the integer part you just multiply by the frame rate, and you need just find the nearest frame boundary corresponding to the decimal part.

FCPXML File creation using script

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.