101 lines
4.2 KiB
Python
101 lines
4.2 KiB
Python
![]() |
#!/usr/bin/python
|
||
|
# -*- coding: utf-8 -*-
|
||
|
import time
|
||
|
|
||
|
# pip install ffmpeg-python
|
||
|
|
||
|
import ffmpeg
|
||
|
from pathlib import Path
|
||
|
|
||
|
|
||
|
def available_files(folder: str | Path | None = None, starts_w: str | None = None,
|
||
|
contains: str | list[str] | tuple[str] | None = None,
|
||
|
suffix: str = '.log'):
|
||
|
"""
|
||
|
generates all the available filenames
|
||
|
"""
|
||
|
if folder is None:
|
||
|
folder = Path('.')
|
||
|
else:
|
||
|
if isinstance(folder, str):
|
||
|
folder = Path(folder)
|
||
|
if not isinstance(folder, Path):
|
||
|
raise ValueError(f'Wrong type for folder: expected str | Path | None, found {type(folder)}')
|
||
|
if not folder.is_dir():
|
||
|
raise ValueError(f'folder parameter must point to a directory: {folder}')
|
||
|
for f in folder.iterdir():
|
||
|
if f.is_file() and f.suffix == suffix:
|
||
|
if starts_w is not None and not f.name.startswith(starts_w):
|
||
|
continue
|
||
|
if contains is not None:
|
||
|
if isinstance(contains, str):
|
||
|
# a single string
|
||
|
if contains not in f.name:
|
||
|
continue
|
||
|
if isinstance(contains, list):
|
||
|
keep_it = False
|
||
|
for con in contains:
|
||
|
if con in f.name:
|
||
|
keep_it = True
|
||
|
break
|
||
|
if not keep_it:
|
||
|
continue
|
||
|
yield f
|
||
|
|
||
|
|
||
|
def get_duration(file_path):
|
||
|
probe = ffmpeg.probe(file_path)
|
||
|
return float(probe['format']['duration'])
|
||
|
|
||
|
|
||
|
def main():
|
||
|
pass
|
||
|
|
||
|
|
||
|
# PS C:\DV Capture\My Video\Video> history
|
||
|
#
|
||
|
# Id CommandLine
|
||
|
# -- -----------
|
||
|
# 1 dir
|
||
|
# 2 ffmpeg -i '.\My Video 20090106-15.05.15.avi' -c:v libx265 -crf 22 -preset slow -c:a aac -b:a 192k output.mp4
|
||
|
# 3 ffmpeg -i '.`My Video 20100106-15.05.15.avi' -c:v libx265 -crf 22 -preset slow -c:a aac -b:a 192k output.mp4
|
||
|
# 4 ffmpeg -i ".\My Video 20100106-15.05.15.avi" -c:v libx265 -crf 22 -preset slow -c:a aac -b:a 192k output.mp4
|
||
|
# 5 ffmpeg -i ".\My Video 20100106-15.04.41.avi" -c:v libx265 -crf 22 -preset slow -c:a aac -b:a 192k output.mp4
|
||
|
# 6 ffmpeg -i ".\My Video 20100106-15.04.41.avi" -vf idet -frames:v 500 -an -f null -
|
||
|
# 7 ffmpeg -i ".\My Video 20100106-15.04.41.avi" -vf "bwdif" -c:v libx265 -crf 22 -preset slow -c:a aac -b:a 192k output_d.mp4
|
||
|
# 8 ffmpeg -i ".\My Video 20100106-15.04.41.avi" -vf "bwdif" -c:v libx265 -crf 22 -c:a aac -b:a 192k output_d2.mp4
|
||
|
# 9 ffmpeg -hwaccel cuda -hwaccel_output_format cuda -i ".\My Video 20100106-15.04.41.avi" -vf "yadif_cuda=1" -c:v hevc_nvenc -preset slow -cq 22 -c:a aac -b:a 192k output_d3...
|
||
|
# 10 ffmpeg -hwaccel cuda -hwaccel_output_format cuda -i ".\My Video 20100106-15.04.41.avi" -vf "format=nv12, yadif_cuda=1" -c:v hevc_nvenc -preset slow -cq 22 -c:a aac -b:a 1...
|
||
|
# 11 history
|
||
|
# 12 nvidia-smi
|
||
|
# 13 ffmpeg -i ".\My Video 20100106-15.04.41.avi" -vf "yadif_cuda=1" -c:v hevc_nvenc -preset slow -cq 22 -c:a aac -b:a 192k output_d3.mp4
|
||
|
# 14 ffmpeg -hwaccel cuda -hwaccel_output_format cuda -i ".\My Video 20100106-15.04.41.avi" -vf "bwdif" -c:v hevc_nvenc -preset slow -cq 22 -c:a aac -b:a 192k output_d3.mp4
|
||
|
|
||
|
|
||
|
if __name__ == '__main__':
|
||
|
# main()
|
||
|
# base_folder = Path('C:/DV Capture/My Video/Video')
|
||
|
base_folder = Path('C:/Hmc/DV_out/C02_')
|
||
|
total_duration = 0
|
||
|
for f in available_files(base_folder, suffix='.avi'):
|
||
|
prb = ffmpeg.probe(f)
|
||
|
streams = prb.get('streams')
|
||
|
frmt = prb.get('format')
|
||
|
dur = float(frmt.get('duration'))
|
||
|
frc = 1000 * (dur - int(dur))
|
||
|
total_duration += dur
|
||
|
human_dur = time.strftime('%H:%M:%S', time.gmtime(dur))
|
||
|
print(f'------------------ {f} {human_dur}.{frc:03.0f} {dur}')
|
||
|
# print(f'Streams: {streams}')
|
||
|
# for n, stream in enumerate(streams):
|
||
|
# print(f'S:{n}')
|
||
|
# for k, v in stream.items():
|
||
|
# print(f' {k}: {v}')
|
||
|
# print('Format:')
|
||
|
# for k, v in frmt.items():
|
||
|
# print(f'{k}: {v}')
|
||
|
# break
|
||
|
frc = 1000 * (total_duration - int(total_duration))
|
||
|
human_t_dur = time.strftime('%H:%M:%S', time.gmtime(total_duration))
|
||
|
print(f'Totale: {human_t_dur}.{frc:03.0f} {total_duration}')
|