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).


$ 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.

2 Answers 2


The short answer is no.

You can use the drawbox filter 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.


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


% 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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.