diff --git a/source/blender/imbuf/intern/indexer.c b/source/blender/imbuf/intern/indexer.c index ed06df1fb11..747c3aad33b 100644 --- a/source/blender/imbuf/intern/indexer.c +++ b/source/blender/imbuf/intern/indexer.c @@ -489,21 +489,21 @@ static struct proxy_output_ctx *alloc_proxy_output_ffmpeg( rv->of = avformat_alloc_context(); rv->of->oformat = av_guess_format("avi", NULL, NULL); rv->of->url = av_strdup(fname); fprintf(stderr, "Starting work on proxy: %s\n", rv->of->url); rv->st = avformat_new_stream(rv->of, NULL); rv->st->id = 0; - rv->c = avcodec_alloc_context3(NULL); + rv->c = rv->st->codec; rv->c->thread_count = BLI_system_thread_count(); rv->c->thread_type = FF_THREAD_SLICE; rv->c->codec_type = AVMEDIA_TYPE_VIDEO; rv->c->codec_id = AV_CODEC_ID_MJPEG; rv->c->width = width; rv->c->height = height; rv->of->oformat->video_codec = rv->c->codec_id; rv->codec = avcodec_find_encoder(rv->c->codec_id); @@ -515,21 +515,21 @@ static struct proxy_output_ctx *alloc_proxy_output_ffmpeg( return NULL; } if (rv->codec->pix_fmts) { rv->c->pix_fmt = rv->codec->pix_fmts[0]; } else { rv->c->pix_fmt = AV_PIX_FMT_YUVJ420P; } - rv->c->sample_aspect_ratio = rv->st->sample_aspect_ratio; + rv->c->sample_aspect_ratio = st->codec->sample_aspect_ratio; rv->c->time_base.den = 25; rv->c->time_base.num = 1; rv->st->time_base = rv->c->time_base; /* there's no way to set JPEG quality in the same way as in AVI JPEG and image sequence, * but this seems to be giving expected quality result */ ffmpeg_quality = (int)(1.0f + 30.0f * (1.0f - (float)quality / 100.0f) + 0.5f); av_opt_set_int(rv->c, "qmin", ffmpeg_quality, 0); av_opt_set_int(rv->c, "qmax", ffmpeg_quality, 0); @@ -541,37 +541,38 @@ static struct proxy_output_ctx *alloc_proxy_output_ffmpeg( if (avio_open(&rv->of->pb, fname, AVIO_FLAG_WRITE) < 0) { fprintf(stderr, "Couldn't open outputfile! " "Proxy not built!\n"); av_free(rv->of); return 0; } avcodec_open2(rv->c, rv->codec, NULL); - rv->orig_height = av_get_cropped_height_from_codec(rv->c); + rv->orig_height = av_get_cropped_height_from_codec(st->codec); - if (rv->c->width != width || rv->c->height != height) { + if (st->codec->width != width || st->codec->height != height || + st->codec->pix_fmt != rv->c->pix_fmt) { rv->frame = av_frame_alloc(); av_image_fill_arrays( rv->frame->data, rv->frame->linesize, MEM_mallocN(av_image_get_buffer_size(rv->c->pix_fmt, round_up(width, 16), height, 1), "alloc proxy output frame"), rv->c->pix_fmt, round_up(width, 16), height, 1); - rv->sws_ctx = sws_getContext(rv->c->width, + rv->sws_ctx = sws_getContext(st->codec->width, rv->orig_height, - rv->c->pix_fmt, + st->codec->pix_fmt, width, height, rv->c->pix_fmt, SWS_FAST_BILINEAR | SWS_PRINT_INFO, NULL, NULL, NULL); } if (avformat_write_header(rv->of, NULL) < 0) { @@ -581,21 +582,21 @@ static struct proxy_output_ctx *alloc_proxy_output_ffmpeg( av_free(rv->of); return 0; } return rv; } static int add_to_proxy_output_ffmpeg(struct proxy_output_ctx *ctx, AVFrame *frame) { AVPacket packet = {0}; - int ret, got_output; + int ret = 0; av_init_packet(&packet); if (!ctx) { return 0; } if (ctx->sws_ctx && frame && (frame->data[0] || frame->data[1] || frame->data[2] || frame->data[3])) { sws_scale(ctx->sws_ctx, @@ -606,43 +607,42 @@ static int add_to_proxy_output_ffmpeg(struct proxy_output_ctx *ctx, AVFrame *fra ctx->frame->data, ctx->frame->linesize); } frame = ctx->sws_ctx ? (frame ? ctx->frame : 0) : frame; if (frame) { frame->pts = ctx->cfra++; } - ret = avcodec_send_frame(ctx->c, frame); + avcodec_send_frame(ctx->c, frame); while (ret >= 0) { - ret = avcodec_receive_packet(ctx->c, &packet) == 0; + ret = avcodec_receive_packet(ctx->c, &packet); if (ret == AVERROR(EAGAIN) || ret == AVERROR_EOF) { /* No more frames to flush. */ - break; + return 0; } if (ret < 0) { fprintf(stderr, "Error encoding proxy frame %d for '%s': %s\n", ctx->cfra - 1, ctx->of->url, av_err2str(ret)); return 0; } packet.stream_index = ctx->st->index; av_packet_rescale_ts(&packet, ctx->c->time_base, ctx->st->time_base); - ret = av_interleaved_write_frame(ctx->of, &packet); - if (ret != 0) { + if (av_interleaved_write_frame(ctx->of, &packet) != 0) { fprintf(stderr, "Error writing proxy frame %d " "into '%s': %s\n", ctx->cfra - 1, ctx->of->url, av_err2str(ret)); return 0; } }