Skip to content

Commit

Permalink
Merge pull request #48 from vivienbcr/AES-Encryption
Browse files Browse the repository at this point in the history
Add HLS AES encryption
  • Loading branch information
xfrr committed Mar 30, 2020
2 parents 59a0865 + 39b7630 commit 63d0c68
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
34 changes: 34 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -221,5 +221,39 @@ func main() {
}
```

Example with AES encryption :

More information about [HLS encryption with FFMPEG](https://hlsbook.net/how-to-encrypt-hls-video-with-ffmpeg/)

```bash
# Generate key
openssl rand 16 > enc.key
```

Create key file info :

```enc.keyinfo
Key URI
Path to key file
```

```golang
func main() {

trans := new(transcoder.Transcoder)

err := trans.Initialize(inputPath, outputPath)

trans.MediaFile().SetVideoCodec("libx264")

trans.MediaFile().SetHlsSegmentDuration(4)

trans.MediaFile().SetEncryptionKey(keyinfoPath)

progress := trans.Output()

err = <-done
}

----
> Building...
14 changes: 14 additions & 0 deletions models/media.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ type Mediafile struct {
audioFilter string
skipVideo bool
skipAudio bool
encryptionKey string
movflags string
bframe int
pixFmt string
Expand Down Expand Up @@ -596,6 +597,14 @@ func (m *Mediafile) Metadata() Metadata {
return m.metadata
}

func (m *Mediafile) SetEncryptionKey(v string) {
m.encryptionKey = v
}

func (m *Mediafile) EncryptionKey() string {
return m.encryptionKey
}

/** OPTS **/
func (m *Mediafile) ToStrCommand() []string {
var strCommand []string
Expand Down Expand Up @@ -656,6 +665,7 @@ func (m *Mediafile) ToStrCommand() []string {
"VideoFilter",
"HttpMethod",
"HttpKeepAlive",
"EncryptionKey",
"OutputPath",
"Bframe",
"MovFlags",
Expand Down Expand Up @@ -1087,6 +1097,10 @@ func (m *Mediafile) ObtainStreamIds() []string {
return nil
}

func (m *Mediafile) ObtainEncryptionKey() []string {
return []string{"-hls_key_info_file", m.encryptionKey}
}

func (m *Mediafile) ObtainBframe() []string {
if m.bframe != 0 {
return []string{"-bf", fmt.Sprintf("%d", m.bframe)}
Expand Down

0 comments on commit 63d0c68

Please sign in to comment.