仅在ubuntu上出现ffmpeg python子进程错误
我正在开发一个将youtube视频分割成图像的应用程序。我使用MacBookPro进行开发,但我们的应用服务器运行在ubuntu 12.04服务器上。目前运行的服务器上的代码如下仅在ubuntu上出现ffmpeg python子进程错误,python,ubuntu,ffmpeg,Python,Ubuntu,Ffmpeg,我正在开发一个将youtube视频分割成图像的应用程序。我使用MacBookPro进行开发,但我们的应用服务器运行在ubuntu 12.04服务器上。目前运行的服务器上的代码如下 ffmpeg -i {video_file} -vf fps={fps} 我们通过python中的子进程Popen函数调用来运行它。它的性能非常慢,因为它实际上是在播放整个视频文件以获得帧。我发现另一个SO帖子说你可以使用-accurate_seek-ss在特定时间抓取单个帧,但我面临一些问题。当我在SSH进入我们的
ffmpeg -i {video_file} -vf fps={fps}
我们通过python中的子进程Popen函数调用来运行它。它的性能非常慢,因为它实际上是在播放整个视频文件以获得帧。我发现另一个SO帖子说你可以使用-accurate_seek-ss在特定时间抓取单个帧,但我面临一些问题。当我在SSH进入我们的开发服务器时通过命令行运行命令时,它工作正常,但是当我在python中通过子进程Popen调用运行命令时,我得到以下错误:
(standard_in) 1: syntax error
ffmpeg version 3.2.4-static http://johnvansickle.com/ffmpeg/ Copyright (c) 2000-2017 the FFmpeg developers
built with gcc 5.4.1 (Debian 5.4.1-5) 20170205
configuration: --enable-gpl --enable-version3 --enable-static --disable-debug --disable-ffplay --disable-indev=sndio --disable-outdev=sndio --cc=gcc-5 --enable-fontconfig --enable-frei0r --enable-gnutls --enable-gray --enable-libass --enable-libfreetype --enable-libfribidi --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libopus --enable-librtmp --enable-libsoxr --enable-libspeex --enable-libtheora --enable-libvidstab --enable-libvo-amrwbenc --enable-libvorbis --enable-libvpx --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxvid --enable-libzimg
libavutil 55. 34.101 / 55. 34.101
libavcodec 57. 64.101 / 57. 64.101
libavformat 57. 56.101 / 57. 56.101
libavdevice 57. 1.100 / 57. 1.100
libavfilter 6. 65.100 / 6. 65.100
libswscale 4. 2.100 / 4. 2.100
libswresample 2. 3.100 / 2. 3.100
libpostproc 54. 1.100 / 54. 1.100
Option accurate_seek (enable/disable accurate seeking with -ss) cannot be applied to output url test.mkv -- you are trying to apply an input option to an output file or vice versa. Move this option before the file it belongs to.
Error parsing options for output file test.mkv.
Error opening output files: Invalid argument
python代码:
import subprocess
command = "for i in {0..3} ; do ffmpeg -accurate_seek -ss `echo $i*60.0 | bc` -i test.mkv -frames:v 1 images/test_img_$i.jpg ; done"
process = subprocess.Popen(command, stdout=subprocess.PIPE, stderr = subprocess.STDOUT, shell=True)
output = process.communicate()
print output[0].replace('\\n' , '\n')
问题是,当我在我的OSX终端上运行它时,它工作得很好,但是在ubuntu中运行它有一些问题。有没有人有这方面的经验
在osx中运行相同代码时的输出:
ffmpeg version 3.0.2 Copyright (c) 2000-2016 the FFmpeg developers
built with Apple LLVM version 7.3.0 (clang-703.0.31)
configuration: --prefix=/usr/local/Cellar/ffmpeg/3.0.2 --enable-shared --enable-pthreads --enable-gpl --enable-version3 --enable-hardcoded-tables --enable-avresample --cc=clang --host-cflags= --host-ldflags= --enable-opencl --enable-libx264 --enable-libmp3lame --enable-libxvid --enable-libvpx --enable-vda
libavutil 55. 17.103 / 55. 17.103
libavcodec 57. 24.102 / 57. 24.102
libavformat 57. 25.100 / 57. 25.100
libavdevice 57. 0.101 / 57. 0.101
libavfilter 6. 31.100 / 6. 31.100
libavresample 3. 0. 0 / 3. 0. 0
libswscale 4. 0.100 / 4. 0.100
libswresample 2. 0.101 / 2. 0.101
libpostproc 54. 0.100 / 54. 0.100
Input #0, matroska,webm, from 'test.mkv':
Metadata:
COMPATIBLE_BRANDS: iso6avc1mp41
MAJOR_BRAND : dash
MINOR_VERSION : 0
ENCODER : Lavf57.25.100
Duration: 00:02:10.20, start: 0.007000, bitrate: 2729 kb/s
Stream #0:0: Video: h264 (High), yuv420p(tv, bt709), 1920x1080 [SAR 1:1 DAR 16:9], 23.98 fps, 23.98 tbr, 1k tbn, 47.95 tbc (default)
Metadata:
HANDLER_NAME : VideoHandler
DURATION : 00:02:10.172000000
Stream #0:1(eng): Audio: opus, 48000 Hz, stereo, fltp (default)
Metadata:
DURATION : 00:02:10.201000000
[swscaler @ 0x7f9b4b008000] deprecated pixel format used, make sure you did set range correctly
Output #0, image2, to 'images/test_img_0.jpg':
Metadata:
COMPATIBLE_BRANDS: iso6avc1mp41
MAJOR_BRAND : dash
MINOR_VERSION : 0
encoder : Lavf57.25.100
Stream #0:0: Video: mjpeg, yuvj420p(pc), 1920x1080 [SAR 1:1 DAR 16:9], q=2-31, 200 kb/s, 23.98 fps, 23.98 tbn, 23.98 tbc (default)
Metadata:
HANDLER_NAME : VideoHandler
DURATION : 00:02:10.172000000
encoder : Lavc57.24.102 mjpeg
Side data:
unknown side data type 10 (24 bytes)
Stream mapping:
Stream #0:0 -> #0:0 (h264 (native) -> mjpeg (native))
Press [q] to stop, [?] for help
frame= 1 fps=0.0 q=7.2 Lsize=N/A time=00:00:00.04 bitrate=N/A speed= 1x
video:73kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: unknown
....
我忘了提到的一件事是,在我的mac电脑上,我使用自制软件安装ffmpeg,而在Ubuntu上,我使用的是静态构建
其他堆栈溢出参考:问题在于范围表示法
{0..3}
,它在bash中有效,但在其他shell中无效。在我的Ubuntu系统上,正常的登录shell是bash,subprocess.Popen()
withshell=True
调用/bin/sh
,在我的例子中,它不是bash而是dash,它不支持大括号扩展
由于范围没有扩展,循环只运行一次,变量$i
包含字符串{0..3}
。传递给bc
,导致第一个错误(标准)1:语法错误
。因此,精确搜索
参数-ss
到ffmpeg
没有得到任何值
在我的带有dash shell的Ubuntu系统上,带有seq
的循环可以工作:
$ sh
$ for i in $(seq 0 3); do echo $i; done
0
1
2
3
与之相反:
$ sh
$ for i in {0..3}; do echo $i; done
{0..3}
但是由于
seq
不是POSIX,并且可能不会出现在所有系统上,因此最好不要过于依赖shell(另请参见中的警告)。从time
返回一个错误,但是您给出的代码中没有任何time
。请包含一个。我重新运行了python代码并粘贴了正确的错误消息。我忘了我从您可以使用的python代码中删除了time命令