使用Python获取FFProbe信息 [英] Getting FFProbe Information With Python

查看:1080
本文介绍了使用Python获取FFProbe信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在试图将这一点永远归结为现在(我是新手编程),我无法想像出来。

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...

所以在这一点上,我只需要帮助它根据我的argvs来吐出信息我希望能找出如何解析音频信息。

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.

我的尝试似乎很接近:

#!/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('.')]


推荐答案

您的代码中的几个问题


  1. 将Popen的参数列表作为我的文件名哪个是yntax错误使用' - 我'+ filename 而是

  2. shell = True 通常不需要,是不必要的负担。

  1. args list to Popen has last argument as -i filename which is a syntax error use '-i '+filename instead
  2. shell=True is usually not needed and is unnecessary burden.

除了它似乎正在工作,你没有看到输出修复#1 ?

Other than that it seems to be working, are you not seeing output after fixing #1 ?

编辑:看起来你在使用ffprobe命令行时遇到问题,所以我安装了它,你需要的更改是

Looks like you are having problem with ffprobe commandline, so I installed it and changes you require are


  1. 我的ffprobe(ffprobe 0.7.3-4:0.7.3-0ubuntu0.11.10.1)似乎不接受 -i 标志,输入文件只是作为最后一个参数传递。

  2. 您需要通过 -logelevel 并选择logleve 安静作为单独的参数,即 [...,'-loglevel','quiet',..]

  1. My ffprobe (ffprobe 0.7.3-4:0.7.3-0ubuntu0.11.10.1) doesn't seems to accept -i flag, input file is just passed as last argument.
  2. you need to pass -logelevel and option of logleve quiet as separate arguments i.e. [..., '-loglevel', 'quiet',..]

所以在这里进行的这些更改是一个示例脚本

So after these changes here is a sample script

#!/usr/bin/python
import os, sys, subprocess, shlex, re
from subprocess import call
def probe_file(filename):
    cmnd = ['ffprobe', '-show_format', '-pretty', '-loglevel', 'quiet', filename]
    p = subprocess.Popen(cmnd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
    print filename
    out, err =  p.communicate()
    print "==========output=========="
    print out
    if err:
        print "========= error ========"
        print err

probe_file('drop.avi')

我看到正确的输出:

==========output==========
[FORMAT]
filename=drop.avi
nb_streams=1
format_name=avi
format_long_name=AVI format
start_time=0:00:00.000000
duration=0:00:06.066667
size=660.000 Kibyte
bit_rate=891.217 Kbit/s
[/FORMAT]

========= error ========
ffprobe version 0.7.3-4:0.7.3-0ubuntu0.11.10.1, Copyright (c) 2007-2011 the Libav developers
  built on Jan  4 2012 16:08:51 with gcc 4.6.1
  configuration: --extra-version='4:0.7.3-0ubuntu0.11.10.1' --arch=amd64 --prefix=/usr --enable-vdpau --enable-bzlib --enable-libgsm --enable-libschroedinger --enable-libspeex --enable-libtheora --enable-libvorbis --enable-pthreads --enable-zlib --enable-libvpx --enable-runtime-cpudetect --enable-vaapi --enable-gpl --enable-postproc --enable-swscale --enable-x11grab --enable-libdc1394 --enable-shared --disable-static
  libavutil    51.  7. 0 / 51.  7. 0
  libavcodec   53.  6. 0 / 53.  6. 0
  libavformat  53.  3. 0 / 53.  3. 0
  libavdevice  53.  0. 0 / 53.  0. 0
  libavfilter   2.  4. 0 /  2.  4. 0
  libswscale    2.  0. 0 /  2.  0. 0
  libpostproc  52.  0. 0 / 52.  0. 0
Unsupported codec with id 114 for input stream 0

这篇关于使用Python获取FFProbe信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆