我试图捕获ffprobe的输出。首先,我建立了我的命令:
>>> print cmd
['C:\\Program Files\\ffmpeg\\bin\\ffprobe.exe', 'somefile.mov']
然后我使用check_output来获取输出:
>>> import subprocess as sp
>>> output = sp.check_output(cmd)
ffprobe version N-66673-gf0d1b3a Copyright (c) 2007-2014 the FFmpeg developers
built on Oct 6 2014 22:10:42 with gcc 4.9.1 (GCC)
configuration: --enable-gpl --enable-version3 --disable-w32threads --enable-avisynth --enable-bzlib --enable-fontconfi
g --enable-frei0r --enable-gnutls --enable-iconv --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --
enable-libfreetype --enable-libgme --enable-libgsm --enable-libilbc --enable-libmodplug --enable-libmp3lame --enable-lib
opencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libopus --enable-librtmp --enable-libschroedinge
r --enable-libsoxr --enable-libspeex --enable-libtheora --enable-libtwolame --enable-libvidstab --enable-libvo-aacenc --
enable-libvo-amrwbenc --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx264 --enable-
libx265 --enable-libxavs --enable-libxvid --enable-zlib
libavutil 54. 9.100 / 54. 9.100
libavcodec 56. 3.101 / 56. 3.101
libavformat 56. 7.104 / 56. 7.104
libavdevice 56. 1.100 / 56. 1.100
libavfilter 5. 1.102 / 5. 1.102
libswscale 3. 1.100 / 3. 1.100
libswresample 1. 1.100 / 1. 1.100
libpostproc 53. 1.100 / 53. 1.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'somefile.mov':
Metadata:
major_brand : qt
minor_version : 512
compatible_brands: qt
encoder : Lavf56.7.104
Duration: 00:20:54.46, start: 0.000000, bitrate: 1734 kb/s
Stream #0:0(eng): Video: h264 (Main) (avc1 / 0x31637661), yuv420p(tv, bt709), 1280x720, 1617 kb/s, 24 fps, 24 tbr, 1
2288 tbn, 24576 tbc (default)
Metadata:
handler_name : DataHandler
Stream #0:1(eng): Audio: aac (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 113 kb/s (default)
Metadata:
handler_name : DataHandler
然而,当我打印输出时,我什么都没得到:
>>> print output
我和Popen得到了相同的结果并且沟通():
>>> output = sp.Popen(cmd, stdout=sp.PIPE)
>>> output.communicate()
('', None)
嗯,我猜它并不是什么都没有。看起来我回来了一个空白的字符串?
答案 0 :(得分:0)
很奇怪......我能用stderr抓住它吗?
>>> output = sp.Popen(cmd, stdout=sp.PIPE, stderr=sp.PIPE)
>>> output.communicate()
('', "ffprobe version N-66673-gf0d1b3a Copyright (c) 2007-2014 the FFmpeg developers\r\n built on Oct 6 2014 22:10:42
with gcc 4.9.1 (GCC)\r\n configuration: --enable-gpl --enable-version3 --disable-w32threads --enable-avisynth --enable-
bzlib --enable-fontconfig --enable-frei0r --enable-gnutls --enable-iconv --enable-libass --enable-libbluray --enable-lib
bs2b --enable-libcaca --enable-libfreetype --enable-libgme --enable-libgsm --enable-libilbc --enable-libmodplug --enable
-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libopus --enable-librtmp
--enable-libschroedinger --enable-libsoxr --enable-libspeex --enable-libtheora --enable-libtwolame --enable-libvidstab
--enable-libvo-aacenc --enable-libvo-amrwbenc --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --
enable-libx264 --enable-libx265 --enable-libxavs --enable-libxvid --enable-zlib\r\n libavutil 54. 9.100 / 54. 9.
100\r\n libavcodec 56. 3.101 / 56. 3.101\r\n libavformat 56. 7.104 / 56. 7.104\r\n libavdevice 56. 1.1
00 / 56. 1.100\r\n libavfilter 5. 1.102 / 5. 1.102\r\n libswscale 3. 1.100 / 3. 1.100\r\n libswresamp
le 1. 1.100 / 1. 1.100\r\n libpostproc 53. 1.100 / 53. 1.100\r\nInput #0, mov,mp4,m4a,3gp,3g2,mj2, from 'somefile.mov':\r\n Metadata:\r\n major_brand : qt \r\n minor_version : 512\r\n
compatible_brands: qt \r\n encoder : Lavf56.7.104\r\n Duration: 00:20:54.46, start: 0.000000, bitrate: 17
34 kb/s\r\n Stream #0:0(eng): Video: h264 (Main) (avc1 / 0x31637661), yuv420p(tv, bt709), 1280x720, 1617 kb/s, 24 fps
, 24 tbr, 12288 tbn, 24576 tbc (default)\r\n Metadata:\r\n handler_name : DataHandler\r\n Stream #0:1(eng)
: Audio: aac (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 113 kb/s (default)\r\n Metadata:\r\n handler_name :
DataHandler\r\n")
我猜我看到的ffprobe的所有输出实际上都是通过stderr输出的。