lisamelton / other_video_transcoding

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

How can I change the HEVC video codec tag? #41

Closed RusselProuse34 closed 4 years ago

RusselProuse34 commented 4 years ago

I'm transcoding a bunch of files for use on a Plex server that will be feeding almost exclusively to Apple devices (iPad Pro, iMac, Apple TV). However, I'm doing the transcoding itself on a Windows machine because it's the only "PC" I own that has a modern Intel chip that can do hardware accelerated 10-bit HEVC. Thus, the only flags I'm settings are --hevc and --mp4. The problem I'm running into is on my iMac. Anytime I try and play the MP4 files themselves outside of Plex, QuickTime gives me an error saying that "The file isn't compatible with QuickTime Player". After some searching, I figured out that the issue is with the video codec tag. other-transcode assigns a tag of hev1, and apparently QuickTime will only play files tagged as hvc1. Is there any way to have other-transcode force the codec tag to be hvc1, and if not, is there a way to batch change the video codec tag without having to re-transcode all of the files that I've already done?

lisamelton commented 4 years ago

@RusselProuse34 I'm sorry you're having this problem.

And I don't know of way to change those tags. This has actually never come up before because, I suppose, most users stick with the default MKV output format and almost no one uses the QuickTime Player anymore.

Does this same problem happen with VLC or mpv?

Also, what happens if you change your file extension from .mp4 to .m4v? The QuickTime Player is very picky about stuff like that.

RusselProuse34 commented 4 years ago

@donmelton Thanks for the reply Don. The files do work in VLC and MPV, probably because they aren't as picky about the tags as QuickTime is. They also work in Plex when streaming to my iPad and Apple TV.

Since everything I'd be watching my media on is an Apple product, I wanted to transcode them to MP4s in advance so that Plex wouldn't have to transcode on the fly every time. And since my iMac is older, Plex feels the need to transcode back to h.264 when viewing on the iMac, probably because it doesn't support hardware acceleration. That's why I figured I'd just open the files directly if I was ever watching on there.

When I changed the file extension to M4V, it gave me the same error.

For reference, this is the thread I found about the codec tags: https://www.reddit.com/r/ffmpeg/comments/cud3iv/mp4_cant_be_opened_by_quicktimeitunes/extli7t/. I was able to run the command that the top comment outlined on one file and it fixed the problem. I'm just not sure how to do it on a bunch of files at once.

It's not a big deal since the files play well almost everywhere, and play in other players on my iMac - I just figured I'd ask in case you had seen this problem before. Thanks again for the help.

lisamelton commented 4 years ago

@RusselProuse34 Thanks for finding that information! I'll keep that around in case anyone else runs into this problem. Sorry that there's not an easy way to "batch" that.

I'll close this issue now since you've resolved the problem yourself, but feel free to continue commenting.

bluehz commented 1 year ago

Change HEVC tag to HVC1 tag on video without transcoding. Each 20 min video takes about 30 secs to convert. I can confirm these will now play on AppleTV (4k) with no issues.

#!/usr/bin/env bash
# run this on the contents of a directory, cd into dir with terminal first
for i in *.mp4; do
  ffmpeg -i "$i" -c:v copy -tag:v hvc1 -c:a copy _OUTPUT/"$i"
done
tknmncr commented 7 months ago

I use mp4 containers rather than MKVs simply because it's trivial to tag mp4s (there are MANY tagging apps out there; I recommend Subler on the Mac), but there are no MKV tagging apps that are straightforward to use (at least none I have found). The only time I ever have an issue with mp4s is when I have specially formatted subtitles (like SSA with fonts and formatting as is common with anime). Having made a career out of data recovery I prefer not to solely rely on filenames for meta data.

I would expand on your code a little bit more. For properly tagged files (with meta data and cover art), that command will fail. It also will not copy all streams if you have more than one audio track, nor will it retain subtitles.

The extra :0 on the tag says to only tag the first video stream. Since tagging with cover art adds a video track of type motion jpeg, it will fail when trying to tag it. The -map 0 says to copy ALL tracks, not just the one ffmpeg arbitrarily considers the "best" track.

Try:

for file in *.mp4 *.m4v
{
    ffmpeg -i "${file}" -c copy -tag:v:0 hvc1 -map 0 _OUTPUT/"${FILE}"
}
salivity commented 1 month ago

I just saw this article and created a tool which you can use within the web browser,https://davidclews.com/article/18.html it will add the hvc1 tag to a compatible HEVC mp4 file. Then these files will work in safari