小编pix*_*lou的帖子

使用__setitem__还需要在python 2中实现__len__

这个非常简单的片段在python 2上失败但是传递了python 3:

class A:
    def __init__(self, value):
        self.value = value

    def __setitem__(self, key, value):
        pass

r = A(1)
r[80:-10] = list(range(10))
Run Code Online (Sandbox Code Playgroud)

在python2上,解释器调用__len__不存在,因此失败:

Traceback (most recent call last):
  File "prog.py", line 9, in <module>
AttributeError: A instance has no attribute '__len__'
Run Code Online (Sandbox Code Playgroud)

这种行为记录在哪里?强制容器具有尺寸是没有意义的.

python python-2.x python-3.x

6
推荐指数
1
解决办法
36
查看次数

使用 h264 流创建 mkv 容器时数据无效,因为 extradata 为空

我需要使用 ffmpeg 的 c api 将原始帧编码为 mkv 容器内的 h264 流。我能找到的所有示例都从解码器复制现有的编解码器参数,因此我不得不对其进行一些修改。

#include <cstdio>
#include <cstring>
#include <iostream>

extern "C" {
#include <libavformat/avformat.h>
#include <libavutil/avutil.h>
#include <libavutil/imgutils.h>
#include <libavutil/opt.h>
#include <libswscale/swscale.h>
}

static char error_msg[4096] = "";


int main(int argc, char **argv) {
  int err;
  char *filename = (char *)av_malloc(4096);
  AVCodec *codec = nullptr;
  SwsContext *color_converter = nullptr;
  AVCodecContext *encoder = nullptr;
  AVFormatContext *container = nullptr;
  AVStream *stream = nullptr;

  std::snprintf(filename, sizeof(filename), "%s", "out.mkv");

  // Create encoder
  codec = avcodec_find_encoder_by_name("libx264");
  if (codec …
Run Code Online (Sandbox Code Playgroud)

c++ encoding ffmpeg

6
推荐指数
1
解决办法
381
查看次数

标签 统计

c++ ×1

encoding ×1

ffmpeg ×1

python ×1

python-2.x ×1

python-3.x ×1