Answers.Body: <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>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-03-29T06:33:47.400Z
Answers.LastActivityDate: 2019-03-29T12:56:13.197Z
Answers.LastEditDate: 2019-03-29T12:56:13.197Z
Answers.UserDisplayName: Serge
Body: <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>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2019-03-27T17:01:48.673Z
Comments.Text: *other part of the clip I applied filters* --> what exactly?
Comments.UserDisplayName: Gyan
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2019-03-27T17:10:42.030Z
Comments.Text: 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.
Comments.UserDisplayName: Serge
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2019-03-28T01:33:05.967Z
Comments.Text: You can’t convert between RGB and YUV perfectly. It’s a lossy conversion.
Comments.UserDisplayName: SlimSCSI
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2019-03-28T07:57:07.353Z
Comments.Text: 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?
Comments.UserDisplayName: Serge
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2019-03-28T08:07:53.517Z
Comments.Text: Updated code in question with codecs and pixel pformats I tried.
Comments.UserDisplayName: Serge
Tags: <ffmpeg><colorspace>
Title: Color changes after video to single frame images back to video using ffmpeg
UserDisplayName: Serge
ThreadText: # 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**
  
  1. [ffmpeg scale filter](https://ffmpeg.org/ffmpeg-filters.html#scale)
  2. [ffmpeg colormatrix filter](https://ffmpeg.org/ffmpeg-filters.html#colormatrix)
  3. [colorspace on ffmpeg wiki](https://trac.ffmpeg.org/wiki/colorspace)
  4. [question on video.stackexchange](https://video.stackexchange.com/questions/16840/ffmpeg-explicitly-tag-h-264-as-bt-601-rather-than-leaving-unspecified)
  
  ---
  
  **Credits**
  
  Found the advice on VideoHelp [forum reply](https://forum.videohelp.com/threads/382802-FFMPEG-is-there-a-way-to-re-encode-changing-only-the-colormatrix#post2479806) from 2017, which in turn references [the question](https://video.stackexchange.com/questions/16840/ffmpeg-explicitly-tag-h-264-as-bt-601-rather-than-leaving-unspecified) on this video.stackexchange. Thanks again, username_1!
  
  
  ---
  
  