RGB565 To PNG/JPEG

While not common, in rare cases you may have an image in its raw pixel format (say in rgb565). It can even be a portion of video. If you ever come accross converting such raw data to say a png or jpeg image, ffmpeg can be used easily. See the following command:

ffmpeg -vcodec rawvideo -f rawvideo -pix_fmt rgb565 -s 1024x768 -i image.raw -f image2 -vcodec png image.png

 1024x768 is the geometry. image.raw is the file containing the image in rgb565 format. image.png is the new file to be written.

Need to great a jpeg file? One can use -vcodec mjpeg image.jpg instead of png.

What if image.raw contains data for multiple frames (of a video)? You can use "%d" and ffmpeg will automatically name the additional files generated:

ffmpeg -vcodec rawvideo -f rawvideo -pix_fmt rgb565 -s 1024x768 -i movie.raw -f image2 -vcodec png image%d.png

Instead of a file, If you have an rgb565 stream, you may attempt to direct the data to stdin of ffmpeg and accomplish the same. In such a case, instead of "-i image.raw", you can use "-i -":

firstCommand | ffmpeg -vcodec rawvideo -f rawvideo -pix_fmt rgb565 -s 1024x768 -i - -f image2 -vcodec png image%d.png

firstCommand should be sending rgb565 raw video data to the standard output of it. We are just redirecting such data to ffmpeg. A trivial example is "cat movie.raw" used in the place of firstCommand.

This was not an easy find! Enjoy.

Comments

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.

More information about formatting options

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.