I am using ffmpeg-python and I am trying to make a code that gets all the clips from a folder, converts all of them to the same format then merge all of them with their audio to one final video file.
Here is how the python script looks like
import os
import ffmpeg
dir = "./clips/"
# Reshape video
for f in os.listdir(dir):
(
ffmpeg
.input(os.path.join(dir, f))
.filter("scale", size="hd1080", force_original_aspect_ratio="increase")
.filter('fps', fps=60, round='up')
.output(str(os.path.join(dir, f))[:-4] + "_reshaped.mp4")
.run()
)
# Select reshaped video
files = []
for f in os.listdir(dir):
if "_reshaped.mp4" in str(os.path.join(dir, f)):
files.append(ffmpeg.input(str(os.path.join(dir, f))))
# eparate video and audio, then flat the array
video_and_audios_files = [item for sublist in map(lambda f: [f.video, f.audio], files) for item in sublist]
# concat all
joined = (
ffmpeg
.concat(*video_and_audios_files, v=1, a=1)
.node
)
# merge video and audio
(
ffmpeg
.output(joined[0], joined[1], "./out.mp4")
.run()
)
Now here is my output, this is the output of the part of the code that merges every clip into one (aka the merge video and audio section of the code)
ffmpeg version 5.1.1-essentials_build-www.gyan.dev Copyright (c) 2000-2022 the FFmpeg developers
built with gcc 12.1.0 (Rev2, Built by MSYS2 project)
configuration: --enable-gpl --enable-version3 --enable-static --disable-w32threads --disable-autodetect --enable-fontconfig --enable-iconv --enable-gnutls --enable-libxml2 --enable-gmp --enable-lzma --enable-zlib --enable-libsrt --enable-libssh --enable-libzmq --enable-avisynth --enable-sdl2 --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxvid --enable-libaom --enable-libopenjpeg --enable-libvpx --enable-libass --enable-libfreetype --enable-libfribidi --enable-libvidstab --enable-libvmaf --enable-libzimg --enable-amf
--enable-cuda-llvm --enable-cuvid --enable-ffnvcodec --enable-nvdec --enable-nvenc --enable-d3d11va --enable-dxva2 --enable-libmfx --enable-libgme --enable-libopenmpt --enable-libopencore-amrwb --enable-libmp3lame --enable-libtheora --enable-libvo-amrwbenc --enable-libgsm --enable-libopencore-amrnb --enable-libopus --enable-libspeex --enable-libvorbis --enable-librubberband
libavutil 57. 28.100 / 57. 28.100
libavcodec 59. 37.100 / 59. 37.100
libavformat 59. 27.100 / 59. 27.100
libavdevice 59. 7.100 / 59. 7.100
libavfilter 8. 44.100 / 8. 44.100
libswscale 6. 7.100 / 6. 7.100
libswresample 4. 7.100 / 4. 7.100
libpostproc 56. 6.100 / 56. 6.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from './clips/clip1_reshaped.mp4':
Metadata:
major_brand : isom
minor_version : 512
compatible_brands: isomiso2avc1mp41
encoder : Lavf59.27.100
Duration: 00:00:26.02, start: 0.000000, bitrate: 7432 kb/s
Stream #0:0[0x1](und): Video: h264 (High) (avc1 / 0x31637661), yuv420p(tv, bt709, progressive), 1920x1080 [SAR 1:1 DAR 16:9], 7425 kb/s, 60 fps, 60 tbr, 15360 tbn (default)
Metadata:
handler_name : VideoHandler
vendor_id : [0][0][0][0]
encoder : Lavc59.37.100 libx264
Input #1, mov,mp4,m4a,3gp,3g2,mj2, from './clips/clip2_reshaped.mp4':
Metadata:
major_brand : isom
minor_version : 512
compatible_brands: isomiso2avc1mp41
encoder : Lavf59.27.100
Duration: 00:00:05.00, start: 0.000000, bitrate: 11445 kb/s
Stream #1:0[0x1](und): Video: h264 (High) (avc1 / 0x31637661), yuv420p(tv, unknown/bt709/unknown, progressive), 1920x1080, 11438 kb/s, 60 fps, 60 tbr, 15360 tbn (default)
Metadata:
handler_name : VideoHandler
vendor_id : [0][0][0][0]
encoder : Lavc59.37.100 libx264
Stream specifier ':a' in filtergraph description [0:v][0:a][1:v][1:a]concat=a=1:n=2:v=1[s0][s1] matches no streams.
Traceback (most recent call last):
File "c:\Users\USERNAME\Desktop\auto_poster\concat_vids.py", line 38, in <module>
.run()
File "C:\Users\USERNAME\AppData\Local\Programs\Python\Python310\lib\site-packages\ffmpeg\_run.py", line 325, in run
raise Error('ffmpeg', out, err)
ffmpeg._run.Error: ffmpeg error (see stderr output for detail)
Can I get some help please ? I am on Windows 10