简体   繁体   中英

Convert raw RGB32 file to JPEG or PNG using FFmpeg

Context

I used a C++ program to write raw bytes to a file (image.raw) in RGB32 format:

RGBARGBARGBA ...

and I want to be able to view it in some way. I have the dimensions of the image.

My tools are limited to command line commands (eg ffmpeg ). I have visited the ffmpeg website for instructions, but it deals more with converting videos to images.


Questions

Is it possible to turn this file into a viewable file type (eg .jpeg , .png ) using ffmpeg . If so, how would I do it?

If it's not possible, is there a way I can use another command?

It that's still not viable, is there any way I can manipulate the RGB32 bytes inside a C++ program to make it more suitable without the use of external libraries? I also don't want to encode .jpeg myself like this .

Use the rawvideo demuxer :

ffmpeg -f rawvideo -pixel_format rgba -video_size 320x240 -i input.raw output.png

Since there is no header specifying the assumed video parameters you must specify them, as shown above, in order to be able to decode the data correctly.

See ffmpeg -pix_fmts for a list of supported input pixel formats which may help you choose the appropriate -pixel_format .

get a single frame from raw RGBA data

ffmpeg -y -f rawvideo -pix_fmt rgba -ss 00:01 -r 1 -s 320x240 -i input.raw -frames:v 1 output.png

-y overwrite output
-r input framerate (placed before -i )
-ss skip to this time
-frames:v number of frames ot output

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM