Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #-------Merge videos with frames in correct order-------
- #0. Import libraries
- #2. Read list of files in folder
- #0. Import libraries
- import glob
- from tkinter import Tcl
- import os
- #path = "/SB-41-SOM-11-03-2022-13-06-53_60FPS_result_threshold80/"
- path = "/media/polymore/ADATA-HD650/42-RTM-Sandbox/08-05-2022/08-05-2022/Frames/Sample-Video/"
- video_name = "video-test"
- video_ext = ".mp4"
- print("----1----")
- file_list = os.listdir(path)
- #b = glob.glob("/Users/cristianpogan/Desktop/Merge-Video/SB-41-SOM-11-03-2022-13-06-53_60FPS_result_threshold80/*.jpg")
- #print(b)
- #print(type(b))
- print("----2----")
- a = Tcl().call('lsort', '-dict', file_list)
- #print(a)
- #print(type(a))
- ext = ".jpeg"
- string_list = ""
- elenco_video = []
- print("Files with extension: ")
- for x in a:
- if x.endswith(ext):
- #elenco_video.append(path + x)
- print(f"file \'{x}\'")
- if string_list != "":
- string_list = string_list + "\'" + str(path) + str(x) + "\'\n"
- else:
- string_list = "\'" + str(path) + str(x) + "\'\n"
- #print(f"file \'{elenco_video[x]}\'")
- #print("elenco_video: ", elenco_video)
- print("string_list: ", string_list)
- file_object = open(Results_text_file, 'a')
- # Append 'hello' at the end of file
- # Close the file
- file_object.close()
- input_file = {'key': []}
- print(type(input_file))
- for x in range(len(elenco_video)):
- #print(elenco_video[x])
- #input_file['key'].append(x)
- input_file["key"].append(elenco_video[x])
- print("Dict: ")
- print(input_file["key"])
- output_video = path + video_name
- #for f in /Users/cristianpogan/Downloads/34-SOM-09-03-2022/*.mp4 ; do
- # echo file \'$f\' >> list4.txt; done && ffmpeg -f concat -safe 0 -i list4.txt -c copy /Users/cristianpogan/Downloads/34-SOM-09-03-2022/34-SOM-09-03-video2.mp4 && rm list4.txt
- '''
- for f in /Users/cristianpogan/Downloads/Test-comparatie-frames/videos-to-split2/*.jpg ; do
- echo list2.txt;
- done &&
- /Users/cristianpogan/Desktop/Merge-Video/SB-41-SOM-11-03-2022-13-06-53_60FPS_result_threshold80/0.jpg
- /Users/cristianpogan/Desktop/Merge-Video/SB-41-SOM-11-03-2022-13-06-53_60FPS_result_threshold80/0.jpg
- && rm list2.txt
- '''
- #os.system(f"ffmpeg -f concat -safe 0 -i {elenco_video[:-1]} -c copy {output_video}{video_ext}")
- #os.system(f"ffmpeg -f concat -safe 0 -i {string_list} -c copy {output_video}{video_ext}")
- os.system(f"ffmpeg -f concat -safe 0 -i {string_list} -c copy {output_video}{video_ext}")
- '''
- def concatenate():
- stringa = "ffmpeg -i \"concat:"
- #elenco_video = glob.glob("*.mp4")
- elenco_file_temp = []
- for f in elenco_video:
- file = "tempp" + str(elenco_video.index(f) + 1) + ".ts"
- #os.system("ffmpeg -i " + f + " -c copy -bsf:v h264_mp4toannexb -f mpegts " + file)
- #os.system("ffmpeg -i " + f + " -c copy -f mpegts " + file)
- #print("ffmpeg -i " + f + " -c copy -bsf:v h264_mp4toannexb -f mpegts " + file)
- elenco_file_temp.append(file)
- #print(elenco_file_temp)
- for f in elenco_file_temp:
- stringa += f
- if elenco_file_temp.index(f) != len(elenco_file_temp)-1:
- stringa += "|"
- else:
- stringa += "\" -c copy output.mp4"#"\" -c copy -bsf:a aac_adtstoasc output.mp4"
- #print(stringa)
- #os.system(stringa)
- concatenate()
- '''
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement