Activity › Forums › Compression Techniques › Lossless encoding 16bpp images to movie file
-
Lossless encoding 16bpp images to movie file
Egon Touste replied 11 years, 2 months ago 5 Members · 18 Replies
-
Laurent Nguyen
May 11, 2011 at 5:06 pmHi Michael,
I made the thing work ! I finally implemented the two stream solution. It works like a charm, with a framerate of ~60fps, all lossless.
Thank you very much for your valuable help and advice, it has been a pleasure. If you were around, I would pay you several beers !
Cheers,
Laurent
-
Ryan Smith
May 13, 2011 at 5:07 pmHi Laurent-
I am struggling with the same problem. Any way you can post your final solution?
I have a series of 8 bit grayscale tif images. It tells me ‘incompatible pixel format “pal8” for codec ‘ffv1′, autoselecting YUV420p’ when I try to encode.
I tried forcing my -pix_fmt with little luck as it says the options I tried (gray, gray8a, gray16be, gray16be) aren’t compatible with ffv1. Lossless encoding is necessary for my project. Any way you could post your call to ffmpeg? Thanks!
-Ryan
-
Laurent Nguyen
May 16, 2011 at 7:56 amHi Ryan,
if I understand your post correctly, you want to do lossless encoding of 8-bit grayscale images.
My call to ffmpeg for 8 bit images is:
ffmpeg -f rawvideo -r 25 -y -s vga -pix_fmt gray -i msb.pipe -an -vcodec ffv1 msb.movI am using a named pipe as input. If you are using images as input, it should look like:
ffmpeg -f image2 -s vga -pix_fmt gray -i im_folder/im%05d.pgm -an -vcodec ffv1 movie.movThe output pixel format will be yuv420p, but when you decode it, you’ll get 8bit grayscale images, and if you compare it to the original input image (image difference), you’ll get an image of value zero. The code for decoding:
ffmpeg -y -s vga -pix_fmt gray -i msb.mov -an temp/msb%05d.pgmHope it helps ! Cheers,
Laurent
-
Ryan Smith
May 16, 2011 at 4:41 pmHi Laurent-
Thanks for the reply! I tried your suggestion, and I am still having some trouble.
Both your encoding and decoding call work without errors, however when I load the decoded tif into Matlab to analyze it, I get a matrix that is 2472x3296x3 of uint8 type. The original image loads in as a 2d matrix of 2472×3296 of uint8 type.
The only thing I changed from your call was forcing the size to vga resolution. Any idea on why my data type is still an RGB image instead of grayscale on the output?
Thanks in advance for all the help, I owe you a beer-
-Ryan
-
Laurent Nguyen
May 18, 2011 at 7:46 amHey Ryan,
I frankly don’t know why it does that. I am quite new to ffmpeg as well ;-). However, there might be some possible tricks:
1. Have you checked the values in your 3 x nx x ny matrix (decoded image) ? If they are all the same values, you could just use one plane.
2. You can also try using a pgm image format as output. I however don’t know if that makes a difference.
3. You can try to force the output format to be grayscale by adding -pix_fmt gray in the end of your call
I won’t say no to a beer 😉
Good luck !
Laurent
-
Andrea Carrillo
June 28, 2011 at 5:19 amGood day Laurent,
I see that you got the solution for your own question “Do you by any chance know of a clean way to do the extraction of the 8bit images from the 16bit image ? “.
Could you please help me to do the same?, the thing is that I having the same problem, compresing 16 bit depth images in lossless (for long time).
I try the command that you mention later on this thread, and it work OK… but I don’t know how to split the 16bit image in 8 bit’s.
I will really appreacite your help.
-
Laurent Nguyen
June 28, 2011 at 7:45 amHi Andrea,
If you consider data to be your string containing the 16-bit image data (without the header), the “even” bytes will go to the first image while the “odd” bytes will go to the second image. It basically means that the first 8-bit image will contain one out of two bytes of the 16-bit image; similarly, the second image will contain the other half.
In python, the parsing looks like that:
msb_data = data[::2]
lsb_data = data[1::2]Where msb_data is the 8-bit image containing the “even” bytes and lsb_data the other 8-bit image.
Hope I was clear ;-). If needed, don’t hesitate to ask
Cheers,
Laurent
-
Egon Touste
March 29, 2015 at 8:29 pmmy advise is to use imagemagick for the job.
it supports 48bit rgb, or 16bit (greyscale) images, including creating 48bit png , and be setup to use ffmpeg for video conversions
..pretty sure you’ll have success using a combination of the twogood luck
Reply to this Discussion! Login or Sign Up