Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/188.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android FFMPEG视频缩略图_Android_Ffmpeg_Android Ndk_Android Ffmpeg - Fatal编程技术网

Android FFMPEG视频缩略图

Android FFMPEG视频缩略图,android,ffmpeg,android-ndk,android-ffmpeg,Android,Ffmpeg,Android Ndk,Android Ffmpeg,我正在尝试使用ffmpeg(v3.4)从视频中提取缩略图以获取视频缩略图,这段代码在大多数视频文件中都运行良好 但是在sws_getContext函数中,一些视频会崩溃 请帮忙,谢谢。任何帮助都将不胜感激 const int TARGET_IMAGE_FORMAT = AV_PIX_FMT_RGBA; const int TARGET_IMAGE_CODEC = AV_CODEC_ID_PNG; int stream_component_open(State *s, int s

我正在尝试使用ffmpeg(v3.4)从视频中提取缩略图以获取视频缩略图,这段代码在大多数视频文件中都运行良好

但是在sws_getContext函数中,一些视频会崩溃 请帮忙,谢谢。任何帮助都将不胜感激

const int TARGET_IMAGE_FORMAT = AV_PIX_FMT_RGBA;
    const int TARGET_IMAGE_CODEC = AV_CODEC_ID_PNG;

    int stream_component_open(State *s, int stream_index) 
{
        AVFormatContext *pFormatCtx = s->pFormatCtx;
        AVCodecContext *codecCtx;
        AVCodec *codec;
        if (stream_index < 0 || stream_index >= pFormatCtx->nb_streams) {
            return FAILURE;
        }
        codecCtx = pFormatCtx->streams[stream_index]->codec;
        codec = avcodec_find_decoder(codecCtx->codec_id);
        if (codec == NULL) {
            return FAILURE;
        }
        if (!codec || (avcodec_open2(codecCtx, codec, NULL) < 0)) {
            return FAILURE;
        }
        switch(codecCtx->codec_type) {

            case AVMEDIA_TYPE_VIDEO:
                s->video_stream = stream_index;
                s->video_st = pFormatCtx->streams[stream_index];
                AVCodec *targetCodec = avcodec_find_encoder(TARGET_IMAGE_CODEC);
                if (!targetCodec) {
                    return FAILURE;
                }
                s->codecCtx = avcodec_alloc_context3(targetCodec);
                if (!s->codecCtx) {
                    return FAILURE;
                }
                s->codecCtx->bit_rate = s->video_st->codec->bit_rate;
                s->codecCtx->width = s->video_st->codec->width;
                s->codecCtx->height = s->video_st->codec->height;
                s->codecCtx->pix_fmt = TARGET_IMAGE_FORMAT;
                s->codecCtx->codec_type = AVMEDIA_TYPE_VIDEO;
                s->codecCtx->time_base.num = s->video_st->codec->time_base.num;
                s->codecCtx->time_base.den = s->video_st->codec->time_base.den;

                if (!targetCodec || avcodec_open2(s->codecCtx, targetCodec, NULL) < 0) {
                    return FAILURE;
                }
    __android_log_print(ANDROID_LOG_ERROR, LOG_TAG, "CRASH START");
                s->sws_ctx = sws_getContext(s->video_st->codec->width,
                        s->video_st->codec->height,
                        s->video_st->codec->pix_fmt,
                        s->video_st->codec->width,
                        s->video_st->codec->height,
                        TARGET_IMAGE_FORMAT,
                        SWS_BILINEAR,
                        NULL,
                        NULL,
                        NULL);
                __android_log_print(ANDROID_LOG_ERROR, LOG_TAG, "THIS WONT COME");
                break;
            default:
                break;
        }
        return SUCCESS;
    }
const int TARGET\u IMAGE\u FORMAT=AV\u PIX\u FMT\u RGBA;
const int TARGET_IMAGE_CODEC=AV_CODEC_ID_PNG;
int stream_组件_open(状态*s,int stream_索引)
{
AVFormatContext*pFormatCtx=s->pFormatCtx;
AVCodecContext*codecCtx;
AVCodec*编解码器;
如果(流索引<0 | |流索引>=pFormatCtx->nb|u流){
返回失败;
}
codecCtx=pFormatCtx->streams[stream_index]->编解码器;
codec=avcodec\u find\u解码器(codecCtx->codec\u id);
如果(编解码器==NULL){
返回失败;
}
如果(!codec | |(avcodec_open2(codecCtx,codec,NULL)<0)){
返回失败;
}
交换机(编解码器CTX->编解码器类型){
案例AVMEDIA_类型_视频:
s->video\u stream=流索引;
s->video_st=pFormatCtx->streams[stream_index];
AVCodec*targetCodec=AVCodec\u find\u编码器(TARGET\u IMAGE\u CODEC);
如果(!targetCodec){
返回失败;
}
s->codecCtx=avcodec\u alloc\u context3(targetCodec);
如果(!s->codecCtx){
返回失败;
}
s->CODECTX->比特率=s->视频->编解码器->比特率;
s->codecCtx->width=s->video\u st->codec->width;
s->codecCtx->height=s->video\u st->codec->height;
s->CODECTX->pix\u fmt=目标图像\u格式;
s->codecCtx->codec\u type=AVMEDIA\u type\u视频;
s->codecCtx->time\u base.num=s->video\u st->codec->time\u base.num;
s->codecCtx->time\u base.den=s->video\u st->codec->time\u base.den;
如果(!targetCodec | | avcodec_open2(s->codecCtx,targetCodec,NULL)<0){
返回失败;
}
__安卓日志打印(安卓日志错误,日志标签,“崩溃启动”);
s->sws\u ctx=sws\u getContext(s->video\u st->codec->width,
s->视频->编解码器->高度,
s->video\u st->codec->pix\u fmt,
s->video\u st->codec->width,
s->视频->编解码器->高度,
目标图像格式,
SWS_双线性,
无效的
无效的
无效);
__android_log_打印(android_log_错误,log_标签,“这不会出现”);
打破
违约:
打破
}
回归成功;
}
添加


在sws_getContext调用ffmpeg_3.4之前,您会遇到什么错误?此外,如果有一个导致崩溃的示例视频,这可能会有所帮助,如果有一种方法可以生成这样的视频,那就更好了,但我知道这可能很难安排。如果您可以在调试模式下运行代码,您将遇到一个带有堆栈跟踪的异常。我们可以从那里继续分析。这里也有同样的问题。它将使应用程序崩溃。@Olivier MATROT不会抛出任何异常。这就像tid 9439(滑动源th)中的libc:Fatal signal 6(SIGABRT)、code-6(SI_TKILL)、pid…和
backtrace:/lib/arm64/libijkffmpeg.so(sws_setcolorspace details+224)
if(s->video_st->codec->pix_fmt==-1)
                s->video_st->codec->pix_fmt=0;