tiff 輸出中的 ffmpeg 色調偏移

tiff 輸出中的 ffmpeg 色調偏移

我使用這些命令從同一輸入 mpeg2 檔案產生 tiff 和 jpeg 輸出

ffmpeg -ss 14 -i '../test/test-in.mpg' -q:v 3 -vframes 1 -aspect 4:3 -vf "crop=22/23*in_w:22/23*in_h,yadif,比例=736:539,pad=736:552:0:7" '../test/test-out.jpg'

ffmpeg -ss 14 -i '../test/test-in.mpg' -vframes 1 -aspect 445:326 -vf "crop=22/23*in_w:22/23*in_h,yadif,scale=720:527 “'../單元測試/out.tiff'

tiff 非常紫色/粉紅色。 jpeg 還可以。

Q:什麼可能導致 tiff 輸出中的顏色偏移,以及如何防止它?

命令列輸出

ffmpeg -ss 15 -i '../test/test.mpg' -vframes 1 -aspect 4:3 -vf "crop=21/23*in_w:21/23*in_h ,yadif,scale=720:540" -vstats_file /home/factory/log/20140630143715-mpg2stills.log '../test/test.tiff' 

ffmpeg version 1.2.4 Copyright (c) 2000-2013 the FFmpeg developers
  built on Oct 26 2013 23:16:12 with gcc 4.6 (Ubuntu/Linaro 4.6.3-1ubuntu5)
  configuration: --enable-gpl --enable-version3 --enable-nonfree --enable-postproc --enable-libfaac --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libtheora --enable-libvorbis --enable-libvpx --enable-libx264 --enable-libxvid
  libavutil      52. 18.100 / 52. 18.100
  libavcodec     54. 92.100 / 54. 92.100
  libavformat    54. 63.104 / 54. 63.104
  libavdevice    54.  3.103 / 54.  3.103
  libavfilter     3. 42.103 /  3. 42.103
  libswscale      2.  2.100 /  2.  2.100
  libswresample   0. 17.102 /  0. 17.102
  libpostproc    52.  2.100 / 52.  2.100
[mpeg @ 0xa4a1440] max_analyze_duration 5000000 reached at 5016000 microseconds
Input #0, mpeg, from '../test/test.mpg':
  Duration: 00:00:30.62, start: 0.384000, bitrate: 7746 kb/s
    Stream #0:0[0x1c0]: Audio: mp2, 48000 Hz, stereo, s16p, 384 kb/s
    Stream #0:1[0x1e0]: Video: mpeg2video (Main), yuv420p, 720x576 [SAR 16:15 DAR 4:3], 25 fps, 25 tbr, 90k tbn, 50 tbc
Output #0, image2, to '../test/test.tiff':
  Metadata:
    encoder         : Lavf54.63.104
    Stream #0:0: Video: tiff, yuv420p, 720x540 [SAR 1:1 DAR 4:3], q=2-31, 200 kb/s, 90k tbn, 25 tbc
Stream mapping:
  Stream #0:1 -> #0:0 (mpeg2video -> tiff)
Press [q] to stop, [?] for help
[mpeg2video @ 0xa4a3060] warning: first frame is no keyframe
frame=    1 fps=0.0 q=0.0 Lsize=N/A time=00:00:00.04 bitrate=N/A    
video:563kB audio:0kB subtitle:0 global headers:0kB muxing overhead -100.003817%

輸入 mpg 的裁剪版本(由 vlc 捕捉)

輸入 mpg 的裁剪版本

輸出 tiff 的裁剪版本(轉換為 png 以便上傳)

輸出 tiff 的裁剪版本

答案1

問題出在 tiff 影像的色彩空間。 ffmpeg 從 mpeg 檔案複製色彩空間,該檔案是 YUV 編碼的。 tiff 檔案的 exif 資料顯示它是“YCbCr”,即 YUV。

某些應用程式可以查看生成的 tiff 文件,但其他應用程式(尤其是 Photoshop)報告該文件已損壞。不確定這是否是 ffmpeg 中的錯誤。所以我透過 imagemagick 傳輸結果而不進行任何轉換,這似乎修復了文件。

然而,imagemagick 假設它是 RGB,並將 exif 資料設為 RGB,而沒有實際更改影像資料。這就是色調轉變發生的情況。同樣,不確定這是否是 imagemagick 中的錯誤。

jpeg 沒有任何問題。

一種正確的解決方案是在 ffmpeg 命令中指定要使用的 pix_fmt。看 https://ffmpeg.org/ffmpeg.html#Advanced-Video-options

所以這樣做了:

ffmpeg -ss 14 -i '../test/test-in.mpg' -vframes 1 -aspect 445:326 -pix_fmt rgb24 -vf "crop=22/23*in_w:22/23*in_h,yadif,scale=720:527" '../unit-test/out.tiff'

相關內容