0

Background

I am trying to convert a tiff image to an h.264 encoded frame. I am using FFMPEG to do so. With a PNG, I can convert using the following command

./ffmpeg -loglevel error -hide_banner -i /path/to/input.png -c:v libx264 -pix_fmt yuv420p10le /path/to/outputFrame.h264

This works great and gives me a proper frame. The PNG is 16 bit greyscale.

I tried the following with a 14bit greyscale tif as an input

./ffmpeg -loglevel error -hide_banner -i /path/to/input.tiff -c:v libx264 -pix_fmt yuv420p10le /path/to/outputFrame.h264

and got an error: This format is not supported (bpp=14, bppcount=1)

I had read elsewhere that

FFmpeg does support upto 16 bpc RGB TIFFs or 8 bit YUV TIFFs or 16 bit grayscale ones..

So used imagemagick identify function to verify my tif it stated that it was indeed a 14 bit grayscale gray image.

So I tried a 10bit version, this gave me same error above except it was now bpp=10 instead of bpp=14.

I then figured the pix-fmt was off, so I tried gray10le with the 10bit image with no luck. Same error.

I want to have the full bit depth of the image anyways, so would prefer a 16 or 14 bit solution.

My Question

How can I take a 14 bit TIF and convert it to a h264 encoded frame using ffmpeg or Imagemagick maintaining the highest bit depth that h264 will allow? I also would prefer not to convert to an intermediary format. I am running on CentOS Linux

Update

When I force the depth down to 8 with the TIF and send it into the above ffmpeg command, it does go through but when I go to open the frame in VLC, it does not come up like it does when I do the same thing with a 16 bit greyscale PNG...

Update 2 Per a comment, I tried forcing the tif to 16 bit grayscale and that worked with the original pixel formats I had in the PNG-centered ffmpeg command.

I am still having a hard time displaying the frame in VLC, but it could be due to the size of the image. It is quite large. I will try tiling it to make sure the data is intact. If its not intact, the question still stands. If its intact I will just "answer my own question"

Dean Knight
  • 660
  • 6
  • 17
  • 1
    IIRC, FFmpeg does not have any non-multiple-of-8 grayscale pix_fmt, which seems to be the root of your problem. Could you "upsample" tiff data to 16-bit grayscale with imagemagick (either as another tiff file or a set of PNG files)? Then, you should be able to feed those images to FFmpeg to create h264 stream. (Sorry I'm not well-versed in imagemagick to know if that's possible.) – kesh Mar 17 '22 at 04:31
  • @kesh That is an interesting observation. Perhaps I do need to force it into being a 16 bit TIF. The PNG's automatically output as 16 bits. The TIF's come in at 14 bits automatically. I will try to force it to 16. – Dean Knight Mar 17 '22 at 04:37
  • Forcing to 16 had an interesting effect. I added an update above. I will see if the data is intact and properly converted – Dean Knight Mar 17 '22 at 04:40
  • @kesh, if you want, feel free to post an answer using your comment. I can mark it as the answer. Otherwise I will mark my answer accepted in 2 days. I would rather give you the credit though. – Dean Knight Mar 17 '22 at 05:05
  • Glad to hear that was the culprit. Thx for the offer but your answer post reads just fine – kesh Mar 17 '22 at 17:09

1 Answers1

1

As Kesh mentioned in the comment:

FFmpeg does not have any non-multiple-of-8 grayscale pix_fmt, which seems to be the root of your problem. Could you "upsample" tiff data to 16-bit grayscale with imagemagick (either as another tiff file or a set of PNG files)? Then, you should be able to feed those images to FFmpeg to create h264 stream.

He was right, I made sure my TIFF was 16 bit greyscale instead of 14, and it went into FFMPEG no problem.

I then tiled my data to check it and make sure the conversion to h264 went as planned. It looks good.

TL;DR Answer

Make sure greyscale TIFs going into FFMPEG are 8 or 16 bit (multiples of 8) bit depth if you want them to encode into h.264 properly.

Dean Knight
  • 660
  • 6
  • 17