refactor: suppression code obsolète (chunks, is_interlaced, mkv_to_mp4, -t)
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -78,31 +78,6 @@ def get_infos(file):
|
|||||||
return infos
|
return infos
|
||||||
|
|
||||||
|
|
||||||
def is_interlaced(file, infos):
|
|
||||||
'''
|
|
||||||
Cette fonction detecte si la vidéo est entrelacée.
|
|
||||||
-> https://fr.wikipedia.org/wiki/Entrelacement_(vid%C3%A9o)
|
|
||||||
'''
|
|
||||||
duration_tier = int(infos['duration'] / 3)
|
|
||||||
command = f"ffmpeg -loglevel info -ss {duration_tier} -t {duration_tier} -i {file} -an -filter:v idet -f null -y /dev/null"
|
|
||||||
result = subprocess.getoutput(command)
|
|
||||||
for line in result.splitlines():
|
|
||||||
if "Multi" in line:
|
|
||||||
TFF = int(line.split('TFF:')[1].split()[0])
|
|
||||||
BFF = int(line.split('BFF:')[1].split()[0])
|
|
||||||
Progressive = int(line.split('Progressive:')[1].split()[0])
|
|
||||||
try:
|
|
||||||
pct = ((TFF + BFF) / (TFF + BFF + Progressive)) * 100
|
|
||||||
pct = round(pct)
|
|
||||||
except ZeroDivisionError:
|
|
||||||
pct = 100
|
|
||||||
if pct > 10:
|
|
||||||
logging.debug(f"Vidéo entrelacée à {pct}%")
|
|
||||||
return True
|
|
||||||
else:
|
|
||||||
logging.debug("Vidéo non entrelacée")
|
|
||||||
return False
|
|
||||||
|
|
||||||
|
|
||||||
def cropping(file, infos):
|
def cropping(file, infos):
|
||||||
'''
|
'''
|
||||||
@@ -280,15 +255,6 @@ def create_mkv(filename):
|
|||||||
remove(file)
|
remove(file)
|
||||||
|
|
||||||
|
|
||||||
def mkv_to_mp4(filename):
|
|
||||||
options = "-c:a copy -c:v copy -c:s copy -movflags faststart"
|
|
||||||
command = f"ffmpeg -loglevel error -i {filename}_FINAL.mkv -map 0 {options} -y NEW_{filename}.mp4"
|
|
||||||
result = subprocess.getoutput(command)
|
|
||||||
if result != "":
|
|
||||||
logging.error(result)
|
|
||||||
else:
|
|
||||||
remove(f"{filename}_FINAL.mkv")
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
import argparse
|
import argparse
|
||||||
@@ -296,38 +262,12 @@ if __name__ == '__main__':
|
|||||||
parser.add_argument("f_input")
|
parser.add_argument("f_input")
|
||||||
parser.add_argument("-d", "--debug", dest="debug", action="store_true")
|
parser.add_argument("-d", "--debug", dest="debug", action="store_true")
|
||||||
parser.add_argument("-s", "--stabilise", dest="stab", action="store_true")
|
parser.add_argument("-s", "--stabilise", dest="stab", action="store_true")
|
||||||
parser.add_argument("-t", "--starttime", dest="starttime")
|
|
||||||
parser.add_argument("-a", "--animation", dest="animation", action="store_true")
|
parser.add_argument("-a", "--animation", dest="animation", action="store_true")
|
||||||
parser.add_argument("-c", "--vhs", dest="vhs", action="store_true")
|
parser.add_argument("-c", "--vhs", dest="vhs", action="store_true")
|
||||||
|
parser.add_argument("--interlaced", dest="interlaced", action="store_true")
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
if args.debug:
|
if args.debug:
|
||||||
logging.basicConfig(format='[%(asctime)s]\n%(message)s', level=logging.DEBUG, datefmt='%d/%m/%Y %H:%M:%S')
|
logging.basicConfig(format='[%(asctime)s]\n%(message)s', level=logging.DEBUG, datefmt='%d/%m/%Y %H:%M:%S')
|
||||||
else:
|
else:
|
||||||
logging.basicConfig(format='[%(asctime)s]\n%(message)s', level=logging.INFO, datefmt='%d/%m/%Y %H:%M:%S')
|
logging.basicConfig(format='[%(asctime)s]\n%(message)s', level=logging.INFO, datefmt='%d/%m/%Y %H:%M:%S')
|
||||||
file = args.f_input
|
pass
|
||||||
# infos = get_infos(file)
|
|
||||||
interlaced = False
|
|
||||||
interlaced = is_interlaced(file, infos)
|
|
||||||
cropsize = cropping(file, infos)
|
|
||||||
volumes = volume_audio(file, infos)
|
|
||||||
if args.stab:
|
|
||||||
stabilization(file)
|
|
||||||
if args.animation:
|
|
||||||
animation = True
|
|
||||||
else:
|
|
||||||
animation = False
|
|
||||||
if not args.starttime:
|
|
||||||
for track in infos['subtitles']:
|
|
||||||
extract_subs(file, track['index'], track['language'])
|
|
||||||
for track in infos['audio']:
|
|
||||||
convert_audio(file, track['index'], volumes[track['index']], track['channels'], track['channel_layout'], track['language'], track['title'])
|
|
||||||
if args.starttime:
|
|
||||||
vid_part_time = int(args.starttime)
|
|
||||||
else:
|
|
||||||
vid_part_time = 0
|
|
||||||
while vid_part_time < infos['duration']:
|
|
||||||
crf = 20
|
|
||||||
convert_video(file, infos, vid_part_time, cropsize, crf, animation, interlaced, args.vhs)
|
|
||||||
vid_part_time += 300
|
|
||||||
create_mkv(file)
|
|
||||||
mkv_to_mp4(file)
|
|
||||||
|
|||||||
Reference in New Issue
Block a user