lisamelton / other_video_transcoding

Other tools to transcode videos.
MIT License
549 stars 25 forks source link

Quicklook / Quicktime not playing back #50

Closed vasuvasu closed 3 years ago

vasuvasu commented 4 years ago

tl;dr output mp4 file doesn't play back via quicklook/quicktime

After reading about other-transcode and the quality and performance you can get using nvenc I've started looking into building a windows pc to do my hevc encodes moving forward (rather than the 2x5690 Mac Pro I've been using at 8 whole frames per second).

I asked a friend with a windows pc and an rtx 2060 to do a test encode for me and send me back the result. It looks great and I think identical to the handbrake based x265_10bit encode I did only 140fps vs 8fps.

However, when I hit spacebar on the file in Finder, it didn't playback like all my encodes from video_transcoding have done. When I try in Quicktime, same thing. When I playback in IINA it plays back just fine and reports it's decoding with VideoToolbox

On a whim I ran the file through emmgunn's MP4Tools (which I think uses ffmpeg under the hood) and did a passthrough of both video and audio to re-container the file and it works as expected! I saved the file info out for the before and after versions and diff'd the two and noticed a couple differences.

Output from other-transcode "codec_tag_string": "hev1" "codec_tag": "0x31766568" avg_frame_rate": "24000/1001

Output from MP4Tools re-container/passthrough of other-transcode file "codec_tag_string": "hvc1" "codec_tag": "0x31637668" avg_frame_rate": "2552750/106471

The command I sent him to run was other-transcode --nvenc --hevc --nvenc-temporal-aq --mp4 --target 1080p=6000 --crop auto --eac3 "path/to/movie.mkv"

So anything I can do to avoid the roundtrip through mp4tools to make the file quicktime/avfoundation/whatever compatible?

vasuvasu commented 4 years ago

Whoops @donmelton looks like this is a duplicate of https://github.com/donmelton/other_video_transcoding/issues/41

I was searching using different terms and didn't find that thread initially, now not sure if I should comment on a closed issue or not.

Is there a way for other-transcode to pass additional flags to the ffmpeg command that gets run, like how video_transcoding could accept and pass additional flags to handbrakecli? It looks like if -tag:v hvc1 can be added to the ffmpeg command that runs, it'd fix the issue? I'd love it if this was just the default in other-transcode but would accept having to add it to my normal command if possible :)

lisamelton commented 4 years ago

@vasuvasu Thanks for using my tools! But I'm sorry you're running into this MP4 playback issue with QuickTime.

I will try an experiment later this week to see if I can get the -tag:v hvc1 trick to work.

vasuvasu commented 4 years ago

Thanks @donmelton!

Maybe couple the tag being hvc1 when the output format is mp4? It seems both hev1 and hvc1 are valid, but avfoundation is being a stickler about hvc1.

Might be a big assumption, but if someone's choosing an mp4 container, then they may also want the hvc1 tag for the most apple compatibility?

RusselProuse34 commented 4 years ago

I submitted #41 and after doing some research, apparently QuickTime on High Sierra or later requires the hvc1 tag. I tried the method described in this Stack Overflow comment and it worked for me. Now I just have to figure out how to apply this method to all of the folders and subfolders of MP4s I've already transcoded :)

weaverm commented 3 years ago

I'd like to give my support to other-transcode doing the Apple-y thing with respect to the hvc1 tag. I was able to make the ffmpeg command in the referenced Stack Overflow comment work but I much prefer using other-transcode than I do ffmpeg.

lisamelton commented 3 years ago

@vasuvasu @RusselProuse34 @weaverm Sorry it took me so long to get to this. I have an implementation that I'm testing now. Just so you know, this tag will only be added for MP4 output.

lisamelton commented 3 years ago

@vasuvasu @RusselProuse34 @weaverm OK, I've checked in the change. I haven't released it yet, but you can download the script from GitHub to try it out.

weaverm commented 3 years ago

I am trying it out now. It'll take my iMac about 3.5 hours to do the work, however, so I'll confirm things in the morning. I do see -tag:v hvc1 on the ffmpeg command line. Initially, it looks like it is doing the new thing.

lisamelton commented 3 years ago

@weaverm Great! Thanks for testing this so quickly!

weaverm commented 3 years ago

Mediainfo shows the updated tag:

Video
ID                                       : 1
Format                                   : HEVC
Format/Info                              : High Efficiency Video Coding
Format profile                           : Main 10@L4@High
Codec ID                                 : hvc1
Codec ID/Info                            : High Efficiency Video Coding
Duration                                 : 1 h 46 min
Bit rate                                 : 5 985 kb/s
Width                                    : 1 920 pixels
Height                                   : 1 080 pixels
Display aspect ratio                     : 16:9
Frame rate mode                          : Constant

And the file plays fine in Quicktime and iTunes on Mojave. Also, the spacebar preview in Finder works.

lisamelton commented 3 years ago

@weaverm Woo hoo! Thanks for testing that.

Also, I should have this released sometime this week.

weaverm commented 3 years ago

Here's a curious side note. I ran an encode last night that included an added audio track.

other-transcode --eac3 --hevc --x265 --mp4 --add-audio 3 /path/to/movie.mkv

In the resulting file, mediainfo shows both audio tracks.

Audio #1
ID                                       : 2
Format                                   : E-AC-3
Format/Info                              : Enhanced AC-3
Commercial name                          : Dolby Digital Plus
Codec ID                                 : ec-3
Duration                                 : 1 h 55 min
Bit rate mode                            : Constant
Bit rate                                 : 640 kb/s
Channel(s)                               : 6 channels
Channel layout                           : L R C LFE Ls Rs
Sampling rate                            : 48.0 kHz
Frame rate                               : 31.250 FPS (1536 SPF)
Compression mode                         : Lossy
Stream size                              : 528 MiB (9%)
Language                                 : English
Service kind                             : Complete Main
Default                                  : Yes
Alternate group                          : 1
Menus                                    : 4

Audio #2
ID                                       : 3
Format                                   : AC-3
Format/Info                              : Audio Coding 3
Commercial name                          : Dolby Digital
Codec ID                                 : ac-3
Duration                                 : 1 h 55 min
Bit rate mode                            : Constant
Bit rate                                 : 192 kb/s
Channel(s)                               : 2 channels
Channel layout                           : L R
Sampling rate                            : 48.0 kHz
Frame rate                               : 31.250 FPS (1536 SPF)
Compression mode                         : Lossy
Stream size                              : 159 MiB (3%)
Language                                 : English
Service kind                             : Complete Main
Default                                  : No
Alternate group                          : 1
Menus                                    : 4

I can access both tracks using mpv. Quicktime (and iTunes), however, only sees the first audio track. My AppleTV 4K can play both tracks. I wonder if this is an artifact of the version of Quicktime on my Mojave Mac? Perhaps it is because I used the --eac3 switch?

If you think this is a separate issue, that's fine with me.

lisamelton commented 3 years ago

@weaverm That is weird. But, yeah, that's probably a separate issue. What happens if both tracks are the same format?

lisamelton commented 3 years ago

@vasuvasu @weaverm OK, this change has now been released as version 0.3.2. Just gem update to get it. Thanks again for all your help!