-
Notifications
You must be signed in to change notification settings - Fork 1
/
avi2mp4withinDir.py
47 lines (37 loc) · 1.56 KB
/
avi2mp4withinDir.py
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
import pandas as pd
import glob
import os
import subprocess
import concurrent.futures
import time
mainPath = r'Y:\Jessie\e3 - Data Analysis\e3 Data\allVideos\avi_Process'
os.chdir(mainPath)
files = glob.glob('*.avi')
def nameNew(fileName):
fileName = fileName.split('.')[0]+'.mp4'
# folderNameSplit = fileName.split(os.sep)
# folderNameSplit = os.sep.join(folderNameSplit[1:-1])
# fileName = fileName.split(os.sep)[-1].split('.')[0]+'.mp4'
# folderName = r'C:\Users\Windows\Desktop\SpeedUPVID'+os.sep+folderNameSplit
# fileName = folderName+os.sep+fileName
# os.makedirs(folderName, exist_ok=True)
return fileName
def tmpFct(file):
newi = nameNew(file)
## %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
''' Conversion note
-codec:v : mpeg4 necessary to be able to have good fps tbn tbr matching
-r: enables to have the frame rate of intres
-qscale:v: this is the quality of the video
-codec:a: needed to have audio codec
-video_track_timescale: force the tbn value
'''
## %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
# subprocess.call('ffmpeg -i ' + file + ' -codec:v mpeg4 -r 500 -qscale:v 4 -codec:a copy -video_track_timescale 500 '+ newi , shell=True)
subprocess.call('ffmpeg -i ' + file + ' -vcodec libx264 -crf 20 '+ newi , shell=True)
print(file, newi)
with concurrent.futures.ProcessPoolExecutor() as executor:
if __name__ == '__main__':
executor.map(tmpFct, files)
finish = time.perf_counter()
print("Finished in time : ", finish)