I Have an A NumPy array Representing the Video in the memory how Can I Use the ffmpegio python module to save it on the File on the disk While adding the audio.
I Try Many things. I Also Ask answer on the python-ffmpegio github page. Discussinnon link
The Whole module Code is on the vidiopy
I Get an Error: -
Traceback (most recent call last):
File "d:\soham_code\video_py\test.py", line 5, in <module>
clip.write_videofile(r'D:\soham_code\video_py\test\test_video.mp4')
File "d:\soham_code\video_py\vidiopy\video\VideoClips.py", line 190, in write_videofile
with ffmpegio.open(
File "C:\Users\Lenovo\AppData\Local\Programs\Python\Python312\Lib\contextlib.py", line 137, in __enter__
return next(self.gen)
^^^^^^^^^^^^^^
File "C:\Users\Lenovo\AppData\Local\Programs\Python\Python312\Lib\site-packages\ffmpegio\__init__.py", line 324, in open
stream = StreamClass(*args, **kwds)
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\Lenovo\AppData\Local\Programs\Python\Python312\Lib\site-packages\ffmpegio\streams\SimpleStreams.py", line 489, in __init__
super().__init__(
File "C:\Users\Lenovo\AppData\Local\Programs\Python\Python312\Lib\site-packages\ffmpegio\streams\SimpleStreams.py", line 365, in __init__
configure.add_url(ffmpeg_args, "input", *input)
TypeError: add_url() takes from 3 to 5 positional arguments but 765 were given
Modified Code: -
def write_videofile(self, filename, fps=None, codec=None,
bitrate=None, audio=True, audio_fps=44100,
preset="medium", pixel_format=None,
audio_codec=None, audio_bitrate=None,
write_logfile=False, verbose=True,
threads=None, ffmpeg_params: dict[str, str] | None = None,
logger='bar', over_write_output=True):
# video_np = np.asarray(tuple(self.iterate_frames_array_t(fps if fps else self.fps if self.fps else (_ for _ in ()
# ).throw(Exception('Make Frame is Not Set.')))))
audio_name, _ = os.path.splitext(filename)
ffmpeg_options = {
'preset': preset,
**(ffmpeg_params if ffmpeg_params is not None else {}),
**({'c:v': codec} if codec else {}),
**({'b:v': bitrate} if bitrate else {}),
**({'pix_fmt': pixel_format} if pixel_format else {}),
**({'c:a': audio_codec} if audio_codec else {}),
**({'ar': audio_fps} if audio_fps else {}),
**({'b:a': audio_bitrate} if audio_bitrate else {}),
**({'threads': threads} if threads else {}),
}
with tempfile.NamedTemporaryFile(
suffix=".wav", prefix=audio_name + "_temp_audio_"
) as temp_audio_file:
if self.audio and audio:
self.audio.write_audio_file(temp_audio_file)
# audio_file_name = temp_audio_file.name
ffmpeg_options.update(
{"extra_inputs": [temp_audio_file.name], "acodec": "copy", "map": ["0:v", "1:a"]}
)
with ffmpegio.open(
filename,
"wv",
fps,
**ffmpeg_options,
overwrite=over_write_output,
show_log=True,) as f:
for I in self.iterate_frames_array_t(fps): # if fps else self.fps if self.fps else (_ for _ in ()
# ).throw(Exception('Make Frame is Not Set.'))):
f.write(I)
I Tried Many things: -
using transcode, providing the -i flag with audio name While using the ffmpegio.write, etc.