Re-encode 4K video to H.265/HEVC with FFmpeg for playback in QuickTime

9,341

Some players rely on metadata to identify if the contents of the file can be used. QT belongs to this category. As confirmed in comments, assigning a codec tag of hvc1 allows playback in QT,

ffmpeg -i otomatsuri.mp4 -c copy -map 0 -vtag hvc1 otomatsuri.mov
Share:
9,341

Related videos on Youtube

rgov
Author by

rgov

Updated on September 18, 2022

Comments

  • rgov
    rgov almost 2 years

    I have a one hour 4K video which was weighing in at 10 GB. I thought I'd try re-encoding to HEVC using FFmpeg to try to save space, something I hadn't tried before.

    However, I switched the container format from .m4v to .mp4, which I didn't realize that QuickTime Player cannot play; it only supports HEVC streams inside of .mov containers. VLC can play the .mp4, so the conversion seems to have succeeded.

    So I tried to switch the container format to .mov, but QuickTime still doesn't want to open it.

    Is there an additional step I'm missing? The conversion ran overnight so I'd rather not do it again, if there's a way to simply change the container.

    $ ffmpeg -i otomatsuri.m4v -c:v libx265 -preset medium -crf 28 -c:a aac -b:a 128k otomatsuri.mp4
    ffmpeg version 3.4.1 Copyright (c) 2000-2017 the FFmpeg developers
      built with Apple LLVM version 9.1.0 (clang-902.0.30)
      configuration: --prefix=/usr/local/Cellar/ffmpeg/3.4.1 --enable-shared --enable-pthreads --enable-version3 --enable-hardcoded-tables --enable-avresample --cc=clang --host-cflags= --host-ldflags= --enable-gpl --enable-libmp3lame --enable-libx264 --enable-libx265 --enable-libxvid --enable-opencl --enable-videotoolbox --disable-lzma
      libavutil      55. 78.100 / 55. 78.100
      libavcodec     57.107.100 / 57.107.100
      libavformat    57. 83.100 / 57. 83.100
      libavdevice    57. 10.100 / 57. 10.100
      libavfilter     6.107.100 /  6.107.100
      libavresample   3.  7.  0 /  3.  7.  0
      libswscale      4.  8.100 /  4.  8.100
      libswresample   2.  9.100 /  2.  9.100
      libpostproc    54.  7.100 / 54.  7.100
    Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'otomatsuri.m4v':
      Metadata:
        major_brand     : M4V 
        minor_version   : 1
        compatible_brands: M4V M4A mp42isom
        creation_time   : 2018-02-09T09:37:48.000000Z
        encoder         : Lavf57.83.100
      Duration: 00:53:53.00, start: 0.000000, bitrate: 24377 kb/s
        Stream #0:0(und): Audio: aac (LC) (mp4a / 0x6134706D), 32000 Hz, mono, fltp, 95 kb/s (default)
        Metadata:
          creation_time   : 2018-02-09T09:37:48.000000Z
          handler_name    : Core Media Audio
        Stream #0:1(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 2880x2160 [SAR 4:3 DAR 16:9], 24278 kb/s, 24 fps, 24 tbr, 60k tbn, 48 tbc (default)
        Metadata:
          creation_time   : 2018-02-09T09:37:48.000000Z
          handler_name    : Core Media Video
    Stream mapping:
      Stream #0:1 -> #0:0 (h264 (native) -> hevc (libx265))
      Stream #0:0 -> #0:1 (aac (native) -> aac (native))
    Press [q] to stop, [?] for help
    x265 [info]: HEVC encoder version 2.6
    x265 [info]: build info [Mac OS X][clang 9.0.0][64 bit] 8bit+10bit+12bit
    x265 [info]: using cpu capabilities: MMX2 SSE2Fast LZCNT SSSE3 SSE4.2 AVX FMA3 BMI2 AVX2
    x265 [info]: Main profile, Level-5 (Main tier)
    x265 [info]: Thread pool created using 4 threads
    x265 [info]: Slices                              : 1
    x265 [info]: frame threads / pool features       : 2 / wpp(34 rows)
    x265 [info]: Coding QT: max CU size, min CU size : 64 / 8
    x265 [info]: Residual QT: max TU size, max depth : 32 / 1 inter / 1 intra
    x265 [info]: ME / range / subpel / merge         : hex / 57 / 2 / 2
    x265 [info]: Keyframe min / max / scenecut / bias: 24 / 250 / 40 / 5.00
    x265 [info]: Lookahead / bframes / badapt        : 20 / 4 / 2
    x265 [info]: b-pyramid / weightp / weightb       : 1 / 1 / 0
    x265 [info]: References / ref-limit  cu / depth  : 3 / on / on
    x265 [info]: AQ: mode / str / qg-size / cu-tree  : 1 / 1.0 / 32 / 1
    x265 [info]: Rate Control / qCompress            : CRF-28.0 / 0.60
    x265 [info]: tools: rd=3 psy-rd=2.00 rskip signhide tmvp strong-intra-smoothing
    x265 [info]: tools: lslices=8 deblock sao
    Output #0, mp4, to 'otomatsuri.mp4':
      Metadata:
        major_brand     : M4V 
        minor_version   : 1
        compatible_brands: M4V M4A mp42isom
        encoder         : Lavf57.83.100
        Stream #0:0(und): Video: hevc (libx265) (hev1 / 0x31766568), yuv420p, 2880x2160 [SAR 4:3 DAR 16:9], q=2-31, 24 fps, 12288 tbn, 24 tbc (default)
        Metadata:
          creation_time   : 2018-02-09T09:37:48.000000Z
          handler_name    : Core Media Video
          encoder         : Lavc57.107.100 libx265
        Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 32000 Hz, mono, fltp, 128 kb/s (default)
        Metadata:
          creation_time   : 2018-02-09T09:37:48.000000Z
          handler_name    : Core Media Audio
          encoder         : Lavc57.107.100 aac
    frame=77592 fps=2.8 q=-0.0 Lsize= 1670478kB time=00:53:52.93 bitrate=4232.9kbits/s speed=0.117x    
    video:1624946kB audio:43103kB subtitle:0kB other streams:0kB global headers:2kB muxing overhead: 0.145604%
    x265 [info]: frame I:    738, Avg QP:25.05  kb/s: 9283.77 
    x265 [info]: frame P:  20942, Avg QP:27.55  kb/s: 6165.77 
    x265 [info]: frame B:  55912, Avg QP:31.10  kb/s: 3280.92 
    x265 [info]: Weighted P-Frames: Y:21.5% UV:15.2%
    x265 [info]: consecutive B-frames: 7.8% 10.9% 15.9% 46.2% 19.1% 
    
    encoded 77592 frames in 27541.51s (2.82 fps), 4116.63 kb/s, Avg QP:30.09
    [aac @ 0x7fd6d7801e00] Qavg: 58695.016
    
    $ ffmpeg -i otomatsuri.mp4 -c copy -map 0  otomatsuri.mov
    ffmpeg version 3.4.1 Copyright (c) 2000-2017 the FFmpeg developers
      built with Apple LLVM version 9.1.0 (clang-902.0.30)
      configuration: --prefix=/usr/local/Cellar/ffmpeg/3.4.1 --enable-shared --enable-pthreads --enable-version3 --enable-hardcoded-tables --enable-avresample --cc=clang --host-cflags= --host-ldflags= --enable-gpl --enable-libmp3lame --enable-libx264 --enable-libx265 --enable-libxvid --enable-opencl --enable-videotoolbox --disable-lzma
      libavutil      55. 78.100 / 55. 78.100
      libavcodec     57.107.100 / 57.107.100
      libavformat    57. 83.100 / 57. 83.100
      libavdevice    57. 10.100 / 57. 10.100
      libavfilter     6.107.100 /  6.107.100
      libavresample   3.  7.  0 /  3.  7.  0
      libswscale      4.  8.100 /  4.  8.100
      libswresample   2.  9.100 /  2.  9.100
      libpostproc    54.  7.100 / 54.  7.100
    Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'otomatsuri.mp4':
      Metadata:
        major_brand     : isom
        minor_version   : 512
        compatible_brands: isomiso2mp41
        encoder         : Lavf57.83.100
      Duration: 00:53:53.00, start: 0.000000, bitrate: 4232 kb/s
        Stream #0:0(und): Video: hevc (Main) (hev1 / 0x31766568), yuv420p(tv, progressive), 2880x2160 [SAR 4:3 DAR 16:9], 4117 kb/s, 24 fps, 24 tbr, 12288 tbn, 24 tbc (default)
        Metadata:
          handler_name    : VideoHandler
        Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 32000 Hz, mono, fltp, 109 kb/s (default)
        Metadata:
          handler_name    : SoundHandler
    Output #0, mov, to 'otomatsuri.mov':
      Metadata:
        major_brand     : isom
        minor_version   : 512
        compatible_brands: isomiso2mp41
        encoder         : Lavf57.83.100
        Stream #0:0(und): Video: hevc (Main) (hev1 / 0x31766568), yuv420p(tv, progressive), 2880x2160 [SAR 4:3 DAR 16:9], q=2-31, 4117 kb/s, 24 fps, 24 tbr, 12288 tbn, 12288 tbc (default)
        Metadata:
          handler_name    : VideoHandler
        Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 32000 Hz, mono, fltp, 109 kb/s (default)
        Metadata:
          handler_name    : SoundHandler
    Stream mapping:
      Stream #0:0 -> #0:0 (copy)
      Stream #0:1 -> #0:1 (copy)
    Press [q] to stop, [?] for help
    frame=77592 fps=18819 q=-1.0 Lsize= 1670479kB time=00:53:52.90 bitrate=4232.9kbits/s speed= 784x    
    video:1624946kB audio:43103kB subtitle:0kB other streams:0kB global headers:2kB muxing overhead: 0.145614%
    
    • Gyan
      Gyan over 6 years
      It may just be an issue of codec tag. Try ffmpeg -i otomatsuri.mp4 -c copy -map 0 -vtag hvc1 otomatsuri.mov
    • rgov
      rgov over 6 years
      @Mulvya Yes this is it. Want to post as an answer so I can accept it?
  • rgov
    rgov over 6 years
    And I think an all-in one conversion is: ffmpeg -i tomatina.m4v -c:v libx265 -preset medium -crf 28 -vtag hvc1 -c:a aac -b:a 128k tomatina.mov
  • Mint
    Mint almost 3 years
    Not sure what -map 0 does, but I got an error when using it "Could not find tag for codec subrip in stream #2, codec not currently supported in container Could not write header for output file #0 (incorrect codec parameters ?): Invalid argument". Removing it seems to make the command work, and play the file with Quicktime.