Java FFMPEG在将tiff图片转换为png时反转颜色

Java FFMPEG在将tiff图片转换为png时反转颜色,java,ffmpeg,png,tiff,converters,Java,Ffmpeg,Png,Tiff,Converters,我们需要将数千张tiff图片转换为png。为了实现这一点,我们使用FFMPEG。我们最近注意到,对于极少数转换的文件(png),颜色是颠倒的:输入tiff文件全是黑白的(黑色背景的技术图形),输出png文件是黑白的(图形变为白色背景变为黑色)。当然我们不想这样,我们需要颜色保持不变 下面是我们正在使用的命令: ffmpeg -y -v warning -i in_file.tif out_file.png 我们已经在这些文件上测试了“否定”参数,并且正确地转换了图片。但我们无法将此参数应用于所

我们需要将数千张tiff图片转换为png。为了实现这一点,我们使用FFMPEG。我们最近注意到,对于极少数转换的文件(png),颜色是颠倒的:输入tiff文件全是黑白的(黑色背景的技术图形),输出png文件是黑白的(图形变为白色背景变为黑色)。当然我们不想这样,我们需要颜色保持不变

下面是我们正在使用的命令:

ffmpeg -y -v warning -i in_file.tif out_file.png
我们已经在这些文件上测试了“否定”参数,并且正确地转换了图片。但我们无法将此参数应用于所有输入tiff文件。 以下是带有否定参数的命令:

ffmpeg -y -v verbose -i input.tif -vf negate output.png
我们正在使用的Java代码:

            String ffmpegPath="/Users/user11/ffmpeg//ffmpeg";
            List<String> commandArgs = new ArrayList<String>();
            commandArgs.add(ffmpegPath);
            //overwrite output file if it exists
            commandArgs.add("-y");      
            commandArgs.add("-v");
            commandArgs.add("verbose");
            //set input file 
            commandArgs.add("-i"); 
            commandArgs.add(picture.getAbsolutePath());
            commandArgs.add(dest.getAbsolutePath());
            
            String cmd = "";
            for(String cmdArg : commandArgs) {
                cmd += cmdArg + " ";
            }



31, 2021 2:15:51 PM 
INFO: Executing : /Users/user11/ffmpeg/ffmpeg -y -v verbose -i /Users/user11/ffmpeg/input.tif /Users/user11/ffmpeg/output.png 
May 31, 2021 2:15:51 PM 
INFO: ReencodePicture output: ffmpeg version 4.4-tessus  https://evermeet.cx/ffmpeg/  Copyright (c) 2000-2021 the FFmpeg developers
May 31, 2021 2:15:51 PM 
INFO: ReencodePicture output:   built with Apple clang version 11.0.0 (clang-1100.0.33.17)
May 31, 2021 2:15:51 PM 
INFO: ReencodePicture output:   configuration: --cc=/usr/bin/clang --prefix=/opt/ffmpeg --extra-version=tessus --enable-avisynth --enable-fontconfig --enable-gpl --enable-libaom --enable-libass --enable-libbluray --enable-libdav1d --enable-libfreetype --enable-libgsm --enable-libmodplug --enable-libmp3lame --enable-libmysofa --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenh264 --enable-libopenjpeg --enable-libopus --enable-librubberband --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libtheora --enable-libtwolame --enable-libvidstab --enable-libvmaf --enable-libvo-amrwbenc --enable-libvorbis --enable-libvpx --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxavs --enable-libxvid --enable-libzimg --enable-libzmq --enable-libzvbi --enable-version3 --pkg-config-flags=--static --disable-ffplay
May 31, 2021 2:15:51 PM 
INFO: ReencodePicture output:   libavutil      56. 70.100 / 56. 70.100
May 31, 2021 2:15:51 PM 
INFO: ReencodePicture output:   libavcodec     58.134.100 / 58.134.100
May 31, 2021 2:15:51 PM 
INFO: ReencodePicture output:   libavformat    58. 76.100 / 58. 76.100
May 31, 2021 2:15:51 PM 
INFO: ReencodePicture output:   libavdevice    58. 13.100 / 58. 13.100
May 31, 2021 2:15:51 PM 
INFO: ReencodePicture output:   libavfilter     7.110.100 /  7.110.100
May 31, 2021 2:15:51 PM 
INFO: ReencodePicture output:   libswscale      5.  9.100 /  5.  9.100
May 31, 2021 2:15:51 PM 
INFO: ReencodePicture output:   libswresample   3.  9.100 /  3.  9.100
May 31, 2021 2:15:51 PM 
INFO: ReencodePicture output:   libpostproc    55.  9.100 / 55.  9.100
May 31, 2021 2:15:51 PM 
INFO: ReencodePicture output: [tiff_pipe @ 0x7fa7f6008200] parser not found for codec tiff, packets or times may be invalid.
May 31, 2021 2:15:51 PM 
INFO: ReencodePicture output:     Last message repeated 1 times
May 31, 2021 2:15:51 PM 
INFO: ReencodePicture output: Input #0, tiff_pipe, from '/Users/user11/ffmpeg/input.tif':
May 31, 2021 2:15:51 PM 
INFO: ReencodePicture output:   Duration: N/A, bitrate: N/A
May 31, 2021 2:15:51 PM 
INFO: ReencodePicture output:   Stream #0:0: Video: tiff, 1 reference frame, monob, 2008x2481 [SAR 1:1 DAR 2008:2481], 25 fps, 25 tbr, 25 tbn, 25 tbc
May 31, 2021 2:15:51 PM 
INFO: ReencodePicture output: Stream mapping:
May 31, 2021 2:15:51 PM 
INFO: ReencodePicture output:   Stream #0:0 -> #0:0 (tiff (native) -> png (native))
May 31, 2021 2:15:51 PM 
INFO: ReencodePicture output: Press [q] to stop, [?] for help
May 31, 2021 2:15:51 PM 
INFO: ReencodePicture output: [graph 0 input from stream 0:0 @ 0x7fa7f4c08300] w:2008 h:2481 pixfmt:monob tb:1/25 fr:25/1 sar:1/1
May 31, 2021 2:15:51 PM 
INFO: ReencodePicture output: Output #0, image2, to '/Users/user11/ffmpeg/output.png':
May 31, 2021 2:15:51 PM 
INFO: ReencodePicture output:   Metadata:
May 31, 2021 2:15:51 PM 
INFO: ReencodePicture output:     encoder         : Lavf58.76.100
May 31, 2021 2:15:51 PM 
INFO: ReencodePicture output:   Stream #0:0: Video: png, 1 reference frame, monob(progressive), 2008x2481 (0x0) [SAR 1:1 DAR 2008:2481], q=2-31, 200 kb/s, 25 fps, 25 tbn
May 31, 2021 2:15:51 PM 
INFO: ReencodePicture output:     Metadata:
May 31, 2021 2:15:51 PM 
INFO: ReencodePicture output:       encoder         : Lavc58.134.100 png
May 31, 2021 2:15:51 PM 
INFO: ReencodePicture output: frame=    1 fps=0.0 q=0.0 size=N/A time=00:00:00.00 bitrate=N/A speed=   0x    
May 31, 2021 2:15:51 PM 
INFO: ReencodePicture output: No more output streams to write to, finishing.
May 31, 2021 2:15:51 PM 
INFO: ReencodePicture output: [AVIOContext @ 0x7fa7f4c14180] Statistics: 0 seeks, 1 writeouts
May 31, 2021 2:15:51 PM 
INFO: ReencodePicture output: frame=    1 fps=0.0 q=-0.0 Lsize=N/A time=00:00:00.04 bitrate=N/A speed=1.31x    
May 31, 2021 2:15:51 PM 
INFO: ReencodePicture output: video:37kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: unknown
May 31, 2021 2:15:51 PM 
INFO: ReencodePicture output: Input file #0 (/Users/user11/ffmpeg/input.tif):
May 31, 2021 2:15:51 PM 
INFO: ReencodePicture output:   Input stream #0:0 (video): 1 packets read (18100 bytes); 1 frames decoded; 
May 31, 2021 2:15:51 PM 
INFO: ReencodePicture output:   Total: 1 packets (18100 bytes) demuxed
May 31, 2021 2:15:51 PM 
INFO: ReencodePicture output: Output file #0 (/Users/user11/ffmpeg/output.png):
May 31, 2021 2:15:51 PM 
INFO: ReencodePicture output:   Output stream #0:0 (video): 1 frames encoded; 1 packets muxed (38013 bytes); 
May 31, 2021 2:15:51 PM 
INFO: ReencodePicture output:   Total: 1 packets (38013 bytes) muxed
May 31, 2021 2:15:51 PM 
INFO: ReencodePicture output: [AVIOContext @ 0x7fa7f4f041c0] Statistics: 18100 bytes read, 0 seeks
May 31, 2021 2:15:51 PM 
INFO: BinaryRepositoryHelper.convertPixTo ffmpeg Process returned : java.lang.UNIXProcess@27ddd392, ended with code 0, and returned in 160 ms, out=/Users/user11/ffmpeg/output.png exists=true





所以我们的问题是:

            String ffmpegPath="/Users/user11/ffmpeg//ffmpeg";
            List<String> commandArgs = new ArrayList<String>();
            commandArgs.add(ffmpegPath);
            //overwrite output file if it exists
            commandArgs.add("-y");      
            commandArgs.add("-v");
            commandArgs.add("verbose");
            //set input file 
            commandArgs.add("-i"); 
            commandArgs.add(picture.getAbsolutePath());
            commandArgs.add(dest.getAbsolutePath());
            
            String cmd = "";
            for(String cmdArg : commandArgs) {
                cmd += cmdArg + " ";
            }



31, 2021 2:15:51 PM 
INFO: Executing : /Users/user11/ffmpeg/ffmpeg -y -v verbose -i /Users/user11/ffmpeg/input.tif /Users/user11/ffmpeg/output.png 
May 31, 2021 2:15:51 PM 
INFO: ReencodePicture output: ffmpeg version 4.4-tessus  https://evermeet.cx/ffmpeg/  Copyright (c) 2000-2021 the FFmpeg developers
May 31, 2021 2:15:51 PM 
INFO: ReencodePicture output:   built with Apple clang version 11.0.0 (clang-1100.0.33.17)
May 31, 2021 2:15:51 PM 
INFO: ReencodePicture output:   configuration: --cc=/usr/bin/clang --prefix=/opt/ffmpeg --extra-version=tessus --enable-avisynth --enable-fontconfig --enable-gpl --enable-libaom --enable-libass --enable-libbluray --enable-libdav1d --enable-libfreetype --enable-libgsm --enable-libmodplug --enable-libmp3lame --enable-libmysofa --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenh264 --enable-libopenjpeg --enable-libopus --enable-librubberband --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libtheora --enable-libtwolame --enable-libvidstab --enable-libvmaf --enable-libvo-amrwbenc --enable-libvorbis --enable-libvpx --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxavs --enable-libxvid --enable-libzimg --enable-libzmq --enable-libzvbi --enable-version3 --pkg-config-flags=--static --disable-ffplay
May 31, 2021 2:15:51 PM 
INFO: ReencodePicture output:   libavutil      56. 70.100 / 56. 70.100
May 31, 2021 2:15:51 PM 
INFO: ReencodePicture output:   libavcodec     58.134.100 / 58.134.100
May 31, 2021 2:15:51 PM 
INFO: ReencodePicture output:   libavformat    58. 76.100 / 58. 76.100
May 31, 2021 2:15:51 PM 
INFO: ReencodePicture output:   libavdevice    58. 13.100 / 58. 13.100
May 31, 2021 2:15:51 PM 
INFO: ReencodePicture output:   libavfilter     7.110.100 /  7.110.100
May 31, 2021 2:15:51 PM 
INFO: ReencodePicture output:   libswscale      5.  9.100 /  5.  9.100
May 31, 2021 2:15:51 PM 
INFO: ReencodePicture output:   libswresample   3.  9.100 /  3.  9.100
May 31, 2021 2:15:51 PM 
INFO: ReencodePicture output:   libpostproc    55.  9.100 / 55.  9.100
May 31, 2021 2:15:51 PM 
INFO: ReencodePicture output: [tiff_pipe @ 0x7fa7f6008200] parser not found for codec tiff, packets or times may be invalid.
May 31, 2021 2:15:51 PM 
INFO: ReencodePicture output:     Last message repeated 1 times
May 31, 2021 2:15:51 PM 
INFO: ReencodePicture output: Input #0, tiff_pipe, from '/Users/user11/ffmpeg/input.tif':
May 31, 2021 2:15:51 PM 
INFO: ReencodePicture output:   Duration: N/A, bitrate: N/A
May 31, 2021 2:15:51 PM 
INFO: ReencodePicture output:   Stream #0:0: Video: tiff, 1 reference frame, monob, 2008x2481 [SAR 1:1 DAR 2008:2481], 25 fps, 25 tbr, 25 tbn, 25 tbc
May 31, 2021 2:15:51 PM 
INFO: ReencodePicture output: Stream mapping:
May 31, 2021 2:15:51 PM 
INFO: ReencodePicture output:   Stream #0:0 -> #0:0 (tiff (native) -> png (native))
May 31, 2021 2:15:51 PM 
INFO: ReencodePicture output: Press [q] to stop, [?] for help
May 31, 2021 2:15:51 PM 
INFO: ReencodePicture output: [graph 0 input from stream 0:0 @ 0x7fa7f4c08300] w:2008 h:2481 pixfmt:monob tb:1/25 fr:25/1 sar:1/1
May 31, 2021 2:15:51 PM 
INFO: ReencodePicture output: Output #0, image2, to '/Users/user11/ffmpeg/output.png':
May 31, 2021 2:15:51 PM 
INFO: ReencodePicture output:   Metadata:
May 31, 2021 2:15:51 PM 
INFO: ReencodePicture output:     encoder         : Lavf58.76.100
May 31, 2021 2:15:51 PM 
INFO: ReencodePicture output:   Stream #0:0: Video: png, 1 reference frame, monob(progressive), 2008x2481 (0x0) [SAR 1:1 DAR 2008:2481], q=2-31, 200 kb/s, 25 fps, 25 tbn
May 31, 2021 2:15:51 PM 
INFO: ReencodePicture output:     Metadata:
May 31, 2021 2:15:51 PM 
INFO: ReencodePicture output:       encoder         : Lavc58.134.100 png
May 31, 2021 2:15:51 PM 
INFO: ReencodePicture output: frame=    1 fps=0.0 q=0.0 size=N/A time=00:00:00.00 bitrate=N/A speed=   0x    
May 31, 2021 2:15:51 PM 
INFO: ReencodePicture output: No more output streams to write to, finishing.
May 31, 2021 2:15:51 PM 
INFO: ReencodePicture output: [AVIOContext @ 0x7fa7f4c14180] Statistics: 0 seeks, 1 writeouts
May 31, 2021 2:15:51 PM 
INFO: ReencodePicture output: frame=    1 fps=0.0 q=-0.0 Lsize=N/A time=00:00:00.04 bitrate=N/A speed=1.31x    
May 31, 2021 2:15:51 PM 
INFO: ReencodePicture output: video:37kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: unknown
May 31, 2021 2:15:51 PM 
INFO: ReencodePicture output: Input file #0 (/Users/user11/ffmpeg/input.tif):
May 31, 2021 2:15:51 PM 
INFO: ReencodePicture output:   Input stream #0:0 (video): 1 packets read (18100 bytes); 1 frames decoded; 
May 31, 2021 2:15:51 PM 
INFO: ReencodePicture output:   Total: 1 packets (18100 bytes) demuxed
May 31, 2021 2:15:51 PM 
INFO: ReencodePicture output: Output file #0 (/Users/user11/ffmpeg/output.png):
May 31, 2021 2:15:51 PM 
INFO: ReencodePicture output:   Output stream #0:0 (video): 1 frames encoded; 1 packets muxed (38013 bytes); 
May 31, 2021 2:15:51 PM 
INFO: ReencodePicture output:   Total: 1 packets (38013 bytes) muxed
May 31, 2021 2:15:51 PM 
INFO: ReencodePicture output: [AVIOContext @ 0x7fa7f4f041c0] Statistics: 18100 bytes read, 0 seeks
May 31, 2021 2:15:51 PM 
INFO: BinaryRepositoryHelper.convertPixTo ffmpeg Process returned : java.lang.UNIXProcess@27ddd392, ended with code 0, and returned in 160 ms, out=/Users/user11/ffmpeg/output.png exists=true





  • 有没有办法识别将被转换为具有反转颜色的png的tiff文件?这样我们就可以知道“否定”参数必须应用于哪些文件
  • 是否还有其他FFMPEG参数可以使用
  • 在过去的几天里,这个问题一直让我们抓狂。任何帮助都将不胜感激。 谢谢

    Tif图片示例


    似乎是一个坏文件

    ImageMagick
    convert
    也不喜欢输入。建议使用
    tiffset
    设置光度学解释标记:

    tiffset-s 262 0 input.tif
    

    现在,使用
    ffmpeg
    进行转换应该可以正常工作。

    显示第一个ffmpeg命令的完整日志。提供一个指向有问题的TIFF文件的链接。您好,Mounia,请在代码括号中添加命令,以获得更好的阅读体验。欢迎来到SO:)非常感谢您的干预。问题中增加了其他信息。如果您能帮助我们检测负责将颜色从tif转换为png的参数,我们将不胜感激。