FORUMS: list search recent posts

Lossless encoding 16bpp images to movie file

COW Forums : FFmpeg

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
Laurent Nguyen
Lossless encoding 16bpp images to movie file
on May 4, 2011 at 3:33:15 pm

Hi,

I am a new user of ffmpeg (it's my first message on this forum !). I am trying to encode grayscale 16bit depth VGA images to a movie file losslessly.

Right now, I am using the flv1 codec (as it is lossless), but for some reason he seems to convert the pixel format to yuv420 (non-reversible process). Are there options to add so that it keeps my movie as grayscale 16bpp ?

The code I'm using:
ffmpeg -f rawvideo -r 25 -y -s vga -pix_fmt gray16be -i temp/im%05d.ppm -an -vcodec ffv1 movie.mov

Any help is welcome. Thanks !!!

Cheers,
Laurent


Return to posts index

Michael Rampe
Re: Lossless encoding 16bpp images to movie file
on May 5, 2011 at 12:31:05 am

[Laurent Nguyen] "Are there options to add so that it keeps my movie as grayscale 16bpp ?"

Try to put "-pix_fmt gray16be" AFTER the -i input file rather than before.

Michael


Return to posts index

Laurent Nguyen
Re: Lossless encoding 16bpp images to movie file
on May 9, 2011 at 7:39:47 am

Hi,

If I only put it AFTER, there are some encoding problems (ffmpeg does not recognizes the input pix format). When put BEFORE and AFTER, the movie is encoded as yuv420p.
I'm wondering why he's doing this. I am going to try with 8bit grayscale images and see how ffmpeg behaves.


Return to posts index


Michael Rampe
Re: Lossless encoding 16bpp images to movie file
on May 10, 2011 at 4:45:06 am

[Laurent Nguyen] "When put BEFORE and AFTER, the movie is encoded as yuv420p.
I'm wondering why he's doing this."


What version do you have installed? Can you post the command line output? Newer versions have added this as an option in the -vf filter chain which might yield the desired result.

Michael


Return to posts index

Laurent Nguyen
Re: Lossless encoding 16bpp images to movie file
on May 10, 2011 at 7:39:53 am

Hi,

thanks for replying. My version of ffmpeg is SVN-r0.5.1-4:0.5.1-1ubuntu1.1

The output I get is:

FFmpeg version SVN-r0.5.1-4:0.5.1-1ubuntu1.1, Copyright (c) 2000-2009 Fabrice Bellard, et al.
configuration: --extra-version=4:0.5.1-1ubuntu1.1 --prefix=/usr --enable-avfilter --enable-avfilter-lavf --enable-vdpau --enable-bzlib --enable-libgsm --enable-libschroedinger --enable-libspeex --enable-libtheora --enable-libvorbis --enable-pthreads --enable-zlib --disable-stripping --disable-vhook --enable-runtime-cpudetect --enable-gpl --enable-postproc --enable-swscale --enable-x11grab --enable-libdc1394 --enable-shared --disable-static
libavutil 49.15. 0 / 49.15. 0
libavcodec 52.20. 1 / 52.20. 1
libavformat 52.31. 0 / 52.31. 0
libavdevice 52. 1. 0 / 52. 1. 0
libavfilter 0. 4. 0 / 0. 4. 0
libswscale 0. 7. 1 / 0. 7. 1
libpostproc 51. 2. 0 / 51. 2. 0
built on Mar 31 2011 18:59:37, gcc: 4.4.3
Input #0, rawvideo, from 'fifo.pipe':
Duration: N/A, start: 0.000000, bitrate: N/A
Stream #0.0: Video: rawvideo, gray16be, 640x480, 25 tbr, 25 tbn, 25 tbc
Output #0, mov, to 'depth.mov':
Stream #0.0: Video: ffv1, yuv420p, 640x480, q=2-31, 200 kb/s, 90k tbn, 25 tbc
Stream mapping:
Stream #0.0 -> #0.0
[mov @ 0xb829a0]Warning, using MS style video codec tag, the file may be unplayable!
Press [q] to stop encoding
frame= 474 fps= 89 q=0.0 Lsize= 22219kB time=18.96 bitrate=9600.2kbits/s
video:22215kB audio:0kB global headers:0kB muxing overhead 0.020406%


I am using a named pipe (called fifo.pipe) to send the frames to ffmpeg.

Thanks !

Laurent


Return to posts index

Laurent Nguyen
Re: Lossless encoding 16bpp images to movie file
on May 10, 2011 at 1:50:06 pm

Hi Michael,

I installed and tried on version 0.6, still not working ;-). When I decode the outputted film, the images are 8-bit greyscale. I am considering splitting the 16bit image into two 8bit images and launch 2 ffmpeg processes. Do you have another option for lossless encoding ?

Thanks !

Laurent

FFmpeg version 0.6.2, Copyright (c) 2000-2010 the FFmpeg developers
built on May 10 2011 13:12:12 with gcc 4.2.1 (Apple Inc. build 5666) (dot 3)
configuration: --prefix=/opt/local --enable-swscale --enable-avfilter --enable-avfilter-lavf --enable-libmp3lame --enable-libvorbis --enable-libtheora --enable-libdirac --enable-libschroedinger --enable-libvpx --enable-libspeex --mandir=/opt/local/share/man --enable-shared --enable-pthreads --disable-indevs --cc=/usr/bin/gcc-4.2 --arch=x86_64 --disable-mmx --disable-mmx2 --disable-sse --disable-ssse3 --disable-amd3dnow --disable-amd3dnowext
libavutil 50.15. 1 / 50.15. 1
libavcodec 52.72. 2 / 52.72. 2
libavformat 52.64. 2 / 52.64. 2
libavdevice 52. 2. 0 / 52. 2. 0
libavfilter 1.19. 0 / 1.19. 0
libswscale 1.11. 0 / 1.11. 0
[rawvideo @ 0x12180c800]Estimating duration from bitrate, this may be inaccurate
Input #0, rawvideo, from 'fifo.pipe':
Duration: N/A, start: 0.000000, bitrate: N/A
Stream #0.0: Video: rawvideo, gray16be, 640x480, 25 tbr, 25 tbn, 25 tbc
[mov @ 0x121832600]Warning, using MS style video codec tag, the file may be unplayable!
Output #0, mov, to 'depth.mov':
Metadata:
encoder : Lavf52.64.2
Stream #0.0: Video: ffv1, yuv420p, 640x480, q=2-31, 200 kb/s, 25 tbn, 25 tbc
Stream mapping:
Stream #0.0 -> #0.0
Press [q] to stop encoding
frame= 474 fps= 48 q=0.0 Lsize= 22219kB time=18.96 bitrate=9600.2kbits/s
video:22215kB audio:0kB global headers:0kB muxing overhead 0.020406%


Return to posts index


Laurent Nguyen
Re: Lossless encoding 16bpp images to movie file
on May 10, 2011 at 2:17:09 pm

Hi Michael,

Sorry for my numerous messages ! I got your point with the -vf options. However, I have problems with this option. When I type:

ffmpeg -filters

I get:

FFmpeg version 0.6.2, Copyright (c) 2000-2010 the FFmpeg developers
built on May 10 2011 13:12:12 with gcc 4.2.1 (Apple Inc. build 5666) (dot 3)
configuration: --prefix=/opt/local --enable-swscale --enable-avfilter --enable-avfilter-lavf --enable-libmp3lame --enable-libvorbis --enable-libtheora --enable-libdirac --enable-libschroedinger --enable-libvpx --enable-libspeex --mandir=/opt/local/share/man --enable-shared --enable-pthreads --disable-indevs --cc=/usr/bin/gcc-4.2 --arch=x86_64 --disable-mmx --disable-mmx2 --disable-sse --disable-ssse3 --disable-amd3dnow --disable-amd3dnowext
libavutil 50.15. 1 / 50.15. 1
libavcodec 52.72. 2 / 52.72. 2
libavformat 52.64. 2 / 52.64. 2
libavdevice 52. 2. 0 / 52. 2. 0
libavfilter 1.19. 0 / 1.19. 0
libswscale 1.11. 0 / 1.11. 0
Filters:


It seems that I cannot use filters... What do I need to install to be able to use it ? Is it libavfilter ?

Please forgive my ignorance, thanks !

Laurent


Return to posts index

Michael Rampe
Re: Lossless encoding 16bpp images to movie file
on May 10, 2011 at 10:05:55 pm

Hi Laurent,

I have tried to replicate your issues and found a few things....

Putting the -pix-fmt after the input does work but the codec you have selected is not compatible with this colour space:

ffmpeg -i newtest3.mp4 -pix_fmt gray16be -an -vcodec ffv1 16grey.mov
produces this error:
"Incompatible pixel format 'gray16be' for codec 'ffv1', auto-selecting format 'yuv420p'"

I then tried rawvideo but then had problems with container compatibility. The more I looked into it, I couldn't find any codec/container combinations that will support this pixel format which I guess makes sense as no displays support this format.

I guess the real question is, what are you trying to achieve by using this pixel format? Is it for delivery to viewers or an intermediary step?

[Laurent Nguyen] "It seems that I cannot use filters... What do I need to install to be able to use it ? Is it libavfilter ?"

yes. Try the latest git version. Mine is:

ffmpeg version git-N-29577-gc402ce4, Copyright (c) 2000-2011 the FFmpeg developers
built on May 4 2011 09:56:05 with gcc 4.2.1 (Apple Inc. build 5664)
configuration: --prefix=/opt/local --enable-gpl --enable-postproc --enable-swscale --enable-avfilter --enable-libmp3lame --enable-libfaac --enable-libx264 --enable-libfreetype --enable-nonfree --enable-shared --arch=x86_64
libavutil 51. 2. 0 / 51. 2. 0
libavcodec 53. 3. 0 / 53. 3. 0
libavformat 53. 0. 3 / 53. 0. 3
libavdevice 53. 0. 0 / 53. 0. 0
libavfilter 2. 4. 0 / 2. 4. 0
libswscale 0. 14. 0 / 0. 14. 0
libpostproc 51. 2. 0 / 51. 2. 0


Return to posts index

Laurent Nguyen
Re: Lossless encoding 16bpp images to movie file
on May 10, 2011 at 10:21:21 pm

Hi Michael,

Thanks for your response.

I guess the real question is, what are you trying to achieve by using this pixel format? Is it for delivery to viewers or an intermediary step?


I am trying to encode depth data from a kinect device. The depth images from the kinect are 11bit depth coded on 16bit greyscale images. I want to first record the data, then process them offline. As the sequences may be arbitrarily long, it is necessary for me to have compression. On the other hand, I don't want to take the risk of using lossy compression as it will add artifacts to the data. So in short, yes, I am using ffmpeg as an intermediary step ;-)

In your opinion, what are the other options (codec-wise) rather than using ffv1 ? I am not very keen on splitting the 16 bit image into two 8bit images and using two encoders, but if it's the only option I'll have to resign. But if you have another option, I'm buying !!!

Thanks for your time and efforts!

Laurent


Return to posts index


Michael Rampe
Re: Lossless encoding 16bpp images to movie file
on May 10, 2011 at 11:26:15 pm

Hmmmmm....

Tricky;-)

The only way I successfully got 16bit grey out of ffmpeg was using raw video as a still image sequence.

ffmpeg -i newtest3.mp4 -pix_fmt gray16be -an -f image2 test%d.raw

I then opened in Photoshop and could output as a lossless png which cut down the size a lot. Unfortunately, I couldn't go straight to png from ffmpeg as it would not allow grey16be and auto scaled to rgb24. You might be able to automate this but it may end up more clunky than using two compressed 8bit streams.

As far as using a video intermediate, I suspect the same to be true.... must be rawvideo as none of the codecs or containers are set to allow this pixel format.

I will keep thinking.....

Michael


Return to posts index

Laurent Nguyen
Re: Lossless encoding 16bpp images to movie file
on May 11, 2011 at 8:09:42 am

Hey Michael,

thanks for the feedback. Too bad it is not working directly. Let's go for the 2 stream solution, then ;-). Do you by any chance know of a clean way to do the extraction of the 8bit images from the 16bit image ?

Cheers,

Laurent


Return to posts index

Laurent Nguyen
Re: Lossless encoding 16bpp images to movie file
on May 11, 2011 at 5:06:41 pm

Hi 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


Return to posts index


Ryan Smith
Re: Lossless encoding 16bpp images to movie file
on May 13, 2011 at 5:07:50 pm

Hi 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


Return to posts index

Laurent Nguyen
Re: Lossless encoding 16bpp images to movie file
on May 16, 2011 at 7:56:04 am

Hi 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.mov

I 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.mov

The 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.pgm

Hope it helps ! Cheers,

Laurent


Return to posts index

Ryan Smith
Re: Lossless encoding 16bpp images to movie file
on May 16, 2011 at 4:41:15 pm

Hi 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 2472x3296 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


Return to posts index


Laurent Nguyen
Re: Lossless encoding 16bpp images to movie file
on May 18, 2011 at 7:46:30 am

Hey 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


Return to posts index

Andrea Carrillo
Re: Lossless encoding 16bpp images to movie file
on Jun 28, 2011 at 5:19:04 am

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


Return to posts index

Laurent Nguyen
Re: Lossless encoding 16bpp images to movie file
on Jun 28, 2011 at 7:45:15 am

Hi 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


Return to posts index


egon touste
Re: Lossless encoding 16bpp images to movie file
on Mar 29, 2015 at 8:29:40 pm

my 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 two

good luck


Return to posts index

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
© 2017 CreativeCOW.net All Rights Reserved
[TOP]