Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Compression Techniques Lossless encoding 16bpp images to movie file

  • Lossless encoding 16bpp images to movie file

    Posted by Laurent Nguyen on May 4, 2011 at 3:33 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

    Egon Touste replied 11 years, 2 months ago 5 Members · 18 Replies
  • 18 Replies
  • Michael Rampe

    May 5, 2011 at 12:31 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

  • Laurent Nguyen

    May 9, 2011 at 7:39 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.

  • Michael Rampe

    May 10, 2011 at 4:45 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

  • Laurent Nguyen

    May 10, 2011 at 7:39 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

  • Laurent Nguyen

    May 10, 2011 at 1:50 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%

  • Laurent Nguyen

    May 10, 2011 at 2:17 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

  • Michael Rampe

    May 10, 2011 at 10:05 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

  • Laurent Nguyen

    May 10, 2011 at 10: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

  • Michael Rampe

    May 10, 2011 at 11:26 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

  • Laurent Nguyen

    May 11, 2011 at 8:09 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

Page 1 of 2

We use anonymous cookies to give you the best experience we can.
Our Privacy policy | GDPR Policy