Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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