@@ -142,20 +142,25 @@ def create_v2v_process(
142142 ffmpeg_log_level : str = "warning" ,
143143 dst_frame_size : Optional [Tuple [int , int ]] = None ,
144144 dst_fps : Optional [Union [str , float , int ]] = None ,
145+ dst_ffmpeg_options_output : Optional [dict ] = None ,
145146) -> subprocess .Popen :
147+ output_kwargs : Dict [str , str ] = {}
148+ if dst_ffmpeg_options_output is not None :
149+ output_kwargs .update (dst_ffmpeg_options_output )
146150 video_info = get_video_info_from_path (video_path = video_path )
147151 org_frame_width = video_info ["width" ]
148152 org_frame_height = video_info ["height" ]
149153 org_fps = video_info ["avg_frame_rate" ]
150154 dst_width = org_frame_width if dst_frame_size is None else dst_frame_size [0 ]
151155 dst_height = org_frame_height if dst_frame_size is None else dst_frame_size [1 ]
152156 dst_fps = org_fps if dst_fps is None else dst_fps
157+ video_stream = ffmpeg .input (video_path ).video
158+ audio_stream = ffmpeg .input (video_path ).audio
159+
153160 # extract frame from video
154- input_process_args = (
155- ffmpeg .input (video_path )
156- .output ("pipe:" , format = "rawvideo" , pix_fmt = "rgb24" , loglevel = ffmpeg_log_level )
157- .compile ()
158- )
161+ input_process_args = video_stream .output (
162+ "pipe:" , format = "rawvideo" , pix_fmt = "rgb24" , loglevel = ffmpeg_log_level
163+ ).compile ()
159164 input_process = subprocess .Popen (input_process_args , stdout = subprocess .PIPE )
160165
161166 # merge frame and audio stream into video
@@ -166,10 +171,14 @@ def create_v2v_process(
166171 s = "{}x{}" .format (dst_width , dst_height ),
167172 r = dst_fps ,
168173 )
169- v2a_stream = ffmpeg .input (video_path ).audio
170174 output_process_args = (
171- ffmpeg .concat (i2v_stream , v2a_stream , v = 1 , a = 1 )
172- .output (dst_video_path , pix_fmt = "yuv420p" , loglevel = ffmpeg_log_level )
175+ ffmpeg .concat (i2v_stream , audio_stream , v = 1 , a = 1 )
176+ .output (
177+ dst_video_path ,
178+ pix_fmt = "yuv420p" ,
179+ loglevel = ffmpeg_log_level ,
180+ ** output_kwargs ,
181+ )
173182 .overwrite_output ()
174183 .compile ()
175184 )
0 commit comments