我正在用 libav 制作电影播放器。我正在解码视频数据包,我正在反向工作,我正在寻找工作。所有这些都无法在 x86 android 模拟器上运行,但无法在真正的 android 手机上运行(arm64-v8a)
失败在sws_scale()
- 它返回 0。视频帧继续正确解码,没有错误。
libav 没有错误、警告和警报。我已经连接了一个avlog_callback
void log_callback(void *ptr, int level, const char *fmt, va_list vargs) {
if (level<= AV_LOG_WARNING)
__android_log_print( level, LOG_TAG, fmt, vargs);
}
uint64_t openMovie( char* path, int rotate, float javaDuration )
{
av_log_set_level(AV_LOG_WARNING);
av_log_set_callback(log_callback);
执行此操作的代码sws_scale()
是:
int JVM_getBitmapBuffer( JNIEnv* env, jobject thiz, jlong av, jobject bufferAsInt, jbyte transparent ) {
avblock *block = (avblock *) av;
if (!block) {
__android_log_print(ANDROID_LOG_ERROR, LOG_TAG, " avblock is null");
return AVERROR(EINVAL);
}
if (!block->pCodecCtx) {
__android_log_print(ANDROID_LOG_ERROR, LOG_TAG, " codecctx is null");
return AVERROR(EINVAL);
}
int width = block->pCodecCtx->width;
int height = block->pCodecCtx->height;
if (NULL == block->sws) {
__android_log_print( ANDROID_LOG_ERROR, LOG_TAG, "getBitmapBuffer:\n *** invalid sws context ***" );
}
int scaleRet = sws_scale( block->sws,
block->pFrame->data,
block->pFrame->linesize,
0,
height,
block->pFrameRGB->data,
block->pFrameRGB->linesize
);
if (scaleRet == 0 ) {
__android_log_print(ANDROID_LOG_ERROR, LOG_TAG, " scale failed");
__android_log_print(ANDROID_LOG_ERROR, LOG_TAG, " pframe linesize %d", block->pFrame->linesize[0]);
__android_log_print(ANDROID_LOG_ERROR, LOG_TAG, " pframergb linesize %d", block->pFrameRGB->linesize[0]);
__android_log_print(ANDROID_LOG_ERROR, LOG_TAG, " height %d",
height);
return AVERROR(EINVAL);
}
设置 codex 和 avframes:
//i have tried every combination of 1, 8, 16, and 32 for these values
int alignRGB = 32;
int align = 16;
int width = block->pCodecCtx->width;
int height = block->pCodecCtx->height;
block->pFrame = av_frame_alloc();
block->pFrameRGB = av_frame_alloc();
block->pFrameRGBBuffer = av_malloc(
(size_t)av_image_get_buffer_size(AV_PIX_FMT_RGB32, width, height, alignRGB)
);
av_image_fill_arrays(
block->pFrameRGB->data,
block->pFrameRGB->linesize,
block->pFrameRGBBuffer,
AV_PIX_FMT_RGB32,
width,
height,
alignRGB
);
block->pFrameBuffer = av_malloc(
(size_t) av_image_get_buffer_size(block->pCodecCtx->pix_fmt,
width, height, align
)
);
av_image_fill_arrays(
block->pFrame->data,
block->pFrame->linesize,
block->pFrameBuffer,
block->pCodecCtx->pix_fmt,
width, height,
align
);
block->sws = sws_getContext(
width, height,
AV_PIX_FMT_YUV420P,
width, height,
AV_PIX_FMT_RGB32,
SWS_BILINEAR, NULL, NULL, 0
);
通配符是:
- 我正在使用 React-Native
- 我的模拟器是 x86 android api 28
- 我的真实设备是 arm64-v8a AOSP(大约 api 28,不记得确切(
其他注意事项:
- libav .so 文件是从 mobile-ffmpeg 项目编译的。
- 我也可以 sws_scale 也可以在 x86_64 linux 上使用 SDL 来投影 YV12
- 测试视频在这里:https ://github.com/markkimsal/video-thumbnailer/tree/master/fixtures
block
是一个简单的 C 结构,带有指向相关 AV 内存结构的指针。- 使用 FFMPEG 4.3.2
我很确定它与像素对齐有关。但是关于这个主题的文档实际上是不存在的。它也可能是像素格式 RGBA 和 RGB32 之间的差异,或者可能是小端与大端之间的差异。