Advertisement
Poganu

Frames-into-video.py

May 9th, 2022
847
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.16 KB | None | 0 0
  1. #-------Merge videos with frames in correct order-------
  2. #0. Import libraries
  3. #2. Read list of files in folder
  4.  
  5.  
  6. #0. Import libraries
  7. import glob
  8. from tkinter import Tcl
  9. import os
  10.  
  11. #path = "/SB-41-SOM-11-03-2022-13-06-53_60FPS_result_threshold80/"
  12. path = "/media/polymore/ADATA-HD650/42-RTM-Sandbox/08-05-2022/08-05-2022/Frames/Sample-Video/"
  13. video_name = "video-test"
  14. video_ext = ".mp4"
  15.  
  16. print("----1----")
  17. file_list = os.listdir(path)
  18.  
  19. #b = glob.glob("/Users/cristianpogan/Desktop/Merge-Video/SB-41-SOM-11-03-2022-13-06-53_60FPS_result_threshold80/*.jpg")
  20. #print(b)
  21. #print(type(b))
  22. print("----2----")
  23. a = Tcl().call('lsort', '-dict', file_list)
  24. #print(a)
  25. #print(type(a))
  26.  
  27. ext = ".jpeg"
  28.  
  29. string_list = ""
  30. elenco_video = []
  31. print("Files with extension: ")
  32. for x in a:
  33.     if x.endswith(ext):
  34.         #elenco_video.append(path + x)
  35.         print(f"file \'{x}\'")
  36.         if string_list != "":
  37.             string_list = string_list + "\'" + str(path) + str(x) + "\'\n"
  38.         else:
  39.             string_list = "\'" + str(path) + str(x) + "\'\n"
  40.         #print(f"file \'{elenco_video[x]}\'")
  41.  
  42. #print("elenco_video: ", elenco_video)
  43. print("string_list: ", string_list)
  44.  
  45.  
  46. file_object = open(Results_text_file, 'a')
  47. # Append 'hello' at the end of file
  48.  
  49.  
  50. # Close the file
  51. file_object.close()
  52.  
  53. input_file = {'key': []}
  54. print(type(input_file))
  55. for x in range(len(elenco_video)):
  56.     #print(elenco_video[x])
  57.     #input_file['key'].append(x)
  58.     input_file["key"].append(elenco_video[x])
  59.  
  60. print("Dict: ")
  61. print(input_file["key"])
  62.  
  63. output_video = path + video_name
  64.  
  65. #for f in /Users/cristianpogan/Downloads/34-SOM-09-03-2022/*.mp4 ; do
  66. #   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
  67.  
  68. '''
  69. for f in /Users/cristianpogan/Downloads/Test-comparatie-frames/videos-to-split2/*.jpg ; do
  70.     echo list2.txt;
  71. done &&
  72.  
  73.  
  74. /Users/cristianpogan/Desktop/Merge-Video/SB-41-SOM-11-03-2022-13-06-53_60FPS_result_threshold80/0.jpg
  75. /Users/cristianpogan/Desktop/Merge-Video/SB-41-SOM-11-03-2022-13-06-53_60FPS_result_threshold80/0.jpg
  76.  
  77. && rm list2.txt
  78. '''
  79. #os.system(f"ffmpeg -f concat -safe 0 -i {elenco_video[:-1]} -c copy {output_video}{video_ext}")
  80.  
  81. #os.system(f"ffmpeg -f concat -safe 0 -i {string_list} -c copy {output_video}{video_ext}")
  82. os.system(f"ffmpeg -f concat -safe 0 -i {string_list} -c copy {output_video}{video_ext}")
  83. '''
  84. def concatenate():
  85.     stringa = "ffmpeg -i \"concat:"
  86.     #elenco_video = glob.glob("*.mp4")
  87.     elenco_file_temp = []
  88.     for f in elenco_video:
  89.         file = "tempp" + str(elenco_video.index(f) + 1) + ".ts"
  90.         #os.system("ffmpeg -i " + f + " -c copy -bsf:v h264_mp4toannexb -f mpegts " + file)
  91.         #os.system("ffmpeg -i " + f + " -c copy -f mpegts " + file)
  92.         #print("ffmpeg -i " + f + " -c copy -bsf:v h264_mp4toannexb -f mpegts " + file)
  93.         elenco_file_temp.append(file)
  94.     #print(elenco_file_temp)
  95.     for f in elenco_file_temp:
  96.         stringa += f
  97.         if elenco_file_temp.index(f) != len(elenco_file_temp)-1:
  98.             stringa += "|"
  99.         else:
  100.             stringa += "\" -c copy output.mp4"#"\" -c copy  -bsf:a aac_adtstoasc output.mp4"
  101.     #print(stringa)
  102.     #os.system(stringa)
  103.  
  104. concatenate()
  105. '''
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement