Totox691

Davinci Fusion - Clips to markers

Jan 13th, 2026
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.82 KB | None | 0 0
  1. -- Script DaVinci Resolve - Placement de médias sur marqueurs
  2. -- Lua 5.1
  3. function sleep(seconds)
  4. local debut = os.clock()
  5. while os.clock() - debut <= seconds do end
  6. end
  7.  
  8. local resolve = Resolve()
  9. local projectManager = resolve:GetProjectManager()
  10. local project = projectManager:GetCurrentProject()
  11.  
  12. if not project then
  13. error("No project open")
  14. return
  15. end
  16.  
  17. local mediaPool = project:GetMediaPool()
  18. local timeline = project:GetCurrentTimeline()
  19.  
  20. if not timeline then
  21. error("No active timeline")
  22. return
  23. end
  24.  
  25. -- Récupérer tous les marqueurs de la timeline
  26. local markers = timeline:GetMarkers()
  27. if not markers or next(markers) == nil then
  28. error("No markers found")
  29. return
  30. end
  31.  
  32. -- Convertir les marqueurs en tableau trié
  33. local markerFrames = {}
  34.  
  35. for frameId, markerData in pairs(markers) do
  36. table.insert(markerFrames, tonumber(frameId))
  37. end
  38.  
  39. table.sort(markerFrames)
  40.  
  41. local rootFolder = mediaPool:GetCurrentFolder()
  42.  
  43. local clips=mediaPool:GetSelectedClips()
  44.  
  45. if clips == nil then
  46. clips = rootFolder:GetClipList()
  47. end
  48.  
  49. if not clips or #clips == 0 then
  50. error("No media in Mediapool")
  51. return
  52. end
  53.  
  54. local numClipsPlaced = 0
  55. local minCount = math.min(#clips, #markerFrames - 1)
  56. local e=0 -- compteur d'erreur d'insertion, si erreur reste sur le même marqueur mais clip suivant
  57. for i = 1, minCount do
  58. local startFrame = markerFrames[i-e]
  59. local endFrame = markerFrames[i + 1-e]
  60. local desiredDuration = endFrame - startFrame
  61.  
  62. clips[i]:SetMarkInOut(0, desiredDuration-1, "all")
  63.  
  64. local success = mediaPool:AppendToTimeline(clips[i])
  65.  
  66. sleep(0)
  67.  
  68. if success == nil then
  69. --dump(clips[i])
  70. e=e+1
  71. print("Error when inserting Clip [ "..clips[i]:GetName().. " ], it was skipped")
  72. end
  73. end
  74.  
  75.  
  76.  
  77.  
Advertisement
Add Comment
Please, Sign In to add comment