
    3j.                        S SK r S SKrS SKrS SKrS SKrS SKJr  S SKJr  S SK	J
r
  S SKJrJrJrJrJrJr  S SKJr   " S S\R(                  5      r " S	 S
\R(                  5      r " S S\R(                  5      r " S S\R(                  5      r " S S\R(                  5      r " S S\R(                  5      r " S S\5      rS\4S jrg)    N)Optional)override)Fraction)ComfyExtensioniouiInput	InputImplTypes)argsc                   P    \ rS rSr\S 5       r\S\R                  4S j5       rSr	g)SaveWEBM   c                    [         R                  " SS/SSS[         R                  R                  SSS9[         R                  R                  S	S
S9[         R
                  R                  SSS/S9[         R                  R                  SSSSSS9[         R                  R                  SSSSSSS9/[         R                  R                  [         R                  R                  /SS9$ )Nr   zexport webmz	Save WEBMvideoTimageszPRGBA images are saved with their alpha channel as transparency (vp9 codec only).tooltipfilename_prefixComfyUI)defaultcodecvp9av1)optionsfpsg      8@g{Gz?g     @@r   minmaxstepcrfg      @@r   g     O@   zhHigher crf means lower quality with a smaller file size, lower crf means higher quality higher filesize.)r   r   r   r    r   )node_idsearch_aliasesdisplay_namecategoryis_experimentalinputshiddenis_output_node)
r   SchemaImager	   StringComboFloatHiddenpromptextra_pnginfoclss    8/home/wildlama/comfy/ComfyUI/comfy_extras/nodes_video.pydefine_schemaSaveWEBM.define_schema   s    yy)?$ x  2D  E		 19Ew?ud&tTudt!  V@  A II$$bii&=&=>
 	
    returnc           	      l   [         R                  " U[         R                  " 5       US   R                  S   US   R                  S   5      u  pgpnU SUS S3n
[        R
                  " [        R                  R                  Xj5      SS9nU R                  R                  b7  [        R                  " U R                  R                  5      UR                  S'   U R                  R                  bW  U R                  R                   H=  n[        R                  " U R                  R                  U   5      UR                  U'   M?     UR                  S	   S
:H  =(       a    US:H  nSSS.nUR                  X   [!        [#        US-  5      S5      S9nUR                  S   Ul        UR                  S   Ul        U(       a  SO	US:X  a  SOSUl        SUl        S[-        U5      0Ul        US:X  a  SUR.                  S'   U GH)  nU(       a{  [        R0                  R3                  [4        R6                  " USS S
24   S-  SSS9R9                  [4        R:                  " S5      [4        R<                  S9R?                  5       SS 9nOz[        R0                  R3                  [4        R6                  " USS S!24   S-  SSS9R9                  [4        R:                  " S5      [4        R<                  S9R?                  5       S"S 9nURA                  U5       H  nURC                  U5        M     GM,     URC                  URA                  5       5        URE                  5         [F        RH                  " [J        RL                  " [J        RN                  " X[F        RP                  RR                  5      /5      S#9$ )$Nr   r"   _05z_.webmw)moder1      r   z
libvpx-vp9	libsvtav1)r   r   i  )rateyuva420pr   yuv420p10leyuv420pr!   6preset.   )r   r   cpu)devicedtypergba)format   rgb24r   )*folder_pathsget_save_image_pathget_output_directoryshapeavopenospathjoinr)   r1   jsondumpsmetadatar2   
add_streamr   roundwidthheightpix_fmtbit_ratestrr   
VideoFramefrom_ndarraytorchclamptorL   uint8numpyencodemuxcloser   
NodeOutputr   PreviewVideoSavedResult
FolderTypeoutput)r4   r   r   r   r   r!   full_output_folderfilenamecounter	subfolderfile	containerx
save_alpha	codec_mapstreamframepackets                     r5   executeSaveWEBM.execute    sO   LXLlLl\>>@&)//RSBTV\]^V_VeVefgVhM
Ig/ 1WRL/GGBGGLL);BM	::(+/::cjj6G6G+HIx(::##/ZZ--(,

3::3K3KA3N(O	""1% .
 \\"%*=u~
(=	%%i&6XeCRVJFWY]=^%_||B'R('1RW]fS*E>'*FNN8$E225;;uS"1"W~PS?SYZ`c3d3g3goto{o{  }B  pC  KP  KV  KV3g  4W  4]  4]  4_  hn2  o225;;uS"1"W~PS?SYZ`c3d3g3goto{o{  }B  pC  KP  KV  KV3g  4W  4]  4]  4_  ho2  p --.f% /  	fmmo&}}QSQ^Q^QeQe1f0g hiir8    N)
__name__
__module____qualname____firstlineno__classmethodr6   r   rp   r   __static_attributes__r   r8   r5   r   r      s6    
 
$ 'j"-- 'j 'jr8   r   c                   l    \ rS rSr\S 5       r\S\R                  S\S\	R                  4S j5       rSrg)		SaveVideoJ   c                    [         R                  " SS/SSSS[         R                  R                  SSS9[         R                  R                  S	S
SS9[         R
                  R                  S[        R                  R                  5       SSS9[         R
                  R                  S[        R                  R                  5       SSS9/[         R                  R                  [         R                  R                  /SS9	$ )Nr   zexport videoz
Save Videor   Basicsz8Saves the input images to your ComfyUI output directory.zThe video to save.r   r   zvideo/ComfyUIzThe prefix for the file to save. This may include formatting information such as %date:yyyy-MM-dd% or %Empty Latent Image.width% to include values from nodes.r   r   rO   autoz The format to save the video as.)r   r   r   r   zThe codec to use for the video.T)	r#   r$   r%   r&   essentials_categorydescriptionr(   r)   r*   )r   r+   Videor	   r-   r.   r   VideoContaineras_input
VideoCodecr0   r1   r2   r3   s    r5   r6   SaveVideo.define_schemaK   s    yy*+% (Rw0DE		 1?  Uu  vx1E1E1N1N1PZ`  kM  Nw0@0@0I0I0KU[  fG  H	 II$$bii&=&=>
 	
r8   r   rO   r9   c           	      4   UR                  5       u  pV[        R                  " U[        R                  " 5       UU5      u  pxpnS n[        R
                  (       d  0 nU R                  R                  b%  UR                  U R                  R                  5        U R                  R                  b  U R                  R                  US'   [        U5      S:  a  UnU SU	S S[        R                  R                  U5       3nUR                  [        R                   R#                  X}5      [        R                  " U5      UUS9  [$        R&                  " [(        R*                  " [(        R,                  " X[$        R.                  R0                  5      /5      S9$ )Nr1   r   r;   r<   z_.)rO   r   r^   rR   )get_dimensionsrS   rT   rU   r   disable_metadatar)   r2   updater1   lenr   r   get_extensionsave_torY   rZ   r[   r   rp   r   rq   rr   rs   rt   )r4   r   r   rO   r   ra   rb   ru   rv   rw   rx   saved_metadatar^   ry   s                 r5   r   SaveVideo.execute^   sE   ,,.LXLlLl--/	M
Ig/ $$Hzz''3

 8 89zz  ,%(ZZ%6%6"8}q !)1WRL5+?+?+M+Mf+U*VWGGLL+2''/#	 	 	
 }}QSQ^Q^QeQe1f0g hiir8   r   N)r   r   r   r   r   r6   r	   r   re   r   rp   r   r   r   r8   r5   r   r   J   sM    
 
$ jEKK j# jQSQ^Q^ j jr8   r   c                       \ rS rSr\S 5       r\ SS\R                  S\S\	\R                     S\S\R                  4
S	 jj5       rS
rg)CreateVideo{   c                    [         R                  " SS/SSSS[         R                  R                  SSS	9[         R                  R                  S
SSSSS9[         R
                  R                  SSSS9[         R                  R                  SSSSSSS[         R                  R                  S9/[         R                  R                  5       /S9$ )Nr   zimages to videozCreate Videor   Video ToolszCreate a video from images.r   z"The images to create a video from.r   r   g      >@g      ?g      ^@r   audioTzThe audio to add to the video.)optionalr   	bit_depth   
      zBit depth of the created video. 10-bit keeps smoother gradients with less banding, but some players and downstream nodes may not support it.)r   r   r   r    r   r   display_mode)r#   r$   r%   r&   r   r   r(   outputs)r   r+   r,   r	   r/   AudioIntNumberDisplaynumberr   Outputr3   s    r5   r6   CreateVideo.define_schema|   s    yy!-.' -5x1UVudSQw?_`Z!!#!1!1!8!8  
	" !/
 	
r8   Nr   r   r   r   r9   c                     [         R                  " [        R                  " [        R
                  " X[        U5      S9US95      $ )N)r   r   
frame_rate)r   )r   rp   r
   VideoFromComponentsr   VideoComponentsr   )r4   r   r   r   r   s        r5   r   CreateVideo.execute   s;     }}))%%VXVY][#
 	
r8   r   )Nr   )r   r   r   r   r   r6   r	   r,   floatr   r   intr   rp   r   r   r   r8   r5   r   r   {   sd    
 
: de
[[
',
5=ekk5J
^a
	
 
r8   r   c                   h    \ rS rSr\S 5       r\S\R                  S\R                  4S j5       r
Srg)GetVideoComponents   c                 T   [         R                  " S/ SQSSS[         R                  R                  SSS9/[         R                  R                  SS	9[         R                  R                  S
S	9[         R                  R                  SS	9[         R                  R                  SS	9/S9$ )Nr   )zextract frameszsplit videozvideo to imagesdemuxzGet Video Componentsr   zNExtracts all components from a video: frames, audio, framerate, and bit depth.z%The video to extract components from.r   r   )r%   r   r   r   )r#   r$   r%   r&   r   r(   r   )	r   r+   r   r	   r,   r   r   r/   r   r3   s    r5   r6    GetVideoComponents.define_schema   s    yy(X/hw0WX X6W5U3;7	
 	
r8   r   r9   c                     UR                  5       n[        R                  " UR                  UR                  [        UR                  5      UR                  5       5      $ N)get_componentsr   rp   r   r   r   r   get_bit_depth)r4   r   
componentss      r5   r   GetVideoComponents.execute   sF    ))+
}}Z..
0@0@%
H]H]B^`e`s`s`uvvr8   r   N)r   r   r   r   r   r6   r	   r   r   rp   r   r   r   r8   r5   r   r      sB    
 
$ wEKK wBMM w wr8   r   c                   p    \ rS rSr\S 5       r\S\R                  4S j5       r\S 5       r	\S 5       r
Srg)		LoadVideo   c                 (   [         R                  " 5       n[        R                  " U5       Vs/ s HH  n[        R                  R                  [        R                  R                  X5      5      (       d  MF  UPMJ     nn[         R                  " US/5      n[        R                  " S/ SQSSS[        R                  R                  S[        U5      [        R                  R                  S9/[        R                  R!                  5       /S9$ s  snf )	Nr   r   )zimport videoz
open videoz
video filez
Load Videor   ry   )r   upload)r#   r$   r%   r&   r   r(   r   )rS   get_input_directoryrY   listdirrZ   isfiler[   filter_files_content_typesr   r+   r.   r	   sorted
UploadTyper   r   r   )r4   	input_dirffiless       r5   r6   LoadVideo.define_schema   s     446	JJy1`1qRWW^^BGGLLQZD^5_1`77yIyyG% (vve}R]]EXEXY !
 	
 as   AD7Dr9   c                     [         R                  " U5      n[        R                  " [        R
                  " U5      5      $ r   )rS   get_annotated_filepathr   rp   r
   VideoFromFile)r4   ry   
video_paths      r5   r   LoadVideo.execute   s,    !88>
}}Y44Z@AAr8   c                 p    [         R                  " U5      n[        R                  R	                  U5      nU$ r   )rS   r   rY   rZ   getmtime)sry   r   mod_times       r5   fingerprint_inputsLoadVideo.fingerprint_inputs   s-    !88>
77##J/ r8   c                 \    [         R                  " U5      (       d  SR                  U5      $ g)NzInvalid video file: {}T)rS   exists_annotated_filepathrO   )r   ry   s     r5   validate_inputsLoadVideo.validate_inputs   s'    55d;;+22488r8   r   N)r   r   r   r   r   r6   r   rp   r   r   r   r   r   r8   r5   r   r      s^    
 
$ Bbmm B B    r8   r   c                       \ rS rSr\S 5       r\S\R                  R                  S\	S\	S\
S\R                  4
S j5       rS	rg
)
VideoSlice   c                 n   [         R                  " SS/ SQSS[         R                  R                  S5      [         R                  R                  SSSSS	S
S9[         R                  R                  SSSS	SS9[         R
                  R                  SSSS9/[         R                  R                  5       /S9$ )NzVideo Slice)ztrim video durationzskip first frameszframe load capz
start timer   r   
start_timeg        g     j@g     jgMbP?zStart time in seconds)r   r   r   r    r   durationz0Duration in seconds, or 0 for unlimited duration)r   r   r    r   strict_durationFzNIf True, when the specified duration is not possible, an error will be raised.r   )r#   r%   r$   r&   r   r(   r   )r   r+   r   r	   r/   Booleanr   r3   s    r5   r6   VideoSlice.define_schema   s    yy!&  -w' 3   N   

  %!l ! #0 !E%
 %	
r8   r   r   r   r   r9   c                     UR                  X#US9nUb  [        R                  " U5      $ [        SUR	                  5        SU SU 35      e)N)r   z(Failed to slice video:
Source duration: z
Start time: z
Target duration: )
as_trimmedr   rp   
ValueErrorget_duration)r4   r   r   r   r   trimmeds         r5   r   VideoSlice.execute  si    "":"Y==))78J8J8L7M^\f[ggz  |D  {E  F
 	
r8   r   N)r   r   r   r   r   r6   r   r   Typer   boolrp   r   r   r   r8   r5   r   r      s\    &
 &
P 
BHHMM 
u 
 
`d 
ikiviv 
 
r8   r   c                   L    \ rS rSr\S\\\R                        4S j5       r	Sr
g)VideoExtensioni  r9   c                 J   #    [         [        [        [        [        [
        /$ 7fr   )r   r   r   r   r   r   )selfs    r5   get_node_listVideoExtension.get_node_list  s#      
 	
s   !#r   N)r   r   r   r   r   listtyper   	ComfyNoder   r   r   r8   r5   r   r     s)    
T$r||*<%= 
 
r8   r   r9   c                     #    [        5       $ 7fr   )r   r   r8   r5   comfy_entrypointr   '  s     s   )rY   rW   rh   rS   r\   typingr   typing_extensionsr   	fractionsr   comfy_api.latestr   r   r   r	   r
   r   comfy.cli_argsr   r   r   r   r   r   r   r   r   r   r   r8   r5   <module>r     s    	 	     &  L L <jr|| <j|.j .jb(
",, (
Tw w4& &P1
 1
h

^ 

 r8   