Skip to content

Commit 744002a

Browse files
mainavinhoonaler9
andauthored
mp4: fix H265 + iOS compatibility (#290)
On iOS, H265 requires the hvc1 box instead of the hev1 box. Co-authored-by: aler9 <46489434+aler9@users.noreply.github.com>
1 parent 611652f commit 744002a

File tree

3 files changed

+10
-13
lines changed

3 files changed

+10
-13
lines changed

internal/mp4/codec_boxes.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ func (r *CodecBoxesReader) Read(h *amp4.ReadHandle) (any, error) {
257257
}
258258
r.state = waitingAdditional
259259

260-
case "hev1", "hvc1":
260+
case "hvc1", "hev1":
261261
if r.state != initial {
262262
return nil, fmt.Errorf("unexpected box '%v'", h.BoxInfo.Type)
263263
}
@@ -584,7 +584,7 @@ func WriteCodecBoxes(w *Writer, codec codecs.Codec, trackID int, info *CodecInfo
584584
| |av1C|
585585
|vp09| (VP9)
586586
| |vpcC|
587-
|hev1| (H265)
587+
|hvc1| (H265)
588588
| |hvcC|
589589
|avc1| (H264)
590590
| |avcC|
@@ -682,10 +682,10 @@ func WriteCodecBoxes(w *Writer, codec codecs.Codec, trackID int, info *CodecInfo
682682
}
683683

684684
case *codecs.H265:
685-
_, err := w.WriteBoxStart(&amp4.VisualSampleEntry{ // <hev1>
685+
_, err := w.WriteBoxStart(&amp4.VisualSampleEntry{ // <hvc1>
686686
SampleEntry: amp4.SampleEntry{
687687
AnyTypeBox: amp4.AnyTypeBox{
688-
Type: amp4.BoxTypeHev1(),
688+
Type: amp4.BoxTypeHvc1(),
689689
},
690690
DataReferenceIndex: 1,
691691
},

pkg/formats/fmp4/init_test.go

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -242,15 +242,12 @@ var casesInit = []struct {
242242
{
243243
"h265",
244244
[]byte{
245-
0x00, 0x00, 0x00, 0x20,
246-
'f', 't', 'y', 'p',
245+
0x00, 0x00, 0x00, 0x20, 0x66, 0x74, 0x79, 0x70,
247246
0x6d, 0x70, 0x34, 0x32, 0x00, 0x00, 0x00, 0x01,
248247
0x6d, 0x70, 0x34, 0x31, 0x6d, 0x70, 0x34, 0x32,
249248
0x69, 0x73, 0x6f, 0x6d, 0x68, 0x6c, 0x73, 0x66,
250-
0x00, 0x00, 0x02, 0xb8,
251-
'm', 'o', 'o', 'v',
252-
0x00, 0x00, 0x00, 0x6c,
253-
'm', 'v', 'h', 'd',
249+
0x00, 0x00, 0x02, 0xb8, 0x6d, 0x6f, 0x6f, 0x76,
250+
0x00, 0x00, 0x00, 0x6c, 0x6d, 0x76, 0x68, 0x64,
254251
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
255252
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0xe8,
256253
0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00,
@@ -298,7 +295,7 @@ var casesInit = []struct {
298295
0x23, 0x73, 0x74, 0x62, 0x6c, 0x00, 0x00, 0x00,
299296
0xd7, 0x73, 0x74, 0x73, 0x64, 0x00, 0x00, 0x00,
300297
0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
301-
0xc7, 0x68, 0x65, 0x76, 0x31, 0x00, 0x00, 0x00,
298+
0xc7, 0x68, 0x76, 0x63, 0x31, 0x00, 0x00, 0x00,
302299
0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
303300
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
304301
0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x80, 0x04,

pkg/formats/pmp4/presentation_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -393,7 +393,7 @@ var casesPresentation = []struct {
393393
0x00, 0x00, 0x01, 0x43, 0x73, 0x74, 0x62, 0x6c,
394394
0x00, 0x00, 0x00, 0xc3, 0x73, 0x74, 0x73, 0x64,
395395
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
396-
0x00, 0x00, 0x00, 0xb3, 0x68, 0x65, 0x76, 0x31,
396+
0x00, 0x00, 0x00, 0xb3, 0x68, 0x76, 0x63, 0x31,
397397
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
398398
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
399399
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
@@ -1197,7 +1197,7 @@ var casesPresentation = []struct {
11971197
0x01, 0x00, 0x00, 0x01, 0x43, 0x73, 0x74, 0x62,
11981198
0x6c, 0x00, 0x00, 0x00, 0xc3, 0x73, 0x74, 0x73,
11991199
0x64, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1200-
0x01, 0x00, 0x00, 0x00, 0xb3, 0x68, 0x65, 0x76,
1200+
0x01, 0x00, 0x00, 0x00, 0xb3, 0x68, 0x76, 0x63,
12011201
0x31, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
12021202
0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
12031203
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,

0 commit comments

Comments
 (0)