
    *jS                         d dl Z d dlZd dlZd dlmZ  ed          Z ed          Z ed          Zedz  ZdZ	dZ
d	 Zd
 Zd Zd Zd Zd Zedk    r e             dS dS )    N)PathzT/data/video-pipeline/Channel-Loi-Co-Nhan/project/11062026-001-Biet-Du-Thi-Khong-NhuczD/data/video-pipeline/Channel-Loi-Co-Nhan/data/logo/logoloiconhan.pngzX/data/video-pipeline/Channel-Loi-Co-Nhan/data/bgm/paulyudin-sentimental-story-182512.mp3zlogs/fix_sub_audio_render.log	   #   c                 2   t          j        d          | z   }t          |d           t          j                            dd           t                              dd          5 }|                    |dz              d d d            d S # 1 swxY w Y   d S )	Nz%F %T T)flushparentsexist_okautf-8encoding
)timestrftimeprintLOGparentmkdiropenwrite)slinefs      scripts_fix_sub_audio_render.pylogr      s    	x	 	 	"D	$dJTD111	#	(	(AAqwwtDy/A/A/AAAAAAAAAAAAAAAAAAAs   &BBBc           	          t          dd                    t          t          |                     z              t	          j        t          t          t          |                                d S )NzRUN  )r   joinmapstr
subprocess
check_calllist)cmds    r   runr&      sP    sxxC&&&'''$s3}}--.....    c                     t          t          j        dddddddt          |           gd	                                                    S )
Nffprobe-verrorz-show_entrieszformat=durationz-ofzdefault=nw=1:nk=1Ttext)floatr"   check_outputr!   strip)ps    r   durr2      s    ()DQbchi|  ~A  BC  ~D  ~D  *E  LP  Q  Q  Q  W  W  Y  Y  Z  Z  Zr'   c                     t          t          | dz                      }|dz  }|dz  }|dz  }|dz  }|dz  }|dz  }|dd|dd|dd|dS )Ni  i6 i`  02:,03)intround)secmshmr   s        r   tsr>      s    
5T??Br7{QBKB2u9b%ibSUW[S[QR]_ae]e]_***Q***A***2****r'   c                 x    d                     |                     dd                                                    S )Nr   r   )r   replacesplitr,   s    r   safe_text_one_linerB      s.    88DLLc**0022333r'   c                  6   t                               dd           t          j        t          dz                      d                    d         } t          j        t          dz                      d                    }d |d         D             }t          d	z  }|j                            d
d
           g }t          | d          D ]m\  }}t          ||d                  d                   }|
                    | dt          |d                    dt          |d                    d| d           n|                    d                    |          d           t          dz  }t          dz  }	t          dz  }
d| dt           dt           dt           d	}t!          g dddddd d!d"d#|d#|	d$|d%d&d%d'd(d)d*d+d,d-d.d/d0d1d2d3d4d5d6|
           t          d7z  }t          d8z  }t          d9z  }|j                            d
d
           |                    d:| d;| d;|
 d<d           t          d=z  }t          d>z  }t!          dddddd d!d"d#|d?d@dAdBd(d)d*d+d,d-d.d/d0d1d2d3d4d5|g           t!          ddddd#|dCdDd#t"          d$dEd%dFd%dGd*dHd.d/d0d1d2d3d4d5d6|g           t!          dddd#|ddIdJg           t          j        t          dKz                      d                    }|                    t'          |          t)          |          dLt          t          dMdN           t          dKz                      t          j        |dOdPQ          d           t-          dRt'          |          z              d S )SN r   r   z$audio/master_narration_timeline.jsonitemszscript/scenes.jsonc                      i | ]}|d          |S )scene_id ).0r   s     r   
<dictcomp>zmain.<locals>.<dictcomp>#   s    
3
3
3q1Z=
3
3
3r'   scenesz.subtitles/master_subtitles_one_line_bottom.srtTr      rG   	narrationr   startz --> 
speech_endzrender_onepass/segments.txtzaudio/master_narration.wavzoutput/main_story.mp4zT[0:v]scale=1080:1920:force_original_aspect_ratio=increase,crop=1080:1920,subtitles='z-':force_style='FontName=DejaVu Sans,FontSize=z,Outline=1,Alignment=2,MarginV=z,WrapStyle=2'[base];movie='zW',scale=160:-1,format=rgba,colorchannelmixer=aa=0.55[wm];[base][wm]overlay=W-w-35:35[v]ffmpegz-yr*   r+   z-fconcatz-safe0z-iz-filter_complexz-mapz[v]z1:az-r30z-c:vlibx264z-pix_fmtyuv420pz-c:aaacz-b:a192kz-ar44100z-ac2z	-shortestzoutput/intro/intro.mp4zoutput/intro/intro_pause_4s.mp4zoutput/final/final_concat.txtzfile 'z'
file 'z'
zoutput/final/final_no_bgm.mp4zoutput/final/final_video.mp4z-vfzscale=1080:1920,format=yuv420pz-afz#aresample=44100:async=1:first_pts=0z-stream_loopz-1z[0:a]aresample=44100:async=1:first_pts=0,volume=1.0[a0];[1:a]aresample=44100,volume=0.14[bgm];[a0][bgm]amix=inputs=2:duration=first:dropout_transition=2,alimiter=limit=0.95[a]z0:vz[a]copynull-zoutput/info.jsonone_line_bottom+reencoded_concat_and_final_aac_44100_stereo)final_videoduration_secsubtitle_modesubtitle_font_sizesubtitle_margin_v	audio_fixF   )ensure_asciiindentz	COMPLETE )r   
write_textjsonloadsPROJECT	read_textr   r   	enumeraterB   appendr>   r   SUB_FONT_SIZESUB_MARGIN_VLOGOr&   BGMupdater!   r2   dumpsr   )timelinedataby_idsubblocksiitr-   seglistmastermainvfcintropauselistpno_bgmfinalinfos                     r   mainr      s   NN2N(((Z!GGRR\cRddeefmnH	W11<<g<NN	O	OD
3
3DN
3
3
3E@@CJTD111F(1%% V V"bn 5k BCCTTbGooTTBr,7G4H4HTTDTTTUUUUNN499V$$wN77711G//F
)
)E	*%(	* 	*Wd	* 	* FR	* 	*	* 	* 	*    	|  	|$  	|t  	|G  	|D  	|  	|'  	|#  	|d  	|7  	|4  	|PV  	|Wh  	|ik  	|lr  	|sx  	|y  	|  AF  	|  GK  	|  LP  	|  QW  	|  Xa  	|  bl  	|  mv  	|  w}  	|  ~C  	|  DJ  	|  KQ  	|  RW  	|  X_  	|  `e  	|  fi  	|  ju  	|  v{  	|  }  }  }
*
*E
3
3E
1
1E	Ltd333	HeHHeHHeHHHSZ[[[22F
0
0E$tGD'#d5Oopu  w\  ]a  bf  gm  nw  xB  CL  MS  TY  Z`  ag  hm  nu  v{  |  @F  	G  H  H  H$tGDtDM^  `Q  RX  Y^  _e  fk  lr  sy  z@  AF  GM  NT  UZ  [b  ch  il  mx  y~  	  @  @  @$wtE$vc:;;;	W//::G:LL	M	MDKKs5zzUTe  |I  ^j  wd  e  e  f  f  f++DJt%XY,Z,Z,Zel+mmmCJJr'   __main__)ri   r"   r   pathlibr   rk   rq   rr   r   ro   rp   r   r&   r2   r>   rB   r   __name__rH   r'   r   <module>r      s                    cdd	T
PQQD	cdd++B B B/ / /Z Z Z+ + +4 4 4&  &  & N Zr'   