这个非常简单的片段在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)
这种行为记录在哪里?强制容器具有尺寸是没有意义的.
我需要使用 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)