37

I see that there are a few questions on this subject but I am still getting errors. All I want to do is convert videos in my library to HEVC so they take up less space.
I've tried this:

ffmpeg -i input.mp4 -c:v libx265 output.mp4

ffmpeg seems to take a long time and the output seems to be about the right size. The video will play with VLC but the icon is weird and when I try to open it with QuickTime, I get the error: 'The document “output.mov” could not be opened. The file isn’t compatible with QuickTime Player.'

I don't want to change any of the fancy settings. I just want the files to take up less space and with minimal or no quality loss.

Thanks!

EDIT: Having trouble keeping the time stamp that I put into the videos.
Originally I was using exiftool in terminal. But, sometimes that doesn’t work with videos, so I would airdrop them to my iPhone, use an app called Metapho to change the dates, and then airdrop them back. Exiftool was create but sometimes I just wouldn’t work. It would change the date to something like 1109212 Aug 2nd. Weird. Bottom line is that when I do these conversions, I really don’t want lose the time stamps in them.

ORIGINAL FILE THAT I TIMESTAMPED, IN .264

ffmpeg version 4.2.1 Copyright (c) 2000-2019 the FFmpeg developers
  built with Apple clang version 11.0.0 (clang-1100.0.33.8)
  configuration: --prefix=/usr/local/Cellar/ffmpeg/4.2.1_2 --enable-shared --enable-pthreads --enable-version3 --enable-avresample --cc=clang --host-cflags='-I/Library/Java/JavaVirtualMachines/adoptopenjdk-13.jdk/Contents/Home/include -I/Library/Java/JavaVirtualMachines/adoptopenjdk-13.jdk/Contents/Home/include/darwin -fno-stack-check' --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-libvidstab --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-libsoxr --enable-videotoolbox --disable-libjack --disable-indev=jack
  libavutil      56. 31.100 / 56. 31.100
  libavcodec     58. 54.100 / 58. 54.100
  libavformat    58. 29.100 / 58. 29.100
  libavdevice    58.  8.100 / 58.  8.100
  libavfilter     7. 57.100 /  7. 57.100
  libavresample   4.  0.  0 /  4.  0.  0
  libswscale      5.  5.100 /  5.  5.100
  libswresample   3.  5.100 /  3.  5.100
  libpostproc    55.  5.100 / 55.  5.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'test_original.mov':
  Metadata:
    major_brand     : qt  
    minor_version   : 0
    compatible_brands: qt  
    creation_time   : 2019-10-22T18:48:43.000000Z
    encoder         : HandBrake 0.10.2 2015060900
    com.apple.quicktime.creationdate: 1994-12-25T18:00:00Z
  Duration: 00:01:21.27, start: 0.000000, bitrate: 800 kb/s
    Chapter #0:0: start 0.000000, end 81.265000
    Metadata:
      title           : Chapter 12
    Stream #0:0(und): Video: h264 (Main) (avc1 / 0x31637661), yuv420p(tv, smpte170m/smpte170m/bt709, progressive), 710x482 [SAR 58409:65535 DAR 1043348:794715], 634 kb/s, SAR 9172:10291 DAR 404229:307900, 29.95 fps, 29.97 tbr, 90k tbn, 180k tbc (default)
    Metadata:
      creation_time   : 2019-10-22T18:48:43.000000Z
      handler_name    : Core Media Video
      encoder         : 'avc1'
    Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 160 kb/s (default)
    Metadata:
      creation_time   : 2019-10-22T18:48:43.000000Z
      handler_name    : Core Media Audio
    Stream #0:2(und): Data: bin_data (text / 0x74786574), 0 kb/s
    Metadata:
      creation_time   : 2019-10-22T18:48:43.000000Z
      handler_name    : Core Media Text
At least one output file must be specified

FILE CONVERTED TO HEVC, WITHOUT -COPYTS TAG

ffmpeg version 4.2.1 Copyright (c) 2000-2019 the FFmpeg developers
  built with Apple clang version 11.0.0 (clang-1100.0.33.8)
  configuration: --prefix=/usr/local/Cellar/ffmpeg/4.2.1_2 --enable-shared --enable-pthreads --enable-version3 --enable-avresample --cc=clang --host-cflags='-I/Library/Java/JavaVirtualMachines/adoptopenjdk-13.jdk/Contents/Home/include -I/Library/Java/JavaVirtualMachines/adoptopenjdk-13.jdk/Contents/Home/include/darwin -fno-stack-check' --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-libvidstab --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-libsoxr --enable-videotoolbox --disable-libjack --disable-indev=jack
  libavutil      56. 31.100 / 56. 31.100
  libavcodec     58. 54.100 / 58. 54.100
  libavformat    58. 29.100 / 58. 29.100
  libavdevice    58.  8.100 / 58.  8.100
  libavfilter     7. 57.100 /  7. 57.100
  libavresample   4.  0.  0 /  4.  0.  0
  libswscale      5.  5.100 /  5.  5.100
  libswresample   3.  5.100 /  3.  5.100
  libpostproc    55.  5.100 / 55.  5.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'test_original_HEVC.mov':
  Metadata:
    major_brand     : qt  
    minor_version   : 512
    compatible_brands: qt  
    encoder         : Lavf58.29.100
  Duration: 00:01:21.30, start: 0.000000, bitrate: 494 kb/s
    Chapter #0:0: start 0.000000, end 81.265000
    Metadata:
      title           : Chapter 12
    Stream #0:0: Video: hevc (Main) (hvc1 / 0x31637668), yuv420p(tv, progressive), 710x482 [SAR 9172:10291 DAR 404229:307900], 356 kb/s, 29.97 fps, 29.97 tbr, 30k tbn, 29.97 tbc (default)
    Metadata:
      handler_name    : Core Media Video
      encoder         : Lavc58.54.100 libx265
    Stream #0:1: Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 128 kb/s (default)
    Metadata:
      handler_name    : Core Media Audio
    Stream #0:2(eng): Data: bin_data (text / 0x74786574), 0 kb/s
    Metadata:
      handler_name    : SubtitleHandler
At least one output file must be specified

FILE CONVERTED TO HEVC, WITH -COPYTS TAG

ffmpeg version 4.2.1 Copyright (c) 2000-2019 the FFmpeg developers
  built with Apple clang version 11.0.0 (clang-1100.0.33.8)
  configuration: --prefix=/usr/local/Cellar/ffmpeg/4.2.1_2 --enable-shared --enable-pthreads --enable-version3 --enable-avresample --cc=clang --host-cflags='-I/Library/Java/JavaVirtualMachines/adoptopenjdk-13.jdk/Contents/Home/include -I/Library/Java/JavaVirtualMachines/adoptopenjdk-13.jdk/Contents/Home/include/darwin -fno-stack-check' --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-libvidstab --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-libsoxr --enable-videotoolbox --disable-libjack --disable-indev=jack
  libavutil      56. 31.100 / 56. 31.100
  libavcodec     58. 54.100 / 58. 54.100
  libavformat    58. 29.100 / 58. 29.100
  libavdevice    58.  8.100 / 58.  8.100
  libavfilter     7. 57.100 /  7. 57.100
  libavresample   4.  0.  0 /  4.  0.  0
  libswscale      5.  5.100 /  5.  5.100
  libswresample   3.  5.100 /  3.  5.100
  libpostproc    55.  5.100 / 55.  5.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'test_original_HEVC_keepts.mov':
  Metadata:
    major_brand     : qt  
    minor_version   : 512
    compatible_brands: qt  
    encoder         : Lavf58.29.100
  Duration: 00:01:21.30, start: 0.000000, bitrate: 494 kb/s
    Chapter #0:0: start 0.000000, end 81.265000
    Metadata:
      title           : Chapter 12
    Stream #0:0: Video: hevc (Main) (hvc1 / 0x31637668), yuv420p(tv, progressive), 710x482 [SAR 9172:10291 DAR 404229:307900], 356 kb/s, 29.97 fps, 29.97 tbr, 30k tbn, 29.97 tbc (default)
    Metadata:
      handler_name    : Core Media Video
      encoder         : Lavc58.54.100 libx265
    Stream #0:1: Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 128 kb/s (default)
    Metadata:
      handler_name    : Core Media Audio
    Stream #0:2(eng): Data: bin_data (text / 0x74786574), 0 kb/s
    Metadata:
      handler_name    : SubtitleHandler
At least one output file must be specified
Gyan
  • 85,394
  • 9
  • 169
  • 201
John Terragnoli
  • 371
  • 1
  • 3
  • 4
  • 13
    Try `ffmpeg -i input.mp4 -c:v libx265 -vtag hvc1 output.mp4` – Gyan Nov 07 '19 at 06:12
  • Thanks! That worked! I spent way too much time trying to figure out that on my own. One last question: I'd like to keep the same time stamp. I know the tag -copyts is supposed to do the job, but the time stamp is still changing. This is what I tried: – John Terragnoli Nov 07 '19 at 15:52
  • 1
    ffmpeg -i input.mov -copyts -c:v libx265 -vtag hvc1 output.mov – John Terragnoli Nov 07 '19 at 15:52
  • Also, does the solution you posted reduce the quality? – John Terragnoli Nov 07 '19 at 15:53
  • No, same quality as your command. Why do you want to copy original timestamps? – Gyan Nov 07 '19 at 15:57
  • ok, but the conversion in general will reduce the quality, right? I can't seem to notice a difference. – John Terragnoli Nov 07 '19 at 20:16
  • I'm working on a project to convert all our home videos from 8mm tapes to a useable format. I clipped a lot of the tapes into separate files and timestamped many of them so that they would show up at the right point in my Google Photos timeline. I really don't want to redo the time-stamps, but the videos are starting to take up a lot of space and I was wondering if there was anyway to convert to HEVC without changing the timestamps. – John Terragnoli Nov 07 '19 at 20:18
  • `timestamp` has a specific meaning in media files and does not refer to the clock date+time at which the file was created. That is a creation_time metadata field and copyts has nothing to do with that. Normally, ffmpeg should copy the creation_time over. Can you share one of your source files? – Gyan Nov 09 '19 at 06:53

4 Answers4

48

This answer was posted (under the CC BY-SA 4.0 license) as a comment by Gyan to the question Convert videos from .264 to .265 (HEVC) with ffmpeg.


Run this command for x265 convertation:

ffmpeg -i input.mp4 -c:v libx265 -vtag hvc1 output.mp4
Amin Shojaei
  • 5,451
  • 2
  • 38
  • 46
42

Convert 4k to 1080 (no change in codec)

ffmpeg -i input4kvid.mp4 -vf scale=1920:1080 -c:a copy output1080vid.mp4

Convert h.264 to h.265 (no change in resolution)

ffmpeg -i input.mp4 -c:v libx265 -vtag hvc1 -c:a copy output.mp4

Convert 4k(h.264) to 1080(h.265)

  • Downscaling + Change in compression codec
ffmpeg -i input.mp4 -c:v libx265 -vtag hvc1 -vf scale=1920:1080 -crf 20 -c:a copy output.mp4

Options Explained

-i input file name or file path

-c:v libx265 -vtag hvc1 selecting compression. Default is libx264

-vf scale=1920:1080 specifying output resolution

-c:a copy copy audio as it is without any compression

-preset slow ask compression algorithm to take more time & look for more areas for compression. Default is medium. Other options are faster, fast, medium, slow, slower

-crf 20 Compression quality

-crf 0 high-quality, low compression, large file

-crf 23 default

-crf 51 low-quality, high compression, small file

-vtag hvc1 use codec hvc1 (a.k.a. HEVC or h.265) during conversion.

If -vtag isn't specified (like in the first snippet), it will then use the codec used in the src file.

KeshavDulal
  • 3,060
  • 29
  • 30
  • 1
    What does `-vtag hvc1` do? – HappyFace Aug 16 '22 at 08:30
  • 2
    `-vtag hvc1` explicitly says hey, use codec `hvc1` (aka HEVC - High-Efficiency Video Codec or h.265) during conversion. If it isn't specified (like in the first snippet), it will then use the codec used in the src file. – KeshavDulal Aug 16 '22 at 12:01
12

If you have NVIDIA GPU, you can use hevc_nvenc for the encoder parameter which should be faster than a CPU encoder.

ffmpeg -i input.mp4 -c:v hevc_nvenc -rc vbr_hq -cq 18 -b:v 0k -2pass 0 output.mp4

However, note that hardware encoded files aren't as optimized as CPU encoded

brunoais
  • 6,258
  • 8
  • 39
  • 59
Showfom
  • 121
  • 1
  • 2
-5

for mobile phone users it's better to use the scale of 1080*1920.

ffmpeg -i input4kvid.mp4 -vf scale=1080:1920 -c:a copy output1080vid.mp4