[Cin] I tried to make sws_scale go multithread ..
Andrew Randrianasulu
randrianasulu at gmail.com
Mon Apr 28 16:18:15 CEST 2025
BUT FAILED.
in sense my mod apparently just leaks (swsContext?) so it can't play even
20 sec of 1440*1080 video to completion in termux, running on tablet with
3Gb ram.
There seems to be difference if I set thread count manually (on file
reading only for now) but it looks negative, in other words higher thread
count -> slower total playback .. tried 8, 4,1,16 on 8 cpu tablet. Speed
was going down from 18 fps for unaltered cingg to 13 with 8 threads and
crash/oom with 16 ;)
And if I try to use sws_scale_frame I just got all blank/black frames on
timeline ....
I think switching to sws_scale_frame is important if we want to try new
colormanagement support in ffmpeg.git ...
Resources used, apart from that Blender diff:
https://github.com/mltframework/mlt/blob/master/src/modules/avformat/filter_swscale.c
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.cinelerra-gg.org/pipermail/cin/attachments/20250428/8abd872b/attachment.htm>
-------------- next part --------------
diff --git a/cinelerra-5.1/cinelerra/ffmpeg.C b/cinelerra-5.1/cinelerra/ffmpeg.C
index c8c533ce..a2635a4b 100644
--- a/cinelerra-5.1/cinelerra/ffmpeg.C
+++ b/cinelerra-5.1/cinelerra/ffmpeg.C
@@ -1610,9 +1610,15 @@ int FFVideoConvert::convert_picture_vframe(VFrame *frame, AVFrame *ip, AVFrame *
int cmodel = frame->get_color_model();
AVPixelFormat ofmt = color_model_to_pix_fmt(cmodel);
if( ofmt == AV_PIX_FMT_NB ) return -1;
+
+ //int size = av_image_get_buffer_size(ofmt, frame->get_w(), frame->get_h(), 1);
+ //AVBufferRef *buf = av_buffer_alloc(size);
+
int size = av_image_fill_arrays(ipic->data, ipic->linesize,
frame->get_data(), ofmt, frame->get_w(), frame->get_h(), 1);
+
if( size < 0 ) return -1;
+ //av_frame_get_buffer(ipic, 0);
int bpp = BC_CModels::calculate_pixelsize(cmodel);
int ysz = bpp * frame->get_w(), usz = ysz;
@@ -1653,9 +1659,39 @@ int FFVideoConvert::convert_picture_vframe(VFrame *frame, AVFrame *ip, AVFrame *
return -1;
}
}
- int flags= SWS_BITEXACT | SWS_ACCURATE_RND ;
- convert_ctx = sws_getCachedContext(convert_ctx, ip->width, ip->height, pix_fmt,
- frame->get_w(), frame->get_h(), ofmt, SWS_POINT| flags, NULL, NULL, NULL);
+ int flags= SWS_POINT | SWS_BITEXACT | SWS_ACCURATE_RND ;
+ //convert_ctx = sws_getCachedContext(convert_ctx, ip->width, ip->height, pix_fmt,
+ // frame->get_w(), frame->get_h(), ofmt, SWS_POINT| flags, NULL, NULL, NULL);
+ ;
+ SwsContext *convert_ctx = sws_alloc_context();
+
+ int ret_sws;
+/*
+ convert_ctx = sws_alloc_context();
+ convert_ctx->src_w = ip->width;
+ convert_ctx->src_h = ip->height;
+ convert_ctx->src_format = pix_fmt;
+ convert_ctx->dst_w = frame->get_w();
+ convert_ctx->dst_h = frame->get_h();
+ convert_ctx->dst_format = ofmt;
+ convert_ctx->flags = flags;
+ convert_ctx->dither = NULL;
+ convert_ctx->threads = 8;
+ */
+
+ av_opt_set_int(convert_ctx, "srcw", ip->width, 0);
+ av_opt_set_int(convert_ctx, "srch", ip->height, 0);
+ av_opt_set_int(convert_ctx, "src_format", pix_fmt, 0);
+ av_opt_set_int(convert_ctx, "dstw", frame->get_w(), 0);
+ av_opt_set_int(convert_ctx, "dsth", frame->get_h(), 0);
+ av_opt_set_int(convert_ctx, "dst_format", ofmt, 0);
+ av_opt_set_int(convert_ctx, "sws_flags", flags, 0);
+ av_opt_set_int(convert_ctx, "threads", 0, 0);
+
+ if ((ret_sws = sws_init_context(convert_ctx, NULL, NULL)) < 0)
+ return -1;
+
+
if( !convert_ctx ) {
fprintf(stderr, "FFVideoConvert::convert_picture_frame:"
" sws_getCachedContext() failed\n");
@@ -1688,9 +1724,15 @@ int FFVideoConvert::convert_picture_vframe(VFrame *frame, AVFrame *ip, AVFrame *
color_table, color_range, color_table, color_range,
brightness, contrast, saturation);
}
-
+
+ enum AVColorTransferCharacteristic trc = AVCOL_TRC_ARIB_STD_B67;
+ ip->color_trc = AVCOL_TRC_LINEAR;
+ ipic->color_trc = trc;
+
+
int ret = sws_scale(convert_ctx, ip->data, ip->linesize, 0, ip->height,
ipic->data, ipic->linesize);
+ //int ret = sws_scale_frame(convert_ctx, ipic, ip);
if( ret < 0 ) {
ff_err(ret, "FFVideoConvert::convert_picture_frame: sws_scale() failed\nfile: %s\n",
vid->ffmpeg->fmt_ctx->url);
More information about the Cin
mailing list