diff --git a/cinelerra-5.1/cinelerra/ffmpeg.C b/cinelerra-5.1/cinelerra/ffmpeg.C
index 6bc8f7f1..17724176 100644
--- a/cinelerra-5.1/cinelerra/ffmpeg.C
+++ b/cinelerra-5.1/cinelerra/ffmpeg.C
@@ -51,6 +51,7 @@
 #ifdef HAVE_DV
 #include "libdv.h"
 #endif
+#include "lcms2.h"
 #include "libmjpeg.h"
 #include "mainerror.h"
 #include "mwindow.h"
@@ -1734,6 +1735,36 @@ int FFVideoConvert::convert_picture_vframe(VFrame *frame, AVFrame *ip, AVFrame *
 			vid->ffmpeg->fmt_ctx->url);
 		return -1;
 	}
+	
+	const AVFrameSideData *sd;
+	cmsHPROFILE profile, profile1;
+	cmsContext cms_ctx;
+	cmsHTRANSFORM hTransform;
+
+	sd = av_frame_get_side_data(ip, AV_FRAME_DATA_ICC_PROFILE);
+	if(sd) {
+	profile = cmsOpenProfileFromMemTHR(cms_ctx, sd->data, sd->size);
+	char *profile1_path, *profile1_path_hardcoded; 
+	profile1_path = getenv("CIN_CM_PROFILE");
+	//strcpy(profile1_path_hardcoded, "/usr/share/apps/krita/profiles/WideGamut.icm");
+	
+	if(profile1_path) {
+	profile1 = cmsOpenProfileFromFile(profile1_path, "r");
+	
+	hTransform = cmsCreateTransform(profile,
+                                TYPE_RGBA_8,
+                                profile1,
+                                TYPE_RGBA_8,
+                                INTENT_PERCEPTUAL, 0);
+	
+	//printf ("cmodel: %i \n", cmodel);
+	if (cmodel == BC_RGBA8888) {
+	cmsDoTransform(hTransform, ipic->data, ipic->data, ipic->linesize[0] * ipic->height);
+	printf("cms! \n");
+	}
+	}
+	}
+
 	return 0;
 }
 
@@ -1863,6 +1894,8 @@ int FFVideoConvert::convert_vframe_picture(VFrame *frame, AVFrame *op, AVFrame *
 		ff_err(ret, "FFVideoConvert::convert_frame_picture: sws_scale() failed\n");
 		return -1;
 	}
+	
+
 	return 0;
 }
 
