【问题标题】:Read a Bytes image from Amazon Kinesis output in python从 Python 中的 Amazon Kinesis 输出读取字节图像
【发布时间】:2020-02-05 10:34:36
【问题描述】:

我使用imageio.get_reader(BytesIO(a), 'ffmpeg') 加载字节图像并将其保存为普通图像。

但是当我使用imageio.get_reader(BytesIO(a), 'ffmpeg')读取图像时会抛出以下错误

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/tango/anaconda3/lib/python3.6/site-packages/imageio/core/functions.py", line 186, in get_reader
    return format.get_reader(request)
  File "/home/tango/anaconda3/lib/python3.6/site-packages/imageio/core/format.py", line 164, in get_reader
    return self.Reader(self, request)
  File "/home/tango/anaconda3/lib/python3.6/site-packages/imageio/core/format.py", line 214, in __init__
    self._open(**self.request.kwargs.copy())
  File "/home/tango/anaconda3/lib/python3.6/site-packages/imageio/plugins/ffmpeg.py", line 323, in _open
    self._initialize()
  File "/home/tango/anaconda3/lib/python3.6/site-packages/imageio/plugins/ffmpeg.py", line 466, in _initialize
    self._meta.update(self._read_gen.__next__())
  File "/home/tango/anaconda3/lib/python3.6/site-packages/imageio_ffmpeg/_io.py", line 150, in read_frames
    raise IOError(fmt.format(err2))
OSError: Could not load meta information
=== stderr ===

ffmpeg version 4.2 Copyright (c) 2000-2019 the FFmpeg developers
  built with gcc 7.3.0 (crosstool-NG 1.23.0.449-a04d0)
  configuration: --prefix=/home/tango/anaconda3 --cc=/home/conda/feedstock_root/build_artifacts/ffmpeg_1566210161358/_build_env/bin/x86_64-conda_cos6-linux-gnu-cc --disable-doc --disable-openssl --enable-avresample --enable-gnutls --enable-gpl --enable-hardcoded-tables --enable-libfreetype --enable-libopenh264 --enable-libx264 --enable-pic --enable-pthreads --enable-shared --enable-static --enable-version3 --enable-zlib --enable-libmp3lame
  libavutil      56. 31.100 / 56. 31.100
  libavcodec     58. 54.100 / 58. 54.100
  libavformat    58. 29.100 / 58. 29.100
  libavdevice    58.  8.100 / 58.  8.100
  libavfilter     7. 57.100 /  7. 57.100
  libavresample   4.  0.  0 /  4.  0.  0
  libswscale      5.  5.100 /  5.  5.100
  libswresample   3.  5.100 /  3.  5.100
  libpostproc    55.  5.100 / 55.  5.100
[matroska,webm @ 0x5619b9da3cc0] File ended prematurely
[matroska,webm @ 0x5619b9da3cc0] Could not find codec parameters for stream 0 (Video: h264, none, 1280x720): unspecified pixel format
Consider increasing the value for the 'analyzeduration' and 'probesize' options
Input #0, matroska,webm, from '/tmp/imageio_zm6hhpgr':
  Metadata:
    title           : Kinesis Video SDK
    encoder         : Kinesis Video SDK 1.0.0
    AWS_KINESISVIDEO_FRAGMENT_NUMBER: 91343852333183888465720004820715065721442989478
    AWS_KINESISVIDEO_SERVER_TIMESTAMP: 1580791384.096
    AWS_KINESISVIDEO_PRODUCER_TIMESTAMP: 1580791377.843
  Duration: N/A, bitrate: N/A
    Stream #0:0(eng): Video: h264, none, 1280x720, SAR 1:1 DAR 16:9, 1k tbr, 1k tbn, 2k tbc (default)
    Metadata:
      title           : kinesis_video
Stream mapping:
  Stream #0:0 -> #0:0 (h264 (native) -> rawvideo (native))
Press [q] to stop, [?] for help
Cannot determine format of input stream 0:0 after EOF
Error marking filters as finished
Conversion failed!

上述读取 MKV 字节文件的方法是基于 thread 完成的

或者有什么方法可以解析和读取MKV字节文件。

【问题讨论】:

  • 你是base64解码数据吗?
  • 它是什么类型的运动流?数据是如何进入其中的?
  • 数据使用 H.264 编解码器编码并流式传输到 kinesis 视频流,在接收端它将采用 mkv 格式(以字节为单位)。即时解析 mkv 块,需要
  • 您确定先读取字节然后使用imageio.get_reader吗?你能分享一下你在imageio.get_reader函数之前用的是什么吗?

标签: python image ffmpeg byte amazon-kinesis


【解决方案1】:

老问题,但我会在这里为未来的读者留下答案:)

一般来说,如果您有一个对视频(或图像)进行编码的字节字符串,则很有可能您可以将其直接传递给 ImageIO 的高级 API,并且它可以直接读取字节。在 MKV(和其他一些视频格式)的情况下,ImageIO 需要一些帮助,因为当前的 ffmpeg 插件难以处理字节字符串。 [有一个新插件正在解决这个问题和其他问题。]

ImageIO

import imageio as iio

req = iio.core.Request(mkv_bytes, "r")

# note: this is where imageIO needs some help, see
# https://github.com/imageio/imageio/issues/686
req._extension = ".mkv"

first_frame = iio.imread(req)

ImageIO>2.15.0(本周发布 - W6 2022)

import imageio as iio

first_frame = iio.v3.imread(mkv_bytes, format_hint=".mkv")

【讨论】:

    猜你喜欢
    • 2015-01-26
    • 1970-01-01
    • 1970-01-01
    • 2015-04-07
    • 2015-08-26
    • 2023-03-20
    • 2016-12-21
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多