new video media header box

This commit is contained in:
Martin Riedl 2024-11-07 19:01:44 +01:00
parent 7c1d6fcf06
commit e99afbd415
Signed by: martinr92
GPG key ID: FB68DA65516A804C
4 changed files with 65 additions and 0 deletions

2
Box.go
View file

@ -50,6 +50,8 @@ const (
BoxTypeTrackFragmentHeader = "tfhd"
// BoxTypeTrackFragmentRun Track Fragment Run Box
BoxTypeTrackFragmentRun = "trun"
// BoxTypeVideoMediaHeader Video Media Header Box
BoxTypeVideoMediaHeader = "vmhd"
)
// Box is an abstract box struct

View file

@ -134,6 +134,8 @@ func parseNextBox(reader io.Reader, filePosition uint64) (box interface{}, endPo
box = ParseTrackFragmentHeaderBox(filePosition, boxHeaderSize, boxContentBytes)
case BoxTypeTrackFragmentRun:
box, err = ParseTrackFragmentRunBox(filePosition, boxHeaderSize, boxContentBytes)
case BoxTypeVideoMediaHeader:
box = ParseVideoMediaHeaderBox(filePosition, boxHeaderSize, boxContentBytes)
default:
logger.Println("unknown box type", boxType, "at", filePosition)
return nil, filePosition, false, errors.New("unknown box type " + boxType)

View file

@ -106,6 +106,14 @@ Implementation progress
| 8.16.5 Producer Reference Time Box | prft | - |
| 8.17.3 Complete Track Information Box | cinf | - |
| 9.1.2.1 SRTP Process box | srpp | - |
| 9.2.4.7 FEC Information Box | feci | - |
| 12.1.2 Video media header | vmhd | 100% |
| 12.2.1 Media handler | soun | - |
| 12.2.2 Sound media header | smhd | - |
| 12.2.4 Channel layout | chnl | - |
| 12.2.5 Downmix Instructions | dmix | - |
| 12.2.7 Audio stream loudness | ludt | - |
| 12.4.2 Hint Media Header Box | hmhd | - |
## Helper Tools

53
VideoMediaHeaderBox.go Normal file
View file

@ -0,0 +1,53 @@
// Copyright 2024 Martin Riedl
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package gomp4
import "encoding/binary"
// VideoMediaHeaderBox video media header box struct
//
// 12.1.2 Video media header
//
// Box Types: vmhd
// Container: Media Information Box (minf)
// Mandatory: Yes
// Quantity: Exactly one
// Video tracks use the VideoMediaHeaderbox in the media information box as defined in 8.4.5. The video
// media header contains general presentation information, independent of the coding, for video media.
// Note that the flags field has the value 1.
type VideoMediaHeaderBox struct {
*FullBox
// specifies a composition mode for this video track, from the following enumerated
// set, which may be extended by derived specifications:
// copy = 0 copy over the existing image
GraphicsMode uint16
// is a set of 3 colour values (red, green, blue) available for use by graphics modes
CPColor []uint16
}
// ParseVideoMediaHeaderBox creates a new Video Media Header Box struct
func ParseVideoMediaHeaderBox(filePosition uint64, headerSize uint32, content []byte) *VideoMediaHeaderBox {
box := &VideoMediaHeaderBox{
FullBox: newFullBox(&Box{filePosition, headerSize}, content[0:4]),
}
position := 4
box.GraphicsMode = binary.BigEndian.Uint16(content[position : position+2])
box.CPColor = append(box.CPColor, binary.BigEndian.Uint16(content[position+2:position+4]))
box.CPColor = append(box.CPColor, binary.BigEndian.Uint16(content[position+4:position+6]))
box.CPColor = append(box.CPColor, binary.BigEndian.Uint16(content[position+6:position+8]))
return box
}