Created
March 15, 2018 05:44
-
-
Save motoishmz/3642d94cf4436451c5f038e877e52549 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import subprocess as sp | |
import json | |
import pandas as pd | |
def _find_all_files_with_ext(dir, ext): | |
suffix = os.extsep + ext.lower() | |
for root, dirs, files in os.walk(dir): | |
for file in files: | |
if file.lower().endswith(suffix): | |
yield os.path.join(root, file) | |
def find_all_files_with_ext(dir, ext): | |
return list(_find_all_files_with_ext(dir, ext)) | |
def getLength(filename): | |
result = subprocess.Popen(['ffprobe', filename], | |
stdout = subprocess.PIPE, stderr = subprocess.STDOUT) | |
return [x for x in result.stdout.readlines() if "Duration" in x] | |
def probe(vid_file_path): | |
''' Give a json from ffprobe command line | |
@vid_file_path : The absolute (full) path of the video file, string. | |
''' | |
if type(vid_file_path) != str: | |
raise Exception('Gvie ffprobe a full file path of the video') | |
return | |
command = ["ffprobe", | |
"-loglevel", "quiet", | |
"-print_format", "json", | |
"-show_format", | |
vid_file_path | |
] | |
pipe = sp.Popen(command, stdout=sp.PIPE, stderr=sp.STDOUT) | |
out, err = pipe.communicate() | |
return json.loads(out) | |
# return out | |
for file in find_all_files_with_ext('.', 'mp4'): | |
path = os.path.abspath(file) | |
print(probe(path)) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment