Skip to content

Commit 85e76f7

Browse files
committed
Add HTTP upload example
1 parent 5080d0f commit 85e76f7

File tree

1 file changed

+74
-0
lines changed

1 file changed

+74
-0
lines changed

examples/http_upload/main.go

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
// Refer to the Shaka Packager HTTP upload tutorial for more details:
2+
// https://shaka-project.github.io/shaka-packager/html/tutorials/http_upload.html
3+
// This implementation follows the HTTP upload process, ensuring media segments
4+
// and MPD files are uploaded correctly to the specified server.
5+
package main
6+
7+
import (
8+
"fmt"
9+
"log"
10+
"path"
11+
12+
packlit "github.com/m4urici0gm/packlit/pkg"
13+
)
14+
15+
func buildFlags(uploadURL string) *packlit.ShakaFlags {
16+
return packlit.NewFlags(
17+
packlit.WithUserAgentFlag("Packlit-client/1.0"),
18+
packlit.WithCaFileFlag("/etc/ssl/certs/ca-certificates.crt"),
19+
packlit.WithClientCertFileFlag("/etc/ssl/certs/client-cert.pem"),
20+
packlit.WithClientCertPrivateKeyFileFlag("/etc/ssl/private/client-key.pem"),
21+
packlit.WithClientCertPrivateKeyPasswordFlag("supersecurepassword"),
22+
packlit.WithDisablePeerVerificationFlag(),
23+
packlit.WithIgnoreHttpOutputFailuresFlag(),
24+
packlit.WithStaticLiveMpd(),
25+
packlit.WithSegmentDuration("4"),
26+
packlit.WithMpdOutput(path.Join(uploadURL, "h264.mpd")),
27+
)
28+
}
29+
30+
type stream struct {
31+
streamType packlit.StreamType
32+
input string
33+
}
34+
35+
func main() {
36+
uploadURL := "http://localhost:6767/vod"
37+
38+
streams := []stream{
39+
{streamType: "audio", input: "audio.mp4"},
40+
{streamType: "video", input: "video.mp4"},
41+
}
42+
43+
builder := packlit.NewBuilder()
44+
flags := buildFlags(uploadURL)
45+
46+
for _, stream := range streams {
47+
initSegment := path.Join(uploadURL, fmt.Sprintf("%v-init.mp4", stream.streamType))
48+
segmentTemplate := path.Join(uploadURL, fmt.Sprintf("%v-$Time$.m4s", stream.streamType))
49+
50+
builder.WithStream(
51+
packlit.NewStreamBuilder().
52+
WithInput(stream.input).
53+
WithStream(stream.streamType).
54+
AddOption(packlit.WithInitSegment(initSegment)).
55+
AddOption(packlit.WithSegmentTemplate(segmentTemplate)).
56+
Build(),
57+
)
58+
}
59+
60+
packager := builder.WithFlag(flags).Build()
61+
62+
cmd, err := packager.PreviewCommand()
63+
if err != nil {
64+
log.Fatalf("error: when previewing command %v", err)
65+
}
66+
67+
// Print command
68+
log.Println(cmd)
69+
70+
packagerExecutor := packlit.NewExecutor(packager)
71+
if err := packagerExecutor.Run(); err != nil {
72+
log.Fatalf("error when running shaka-packager: %v", err)
73+
}
74+
}

0 commit comments

Comments
 (0)