mirror of
https://github.com/xavier150/convert-video-for-Resolve
synced 2025-11-08 18:45:04 +01:00
Use ffmpeg python + More feed back
This commit is contained in:
@@ -1,10 +1,20 @@
|
|||||||
print("start")
|
|
||||||
|
|
||||||
import os
|
import os
|
||||||
|
import ffmpeg
|
||||||
from os import listdir
|
from os import listdir
|
||||||
from os.path import isfile, join
|
from os.path import isfile, join
|
||||||
import time
|
import time
|
||||||
|
|
||||||
|
source_path = os.path.join(os.path.dirname(os.path.realpath(__file__)),"Source")
|
||||||
|
export_path = os.path.join(os.path.dirname(os.path.realpath(__file__)),"Export")
|
||||||
|
|
||||||
|
def CheckPrerequisites ():
|
||||||
|
print("Check prerequisites..")
|
||||||
|
#time.sleep(1)
|
||||||
|
VerifiDirs(source_path)
|
||||||
|
VerifiDirs(export_path)
|
||||||
|
print("Check prerequisites finished!")
|
||||||
|
return True
|
||||||
|
|
||||||
def VerifiDirs(directory):
|
def VerifiDirs(directory):
|
||||||
# Check and create a folder if it does not exist
|
# Check and create a folder if it does not exist
|
||||||
|
|
||||||
@@ -13,34 +23,64 @@ def VerifiDirs(directory):
|
|||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
source_path = os.path.join(os.path.dirname(os.path.realpath(__file__)),"Source")
|
def ClearConsole():
|
||||||
export_path = os.path.join(os.path.dirname(os.path.realpath(__file__)),"Export")
|
os.system('cls' if os.name=='nt' else 'clear')
|
||||||
VerifiDirs(source_path)
|
pass
|
||||||
VerifiDirs(export_path)
|
|
||||||
|
|
||||||
files = [f for f in listdir(source_path) if isfile(join(source_path, f))] #Get all files
|
class FileToConvert():
|
||||||
|
def __init__(self, file_name):
|
||||||
|
self.file_name = file_name
|
||||||
|
self.status = "Waiting"
|
||||||
|
|
||||||
def convert(fileName):
|
def ConvertFile(self):
|
||||||
|
SourceFile = os.path.join(source_path, self.file_name)
|
||||||
|
new_file_name = self.file_name
|
||||||
|
new_file_name = new_file_name[:-4]
|
||||||
|
new_file_name = new_file_name+".mov"
|
||||||
|
ExportFile = os.path.join(export_path, new_file_name)
|
||||||
|
|
||||||
SourceFile = os.path.join(source_path, fileName)
|
stream = ffmpeg.input(SourceFile)
|
||||||
newFileName = fileName
|
vcodec = "mjpeg" #Video codec
|
||||||
#newFileName = newFileName[32:] #Lenge of vlc-record-2019-12-31-03h03m48s-
|
acodec = "pcm_s16be" #Audio codec
|
||||||
newFileName = newFileName[:-4]
|
stream = ffmpeg.output(stream, ExportFile, acodec=acodec, vcodec=vcodec)
|
||||||
#newFileName = newFileName+str(time.time())
|
ffmpeg.run(stream)
|
||||||
newFileName = newFileName+".mov"
|
self.status = "Success"
|
||||||
ExportFile = os.path.join(export_path, newFileName)
|
|
||||||
|
|
||||||
com = "cmd /k 'ffmpeg -i \""+SourceFile+"\" -vcodec mjpeg -q:v 2 -acodec pcm_s16be -q:a 0 -f mov \""+ExportFile+"\"'"
|
|
||||||
com = "cmd /c ffmpeg -i \""+SourceFile+"\" -vcodec mjpeg -q:v 2 -acodec pcm_s16be -q:a 0 -f mov \""+ExportFile+"\""
|
|
||||||
#com = 'cmd /c "ffmpeg"'
|
|
||||||
print(com)
|
|
||||||
os.system(com)
|
|
||||||
|
|
||||||
#video = moviepy.VideoFileClip(SourceFile)
|
#video = moviepy.VideoFileClip(SourceFile)
|
||||||
#video.write_videofile(os.path.join(ExportFile),fps=24, codec='libx264', audio_codec='m4a')
|
#video.write_videofile(os.path.join(ExportFile),fps=24, codec='libx264', audio_codec='m4a')
|
||||||
#video.audio.write_audiofile(os.path.join(os.path.join(export_path, "sound"+".m4a")))
|
#video.audio.write_audiofile(os.path.join(os.path.join(export_path, "sound"+".m4a")))
|
||||||
|
|
||||||
|
check_prerequisites = CheckPrerequisites()
|
||||||
|
ClearConsole()
|
||||||
|
|
||||||
|
print("This script convert video files for DaVinci Resolve! :D")
|
||||||
|
print("https://github.com/xavier150/convert-video-for-Resolve by Xavier Loux.")
|
||||||
|
print("")
|
||||||
|
|
||||||
|
if check_prerequisites:
|
||||||
|
input('Place your video file(s) in "Source" folder and Enter to continue...')
|
||||||
|
ClearConsole()
|
||||||
|
|
||||||
|
files = [f for f in listdir(source_path) if isfile(join(source_path, f))] #Get all files
|
||||||
|
print(str(len(files)) + ' file(s) found in "Source" folder!')
|
||||||
|
for file in files:
|
||||||
|
print("- " + file)
|
||||||
|
input("Press Enter to continue...")
|
||||||
|
ClearConsole()
|
||||||
|
|
||||||
|
converted_files = []
|
||||||
|
for file in files:
|
||||||
|
convert = FileToConvert(file)
|
||||||
|
convert.ConvertFile()
|
||||||
|
converted_files.append(convert)
|
||||||
|
|
||||||
|
ClearConsole()
|
||||||
|
print(str(len(files)) + ' file(s) converted in "Converted" folder!')
|
||||||
|
for x, converted_file in enumerate(converted_files):
|
||||||
|
print(str(x+1) + '/' + str(len(converted_files)) + ' - ' + converted_file.file_name + ' : ' + converted_file.status)
|
||||||
|
print("Thanks for using my script! :D")
|
||||||
|
print("https://github.com/xavier150/convert-video-for-Resolve by Xavier Loux.")
|
||||||
|
print("")
|
||||||
|
input("Press Enter to exit...")
|
||||||
|
|
||||||
|
|
||||||
for file in files:
|
|
||||||
print(file)
|
|
||||||
convert(file)
|
|
||||||
|
|||||||
Reference in New Issue
Block a user