Skip to content

Commit be0396d

Browse files
committed
Add support for VP9
1 parent 2ae23dd commit be0396d

File tree

7 files changed

+29
-19
lines changed

7 files changed

+29
-19
lines changed

examples/vp8_to_h264.exs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,4 @@ defmodule Example do
2828
end
2929

3030
File.mkdir("tmp")
31-
Example.convert(Path.join("./test/fixtures", "video.ivf"), Path.join("./tmp", "video.h264"))
31+
Example.convert(Path.join("./test/fixtures", "video_vp8.ivf"), Path.join("./tmp", "video.h264"))

lib/transcoder.ex

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,15 @@ defmodule Membrane.Transcoder do
88
* `Membrane.H264`
99
* `Membrane.H265`
1010
* `Membrane.VP8`
11+
* `Membrane.VP9`
1112
* `Membrane.RawVideo`
13+
* `Membrane.RemoteStream{content_type: Membrane.VP8}` (only as an input stream)
14+
* `Membrane.RemoteStream{content_type: Membrane.VP9}` (only as an input stream)
1215
1316
The following audio stream formats are supported:
1417
* `Membrane.AAC`
1518
* `Membrane.Opus`
19+
* `Membrane.MP3`
1620
* `Membrane.RawAudio`
1721
* `Membrane.RemoteStream{content_type: Membrane.Opus}` (only as an input stream)
1822
"""
@@ -23,7 +27,7 @@ defmodule Membrane.Transcoder do
2327
require Membrane.Logger
2428

2529
alias __MODULE__.{Audio, Video}
26-
alias Membrane.{AAC, Funnel, H264, H265, Opus, RawAudio, RawVideo, RemoteStream, VP8}
30+
alias Membrane.{AAC, Funnel, H264, H265, Opus, RawAudio, RawVideo, RemoteStream, VP8, VP9}
2731

2832
@typedoc """
2933
Describes stream formats acceptable on the bin's input and output.
@@ -32,6 +36,7 @@ defmodule Membrane.Transcoder do
3236
H264.t()
3337
| H265.t()
3438
| VP8.t()
39+
| VP9.t()
3540
| RawVideo.t()
3641
| AAC.t()
3742
| Opus.t()
@@ -41,7 +46,7 @@ defmodule Membrane.Transcoder do
4146
@typedoc """
4247
Describes stream format modules that can be used to define inputs and outputs of the bin.
4348
"""
44-
@type stream_format_module :: H264 | H265 | VP8 | RawVideo | AAC | Opus | RawAudio
49+
@type stream_format_module :: H264 | H265 | VP8 | VP9 | RawVideo | AAC | Opus | RawAudio
4550

4651
@typedoc """
4752
Describes a function which can be used to provide output format based on the input format.

lib/transcoder/video.ex

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@ defmodule Membrane.Transcoder.Video do
33

44
import Membrane.ChildrenSpec
55
require Membrane.Logger
6-
alias Membrane.{ChildrenSpec, H264, H265, RawVideo, RemoteStream, VP8}
6+
alias Membrane.{ChildrenSpec, H264, H265, RawVideo, RemoteStream, VP8, VP9}
77

8-
@type video_stream_format :: VP8.t() | H264.t() | H265.t() | RawVideo.t()
8+
@type video_stream_format :: VP8.t() | VP9.t() | H264.t() | H265.t() | RawVideo.t()
99

1010
defguard is_video_format(format)
1111
when is_struct(format) and
12-
(format.__struct__ in [VP8, H264, H265, RawVideo] or
13-
(format.__struct__ == RemoteStream and format.content_format == VP8 and
12+
(format.__struct__ in [VP8, VP9, H264, H265, RawVideo] or
13+
(format.__struct__ == RemoteStream and format.content_format in [VP8, VP9] and
1414
format.type == :packetized))
1515

1616
@spec plug_video_transcoding(
@@ -79,15 +79,18 @@ defmodule Membrane.Transcoder.Video do
7979
|> child(:h265_decoder, %H265.FFmpeg.Decoder{})
8080
end
8181

82-
defp maybe_plug_parser_and_decoder(builder, %VP8{}) do
83-
builder |> child(:vp8_decoder, %VP8.Decoder{})
82+
defp maybe_plug_parser_and_decoder(builder, %vpx{}) when vpx in [VP8, VP9] do
83+
decoder_module = Module.concat(vpx, Decoder)
84+
builder |> child(:vp8_decoder, decoder_module)
8485
end
8586

8687
defp maybe_plug_parser_and_decoder(builder, %RemoteStream{
87-
content_format: VP8,
88+
content_format: vpx,
8889
type: :packetized
89-
}) do
90-
builder |> child(:vp8_decoder, %VP8.Decoder{})
90+
})
91+
when vpx in [VP8, VP9] do
92+
decoder_module = Module.concat(vpx, Decoder)
93+
builder |> child(:vp8_decoder, decoder_module)
9194
end
9295

9396
defp maybe_plug_parser_and_decoder(builder, %RawVideo{}) do
@@ -112,15 +115,16 @@ defmodule Membrane.Transcoder.Video do
112115
})
113116
end
114117

115-
defp maybe_plug_encoder_and_parser(builder, %VP8{}) do
118+
defp maybe_plug_encoder_and_parser(builder, %vpx{}) when vpx in [VP8, VP9] do
116119
cpu_quota = :erlang.system_info(:cpu_quota)
117120

118121
number_of_threads =
119122
if cpu_quota != :unknown,
120123
do: cpu_quota,
121124
else: :erlang.system_info(:logical_processors_available)
122125

123-
builder |> child(:vp8_encoder, %VP8.Encoder{g_threads: number_of_threads, cpu_used: 15})
126+
encoder = Module.concat(vpx, Encoder) |> struct!(g_threads: number_of_threads, cpu_used: 15)
127+
builder |> child(:vp8_encoder, encoder)
124128
end
125129

126130
defp maybe_plug_encoder_and_parser(builder, %RawVideo{}) do
File renamed without changes.

test/fixtures/video_vp9.ivf

106 KB
Binary file not shown.

test/integration_test.exs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,18 @@ defmodule Membrane.Transcoder.IntegrationTest do
33
import Membrane.Testing.Assertions
44
import Membrane.ChildrenSpec
55

6-
alias Membrane.{AAC, H264, H265, Opus, RawAudio, RawVideo, VP8}
6+
alias Membrane.{AAC, H264, H265, Opus, RawAudio, RawVideo, VP8, VP9}
77
alias Membrane.Testing
88
alias Membrane.Transcoder.Support.Preprocessors
99

1010
@video_inputs [
1111
%{input_format: H264, input_file: "video.h264", preprocess: &Preprocessors.parse_h264/1},
1212
%{input_format: RawVideo, input_file: "video.h264", preprocess: &Preprocessors.decode_h264/1},
1313
%{input_format: H265, input_file: "video.h265", preprocess: &Preprocessors.parse_h265/1},
14-
%{input_format: VP8, input_file: "video.ivf", preprocess: &Preprocessors.parse_vp8/1}
14+
%{input_format: VP8, input_file: "video_vp8.ivf", preprocess: &Preprocessors.parse_vpx/1},
15+
%{input_format: VP9, input_file: "video_vp9.ivf", preprocess: &Preprocessors.parse_vpx/1}
1516
]
16-
@video_outputs [RawVideo, H264, H265, VP8]
17+
@video_outputs [RawVideo, H264, H265, VP8, VP9]
1718
@video_cases for input <- @video_inputs,
1819
output <- @video_outputs,
1920
do: Map.put(input, :output_format, output)

test/support/preprocessors.ex

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ defmodule Membrane.Transcoder.Support.Preprocessors do
3737
})
3838
end
3939

40-
@spec parse_vp8(Membrane.ChildrenSpec.builder()) :: Membrane.ChildrenSpec.builder()
41-
def parse_vp8(link_builder) do
40+
@spec parse_vpx(Membrane.ChildrenSpec.builder()) :: Membrane.ChildrenSpec.builder()
41+
def parse_vpx(link_builder) do
4242
child(link_builder, Membrane.IVF.Deserializer)
4343
end
4444

0 commit comments

Comments
 (0)