I've been attempting to figure this out for forever now (I'm new to programming) and I can't figure it out.
I'm attempting to build a script that will test the file, and give me output from which I can get information like "Audio Format" that I can then put into the filename. However, I can't even get the script to return any file info. I've hit a wall at inserting an input file...
So at this point I just need help getting it to spit out info based on the argvs I've thrown in. Hopefully I'll be able to figure out how to parse the audio info from that.
My attempt that seems to be close:
#!/usr/bin/python
import os, sys, subprocess, shlex, re
from subprocess import call
def probe_file(filename):
p = subprocess.Popen(['/opt/local/bin/ffprobe', '-show_format', '-pretty', '-loglevel quiet', -i filename], stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)
print filename
print p.communicate()
[probe_file (f) for f in os.listdir('.') if not f.startswith('.')]
Few problems in your code
-i filename
which is a syntax error use'-i '+filename
insteadshell=True
is usually not needed and is unnecessary burden.Other than that it seems to be working, are you not seeing output after fixing #1 ?
Edit: Looks like you are having problem with ffprobe commandline, so I installed it and changes you require are
-i
flag, input file is just passed as last argument.-logelevel
and option of loglevequiet
as separate arguments i.e.[..., '-loglevel', 'quiet',..]
So after these changes here is a sample script
And I see the correct output:
Here is technique I think it is both simple to use and easy to parse (tested with ffmpeg 3.x):
The data available comes from a string representation that looks like this:
There is FFProbe wrapper for Python (https://pypi.org/project/ffprobe/).
You can install it easily:
(sudo) pip install ffprobe
A typical usage:
An alternative to FFProbe is pymediainfo library (https://pymediainfo.readthedocs.io/en/stable/). You can find usage in the documentation site.