Initial Commit
This commit is contained in:
25
unshackle/core/utils/subprocess.py
Normal file
25
unshackle/core/utils/subprocess.py
Normal file
@@ -0,0 +1,25 @@
|
||||
import json
|
||||
import subprocess
|
||||
from pathlib import Path
|
||||
from typing import Union
|
||||
|
||||
from unshackle.core import binaries
|
||||
|
||||
|
||||
def ffprobe(uri: Union[bytes, Path]) -> dict:
|
||||
"""Use ffprobe on the provided data to get stream information."""
|
||||
if not binaries.FFProbe:
|
||||
raise EnvironmentError('FFProbe executable "ffprobe" not found but is required.')
|
||||
|
||||
args = [binaries.FFProbe, "-v", "quiet", "-of", "json", "-show_streams"]
|
||||
if isinstance(uri, Path):
|
||||
args.extend(
|
||||
["-f", "lavfi", "-i", "movie={}[out+subcc]".format(str(uri).replace("\\", "/").replace(":", "\\\\:"))]
|
||||
)
|
||||
elif isinstance(uri, bytes):
|
||||
args.append("pipe:")
|
||||
try:
|
||||
ff = subprocess.run(args, input=uri if isinstance(uri, bytes) else None, check=True, capture_output=True)
|
||||
except subprocess.CalledProcessError:
|
||||
return {}
|
||||
return json.loads(ff.stdout.decode("utf8"))
|
||||
Reference in New Issue
Block a user