stashapp / stash

An organizer for your porn, written in Go. Documentation: https://docs.stashapp.cc
https://stashapp.cc/
GNU Affero General Public License v3.0
9.21k stars 795 forks source link

[Feature] Support TIF images #4053

Open zhyu opened 1 year ago

zhyu commented 1 year ago

It seems TIF images cannot be processed correctly.

Auto-gallery creation is not working after scanning a folder containing TIF images only. Thumbnail generation is not working and TIF images cannot be displayed as well.

A snippet of error logs:

2023-08-23 16:48:10
Error   
stderr: [out#0/image2pipe @ 0x600003bc40c0] Output file does not contain any stream
2023-08-23 16:48:10
Error   
error generating thumbnail for /path/file.TIF: error running ffmpeg command <-hide_banner -v error -y -i - -vf scale=640:640:force_original_aspect_ratio=decrease -c:v mjpeg -frames:v 1 -q:v 5 -f image2pipe - -f mjpeg>: exit status 1 
DingDongSoLong4 commented 1 year ago

This is probably the same issue as #4044. Stash does not properly support TIF/TIFF images - only png, gif, jpeg, webp and avif. Any other formats are sent through to ffmpeg, and are incorrectly detected as Image Clips. ffmpeg also appears to not be able to generate thumbnails properly for TIFF images.

The image extension list is a bit deceptive - adding an extension there only means that Stash will scan it (instead of ignoring it) and try to parse the format as an image. This image parsing ignores the file extension entirely, and it is only able to recognize images that in the formats I listed above.

A bit of a rework is needed, which should fix both this issue and #4044.

zhyu commented 1 year ago

I see. So I locally patched stash like https://github.com/stashapp/stash/pull/3913, now TIF/TIFF images are recognized as images. The thumbnail generation is still not working as you mentioned.

The error log suggests ffmpeg reads from stdin to generate thumbnails (-i -) and I can reproduce the error locally with cat image.tif | ffmpeg #args from the error log.

However, the error is gone if I update the command to read from the local file (-i /path/to/image.tif) and I can open the generated thumbnail file without issues 🤔

zhyu commented 1 year ago

Interestingly, if I move -i - to the end of the arg list, the error is gone as well. However, the image quality of the generated thumbnail is much worse than the thumbnail generated with -i /path/to/image.tif.

Maybe the command to generate thumbnails needs to be tuned.

zhyu commented 1 year ago

I patched the ffmpegImageThumbnail function locally to fallback to read from the image file if error happens when reading from stdin, now thumbnails for TIF files can be generated as expected.

DingDongSoLong4 commented 1 year ago

Yeah the patch in #3913 is a bit of a hack imo. The reason why we have ffmpeg read from stdin is because we need to be able to generate thumbnails from images which are inside zip files, which ffmpeg can't read from directly. The file is read by stash (either from inside a zip file or directly from the filesystem) and sent to ffmpeg's stdin.

I found this issue on ffmpeg's bugtracker: https://trac.ffmpeg.org/ticket/5561 ffmpeg doesn't support reading tiff images from stdin.

DingDongSoLong4 commented 1 year ago

I think the solution might be to use vips for everything, and only fallback to using built-in image detection or ffmpeg if it is not present. libvips supports TIFF natively and JPEG XL if libjxl is present, so it should solve both these issues.

We can easily log a warning message if a format that only vips supports is used while vips is not installed.

yoshnopa commented 1 year ago

Just my two cents, without remembering too well, I had problems with vips when implementing the image clips, so there may be some formats not working with it. In case this gets into a PR, make sure all image formats are tested, including the less common avif, gif and webp.

gamerguitarist commented 10 months ago

For the time being, in order to view tiff, here is my workaround

  1. Get a sqlite editor of your choice and run the following query. It copies tiffs files from the video_files table into the image_files table. You could also delete them after copying but I have not tried that.

-- Insert rows into image_files table for video files with video_codec 'tiff' INSERT INTO image_files (file_id, format, width, height) SELECT v.file_id, v.video_codec, v.width, v.height FROM video_files v LEFT JOIN image_files i ON v.file_id = i.file_id AND v.video_codec = 'tiff' WHERE i.file_id IS NULL AND v.file_id NOT IN (SELECT file_id FROM image_files);

-- Retrieve the inserted rows SELECT * FROM image_files WHERE file_id IN (SELECT file_id FROM video_files WHERE video_codec = 'tiff');

You need to do this every time your add new tiff files

  1. Use Safari(native tiff support) or another browser with a Tiff extension, example: Firefox with 'TIFF Viewer'