Магазин: у меня есть папка «Записи» с файлами *.h264.
Теперь я хочу, чтобы файлы были преобразованы в файлы *.mp4. Эта часть работает хорошо.
Но когда в этой папке несколько файлов *.h264, этот скрипт ломается. Говорит, что не может найти файл, который я удалил.
Итак, мой вопрос: может ли этот сценарий запускать def Convert_File() в цикле, пока все файлы не будут преобразованы? Или мне следует создать несколько файлов .py. Например, "convert.py" и "show_clips.py" и объединить их в "start.py"?
Это мой код:
Код: Выделить всё
from moviepy.editor import *
import glob
import os.path
import subprocess
from time import sleep
#Variabels
folder_path = r'/home/pi/Halloween/Recordings' #path to videofiles
file_type = r'/*h264' #extension of the recordings
file_type_conv = r'/*mp4' #extension added after convertion
files = glob.glob(folder_path + file_type) #creates complete path for *.h264
files_conv = glob.glob(folder_path + file_type_conv) #creates complete path for *.mp4
clip_show = sorted(glob.iglob(r'/home/pi/Halloween/Recordings/*'),key=os.path.getctime) #sorts files by date
#Functions
def Convert_File():
if glob.glob(folder_path + file_type): #if there is a *.h264
print('Yes there is')
clip_latest = max(files, key=os.path.getctime) #sort the files by cdate
clip_conv = clip_latest + '.mp4' #adds extension behind file
print(clip_latest)
print(clip_conv)
subprocess.run(['ffmpeg', '-i', clip_latest, clip_conv]) #convert from h264 to mp4
os.remove(clip_latest) #remove the 264 file
print('converted')
else:
print('nothing converted') #no h264 - noting done
#Show Clips
def Show_Clips():
clip1 = VideoFileClip(clip_show [-1]).subclip(0, 1).margin(3)
clip2 = VideoFileClip(clip_show [-2]).subclip(0, 1).margin(3)
clip3 = VideoFileClip(clip_show [-3]).subclip(0, 1).margin(3)
clip4 = VideoFileClip(clip_show [-4]).subclip(0, 1).margin(3)
clip5 = VideoFileClip(clip_show [-5]).subclip(0, 1).margin(3)
clip6 = VideoFileClip(clip_show [-6]).subclip(0, 1).margin(3)
clip7 = VideoFileClip(clip_show [-7]).subclip(0, 1).margin(3)
clip8 = VideoFileClip(clip_show [-8]).subclip(0, 1).margin(3)
clip9 = VideoFileClip(clip_show [-9]).subclip(0, 1).margin(3)
clip10 = VideoFileClip(clip_show [-10]).subclip(0, 1).margin(3)
clip11 = VideoFileClip(clip_show [-11]).subclip(0, 1).margin(3)
clip12 = VideoFileClip(clip_show [-12]).subclip(0, 1).margin(3)
combined = clips_array([[clip1, clip2, clip3],
[clip4, clip5, clip6]])
combined.preview(audio=False, fps=25)
sleep(1)
if __name__ == '__main__':
while True:
try:
Convert_File()
Show_Clips()
except KeyboardInterrupt:
break
Но это не сработало.
Надеюсь, что кто-нибудь сможет помогите мне.
Подробнее здесь: https://stackoverflow.com/questions/770 ... side-a-def
Мобильная версия