Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HEVC output is not playable by QuickTime on macOS 10.13 High Sierra Beta 6 #160

Closed
ntodd opened this issue Aug 16, 2017 · 36 comments

Comments

Projects
None yet
10 participants
@ntodd
Copy link

commented Aug 16, 2017

Using transcode-video --handbrake-option encoder=x265 --mp4 I am unable to create a file that can be played back by QuickTime on 10.13. It appears the output is not compatible with the upcoming HEVC support in macOS. I have not tested playback on iOS 11 beta yet.

video_transcoding 0.17.3
macOS 10.13 beta 6

@donmelton donmelton self-assigned this Aug 16, 2017

@donmelton

This comment has been minimized.

Copy link
Owner

commented Aug 17, 2017

@ntodd Unfortunately, as you may have heard me say on podcasts, "Gramps don't beta." So, I won't install that version of macOS to test.

But the key question is, which version of HandBrakeCLI are you using? Because if there's a generation bug here, it's going to be with HandBrake itself or with the version of LibAV that it includes.

So, you should file a bug with the HandBrake team about this is someone hasn't done so already.

@donmelton

This comment has been minimized.

Copy link
Owner

commented Aug 17, 2017

@ntodd BTW, sorry it took me so long to reply but I've been AFK all day.

@mikumi

This comment has been minimized.

Copy link

commented Aug 19, 2017

@ntodd
I had the same problem. I'm no expert, but looks like it has to do with the packaging of the stream, see this stackoverflow answer: https://stackoverflow.com/a/32485240/968099

From what I understand transcode-video marks the video stream has hev1, but it actually needs to be marked as hvc1 in order to be recognized by Quick Time.

Running mp4box -raw 1 file.mp4 ans then mp4box -add file_track1.hvc output.mp4 as described in the stackoverflow answer solved the issue for me.

Ideally transcode-video would be able to output hvc1 streams directly, maybe as an option. But it's also possible Quick Time won't have this issue anymore in future betas.

@donmelton

This comment has been minimized.

Copy link
Owner

commented Aug 19, 2017

@mikumi Thanks for the information! That would explain a lot to @ntodd and myself. :)

However, it's not transcode-video that is marking the streams as such. It's HandBrakeCLI or the LibAV library within it.

Of course, if the HandBrake team doesn't fix this problem, I could do it within transcode-video by calling mp4box directly. However, that would add another dependency.

@ntodd

This comment has been minimized.

Copy link
Author

commented Aug 19, 2017

Been digging a bit and might have some info.

It looks like ffmpeg has added hvc1 tag support with these two commits:
FFmpeg/FFmpeg@974d508
FFmpeg/FFmpeg@369a3e1

They are currently in master and do not appear to be in a ffmpeg release yet. With the patches, you should be able to do the following with ffmpeg directly to get an hvc1 tagged version:

ffmpeg -i input.mp4 -vcodec copy -acodec copy -tag:v hvc1 output.mp4

I will try to build from master and test, but probably won't have time to check until tomorrow.

@donmelton

This comment has been minimized.

Copy link
Owner

commented Aug 19, 2017

@ntodd Excellent! Since we already have a dependency on FFmpeg then this will make it easier to eventually add support. Unless, of course, the HandBrake team does it first.

Thanks for the research!

@ntodd

This comment has been minimized.

Copy link
Author

commented Aug 22, 2017

Confirming FFmpeg compiled from source works as described above. I tagged a version of the docker image that has the necessary patches (as well as latest libx265) if anyone needs it. Run it with: docker run -itv "pwd":/data ntodd/video-transcoding:0.17.3-ffmpeg

You can then convert hev1 tagged h265 to hvc1 with: ffmpeg -i input.mp4 -vcodec copy -acodec copy -tag:v hvc1 output.mp4 or similar.

Output works in QuickTime on MacOS 10.13 beta 6.

@donmelton

This comment has been minimized.

Copy link
Owner

commented Aug 22, 2017

@ntodd Very cool. And thanks!

ntodd pushed a commit to ntodd/video_transcoding_docker that referenced this issue Aug 22, 2017

@mikumi

This comment has been minimized.

Copy link

commented Aug 23, 2017

@ntodd @donmelton
I just found this. Haven't tested it yet, but looks like the latest handbrake nightly builds will support hvc1 out of the box:
HandBrake/HandBrake@67dfaca

Maybe we just have to wait a little :)

Update: Tested & Works

@donmelton

This comment has been minimized.

Copy link
Owner

commented Aug 23, 2017

@mikumi That's great news! And a much better way to fix this problem.

@k06a

This comment has been minimized.

Copy link

commented Oct 10, 2017

Install HEAD version of ffmpeg:

brew install ffmpeg --with-x265 --HEAD

Update hev1 tag to hvc1:

ffmpeg -i input.mp4 -vcodec copy -acodec copy -tag:v hvc1 output.mp4
@donmelton

This comment has been minimized.

Copy link
Owner

commented Oct 10, 2017

Thanks, @k06a! It's good to know how to do that with FFmpeg, too.

@nobodo

This comment has been minimized.

Copy link

commented Oct 30, 2017

I needed -tag:a ac-3 to make audio work and I had the input file as .mov so output had to be .mov too (.mov -> .mp4 did not work for Quicktime).

ffmpeg -i input.mov -vcodec copy -acodec copy -tag:v hvc1 -tag:a ac-3 output.mov

@k06a

This comment has been minimized.

Copy link

commented Oct 30, 2017

Full version posted here: https://gist.github.com/k06a/45f4ff4e52a7c0ad2add370ab1a315e7

Installation:

brew install mp4box
brew install ffmpeg --with-fdk-aac --with-tools --with-freetype --with-libass --with-libvorbis --with-libvpx --with-x265 --HEAD

Converting video, than audio, than combining into 1 file and finally fix tag:

ffmpeg -i input.mov -c:v libx265 -c:a aac -preset ultrafast -an -x265-params crf=25 video.mp4
ffmpeg -i input.mov -c:a libfdk_aac -profile:a aac_he_v2 audio.aac
mp4box -add audio.aac -add video.mp4 output.mp4
ffmpeg -i output.mp4 -vcodec copy -acodec copy -tag:v hvc1 output_apple.mp4
@donmelton

This comment has been minimized.

Copy link
Owner

commented Oct 30, 2017

@k06a Thanks for doing all the research and testing on this!

@aujang

This comment has been minimized.

Copy link

commented Nov 12, 2017

@ntodd Thank you so much for this. I was able to convert a large batch of improperly tagged files in seconds and they now all play flawlessly on my Apple TV. You're my hero. :)

@lazling

This comment has been minimized.

Copy link

commented Nov 23, 2017

Try a HEVC converter for Mac like brorsoft video converter for mac.

@donmelton

This comment has been minimized.

Copy link
Owner

commented Nov 23, 2017

@lazling Do you mean the iSkysoft iMedia Converter? I think that would just re-transcode the input and degrade quality. Something a little more subtle and low-level is needed for this issue when the files are already transcoded. I think this is just a tagging problem with metadata.

@lazling

This comment has been minimized.

Copy link

commented Nov 28, 2017

@donmelton I mean Brorsoft Video Converter. It is a good HEVC/h265 converting tool. Converting always brings some loss but it can be ignore when you play it.

@tommydj10

This comment has been minimized.

Copy link

commented Dec 4, 2017

In HandBrake if you use audio coding .mp3 then the audio will NOT work for QuickTime, but if you select HE-AAC then it works after having run the command ffmpeg -i input.mp4 -vcodec copy -acodec copy -tag:v hvc1 output.mp4

@ntodd

This comment has been minimized.

Copy link
Author

commented Dec 9, 2017

If it helps anyone, I built a version of the docker image that compiles more current versions of ffmpeg and handbrake so output from transcode-video is tagged with hvc1 correctly. You can also use included ffmpeg to re-tag any existing h265 videos.

You can pull ntodd/video-transcoding:head to get this version and the dockerfile is at https://github.com/ntodd/video_transcoding_docker/blob/head/video-transcoding/Dockerfile.

Instructions for basic usage of the docker image are at https://hub.docker.com/r/ntodd/video-transcoding/, just be sure to pull the head version to get the latest.

@donmelton

This comment has been minimized.

Copy link
Owner

commented Dec 9, 2017

@ntodd Thanks!

@Necktwi

This comment has been minimized.

Copy link

commented Jan 22, 2018

@k06a what is the option -an? I want to use default crf and default preset;
ffmpeg -i input.mov -c:v libx265 -c:a aac -an video.mp4
does this work?

@donmelton

This comment has been minimized.

Copy link
Owner

commented Jan 22, 2018

@Necktwi The -an option for ffmpeg disables audio output so I don't think you want to use that.

@Necktwi

This comment has been minimized.

Copy link

commented Jan 23, 2018

@k06a I get Unable to initialize the encoder: SBR library initialization error

ffmpeg -y -i ArjunReddy.mp4 -c:a libfdk_aac -profile:a aac_he_v2 audio.aac
ffmpeg version 3.4.1 Copyright (c) 2000-2017 the FFmpeg developers
  built with Apple LLVM version 9.0.0 (clang-900.0.39.2)
  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-libass --enable-libfdk-aac --enable-libfreetype --enable-libmp3lame --enable-libvorbis --enable-libvpx --enable-libx264 --enable-libx265 --enable-libxvid --enable-opencl --enable-videotoolbox --disable-lzma --enable-nonfree
  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 'ArjunReddy.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    title           : www.movierulz.ms
    encoder         : Lavf57.71.100
  Duration: 03:01:42.99, start: 0.000000, bitrate: 1125 kb/s
    Stream #0:0(tel): Video: h264 (Main) (avc1 / 0x31637661), yuv420p(tv, bt709), 1280x544 [SAR 1:1 DAR 40:17], 990 kb/s, 20.31 fps, 16k tbr, 16k tbn, 180k tbc (default)
    Metadata:
      handler_name    : VideoHandler
    Stream #0:1(tel): Audio: ac3 (ac-3 / 0x332D6361), 44100 Hz, 5.1(side), fltp, 128 kb/s (default)
    Metadata:
      handler_name    : SoundHandler
    Side data:
      audio service type: main
Stream mapping:
  Stream #0:1 -> #0:0 (ac3 (native) -> aac (libfdk_aac))
Press [q] to stop, [?] for help
[libfdk_aac @ 0x7fd9a5801800] Unable to initialize the encoder: SBR library initialization error
Error initializing output stream 0:0 -- Error while opening encoder for output stream #0:0 - maybe incorrect parameters such as bit_rate, rate, width or height
Conversion failed!

@k06a

This comment has been minimized.

Copy link

commented Jan 23, 2018

@Necktwi try aac_he profile instead of aac_he_v2, looks like aac_he_v2 is for stereo only, but you have mono audio (one of 5.1 maybe?)

@k06a

This comment has been minimized.

Copy link

commented Jan 23, 2018

@Necktwi

This comment has been minimized.

Copy link

commented Jan 23, 2018

@k06a, using aac_he in the above gave a time-scaled video! Actual clip is of 5 min but the output is 15 min.
screen shot 2018-01-23 at 8 11 15 pm

@k06a

This comment has been minimized.

Copy link

commented Jan 23, 2018

@Necktwi you can try to keep original audio by removing -an option on video convertion. At least until we discover how make aach_he work as expected.

@Necktwi

This comment has been minimized.

Copy link

commented Jan 23, 2018

@k06a please find the video I am trying to convert at https://github.com/necktwi/toHEVC/blob/master/ARCut.mp4

@Necktwi

This comment has been minimized.

Copy link

commented Jan 23, 2018

if i remove -an i get Too many packets buffered for output stream 0:1.

@ntodd

This comment has been minimized.

Copy link
Author

commented Jan 23, 2018

@Necktwi Your source file is causing ffmpeg to run out of buffer space while waiting to write the output. I was able to get your file converted (with some warnings) by adding -max_muxing_queue_size 500 to the ffmpeg options.

However, this doesn't appear related to the original HEVC playback issue above or the video_transcoding package, so you might be able to get the best help regarding your source file issues from the ffmpeg community. I found this ffmpeg issue which might be a good place to start.

@donmelton Since the original problem in this issue is resolved with newer ffmpeg and Handbrake dependencies, do you think it's appropriate to note the recommended versions for optimal HEVC output in the readme and close this issue? I will probably promote my head version of the docker image to latest soon to include these updated dependencies by default.

@donmelton

This comment has been minimized.

Copy link
Owner

commented Jan 23, 2018

@ntodd I don't normally recommend unreleased versions (particularly of HandBrake) but why don't you let me know which versions those are and I'll see how I can explain that.

@FlorianWendelborn

This comment has been minimized.

Copy link

commented Feb 18, 2018

This worked for me: https://danconnor.com/posts/21d8bd7c22f6ae6b423c3c09/how_to_encode_h_265_hevc_video_that_will_play_in_quicktime_on_macos_using_ffmpeg_

I had some files from an older camera that just refused being converted by any software I threw at them. Now it works flawlessly in HEVC.

@donmelton

This comment has been minimized.

Copy link
Owner

commented Feb 18, 2018

@dodekeract Sorry that I missed this yesterday. That's a very handy link. Thanks!

@donmelton

This comment has been minimized.

Copy link
Owner

commented Oct 20, 2018

I'm pretty sure this has been resolved by now. And, if not, there's not much I can do about it. So I'm going to close this.

@donmelton donmelton closed this Oct 20, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.