-
Notifications
You must be signed in to change notification settings - Fork 84
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: File.UpdateSidx to update or add a top-level sidx box
- Loading branch information
Showing
6 changed files
with
271 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,53 @@ | ||
// add-sidx adds a top-level sidx box describing the segments of a fragmented files. | ||
// | ||
// Segments are identified by styp boxes if they exist, otherwise by | ||
// the start of moof or emsg boxes. | ||
package main | ||
|
||
import ( | ||
"flag" | ||
"fmt" | ||
"log" | ||
"os" | ||
|
||
"github.com/Eyevinn/mp4ff/mp4" | ||
) | ||
|
||
func main() { | ||
|
||
usePTO := flag.Bool("nzept", false, "Use non-zero earliestPresentationTime") | ||
flag.Parse() | ||
args := flag.Args() | ||
if len(args) != 2 { | ||
fmt.Println("Usage: add-sidx <input.mp4> <output.mp4>") | ||
return | ||
} | ||
|
||
err := run(args[0], args[1], *usePTO) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
} | ||
|
||
func run(inPath, outPath string, nonZeroEPT bool) error { | ||
inFile, err := mp4.ReadMP4File(inPath) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
err = inFile.UpdateSidx(true /* addIfNotExists */, nonZeroEPT) | ||
if err != nil { | ||
return fmt.Errorf("addSidx failed: %w", err) | ||
} | ||
|
||
w, err := os.Create(outPath) | ||
if err != nil { | ||
return fmt.Errorf("cannot create output file: %w", err) | ||
} | ||
defer w.Close() | ||
err = inFile.Encode(w) | ||
if err != nil { | ||
return fmt.Errorf("failed to encode output file: %w", err) | ||
} | ||
return nil | ||
} |
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,23 @@ | ||
package main | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/Eyevinn/mp4ff/mp4" | ||
) | ||
|
||
func TestAddSidx(t *testing.T) { | ||
sidxOut := "testV300_sidx.mp4" | ||
inPath := "../resegmenter/testdata/testV300.mp4" | ||
err := run(inPath, sidxOut, false) | ||
if err != nil { | ||
t.Error(err) | ||
} | ||
reRead, err := mp4.ReadMP4File(sidxOut) | ||
if err != nil { | ||
t.Error(err) | ||
} | ||
if reRead.Sidx == nil { | ||
t.Error("No sidx box added") | ||
} | ||
} |
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
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