Skip to content

Fix HEVC hvc1 tagging: set stream codec_tag and cover all HEVC encoders#154

Open
AlvinShenSSW wants to merge 1 commit into
ladaapp:mainfrom
AlvinShenSSW:fix-hvc1-codec-tag
Open

Fix HEVC hvc1 tagging: set stream codec_tag and cover all HEVC encoders#154
AlvinShenSSW wants to merge 1 commit into
ladaapp:mainfrom
AlvinShenSSW:fix-hvc1-codec-tag

Conversation

@AlvinShenSSW

Copy link
Copy Markdown

Problem

HEVC output in ISOBMFF containers (mp4/mov/m4v) is tagged hev1, which Apple's AVFoundation rejects — no Finder thumbnails / QuickLook previews, and no playback in QuickTime or Safari. The intended tag is hvc1.

The current code sets this through the encoder options dict:

if encoder == 'hevc_videotoolbox':
    stream_options['tag'] = 'hvc1'
video_stream_out.options = stream_options

But PyAV/ffmpeg treats stream.options as encoder private options and silently ignores an unknown tag key, so the output stays hev1. (#153 widens this to all HEVC encoders but keeps the same ineffective mechanism, so it doesn't actually change the tag either.)

Verification (PyAV 16.1.0)

approach resulting codec_tag_string
stream.options['tag'] = 'hvc1' hev1
stream.codec_tag = 'hvc1' hvc1
no tag (default) hev1

Confirmed end-to-end through VideoWriter with both libx265 and hevc_nvenc: the muxed output goes from hev1 to hvc1.

Fix

Set the tag via the stream's codec_tag (the muxer FourCC) instead of encoder options, and apply it to all HEVC encoders (libx265, hevc_nvenc, hevc_amf, hevc_qsv, hevc_videotoolbox) when writing mp4/mov/m4v. Metadata-only change; non-Apple players accept both tags.

Supersedes #153.

The existing hvc1 tagging set the tag via stream.options['tag'], but PyAV/
ffmpeg treats that as an encoder private option and silently ignores it, so
HEVC output in ISOBMFF containers (mp4/mov/m4v) stayed tagged 'hev1'. Apple's
AVFoundation (Finder thumbnails, QuickLook, QuickTime, Safari) rejects 'hev1'.

Verified with PyAV 16.1.0: stream.options['tag']='hvc1' yields 'hev1', while
stream.codec_tag='hvc1' yields 'hvc1'. Set codec_tag on the stream instead so
the muxer FourCC is actually written, and apply it to all HEVC encoders
(libx265, hevc_nvenc, hevc_amf, hevc_qsv, hevc_videotoolbox), not just
hevc_videotoolbox. Metadata-only change; non-Apple players accept both tags.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants