Skip to content

Instantly share code, notes, and snippets.

@motoishmz
Created March 15, 2018 05:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save motoishmz/3642d94cf4436451c5f038e877e52549 to your computer and use it in GitHub Desktop.
Save motoishmz/3642d94cf4436451c5f038e877e52549 to your computer and use it in GitHub Desktop.
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