Skip to content

Use ffprobe's -print_format json to parse, and also let ffprobe handle the "file" instead #4

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
ghost opened this issue Apr 27, 2020 · 3 comments

Comments

@ghost
Copy link

ghost commented Apr 27, 2020

Just found this recently and I think it would be best to use -print_format json instead of parsing the normal output. I also noticed that it checks whether the file existed or not. This unfortunately prevents it from working with HTTP and FTP.

@richardARPANET
Copy link

@Mz49 I just ended up using this.

import json
import subprocess

def _ffprobe(file_path):
    command = (
        'ffprobe -v quiet -print_format json -show_format -show_streams '
        f'{file_path}'
    )
    result = subprocess.run(command.split(), capture_output=True)
    if result.returncode == 0 and file_path.exists():
        return json.loads(result.stdout)
    raise RuntimeError(
        f'FFProbe failed for {file_path}, output: {result.stderr}'
    )

@bigntallmike
Copy link

I'm doing something like this myself in another project and was about to suggest it:

cmd = "ffprobe -v quiet -print_format json -show_streams"
args = shlex.split(cmd)
args.append(info.FILENAME)
ffprobeOutput = subprocess.check_output(args).decode('utf-8')
ffprobeOutput = json.loads(ffprobeOutput)

If it simplifies parsing for you at all

@jboy
Copy link

jboy commented Aug 13, 2023

If anyone's looking for a longer-term solution, I've:

  • implemented the aboveffprobe -print_format json command-line
  • enabled support for remote media streams (as the ffprobe program already does)
  • made the checks for file-existence optional

plus a bunch of other bug-fixes, features, and improvements, in a fork:
https://github.com/jboy/ffprobe3-python3

(Python3 only, sorry.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants