使用python對視頻文件分辨率進行分組的實例代碼
在平時的工作中,我們的目錄有很多的視頻文件,如果你沒有一個好的視頻分類習慣,在找視頻素材的時候會很費時,通過對視頻的分辨路進行分類可以在需要的時候快速找到你想要的視頻分辨率。當然人工去分類是一種比較費時費力的工作,通過軟件也好,程序也罷都是為了可以提高我們的工作效率。
代碼分享
import os
import subprocess
import json
import shutil
import datetime
def get_files(file_dir):
for root, dirs, files in os.walk(file_dir):
if len(files) > 0:
# 獲取圖片路徑
for f in files:
if f.endswith(".mp4"):
p = os.path.join(root, f)
h, w, t = get_video_info(p)
new_dir = os.path.realpath(
"{}\{}x{}".format(file_dir, h, w))
if not os.path.exists(new_dir):
os.makedirs(new_dir)
shutil.move(p, os.path.join(new_dir, "{}.mp4".format(t)))
def get_video_info(file_path):
cmd = "ffprobe -v quiet -print_format json -show_streams -i {}".format(
file_path)
with open('output.json', 'w') as f:
subprocess.call(cmd, stdout=f)
with open('output.json', 'r') as f:
streams = json.load(f)
for i in streams["streams"]:
if i['codec_type'] == "video":
print(file_path)
t2 = ""
try:
t1 = datetime.datetime.strptime(
i['tags']['creation_time'], "%Y-%m-%dT%H:%M:%S.%f%z")
t2 = datetime.datetime.strftime(t1, '%Y%m%d%H%M%S')
except KeyError:
t2 = datetime.datetime.now().strftime('%Y%m%d%H%M%S')
return i['height'], i['width'], t2
else:
continue
if __name__ == "__main__":
file_dir = input("dir:")
get_files(file_dir)
代碼使用了ffprobe獲取視頻信息
原文:http://www.rencaixiu.cn/archives/811/
到此這篇關(guān)于使用python對視頻文件分辨率進行分組的文章就介紹到這了,更多相關(guān)python視頻文件分辨率分組內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
Python實戰(zhàn)快速上手BeautifulSoup庫爬取專欄標題和地址
BeautifulSoup是爬蟲必學的技能,BeautifulSoup最主要的功能是從網(wǎng)頁抓取數(shù)據(jù),Beautiful Soup自動將輸入文檔轉(zhuǎn)換為Unicode編碼,輸出文檔轉(zhuǎn)換為utf-8編碼2021-10-10
Python求區(qū)間正整數(shù)內(nèi)所有素數(shù)之和的方法實例
這篇文章主要給大家介紹了Python對區(qū)間正整數(shù)內(nèi)所有素數(shù)之和的相關(guān)資料,文中介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧2020-10-10
selenium執(zhí)行js并繞過webdriver監(jiān)測常見方法
這篇文章主要為大家介紹了selenium執(zhí)行js并繞過webdriver監(jiān)測常見方法,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步早日升職加薪2022-04-04
Python并行庫joblib之delayed函數(shù)與Parallel函數(shù)詳解
這篇文章主要介紹了Python并行庫joblib之delayed函數(shù)與Parallel函數(shù)詳解,Joblib就是一個可以簡單地將Python代碼轉(zhuǎn)換為并行計算模式的軟件包,它可非常簡單并行我們的程序,從而提高計算速度,需要的朋友可以參考下2023-08-08

