Skip to content

Commit 9528d72

Browse files
authored
Merge pull request #32 from edgeware/clearer-doc
Improved documentation
2 parents 3ce9f47 + 45fbead commit 9528d72

File tree

12 files changed

+50
-32
lines changed

12 files changed

+50
-32
lines changed

README.md

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,16 @@
66
[![Go Report Card](https://goreportcard.com/badge/github.com/edgeware/mp4ff)](https://goreportcard.com/report/github.com/edgeware/mp4ff)
77
[![license](https://img.shields.io/github/license/edgeware/mp4ff.svg)](https://github.com/edgeware/mp4ff/blob/master/LICENSE.md)
88

9-
MP4/ISOBMFF media file parser and writer. Focused on fragmented files as used for streaming in DASH, MSS and HLS fMP4.
9+
Package mp4ff implements MP4 media file parser and writer for AVC video, AAC audio and stpp/wvtt subtitles.
10+
Focused on fragmented files as used for streaming in DASH, MSS and HLS fMP4.
1011

1112
## Library
1213

13-
The library has functions for parsing (called Decode) and writing (Encode).
14+
The library has functions for parsing (called Decode) and writing (Encode) in the package `mp4ff/mp4`.
15+
It also contains codec specific parsing of of AVC/H.264 including complete parsing of
16+
SPS and PPS in the package `mp4ff.avc`.
1417

15-
Traditional multiplexed non-fragmented mp4 files can be parsed and decoded, see `examples/segment`.
18+
Traditional multiplexed non-fragmented mp4 files can also be parsed and decoded, see `examples/segment`.
1619

1720
The focus is, however, on non-multiplexed single-track fragmented mp4 files as used in DASH, HLS, and CMAF.
1821

@@ -114,7 +117,7 @@ it can be calculated. It is set to `MoofBox.Size()+8`.
114117

115118
Some simple command line tools are available in `cmd`.
116119

117-
1. `mp4ff-pslister` extracts and displays pps and sps for AVC in an mp4 file
120+
1. `mp4ff-pslister` extracts and displays pps and sps for AVC in an mp4 file.
118121

119122
## Example code
120123

@@ -133,7 +136,7 @@ The APIs should be fairly stable, but minor non-backwards-compatible tweaks may
133136

134137
MIT, see [LICENSE.md](LICENSE.md).
135138

136-
Some code in pkg/mp4, es from or is based on https://github.com/jfbus/mp4 which has
139+
Some code in pkg/mp4, comes from or is based on https://github.com/jfbus/mp4 which has
137140
`Copyright (c) 2015 Jean-François Bustarret`.
138141

139142
Some code in pkg/bits comes from or is based on https://github.com/tcnksm/go-casper/tree/master/internal/bits

avc/doc.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
/*
2+
Package avc implements parsing of AVC(H.264) nal headers, slice headers and complete SPS and PPS.
3+
*/
4+
package avc

bits/README.md

Lines changed: 0 additions & 4 deletions
This file was deleted.

bits/bits.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,12 @@ import (
55
"io"
66
)
77

8-
// Writer writes bits into underlying io.Writer. Stops at first error
8+
// Writer writes bits into underlying io.Writer. Stops writing at first error.
9+
// Errors that have occured can later be checked with Error().
910
type Writer struct {
1011
n int // current number of bits
1112
v uint // current accumulated value
12-
err error // Has a write caused an error
13+
err error // The first error caused by any write operation
1314

1415
wr io.Writer
1516
}
@@ -130,11 +131,12 @@ func (r *Reader) MustRead(n int) uint {
130131
return v
131132
}
132133

133-
// MustReadFlag - read 1 bit into flag
134+
// MustReadFlag - read 1 bit into flag and panic if not possible
134135
func (r *Reader) MustReadFlag() bool {
135136
return r.MustRead(1) == 1
136137
}
137138

139+
// mask - n-bit binary mask
138140
func mask(n int) uint {
139141
return (1 << uint(n)) - 1
140142
}

bits/doc.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
/*
2-
Package bits implements bit reading and writing.
2+
Package bits implements bit reading and writing including EBSP.
33
44
Beyond plain bit reading and writing, it includes reading of ebsp (Encapsulated Byte Sequence Packets)
5-
Golomb codes as usid in the AVC/H.264 video coding standard.
5+
Golomb codes as used in the AVC/H.264 and HEVC video coding standards.
66
77
*/
88
package bits

bits/ebsp.go

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ import (
77
"io"
88
)
99

10+
const (
11+
startCodeEmulationPreventionByte = 0x03
12+
)
13+
1014
var ErrNotReedSeeker = errors.New("Reader does not support Seek")
1115

1216
// NewEBSPReader - return a new Reader.
@@ -39,7 +43,7 @@ func (r *EBSPReader) MustRead(n int) uint {
3943
panic("Reading error")
4044
}
4145
r.pos++
42-
if r.zeroCount == 2 {
46+
if r.zeroCount == 2 && b == startCodeEmulationPreventionByte {
4347
err = binary.Read(r.rd, binary.BigEndian, &b)
4448
if err != nil {
4549
panic("Reading error")
@@ -70,7 +74,7 @@ func (r *EBSPReader) MustReadFlag() bool {
7074
return r.MustRead(1) == 1
7175
}
7276

73-
// MustReadExpGolomb - Read one unsigned exponential golomb code
77+
// MustReadExpGolomb - Read one unsigned exponential golomb code. Panic if not possible
7478
func (r *EBSPReader) MustReadExpGolomb() uint {
7579
leadingZeroBits := 0
7680

@@ -88,7 +92,7 @@ func (r *EBSPReader) MustReadExpGolomb() uint {
8892
return res + endBits
8993
}
9094

91-
// MustReadSignedGolomb - Read one signed exponential golomb code
95+
// MustReadSignedGolomb - Read one signed exponential golomb code. Panic if not possible
9296
func (r *EBSPReader) MustReadSignedGolomb() int {
9397
unsignedGolomb := r.MustReadExpGolomb()
9498
if unsignedGolomb%2 == 1 {
@@ -108,13 +112,13 @@ func (r *EBSPReader) NrBitsReadInCurrentByte() int {
108112
return 8 - r.n
109113
}
110114

111-
// EBSP2rbsp - convert from EBSP to RBSP by removing escape 0x03 after two 0x00
115+
// EBSP2rbsp - convert from EBSP to RBSP by removing start code emulation prevention bytes
112116
func EBSP2rbsp(ebsp []byte) []byte {
113117
zeroCount := 0
114118
output := make([]byte, 0, len(ebsp))
115119
for i := 0; i < len(ebsp); i++ {
116120
b := ebsp[i]
117-
if zeroCount == 2 && b == 3 {
121+
if zeroCount == 2 && b == startCodeEmulationPreventionByte {
118122
zeroCount = 0
119123
} else {
120124
if b != 0 {
@@ -140,7 +144,7 @@ func (r *EBSPReader) Read(n int) (uint, error) {
140144
return 0, err
141145
}
142146
r.pos++
143-
if r.zeroCount == 2 && b <= 3 {
147+
if r.zeroCount == 2 && b == startCodeEmulationPreventionByte {
144148
err = binary.Read(r.rd, binary.BigEndian, &b)
145149
if err != nil {
146150
return 0, err
@@ -220,7 +224,7 @@ func (r *EBSPReader) IsSeeker() bool {
220224
}
221225

222226
// MoreRbspData - false if next bit is 1 and last 1 in fullSlice
223-
// Underlying reader must support ReadSeeker interface
227+
// Underlying reader must support ReadSeeker interface to reset after check
224228
func (r *EBSPReader) MoreRbspData() (bool, error) {
225229
if !r.IsSeeker() {
226230
return false, ErrNotReedSeeker
@@ -239,7 +243,7 @@ func (r *EBSPReader) MoreRbspData() (bool, error) {
239243
}
240244
return true, nil
241245
}
242-
// Must check if all remaining bits are zero
246+
// If all remainging bits are zero, there is no more rbsp data
243247
more := false
244248
for {
245249
b, err := r.Read(1)
@@ -261,6 +265,7 @@ func (r *EBSPReader) MoreRbspData() (bool, error) {
261265
return more, nil
262266
}
263267

268+
// reset EBSPReader based on copy of previous state
264269
func (r *EBSPReader) reset(prevState EBSPReader) error {
265270
rdSeek, ok := r.rd.(io.ReadSeeker)
266271

bits/esbp_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ func TestGolomb(t *testing.T) {
5656
})
5757
}
5858

59+
// TestEbspParser including startCodeEmulationPrevention removal
5960
func TestEbspParser(t *testing.T) {
6061

6162
cases := []struct{ name, start, want string }{

cmd/mp4ff-pslister/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ func main() {
5959
avcC := stsd.AvcX.AvcC
6060
trackID := trak.Tkhd.TrackID
6161
if *verbose {
62-
fmt.Printf("Videavo track ID=%d\n", trackID)
62+
fmt.Printf("Video track ID=%d\n", trackID)
6363
}
6464
var spsInfo *avc.SPS
6565
var err error

doc.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/*
2-
Package mp4ff implements MP4 media file parser and writer.
2+
Package mp4ff implements MP4 media file parser and writer for AVC video, AAC audio and stpp/wvtt subtitles.
3+
Focused on fragmented files as used for streaming in DASH, MSS and HLS fMP4.
34
45
MP4 library
56

examples/resegmenter/main.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
// mp4ff-resegmenter resegments mp4 files into concatenated segments with new duration.
1+
// resegmenter resegments mp4 files into concatenated segments with new duration.
22
//
3-
// The mp4 files must look like a CMAF track with init segment and media segments.
3+
// The input file must be a CMAF track with init segment and media segments.
44
//
55
// Usage:
66
//
7-
// mp4ff-resegmenter -f <input.mp4> -o <output.mp4> -b <chunk_dur>
7+
// resegmenter -f <input.mp4> -o <output.mp4> -b <chunk_dur>
88
// -b int
99
// Required: chunk duration (ticks)
1010
// -f string

0 commit comments

Comments
 (0)