Skip to content

Instantly share code, notes, and snippets.

@cn-ml
Last active August 3, 2021 20:23
Show Gist options
  • Save cn-ml/1ea86e3349b7f469e3efc18092836391 to your computer and use it in GitHub Desktop.
Save cn-ml/1ea86e3349b7f469e3efc18092836391 to your computer and use it in GitHub Desktop.
ffmpeg based video checking tool, accepts files as CLI args and runs ffmpeg for all files (now with file globbing).
#!/usr/bin/python3
import sys
import subprocess
import glob
from yachalk import chalk
def test_file(file):
proc = subprocess.Popen(['ffmpeg', '-v', 'error', '-i', file, '-f', 'null', '-'], stderr=subprocess.PIPE, shell=True)
line = proc.stderr.readline()
if not line:
return True
try:
print(chalk.red(f'{chalk.bold("Error")}: {line.decode().strip()}'))
proc.kill()
proc.terminate()
except:
pass
return False
for file in (file for pattern in sys.argv[1:] for file in glob.glob(pattern)):
print(chalk.blue(f'Testing file {file}'))
try:
if test_file(file):
print(chalk.green(f'File {file} is okay!'))
else:
print(chalk.red(f'File {file} contains errors!'))
except Exception as ex:
print(chalk.red(f'Error while testing {file}: {ex}'))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment