Advertisement
Guest User

batch export premiere

a guest
Nov 5th, 2024
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.50 KB | Source Code | 0 0
  1. import pymiere
  2. import time
  3. from pathlib import Path
  4.  
  5. def get_track_selection(sequence):
  6.     track_count = sequence.videoTracks.numTracks
  7.     print(f"\nAvailable Video Tracks: {track_count}")
  8.    
  9.     for i in range(track_count):
  10.         track = sequence.videoTracks[i]
  11.         clip_count = len(track.clips)
  12.         print(f"Track {i+1}: {clip_count} clips")
  13.    
  14.     while True:
  15.         track_num = input("\nWhich track would you like to process? (Enter 1-{}): ".format(track_count))
  16.         if track_num.isdigit() and 1 <= int(track_num) <= track_count:
  17.             return int(track_num) - 1
  18.  
  19. def confirm_clips(track):
  20.     clip_count = len(track.clips)
  21.     print(f"\nFound {clip_count} clips to process:")
  22.    
  23.     for i, clip in enumerate(track.clips):
  24.         print(f"  {i+1}. {clip.name}")
  25.    
  26.     while True:
  27.         ready = input("\nReady to process? (y/n): ").lower()
  28.         if ready == 'y':
  29.             return True
  30.         elif ready == 'n':
  31.             return False
  32.  
  33. def batch_encode():
  34.     sequence = pymiere.objects.app.project.activeSequence
  35.     selected_track_index = get_track_selection(sequence)
  36.     video_track = sequence.videoTracks[selected_track_index]
  37.    
  38.     if not confirm_clips(video_track):
  39.         print("Operation cancelled")
  40.         return
  41.    
  42.     preset_path = r"Path\To\Export\Settings\Preset.epr"
  43.     export_base = r"Path\To\Export\Folder"
  44.    
  45.     print(f"\nProcessing clips from Track {selected_track_index + 1}")
  46.    
  47.     # Audio frame tick offset (5292000 ticks)
  48.     AUDIO_FRAME_OFFSET = 5292000
  49.     TICKS_PER_SECOND = 254016000000
  50.    
  51.     for clip in video_track.clips:
  52.         export_path = Path(export_base) / f"{clip.name}"
  53.         print(f"Queuing: {clip.name}")
  54.        
  55.         # Add audio frame offset to ensure correct frame boundaries
  56.         start_ticks = clip.start.ticks + AUDIO_FRAME_OFFSET
  57.         end_ticks = clip.end.ticks + AUDIO_FRAME_OFFSET
  58.        
  59.         # Convert ticks to seconds
  60.         start_seconds = start_ticks / TICKS_PER_SECOND
  61.         end_seconds = end_ticks / TICKS_PER_SECOND
  62.        
  63.         sequence.setInPoint(start_seconds)
  64.         sequence.setOutPoint(end_seconds)
  65.         time.sleep(0.1)
  66.        
  67.         pymiere.objects.app.encoder.encodeSequence(
  68.             sequence,
  69.             str(export_path),
  70.             preset_path,
  71.             1,
  72.             0
  73.         )
  74.    
  75.     print("\nStarting batch export...")
  76.     pymiere.objects.app.encoder.startBatch()
  77.  
  78. if __name__ == "__main__":
  79.     batch_encode()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement