How can I maintain a 2x pixel density when encoding a Retina retina image using ffmpeg?

Whenever I use ffmpeg to encode a HiDPI / Retina screen recording, the video plays at 2x, so it looks blurry because the pixel density is not preserved.

How to keep original pixel density for HiDPI screen recordings using ffmpeg?

How to reproduce:

  • Use QuickTime Player to create screen recordings on Mac Retina.
  • Play the video recorded in the QuickTime player using the view ⌘1 Actual Size. Please note that its 2: 1 playback on the Retina Display screen, so the video looks sharp. Its playback in half the space of the actual recorded pixels.
  • Use ffmpeg to encode the video with the following command:

    ffmpeg -i haha.mov -c:v libx264 -crf 23 haha-lg.mov
    
  • Play a new compressed ffmpeg video in QuickTime Player using a view ⌘1 Actual Size. Please note that its playback is 1: 1, so the video looks fuzzy.

To clarify, the video does not look blurry because it is compressed. Rather, it looks blurry because the video plays twice as much as it should, with a density of 1: 1 pixels, instead of the required density of 2: 1 pixels, apparently because some metadata is discarded during encoding.

For recording, the VLC plays both videos too large (blurry). Thus, the ability to play HiDPI video seems to be a feature of the QuickTime player.

Here is the detailed information ffmpeg shows the original entry on the screen:

Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'haha.mov':
  Metadata:
    major_brand     : qt  
    minor_version   : 0
    compatible_brands: qt  
    creation_time   : 2018-02-26T16:46:00.000000Z
    com.apple.quicktime.make: Apple
    com.apple.quicktime.model: iMac18,3
    com.apple.quicktime.software: Mac OS X 10.13.3 (17D102)
    com.apple.quicktime.creationdate: 2018-02-26T10:45:50-0600
  Duration: 00:00:04.35, start: 0.000000, bitrate: 10947 kb/s
    Stream #0:0(und): Video: h264 (Main) (avc1 / 0x31637661), yuv420p(tv, bt709), 1396x928 [SAR 1:1 DAR 349:232], 10701 kb/s, 60 fps, 60 tbr, 6k tbn, 12k tbc (default)
    Metadata:
      creation_time   : 2018-02-26T16:46:00.000000Z
      handler_name    : Core Media Data Handler
      encoder         : H.264

And here is the information for the compressed version of ffmpeg:

Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'haha-lg.mov':
  Metadata:
    major_brand     : qt  
    minor_version   : 512
    compatible_brands: qt  
    encoder         : Lavf57.83.100
  Duration: 00:00:04.35, start: 0.000000, bitrate: 1923 kb/s
    Stream #0:0(eng): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 1396x928 [SAR 1:1 DAR 349:232], 1783 kb/s, 60 fps, 60 tbr, 15360 tbn, 120 tbc (default)
    Metadata:
      handler_name    : DataHandler
      encoder         : Lavc57.107.100 libx264
+4
1

FFmpeg . () FFmpeg bug tracker, , , .

+3

Source: https://habr.com/ru/post/1599288/


All Articles