在ffplay中添加简单的异或加密
Adding simple xor encryption in ffplay
查看 ffplay.c (https://github.com/FFmpeg/FFmpeg/blob/master/ffplay.c) 并希望支持一些基本加密,哪几行代码最相关?
为简单起见,假设我们使用的是基本 XOR 密钥,其长度与视频数据相匹配。
换句话说-实际读取的数据和return字节在哪里(以便我们可以在return编辑字节之前修改它)? :)
可以使用自定义 I/O context 使用您自己的 callbacks/buffers:
MyIOContext *ioCtx = new MyIOContext("random_file");
AVFormatContext *avFormatCtx = avformat_alloc_context();
ioCtx->initAVFormatContext(avFormatCtx);
if (avformat_open_input(&avFormatCtx, "", NULL, NULL) != 0) {
// handle error
}
// ...
avformat_close_input(&avFormatCtx);
来自 same source 的示例读取函数:
static int IOReadFunc(void *data, uint8_t *buf, int buf_size) {
MyIOContext *hctx = (MyIOContext*)data;
size_t len = fread(buf, 1, buf_size, hctx->fh);
if (len == 0) {
// Let FFmpeg know that we have reached EOF, or do something else
return AVERROR_EOF;
}
return (int)len;
}
以及分配:
// allocate the AVIOContext
ioCtx = avio_alloc_context(
buffer, bufferSize, // internal buffer and its size
0, // write flag (1=true,0=false)
(void*)this, // user data, will be passed to our callback functions
IOReadFunc,
0, // no writing
IOSeekFunc
);
查看 ffplay.c (https://github.com/FFmpeg/FFmpeg/blob/master/ffplay.c) 并希望支持一些基本加密,哪几行代码最相关?
为简单起见,假设我们使用的是基本 XOR 密钥,其长度与视频数据相匹配。
换句话说-实际读取的数据和return字节在哪里(以便我们可以在return编辑字节之前修改它)? :)
可以使用自定义 I/O context 使用您自己的 callbacks/buffers:
MyIOContext *ioCtx = new MyIOContext("random_file");
AVFormatContext *avFormatCtx = avformat_alloc_context();
ioCtx->initAVFormatContext(avFormatCtx);
if (avformat_open_input(&avFormatCtx, "", NULL, NULL) != 0) {
// handle error
}
// ...
avformat_close_input(&avFormatCtx);
来自 same source 的示例读取函数:
static int IOReadFunc(void *data, uint8_t *buf, int buf_size) {
MyIOContext *hctx = (MyIOContext*)data;
size_t len = fread(buf, 1, buf_size, hctx->fh);
if (len == 0) {
// Let FFmpeg know that we have reached EOF, or do something else
return AVERROR_EOF;
}
return (int)len;
}
以及分配:
// allocate the AVIOContext
ioCtx = avio_alloc_context(
buffer, bufferSize, // internal buffer and its size
0, // write flag (1=true,0=false)
(void*)this, // user data, will be passed to our callback functions
IOReadFunc,
0, // no writing
IOSeekFunc
);