-
Notifications
You must be signed in to change notification settings - Fork 93
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: new tool mp4ff-crop to crop progressive mp4 files
- Loading branch information
Showing
5 changed files
with
595 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package main | ||
|
||
type byteRange struct { | ||
start uint64 | ||
end uint64 // Included | ||
} | ||
|
||
type byteRanges struct { | ||
ranges []byteRange | ||
} | ||
|
||
func createByteRanges() *byteRanges { | ||
return &byteRanges{} | ||
} | ||
|
||
func (b *byteRanges) addRange(start, end uint64) { | ||
if len(b.ranges) == 0 || b.ranges[len(b.ranges)-1].end+1 != start { | ||
b.ranges = append(b.ranges, byteRange{start, end}) | ||
return | ||
} | ||
b.ranges[len(b.ranges)-1].end = end | ||
} | ||
|
||
func (b *byteRanges) size() uint64 { | ||
var totSize uint64 = 0 | ||
for _, br := range b.ranges { | ||
totSize += br.end - br.start + 1 | ||
} | ||
return uint64(totSize) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package main | ||
|
||
import ( | ||
"bytes" | ||
"log" | ||
"os" | ||
"testing" | ||
|
||
"github.com/edgeware/mp4ff/mp4" | ||
) | ||
|
||
// TestCroppedFileDuration - simple test to check that cropped file has right duration | ||
// In general, this duration will not be exactly the same as the one asked for. | ||
func TestCroppedFileDuration(t *testing.T) { | ||
testFile := "../../mp4/testdata/prog_8s.mp4" | ||
cropDur := 2000 | ||
|
||
ifh, err := os.Open(testFile) | ||
if err != nil { | ||
t.Error(err) | ||
} | ||
defer ifh.Close() | ||
parsedMp4, err := mp4.DecodeFile(ifh, mp4.WithDecodeMode(mp4.DecModeLazyMdat)) | ||
if err != nil { | ||
t.Error(err) | ||
} | ||
|
||
buf := bytes.Buffer{} | ||
|
||
err = cropMP4(parsedMp4, cropDur, &buf, ifh) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
decCropped, err := mp4.DecodeFile(&buf) | ||
if err != nil { | ||
t.Error(err) | ||
} | ||
moovDur := decCropped.Moov.Mvhd.Duration | ||
moovTimescale := decCropped.Moov.Mvhd.Timescale | ||
if uint64(cropDur)*uint64(moovTimescale) != moovDur*1000 { | ||
t.Errorf("got %d/%dms instead of %dms", moovDur, moovTimescale, cropDur) | ||
} | ||
} |
Oops, something went wrong.