1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

解像度を下げる

Posted at

pythonでファイル名一覧をとって jpgファイルをffmpegで解像度下げる


import glob
import subprocess
import os
import time
import sys
import re
from unittest import result

# ファイル名と拡張子に分離する
def parse_filename(content):
    filename1 = re.search('^[a-zA-Z\d_]*[^.]', content);
    extend = re.search('[.][a-zA-Z\d]+', content);
    return [filename1.group(), extend.group()]


def mainloop():
    path = r'./'

    folderfile = os.listdir(path)
    for file in folderfile:
        if file.find(".JPG") > 0 or file.find(".jpg") > 0:
            print(file) 
        
            t_file = parse_filename(file)
            t_filename = t_file[0]
            t_extend = t_file[1]

            cmd = 'ffmpeg -i {0}{1} -vf "scale=1440:-1" -q 2 {0}_1440x1{1}'.format(t_filename,t_extend)
            subprocess.call(cmd)

            print(cmd) 
            return 0

    return 0

if __name__ == "__main__":

    mainloop()
    exit(1)


1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?