<p>Solved the problem by setting colormatrix conversion using swscale lib. Added to my filter chain:</p>

<pre><code>scale=in_color_matrix=bt601:out_color_matrix=bt709
</code></pre>

<p>and</p>

<pre><code>-colorspace bt709
</code></pre>

<p>to the output.</p>

<hr>

<p><strong>References</strong></p>

<ol>
<li><a href="https://ffmpeg.org/ffmpeg-filters.html#scale" rel="nofollow noreferrer">ffmpeg scale filter</a></li>
<li><a href="https://ffmpeg.org/ffmpeg-filters.html#colormatrix" rel="nofollow noreferrer">ffmpeg colormatrix filter</a></li>
<li><a href="https://trac.ffmpeg.org/wiki/colorspace" rel="nofollow noreferrer">colorspace on ffmpeg wiki</a></li>
<li><a href="https://video.stackexchange.com/questions/16840/ffmpeg-explicitly-tag-h-264-as-bt-601-rather-than-leaving-unspecified">question on video.stackexchange</a></li>
</ol>

<hr>

<p><strong>Credits</strong></p>

<p>Found the advice on VideoHelp <a href="https://forum.videohelp.com/threads/382802-FFMPEG-is-there-a-way-to-re-encode-changing-only-the-colormatrix#post2479806" rel="nofollow noreferrer">forum reply</a> from 2017, which in turn references <a href="https://video.stackexchange.com/questions/16840/ffmpeg-explicitly-tag-h-264-as-bt-601-rather-than-leaving-unspecified">the question</a> on this video.stackexchange.  Thanks again, Gyan!</p>

CC BY-SA 4.0
2019-03-29T06:33:47.400Z
2019-03-29T12:56:13.197Z
2019-03-29T12:56:13.197Z
Serge
<p>Given master video in mov rle:</p>

<pre><code>Video: qtrle (rle  / 0x20656C72), rgb24(progressive)
</code></pre>

<p>Converted the video to a serie of single .bmp frames. </p>

<pre><code>ffmpeg -i source.mov $FRAMES/f%03d.bmp
</code></pre>

<p>Frames from unchanged parts I recompiled to mpeg ts intermediate files:</p>

<pre><code>ffmpeg                   \
-framerate 25            \
-start_number $i         \
-i "$FRAMES/f%03d.bmp"   \
-vframes $n              \
-c:v libx264rgb          \ # libx264
  -preset slow           \
  -tune animation        \
  -crf 20                \
  -pix_fmt rgb24         \ # yuv420p 
-bsf:v h264_mp4toannexb  \
-f mpegts                \
-y -an -hide_banner      \
"$FOLDER_TS/_${i}_${o}.ts"
</code></pre>

<p>To other part of the clip I applied filters like pad, zoompan, format. Overlaid PNG with transparency, animated. Output to the same format h264 .ts</p>

<p>Concat the .ts parts to mp4 movie file.</p>

<p><strong>Color</strong> seems to have changed a little. Can be noticed when joining source movie with the processed one.</p>

<p>What stage of the process could affect the slight changes in colors?</p>

<p>Is it the pixel format conversion or BMP format usage?</p>

<p>How to convert movie file to sinlge frame images preserving exact color?</p>

CC BY-SA 4.0
2019-03-27T17:01:48.673Z
*other part of the clip I applied filters* --> what exactly?
Gyan
CC BY-SA 4.0
2019-03-27T17:10:42.030Z
Clip length is 10s @ 25fps = 250 frames.
Frames 1–50 and 208-250 are kept as is, I render them directly to .ts
Over middle frames I *overlay* PNG with padding and use *zoompan* to scale/position. All parts joined together looks consistently in color. 
The slight color difference occurs compared to the original master video.
Serge
CC BY-SA 4.0
2019-03-28T01:33:05.967Z
You can’t convert between RGB and YUV perfectly. It’s a lossy conversion.
SlimSCSI
CC BY-SA 4.0
2019-03-28T07:57:07.353Z
Thanks @SlimSCSI, after posting the question I figured that too. I tried changing `libx264` to `libx264rgb` and `yuv420p` to `rgb24`. That reduced color difference but it's still in place.

What else could possibly go wrong? Is BMP format with its `bgr24` a good option for intermediate images?
Serge
CC BY-SA 4.0
2019-03-28T08:07:53.517Z
Updated code in question with codecs and pixel pformats I tried.
Serge
<ffmpeg><colorspace>
Color changes after video to single frame images back to video using ffmpeg
Serge
# Color changes after video to single frame images back to video using ffmpeg

(Asked by: username_0 on 2019-03-27)

Given master video in mov rle:
Video: qtrle (rle  / 0x20656C72), rgb24(progressive)

Converted the video to a serie of single .bmp frames. 
ffmpeg -i source.mov $FRAMES/f%03d.bmp

Frames from unchanged parts I recompiled to mpeg ts intermediate files:
ffmpeg                   \
-framerate 25            \
-start_number $i         \
-i "$FRAMES/f%03d.bmp"   \
-vframes $n              \
-c:v libx264rgb          \ # libx264
  -preset slow           \
  -tune animation        \
  -crf 20                \
  -pix_fmt rgb24         \ # yuv420p 
-bsf:v h264_mp4toannexb  \
-f mpegts                \
-y -an -hide_banner      \
"$FOLDER_TS/_${i}_${o}.ts"

To other part of the clip I applied filters like pad, zoompan, format. Overlaid PNG with transparency, animated. Output to the same format h264 .ts
Concat the .ts parts to mp4 movie file.
Color seems to have changed a little. Can be noticed when joining source movie with the processed one.
What stage of the process could affect the slight changes in colors?
Is it the pixel format conversion or BMP format usage?
How to convert movie file to sinlge frame images preserving exact color?

**Tags:** ffmpeg, colorspace

> **Comments:**
> **username_1**: *other part of the clip I applied filters* --> what exactly?  
> **username_0**: Clip length is 10s @ 25fps = 250 frames. Frames 1–50 and 208-250 are kept as is, I render them directly to .ts Over middle frames I *overlay* PNG with padding and use *zoompan* to scale/position. All parts joined together looks consistently in color.  The slight color difference occurs compared to the original master video.  
> **username_2**: You can’t convert between RGB and YUV perfectly. It’s a lossy conversion.  
> **username_0**: Thanks @username_2, after posting the question I figured that too. I tried changing `libx264` to `libx264rgb` and `yuv420p` to `rgb24`. That reduced color difference but it's still in place.  What else could possibly go wrong? Is BMP format with its `bgr24` a good option for intermediate images?  
> **username_0**: Updated code in question with codecs and pixel pformats I tried.  

---

## 1 answers

### Answer by username_0 on 2019-03-29. Score: 0

Solved the problem by setting colormatrix conversion using swscale lib. Added to my filter chain:
scale=in_color_matrix=bt601:out_color_matrix=bt709

and
-colorspace bt709

to the output.

References

ffmpeg scale filter
ffmpeg colormatrix filter
colorspace on ffmpeg wiki
question on video.stackexchange


Credits
Found the advice on VideoHelp forum reply from 2017, which in turn references the question on this video.stackexchange.  Thanks again, username_1!


---

