简体   繁体   中英

Can't write video using moviepy. output format error

I'm trying to concatenate videos in each folder so that I get one video in each folder instead of multiple short ones. This is an external USB drive if that matters.

My code seems to iterate over the files as expected, but I keep getting this error after the audio is written, during the "writing video" action, I believe: b"[NULL @ 000002a8340ae640] Unable to find a suitable output format for 'D:\\taxes\\folder\\test'\r\nD:\\taxes\\folder\\test: Invalid argument\r\n"

I haven't found a way to force an output format yet. Any thoughts?

import os
from moviepy.editor import *

startingDir = r'D:\taxes'

avoid = ['0incomplete', 'old', 'that', 'this']

for thing in os.listdir(startingDir):
    clips = []
    name = ''
    
    if thing in avoid:
        print('                              avoided {}'.format(thing))
        continue

    folder = os.path.join(startingDir, thing)

    if os.path.isdir(folder):
        for clip in os.listdir(folder):
            print (clip)
            clips.append(VideoFileClip(os.path.join(folder, clip)))
        print('\n')

        try:
            final = concatenate_videoclips(clips)
            final.write_videofile(os.path.join(folder, 'test'), audio=True, codec='libx264', threads=10)
            final.close() 
        except Exception as e:
            print (e)
            print('\n Continuing... \n\n')
            continue

"Unable to find a suitable output format" error message means that FFmpeg can't determine the format of the output video file.

If the format is not explicitly defined by an argument, FFmpeg uses the file extension to determine the file format.

The file name you are using is test with no extension, so FFmpeg can't determine the format.

Replace: final.write_videofile(os.path.join(folder, 'test'), audio=True, codec='libx264', threads=10) with:

final.write_videofile(os.path.join(folder, 'test.mp4'), audio=True, codec='libx264', threads=10)

.mp4 defines MP4 file format.
We may also choose 'test.mkv' for MKV file format (or 'test.avi' for AVI format)...


MoviePy uses FFmpeg behind the scenes.
If we really want to create a video file named test with no extension, we may add ffmpeg_params=['-f', 'mp4'] argument:

final.write_videofile(os.path.join(folder, 'test'), audio=True, codec='libx264', threads=10, ffmpeg_params=['-f', 'mp4'])

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM