我目前正在编写一个简单的脚本,将ffmpeg的输出通过管道传输到opencv,但是它一直在向我大喊大叫。
我的整个命令行是
ffmpeg -flags output_corrupt -analyzeduration 32 -probesize 32 -i temp_file.h264 -updatefirst 1 -y -qscale:v 2 -vf scale =“ 240:-1” -f image2pipe-| python cap.py
我的python脚本代码如下
import sys
import cv2 as cv
import numpy as np
while True:
img = sys.stdin
# print img
# img = cv.imdecode(img, 1)
if img is not None:
cv.imshow("Video", img)
cv.waitkey(1)
else:
print "No image"
执行命令行后,收到以下消息:
ffmpeg version 3.4.2-2 Copyright (c) 2000-2018 the FFmpeg developers
built with gcc 7 (Ubuntu 7.3.0-16ubuntu2)
configuration: --prefix=/usr --extra-version=2 --toolchain=hardened --libdir=/usr/lib/x86_64-linux-gnu --incdir=/usr/include/x86_64-linux-gnu --enable-gpl --disable-stripping --enable-avresample --enable-avisynth --enable-gnutls --enable-ladspa --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libflite --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libgme --enable-libgsm --enable-libmp3lame --enable-libmysofa --enable-libopenjpeg --enable-libopenmpt --enable-libopus --enable-libpulse --enable-librubberband --enable-librsvg --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libssh --enable-libtheora --enable-libtwolame --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx265 --enable-libxml2 --enable-libxvid --enable-libzmq --enable-libzvbi --enable-omx --enable-openal --enable-opengl --enable-sdl2 --enable-libdc1394 --enable-libdrm --enable-libiec61883 --enable-chromaprint --enable-frei0r --enable-libopencv --enable-libx264 --enable-shared
libavutil 55. 78.100 / 55. 78.100
libavcodec 57.107.100 / 57.107.100
libavformat 57. 83.100 / 57. 83.100
libavdevice 57. 10.100 / 57. 10.100
libavfilter 6.107.100 / 6.107.100
libavresample 3. 7. 0 / 3. 7. 0
libswscale 4. 8.100 / 4. 8.100
libswresample 2. 9.100 / 2. 9.100
libpostproc 54. 7.100 / 54. 7.100
[h264 @ 0x557ea6b01a60] Stream #0: not enough frames to estimate rate; consider increasing probesize
[h264 @ 0x557ea6b01a60] decoding for stream 0 failed
Input #0, h264, from 'temp_file.h264':
Duration: N/A, bitrate: N/A
Stream #0:0: Video: h264 (High), yuvj420p(pc, progressive), 1280x720, 29.97 tbr, 1200k tbn, 59.94 tbc
Stream mapping:
Stream #0:0 -> #0:0 (h264 (native) -> mpeg2video (native))
Press [q] to stop, [?] for help
[h264 @ 0x557ea6b22a60] error while decoding MB 54 2, bytestream -16
[h264 @ 0x557ea6b22a60] top block unavailable for requested intra mode -1
[h264 @ 0x557ea6b22a60] error while decoding MB 2 9, bytestream 6907
[h264 @ 0x557ea6b22a60] concealing 1275 DC, 1275 AC, 1275 MV errors in P frame
[h264 @ 0x557ea6b28740] top block unavailable for requested intra mode -1
[h264 @ 0x557ea6b28740] error while decoding MB 27 0, bytestream 5564
[h264 @ 0x557ea6b28740] deblocking filter parameters 7 13 out of range
[h264 @ 0x557ea6b28740] decode_slice_header error
[h264 @ 0x557ea6b28740] concealing 1440 DC, 1440 AC, 1440 MV errors in P frame
[h264 @ 0x557ea6ba5be0] deblocking filter parameters 7 -14 out of range
[h264 @ 0x557ea6ba5be0] decode_slice_header error
[swscaler @ 0x557ea7159ba0] deprecated pixel format used, make sure you did set range correctly
[mpeg2video @ 0x557ea6b2ecc0] too many threads/slices (10), reducing to 9
[h264 @ 0x557ea6ba5be0] concealing 1387 DC, 1387 AC, 1387 MV errors in P frame
Output #0, mpegts, to 'pipe:':
Metadata:
encoder : Lavf57.83.100
Stream #0:0: Video: mpeg2video (Main), yuv420p, 240x135, q=2-31, 200 kb/s, 29.97 fps, 90k tbn, 29.97 tbc
Metadata:
encoder : Lavc57.107.100 mpeg2video
Side data:
cpb: bitrate max/min/avg: 0/0/200000 buffer size: 0 vbv_delay: -1
[h264 @ 0x557ea6bc1b60] deblocking filter parameters -7 0 out of range
[h264 @ 0x557ea6bc1b60] decode_slice_header error
[h264 @ 0x557ea6bc1b60] concealing 1413 DC, 1413 AC, 1413 MV errors in P frame
[h264 @ 0x557ea6bddae0] top block unavailable for requested intra mode -1
[h264 @ 0x557ea6bddae0] error while decoding MB 9 0, bytestream 6647
[h264 @ 0x557ea6bddae0] concealing 1186 DC, 1186 AC, 1186 MV errors in P frame
[h264 @ 0x557ea6bf9a60] top block unavailable for requested intra mode
[h264 @ 0x557ea6bf9a60] error while decoding MB 16 9, bytestream 6182
[h264 @ 0x557ea6bf9a60] top block unavailable for requested intra mode -1
[h264 @ 0x557ea6bf9a60] error while decoding MB 6 18, bytestream 7043
[h264 @ 0x557ea6bf9a60] concealing 1440 DC, 1440 AC, 1440 MV errors in P frame
[h264 @ 0x557ea6c159e0] top block unavailable for requested intra mode -1
[h264 @ 0x557ea6c159e0] error while decoding MB 12 9, bytestream 6863
[h264 @ 0x557ea6c159e0] concealing 1342 DC, 1342 AC, 1342 MV errors in P frame
[h264 @ 0x557ea6c31d40] top block unavailable for requested intra mode
[h264 @ 0x557ea6c31d40] error while decoding MB 29 18, bytestream 6611
[h264 @ 0x557ea6c31d40] concealing 1405 DC, 1405 AC, 1405 MV errors in P frame
[h264 @ 0x557ea6c4e0a0] top block unavailable for requested intra mode
[h264 @ 0x557ea6c4e0a0] error while decoding MB 25 9, bytestream 6051
[h264 @ 0x557ea6c4e0a0] top block unavailable for requested intra mode -1
[h264 @ 0x557ea6c4e0a0] error while decoding MB 70 18, bytestream 5088
[h264 @ 0x557ea6c4e0a0] concealing 1419 DC, 1419 AC, 1419 MV errors in P frame
[h264 @ 0x557ea6c6a400] top block unavailable for requested intra mode
[h264 @ 0x557ea6c6a400] error while decoding MB 14 9, bytestream 6071
[h264 @ 0x557ea6c6a400] deblocking filter parameters -9 0 out of range
[h264 @ 0x557ea6c6a400] decode_slice_header error
[h264 @ 0x557ea6c6a400] concealing 1440 DC, 1440 AC, 1440 MV errors in P frame
[h264 @ 0x557ea6c86760] top block unavailable for requested intra mode -1
[h264 @ 0x557ea6c86760] error while decoding MB 54 9, bytestream 4422
[h264 @ 0x557ea6c86760] concealing 1256 DC, 1256 AC, 1256 MV errors in P frame
[h264 @ 0x557ea6ca2ac0] top block unavailable for requested intra mode -1
[h264 @ 0x557ea6ca2ac0] error while decoding MB 22 9, bytestream 5862
[h264 @ 0x557ea6ca2ac0] concealing 1335 DC, 1335 AC, 1335 MV errors in P frame
[h264 @ 0x557ea6b2f180] deblocking filter parameters 7 -4 out of range
[h264 @ 0x557ea6b2f180] decode_slice_header error
[h264 @ 0x557ea6b2f180] concealing 1430 DC, 1430 AC, 1430 MV errors in P frame
Traceback (most recent call last):
File "cap.py", line 11, in <module>
cv.imshow("Video", img)
TypeError: mat is not a numpy array, neither a scalar
[h264 @ 0x557ea6b22a60] concealing 1319 DC, 1319 AC, 1319 MV errors in P frame
[h264 @ 0x557ea6b28740] top block unavailable for requested intra mode -1
[h264 @ 0x557ea6b28740] error while decoding MB 16 9, bytestream 6218
[h264 @ 0x557ea6b28740] concealing 1416 DC, 1416 AC, 1416 MV errors in P frame
[h264 @ 0x557ea6ba5be0] top block unavailable for requested intra mode -1
[h264 @ 0x557ea6ba5be0] error while decoding MB 12 0, bytestream 6854
[h264 @ 0x557ea6ba5be0] top block unavailable for requested intra mode -1
[h264 @ 0x557ea6ba5be0] error while decoding MB 2 9, bytestream 7092
opencv似乎无法识别我通过管道传递给它的图像
Traceback (most recent call last):
File "cap.py", line 11, in <module>
cv.imshow("Video", img)
TypeError: mat is not a numpy array, neither a scalar
有人知道问题出在哪里吗?感谢您的任何帮助。