Skip to content

Instantly share code, notes, and snippets.

@animetosho
Created February 16, 2022 08:40
Show Gist options
  • Save animetosho/a896b24c12de1a438e1096e1361cf67e to your computer and use it in GitHub Desktop.
Save animetosho/a896b24c12de1a438e1096e1361cf67e to your computer and use it in GitHub Desktop.
ffmpeg patch to fix up muxing HEVC streams with bad version, instead of erroring out
--- a/libavformat/hevc.c
+++ b/libavformat/hevc.c
@@ -1080,6 +1080,15 @@
return 0;
} else if (!(AV_RB24(data) == 1 || AV_RB32(data) == 1)) {
/* Not a valid Annex B start code prefix */
+ if (*data == 0) {
+ /* The version field is is ignored by the decoder, so any value should be allowed. As this code relies on magic identifiers, we'll be a bit more strict and only accept '0' as a candidate to be fixed */
+ /* (these instances are outputs likely sourced from older/buggy tools) */
+ /* it might be ideal to do extra checks on the subsequent field (profile/tier) but I can't find open documentation on how they work */
+ av_log(pb, AV_LOG_WARNING, "HEVCDecoderConfigurationRecord.configurationVersion changed from %"PRIu8" to 1\n", *data);
+ avio_w8(pb, 1);
+ avio_write(pb, data + 1, size - 1);
+ return 0;
+ }
return AVERROR_INVALIDDATA;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment