【问题标题】:FFmpeg Convert to JPEG works in VLC but not in Mac Preview?FFmpeg Convert to JPEG 适用于 VLC 但不适用于 Mac Preview?
【发布时间】:2019-07-25 03:32:08
【问题描述】:

我正在尝试使用 ffmpeg 将 PNG 图像转换为 JPEG 图像。据我所知,它运行良好,但在 Mac Preview 中无法正常显示。

我正在运行以下命令:

$ ffmpeg -i foo.png foo.jpg

它会产生以下输出:

ffmpeg version 4.1.3 Copyright (c) 2000-2019 the FFmpeg developers
  built with Apple LLVM version 10.0.0 (clang-1000.11.45.5)
  configuration: --prefix=/usr/local/Cellar/ffmpeg/4.1.3_1 --enable-shared --enable-pthreads --enable-version3 --enable-hardcoded-tables --enable-avresample --cc=clang --host-cflags='-I/Library/Java/JavaVirtualMachines/adoptopenjdk-11.0.2.jdk/Contents/Home/include -I/Library/Java/JavaVirtualMachines/adoptopenjdk-11.0.2.jdk/Contents/Home/include/darwin' --host-ldflags= --enable-ffplay --enable-gnutls --enable-gpl --enable-libaom --enable-libbluray --enable-libmp3lame --enable-libopus --enable-librubberband --enable-libsnappy --enable-libtesseract --enable-libtheora --enable-libvorbis --enable-libvpx --enable-libx264 --enable-libx265 --enable-libxvid --enable-lzma --enable-libfontconfig --enable-libfreetype --enable-frei0r --enable-libass --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-librtmp --enable-libspeex --enable-videotoolbox --disable-libjack --disable-indev=jack --enable-libaom --enable-libsoxr
  libavutil      56. 22.100 / 56. 22.100
  libavcodec     58. 35.100 / 58. 35.100
  libavformat    58. 20.100 / 58. 20.100
  libavdevice    58.  5.100 / 58.  5.100
  libavfilter     7. 40.101 /  7. 40.101
  libavresample   4.  0.  0 /  4.  0.  0
  libswscale      5.  3.100 /  5.  3.100
  libswresample   3.  3.100 /  3.  3.100
  libpostproc    55.  3.100 / 55.  3.100
Input #0, png_pipe, from 'foo.png':
  Duration: N/A, bitrate: N/A
    Stream #0:0: Video: png, rgba(pc), 200x231, 25 tbr, 25 tbn, 25 tbc
Stream mapping:
  Stream #0:0 -> #0:0 (png (native) -> mjpeg (native))
Press [q] to stop, [?] for help
[swscaler @ 0x7ffeaf00ae00] deprecated pixel format used, make sure you did set range correctly
Output #0, image2, to 'foo.jpg':
  Metadata:
    encoder         : Lavf58.20.100
    Stream #0:0: Video: mjpeg, yuvj444p(pc), 200x231, q=2-31, 200 kb/s, 25 fps, 25 tbn, 25 tbc
    Metadata:
      encoder         : Lavc58.35.100 mjpeg
    Side data:
      cpb: bitrate max/min/avg: 0/0/200000 buffer size: 0 vbv_delay: -1
frame=    1 fps=0.0 q=3.7 Lsize=N/A time=00:00:00.04 bitrate=N/A speed= 4.7x    
video:12kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: unknown

当我在大多数应用程序(如 VLC 或 Google Chrome)中打开 foo.jpg 时,我得到的正是我所期望的:一个看起来与输入 foo.png 完全相同的图像。

但是,这是在 Finder 预览中显示的内容,与我在“预览”中打开文件时显示的内容相同。

~~~不知这是否与deprecated pixel format used, make sure you did set range correctly错误有关,但我不确定,尤其是图像很好,问题似乎出在其他地方。~~~

似乎deprecated pixel format 错误不是问题(这是内部问题),所以我想我只需要正确指定像素格式。

【问题讨论】:

    标签: image ffmpeg jpeg preview


    【解决方案1】:

    看起来 QT / AVFoundation 不喜欢 JPEG 中的全采样色度。

    第一次尝试

    ffmpeg -i foo.png -pix_fmt yuvj422p foo.jpg
    

    否则,

    ffmpeg -i foo.png -pix_fmt yuvj420p foo.jpg
    

    关于不推荐使用的格式的警告与 ffmpeg 内部有关,而不是生成的输出。

    【讨论】:

    • 我想这与为什么我在制作与 QuickTime 兼容的视频时总是必须使用 -pix_fmt yuv420p 的原因有关?你知道你的额外j有什么不同吗?
    • j 代表jpeg。正常 YUV(在视频中)的范围有限:16-235,而对于 JPEG,它的范围是 0-255。
    • 我明白了。感谢您花时间解释。
    • 感谢您的回复。看起来两者都有效,但根据您的订单,我会坚持使用yuvj244p
    【解决方案2】:

    您可以使用内置的、Apple 提供的 sips“可编写脚本的图像处理系统” 工具来进行转换,从而避免该问题,并且减少对安装外部设备的依赖工具:

    sips -s format jpeg input.png --out output.jpg
    

    【讨论】:

    • 这也是一个不错的选择,但由于我已经安装了 ffmpeg 并将其用于音频/视频转换,我宁愿坚持使用 ffmpeg 而不是学习新工具。
    猜你喜欢
    • 2016-11-07
    • 2020-05-10
    • 1970-01-01
    • 2012-02-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多