I a have a (nested) list od BytesIO objects (images) that I would like to pass to ffmpeg and make a video. I do know, the ffmpeg cannot take it straight. What should I convert it in first? There might be a better way using 'pipe:', which I did not succeed to implement yet. (in this example code I ignore image duration and audio, too)
def merge_videos(file_id: float, audio_list: List[BinaryIO], duration_list: List[float], images_nested_list):
# flatten the nested list of images
images_list = [image for images_sublist in images_nested_list for image in images_sublist]
additional_parameters = {'c:a': 'aac', 'c:v': 'libx264'}
# Create a BytesIO object to hold the output video data
output_data = io.BytesIO()
# create the FFmpeg command with the specified parameters and pipe the output to the BytesIO object
command = ffmpeg.output(*images_list, '-', vf='fps=10,format=yuv420p', preset='veryfast', shortest=None, r=10, max_muxing_queue_size=4000, **additional_parameters).pipe(output_data)
try:
# run the FFmpeg command with error and output capture
subprocess.check_output(['ffmpeg', '-y', '-f', 'concat', '-safe', '0', '-i', 'audio.txt', '-i', '-', '-c:v', 'copy', '-c:a', 'aac', f"{PROJECT_PATH}/data/final-{file_id}.mp4"], input=output_data.getvalue())
log.info("Final video with file_id %s has been converted successfully", file_id)
...this code returns:
TypeError: Expected incoming stream(s) to be of one of the following types: ffmpeg.nodes.FilterableStream; got <class '_io.BytesIO'>
How to handle it please? Thanks for help.