aboutsummaryrefslogtreecommitdiff
path: root/track/display_test.go
blob: aae4739c518164f42d72e9c09f58c92377f7c386 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package track_test

import (
	"bytes"
	"encoding/binary"
	"testing"

	"github.com/tetsuo/mp4/track"
)

func TestCodedDimensionsStaySeparateFromTrackHeaderDisplayDimensions(t *testing.T) {
	moov := readMoov(t, "../test-data/h264-aac-10s.mp4")
	marker := bytes.Index(moov, []byte("tkhd"))
	if marker < 0 || marker+88 > len(moov) {
		t.Fatal("fixture has no usable tkhd")
	}
	version := moov[marker+4]
	offset := marker + 8 + 72
	if version == 1 {
		offset = marker + 8 + 84
	}
	if offset+8 > len(moov) {
		t.Fatal("truncated tkhd")
	}
	binary.BigEndian.PutUint32(moov[offset:], 1111<<16)
	binary.BigEndian.PutUint32(moov[offset+4:], 777<<16)

	tracks, _, _, err := track.ParseTracks(moov)
	if err != nil {
		t.Fatal(err)
	}
	video := tracks[0]
	if video.DisplayWidth != 1111 || video.DisplayHeight != 777 {
		t.Fatalf("display dimensions = %dx%d", video.DisplayWidth, video.DisplayHeight)
	}
	if video.Width == video.DisplayWidth || video.Height == video.DisplayHeight {
		t.Fatalf("coded dimensions were overwritten: coded=%dx%d display=%dx%d",
			video.Width, video.Height, video.DisplayWidth, video.DisplayHeight)
	}
}