<p>For later reference, here is what I found out:</p>
<pre><code>% identify 300.jpg
300.jpg JPEG 200x300 200x300+0+0 8-bit sRGB 10839B 0.000u 0:00.000
</code></pre>
<p>Convert to yuv444:</p>
<pre><code>% ffmpeg -y -i 300.jpg -pix_fmt yuv444p 300.yuv
</code></pre>
<p>Convert to mp4:</p>
<pre><code>% ffmpeg -y -s 200x300 -pix_fmt yuv444p -i 300.yuv -c:v libx264 -pix_fmt yuv444p -profile:v high444 -crf 0 -preset:v slow lossless.m4v
</code></pre>
<p>Convert back to image:</p>
<pre><code>% ffmpeg -y -i lossless.m4v -vcodec rawvideo -pix_fmt yuv444p m4v_decoded.yuv
</code></pre>
<p>Verify:</p>
<pre><code>% md5sum m4v_decoded.yuv 300.yuv
b7e89f5a091b680e6991c6ae6aad8564  m4v_decoded.yuv
b7e89f5a091b680e6991c6ae6aad8564  300.yuv
</code></pre>
<p>Thanks to <a href="https://stackoverflow.com/a/18506577/136285">SO</a>.</p>
<hr />
<p>To extract all I-Frames:</p>
<pre><code>% ffmpeg -skip_frame nokey -i file -vsync 0 -frame_pts true out%d.png
</code></pre>
<p>Thanks to <a href="https://superuser.com/questions/1421133/extract-i-frames-to-images-quickly">SuperUser</a>.</p>
<hr />
<p>For 420 pay attention that high profile is not supported.</p>
<p>Thanks again to <a href="https://superuser.com/a/1095656/106444">SuperUser</a>.</p>

CC BY-SA 4.0
2023-03-28T12:47:42.730Z
2023-03-28T13:06:04.870Z
2023-03-28T13:06:04.870Z
malat
<p>The short answer is no.</p>
<p>You can use the <a href="https://ffmpeg.org/ffmpeg-filters.html#drawbox" rel="nofollow noreferrer">drawbox filter</a> to overlay a gray or any other color box over a rectangular region of a video.</p>
<p>However, it then has to be re-encoded. You can specify lossless encoding, however the output stream will usually be (much) larger.</p>

CC BY-SA 4.0
2023-03-17T06:53:09.247Z
Ok, thanks. I found a [simple example](https://superuser.com/questions/877523/how-to-draw-a-box-at-the-bottom-of-the-video-using-ffmpeg) to play with.
malat
CC BY-SA 4.0
2023-03-17T04:22:51.787Z
2023-03-17T15:48:14.413Z
2023-03-17T15:48:14.413Z
Gyan
<p>I am familiar with the UNIX command <code>jpegtran</code> which supports the <code>wipe</code> (1) command line option for JPEG (ITU.81) format.</p>
<p>Using ffmpeg one can <a href="https://video.stackexchange.com/questions/7903/how-to-losslessly-encode-a-jpg-image-sequence-to-a-video-in-ffmpeg">losslessly encode a jpg image sequence</a> to a MJPEG video.</p>
<p>I was wondering if ffmpeg would support the same <code>wipe</code> implementation for h264 ? I could not find anything related to lossless-editing of video other than <a href="https://github.com/mifi/lossless-cut" rel="nofollow noreferrer">this</a>. Looking at the features page, I do not see anything related to 'wipe' or 'mask' image.</p>
<p>I am looking for masking of a rectangular region, replacement color is not important (eg. neutral gray as in jpegtran implementation is acceptable).</p>
<p>(1)</p>
<p>$ man jpegtran
[...]</p>
<pre><code>A complementary lossless wipe option is provided to discard (gray out) data inside a given image region while losslessly preserving what is outside:

       -wipe WxH+X+Y
              Wipe (gray out) a rectangular region of width W and height H from the input image, starting at point X,Y.

       Attaching an 'f' character (&quot;flatten&quot;) to the width number will cause the region to be filled with the average of adjacent blocks rather than grayed out.  If the wipe region and the region outside
       the wipe region, when adjusted to the nearest iMCU boundary, form two horizontally adjacent rectangles, then attaching an 'r' character (&quot;reflect&quot;) to the width number will cause the  wipe  region
       to be filled with repeated reflections of the outside region rather than grayed out.
</code></pre>

<ffmpeg><h.264><lossless>
Lossless masking of MP4/h.264
malat
# Lossless masking of MP4/h.264

(Asked by: username_0 on 2023-03-15)

I am familiar with the UNIX command jpegtran which supports the wipe (1) command line option for JPEG (ITU.81) format.
Using ffmpeg one can losslessly encode a jpg image sequence to a MJPEG video.
I was wondering if ffmpeg would support the same wipe implementation for h264 ? I could not find anything related to lossless-editing of video other than this. Looking at the features page, I do not see anything related to 'wipe' or 'mask' image.
I am looking for masking of a rectangular region, replacement color is not important (eg. neutral gray as in jpegtran implementation is acceptable).
(1)
$ man jpegtran
[...]
A complementary lossless wipe option is provided to discard (gray out) data inside a given image region while losslessly preserving what is outside:

       -wipe WxH+X+Y
              Wipe (gray out) a rectangular region of width W and height H from the input image, starting at point X,Y.

       Attaching an 'f' character ("flatten") to the width number will cause the region to be filled with the average of adjacent blocks rather than grayed out.  If the wipe region and the region outside
       the wipe region, when adjusted to the nearest iMCU boundary, form two horizontally adjacent rectangles, then attaching an 'r' character ("reflect") to the width number will cause the  wipe  region
       to be filled with repeated reflections of the outside region rather than grayed out.

**Tags:** ffmpeg, h.264, lossless


---

## 2 answers

### Answer by username_1 on 2023-03-17. Score: 1 | Accepted answer

The short answer is no.

You can use the [drawbox filter](https://ffmpeg.org/ffmpeg-filters.html#drawbox) to overlay a gray or any other color box over a rectangular region of a video.

However, it then has to be re-encoded. You can specify lossless encoding, however the output stream will usually be (much) larger.

> **Comments:**
> **username_0**: Ok, thanks. I found a [simple example](https://superuser.com/questions/877523/how-to-draw-a-box-at-the-bottom-of-the-video-using-ffmpeg) to play with.  

---

### Answer by username_0 on 2023-03-28. Score: 0

For later reference, here is what I found out:
% identify 300.jpg
300.jpg JPEG 200x300 200x300+0+0 8-bit sRGB 10839B 0.000u 0:00.000

Convert to yuv444:
% ffmpeg -y -i 300.jpg -pix_fmt yuv444p 300.yuv

Convert to mp4:
% ffmpeg -y -s 200x300 -pix_fmt yuv444p -i 300.yuv -c:v libx264 -pix_fmt yuv444p -profile:v high444 -crf 0 -preset:v slow lossless.m4v

Convert back to image:
% ffmpeg -y -i lossless.m4v -vcodec rawvideo -pix_fmt yuv444p m4v_decoded.yuv

Verify:
% md5sum m4v_decoded.yuv 300.yuv
b7e89f5a091b680e6991c6ae6aad8564  m4v_decoded.yuv
b7e89f5a091b680e6991c6ae6aad8564  300.yuv

Thanks to SO.

To extract all I-Frames:
% ffmpeg -skip_frame nokey -i file -vsync 0 -frame_pts true out%d.png

Thanks to SuperUser.

For 420 pay attention that high profile is not supported.
Thanks again to SuperUser.


---

