1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133
| import os
import io
import sys
print ()
try:
print ("dossier = ",sys.argv[1])
print ("Fichier_xml = ",sys.argv[2])
print ("fps = ",sys.argv[3])
#print ("Fichier source",sys.argv[5])
#print ("Fichier cible",sys.argv[6])
dossier=str(sys.argv[1])
fichier=str(sys.argv[2])
fps=int(sys.argv[3])
#duréemin=int(sys.argv[4])
#sourcefile=sys.argv[5]
#destfile=sys.argv[6]
except:
print ("utilisation incrust_xml.py C:\\Users\\Yoann\\Desktop Fichier_xml 25")
sys.exit("Erreur lors du chargement de certains arguments de la commande")
try:
dossier=os.chdir(dossier)
except:
print ("impossible d'aller dans le dossier", dossier)
sys.exit("Erreur lors du chargement de certains arguments de la commande")
print ()
list_image=[]
from lxml import etree
tree = etree.parse(fichier)
for file in tree.xpath("/xmeml/sequence/media/video/track/clipitem/file"):
list_image.append(file.get("id"))
for file in tree.xpath("/xmeml/sequence/timecode/frame"):
offset=(file.text)
offset=int(offset)
list_in=[]
for file in tree.xpath("/xmeml/sequence/media/video/track/clipitem/in"):
list_in.append(file.text)
list_out=[]
for file in tree.xpath("/xmeml/sequence/media/video/track/clipitem/out"):
list_out.append(file.text)
def convert_tc (frame):
global offset
frame=frame+offset
seconde=0
minute=0
heure=0
while frame>fps-1:
frame=frame-fps
seconde=seconde+1
while seconde >59:
seconde=seconde-60
minute= minute+1
while minute > 59:
minute= minute-60
heure=heure+1
return (heure, minute, seconde, frame)
print(list_in)
print("offset = ", offset)
print("#############")
#exemple
#ffmpeg -i 2-tc.mp4 -i 1.png -i 2.png -i 3.png -filter_complex "[0:v][1:v]overlay=100:75:enable=between(t\,2\,4)[bkg]; [bkg][2:v]overlay=100:75:enable=between(t\,6\,8)[bkg]; [bkg][2:v]overlay=100:75:enable=between(t\,10\,12)" -c:a copy output.mp4
command_header="ffmpeg -i \"blabla.mov\" "
command_footer="output.mp4"
command_file=""
command_tc=""
command_add=""
i=0
while i < len(list_image):
#while i < 3:
tc_in=int(list_in[i])
print ("tc_in")
print("frame", tc_in)
print ("seconde", tc_in/25)
heure,minute,seconde,frame = convert_tc(tc_in)
print("soit ", heure,":",minute,":",seconde,":",frame)
print(list_image[i])
tc_out=int(list_out[i])
print("tc_out")
print ("frame", tc_out)
print ("seconde", tc_out/25)
heure,minute,seconde,frame = convert_tc(tc_out)
print("tc_out = ", heure,":",minute,":",seconde,":",frame)
print()
command_file=command_file+"-i "+list_image[i]+" "
#print (command_file)
print (i)
if i==0:
command_add="-filter_complex \"[0:v][1:v]overlay=0:0:enable=between(t\,"+str(tc_in/25)+"\,"+str(tc_out/25)+")[bkg]; "
if i>0:
if i<len(list_image)-1:
#if i<3-1:
command_add="[bkg]["+str(i+1)+":v]overlay=0:0:enable=between(t\,"+str(tc_in/25)+"\,"+str(tc_out/25)+")[bkg]; "
else:
command_add="[bkg]["+str(i+1)+":v]overlay=0:0:enable=between(t\,"+str(tc_in/25)+"\,"+str(tc_out/25)+")\" "
command_tc=command_tc+command_add
#print (command_tc)
i=i+1
print()
print()
command=command_header+command_file+command_tc+command_footer
print (command)
print()
print()
os.system(command) |
Partager