-
Notifications
You must be signed in to change notification settings - Fork 0
/
myffmpeg.py
45 lines (33 loc) · 1.04 KB
/
myffmpeg.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
# -*- coding: utf-8 -*-
# @Author: longfengpili
# @Date: 2024-08-23 10:51:34
# @Last Modified by: longfengpili
# @Last Modified time: 2024-09-01 13:40:25
# @github: https://github.com/longfengpili
from pathlib import Path
from pydbapi.conf import LOGGING_CONFIG
import ffmpeg
import logging
logging.config.dictConfig(LOGGING_CONFIG)
logger = logging.getLogger(__name__)
def get_files(path: str = None):
path = path or './'
path = Path(path)
files = [file for file in path.rglob('*.mp4')]
return files
def convert_video(file: Path, target_path: str = None, r: int = 60):
file = file.resolve()
target_path = target_path or f'{file.drive}/'
tpath = Path(target_path) / 'new_video'
tfile = tpath / f'new_{file.name}'
if not tpath.exists():
tpath.mkdir(parents=True)
if tfile.exists():
return
tfile = tfile.as_posix()
ffmpeg.input(file).output(tfile, r=r).run()
if __name__ == '__main__':
files = get_files()
for file in files:
logger.info(file)
convert_video(file)