Skip to content

Commit 1ae9a07

Browse files
authored
Merge pull request #110 from edgeware/v0.25.0
Version 0.25.0
2 parents 57268e3 + 5ace81e commit 1ae9a07

File tree

4 files changed

+38
-14
lines changed

4 files changed

+38
-14
lines changed

README.md

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,15 @@ All child boxes of container box such as `MoovBox` are listed in the `Children`
3939
most prominent child boxes have direct links with names which makes it possible to write a path such
4040
as
4141

42+
```go
4243
fragment.Moof.Traf.Trun
44+
```
4345

4446
to access the (only) `trun` box in a fragment with only one `traf` box, or
4547

48+
```go
4649
fragment.Moof.Trafs[1].Trun[1]
50+
```
4751

4852
to get the second `trun` of the second `traf` box (provided that they exist).
4953

@@ -54,9 +58,11 @@ A typical use case is to a fragment consisting of an init segment followed by a
5458
The first step is to create the init segment. This is done in three steps as can be seen in
5559
`examples/initcreator`:
5660

57-
1. `init := mp4.CreateEmptyInit()`
58-
2. `init.AddEmptyTrack(timescale, mediatype, language)`
59-
3. `init.Moov.Trak.SetHEVCDescriptor("hvc1", vpsNALUs, spsNALUs, ppsNALUs)`
61+
```go
62+
init := mp4.CreateEmptyInit()
63+
init.AddEmptyTrack(timescale, mediatype, language)
64+
init.Moov.Trak.SetHEVCDescriptor("hvc1", vpsNALUs, spsNALUs, ppsNALUs)
65+
```
6066

6167
Here the third step fills in codec-specific parameters into the sample descriptor of the single track.
6268
Multiple tracks are also available via the slice attribute `Traks` instead of `Trak`.
@@ -72,6 +78,7 @@ fragment in each segment. Example code for this can be found in `examples/segmen
7278
One way of creating a media segment is to first create a slice of `FullSample` with the data needed.
7379
The definition of `mp4.FullSample` is
7480

81+
```go
7582
mp4.FullSample{
7683
Sample: mp4.Sample{
7784
Flags uint32 // Flag sync sample etc
@@ -82,6 +89,7 @@ The definition of `mp4.FullSample` is
8289
DecodeTime uint64 // Absolute decode time (offset + accumulated sample Dur)
8390
Data []byte // Sample data
8491
}
92+
```
8593

8694
The `mp4.Sample` part is what will be written into the `trun` box.
8795
`DecodeTime` is the media timeline accumulated time.
@@ -90,16 +98,20 @@ be set as the `BaseMediaDecodeTime` in the `tfdt` box.
9098

9199
Once a number of such full samples are available, they can be added to a media segment like
92100

101+
```go
93102
seg := mp4.NewMediaSegment()
94103
frag := mp4.CreateFragment(uint32(segNr), mp4.DefaultTrakID)
95104
seg.AddFragment(frag)
96105
for _, sample := range samples {
97106
frag.AddFullSample(sample)
98107
}
108+
```
99109

100110
This segment can finally be output to a `w io.Writer` as
101111

112+
```go
102113
err := seg.Encode(w)
114+
```
103115

104116
For multi-track segments, the code is a bit more involved. Please have a look at `examples/segmenter`
105117
to see how it is done. One can also write the media data part of the samples
@@ -115,17 +127,23 @@ to later.
115127

116128
For decoding, this is supported by running `mp4.DecodeFile()` in lazy mode as
117129

130+
```go
118131
parsedMp4, err = mp4.DecodeFile(ifd, mp4.WithDecodeMode(mp4.DecModeLazyMdat))
132+
```
119133

120134
In this case, the media data of the `mdat` box will not be read, but only its size is being set.
121135
To read or copy the actual data corresponding to a sample, one must calculate the
122136
corresponding byte range and either call
123137

138+
```go
124139
func (m *MdatBox) ReadData(start, size int64, rs io.ReadSeeker) ([]byte, error)
140+
```
125141

126142
or
127143

144+
```
128145
func (m *MdatBox) CopyData(start, size int64, rs io.ReadSeeker, w io.Writer) (nrWritten int64, err error)
146+
```
129147

130148
Example code for this, including lazy writing of `mdat`, can be found in `examples/segmenter`
131149
with the `lazy` mode set.

Versions.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
| Version | Highlight |
44
| ------ | --------- |
5+
| 0.25.0 | Support sample intervals. Control first sample flags. Create subtitle init segments. Minor improvements and fixes |
56
| 0.24.0 | api-change: DecodeFile lazy mode. Enhanced segmenter example with lazy read/write. |
67
| 0.23.1 | fix: segment encode mode without optimization
78
| 0.23.0 | api-change: encode mode and optimization options |

mp4/README.md

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
# Parsing and generation of MP4 (isobmff) boxes.
22

33
## Background
4-
The Box interfaces and some code in this directory is from the project https://github.com/jfbus/mp4. It has been vastly enhanced and the focus has changed from progessive mp4 files to segmented files.
4+
The Box interfaces and some code in this directory is from the project https://github.com/jfbus/mp4. It has been vastly enhanced and the focus has changed from progressive mp4 files to segmented files.
55

66
## Overall structure
7-
Most boxes have their own file named after the box, but in some cases, there may be multiple boxes that have the same content, and the code is then having a generic name like visualsampleentry.go.
7+
Most boxes have their own file named after the box, but in some cases, there may be multiple boxes that have the same content, and the code is then having a generic name like `visualsampleentry.go`.
88

99

1010
The Box interface is specified in `box.go`. It does not contain decode (parsing) methods which have distinct names for each box type
@@ -16,23 +16,28 @@ To implement a new box `fooo`, the following is needed.
1616

1717
Create a file `fooo.go` and create a struct type `FoooBox`.
1818

19-
Fooo should then implement the Box interface methods:
19+
FoooBox should then implement the Box interface methods:
2020

21+
```go
2122
Type()
2223
Size()
2324
Encode()
2425
Info()
26+
```
2527

26-
but also its own decode method `DecodeFooo`, and register that method in the `decoders` map in `box.go`. For a simple example, look at the `prft` box in `prft.go`.
28+
but also its own decode method `DecodeFooo`, and register that method in the `decoders` map in `box.go`.
29+
For a simple example, look at the `prft` box in `prft.go`.
2730

28-
A test file `fooo_test.go` should have a test using the method `boxDiffAfterEncodeAndDecode`to check that the box information is equal after
29-
encoding and decoding.
31+
A test file `fooo_test.go` should have a test using the method `boxDiffAfterEncodeAndDecode` to check that
32+
the box information is equal after encoding and decoding.
3033

3134
Container boxes like `moof`, have a list of all their children called `Children`,
3235
but also direct pointers to the children with appropriate names, like `Mfhd`
33-
and `Traf`. This makes it easy to chain box paths to reach an element like a TfhdBox as
36+
and `Traf`. This makes it easy to chain box paths to reach an element like a `TfhdBox` as
3437

38+
```go
3539
file.Moof.Traf.Tfhd
40+
```
3641

3742
When there may be multiple children with the same name, there may be both a
3843
slice `Trafs` with all boxes and `Traf` that points to the first.
@@ -44,9 +49,9 @@ To handle media sample data there are two structures:
4449

4550
A MediaSegment can be fragmented into multiple fragments by the method
4651

52+
```go
4753
func (s *MediaSegment) Fragmentify(timescale uint64, trex *TrexBox, duration uint32) ([]*Fragment, error)
48-
49-
54+
```
5055

5156
## License
5257
See [LICENSE.md](LICENSE.md)

mp4/version.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ import (
77
)
88

99
var (
10-
commitVersion string = "v0.24.0+dev" // May be updated using build flags
11-
commitDate string // commitDate in Epoch seconds (may be overridden using build flags)
10+
commitVersion string = "v0.25.0" // May be updated using build flags
11+
commitDate string // commitDate in Epoch seconds (may be overridden using build flags)
1212
)
1313

1414
// GetVersion - get version and also commitHash and commitDate if inserted via Makefile

0 commit comments

Comments
 (0)