-
Notifications
You must be signed in to change notification settings - Fork 0
Add multivariant output support to Membrane.Transcoder #21
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
khamilowicz
wants to merge
5
commits into
master
Choose a base branch
from
multivariant-output
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
fc71708
Add multivariant output support to Membrane.Transcoder
khamilowicz be2620a
Apply review suggestions
khamilowicz 948a200
Handle cpu quota for cgroups v2 in docker container
khamilowicz 889c051
Use @tag :tmp_dir in integration tests
khamilowicz 76392e6
fix credo
khamilowicz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,91 @@ | ||
| Mix.install([ | ||
| :membrane_file_plugin, | ||
| {:membrane_transcoder_plugin, path: __DIR__ |> Path.join("..") |> Path.expand()} | ||
| ]) | ||
|
|
||
| defmodule Example do | ||
| alias Membrane.{H264, H265, VP8, RCPipeline} | ||
| require RCPipeline | ||
| require Membrane.Pad | ||
|
|
||
| import Membrane.ChildrenSpec | ||
|
|
||
| @doc """ | ||
| Transcodes a single H264 input into three output files simultaneously: | ||
| - output 0: H264 (annexb, repackaged — no re-encode) | ||
| - output 1: H265 (transcoded) | ||
| - output 2: VP8 (transcoded) | ||
|
|
||
| Each output pad carries its own `output_stream_format`, `transcoding_policy`, and | ||
| `native_acceleration` options, all resolved independently inside the transcoder bin. | ||
| """ | ||
| def run(input_file, h264_output_file, h265_output_file, vp8_output_file) do | ||
| pipeline = RCPipeline.start_link!() | ||
|
|
||
| spec = [ | ||
| child(%Membrane.File.Source{location: input_file}) | ||
| |> child(:parser, %H264.Parser{ | ||
| output_stream_structure: :annexb, | ||
| output_alignment: :au, | ||
| generate_best_effort_timestamps: %{framerate: {30, 1}} | ||
| }) | ||
| |> child(:transcoder, Membrane.Transcoder), | ||
|
|
||
| # Output 0 — keep H264, just repackage (no re-encode) | ||
| get_child(:transcoder) | ||
| |> via_out(Membrane.Pad.ref(:output, 0), | ||
| options: [ | ||
| output_stream_format: %H264{alignment: :au, stream_structure: :annexb}, | ||
| transcoding_policy: :if_needed | ||
| ] | ||
| ) | ||
| |> child(:h264_sink, %Membrane.File.Sink{location: h264_output_file}), | ||
|
|
||
| # Output 1 — transcode to H265 | ||
| get_child(:transcoder) | ||
| |> via_out(Membrane.Pad.ref(:output, 1), | ||
| options: [ | ||
| output_stream_format: H265, | ||
| transcoding_policy: :always | ||
| ] | ||
| ) | ||
| |> child(:h265_sink, %Membrane.File.Sink{location: h265_output_file}), | ||
|
|
||
| # Output 2 — transcode to VP8 | ||
| get_child(:transcoder) | ||
| |> via_out(Membrane.Pad.ref(:output, 2), | ||
| options: [ | ||
| output_stream_format: VP8, | ||
| transcoding_policy: :always | ||
| ] | ||
| ) | ||
| |> child(:vp8_sink, %Membrane.File.Sink{location: vp8_output_file}) | ||
| ] | ||
|
|
||
| RCPipeline.subscribe(pipeline, _any) | ||
| RCPipeline.exec_actions(pipeline, spec: spec) | ||
| RCPipeline.await_end_of_stream(pipeline, :h264_sink) | ||
| RCPipeline.await_end_of_stream(pipeline, :h265_sink) | ||
| RCPipeline.await_end_of_stream(pipeline, :vp8_sink) | ||
| RCPipeline.terminate(pipeline) | ||
| end | ||
| end | ||
|
|
||
| File.mkdir_p!(Path.join(__DIR__, "tmp")) | ||
|
|
||
| input = Path.join(__DIR__, "../test/fixtures/video.h264") | ||
| h264_out = Path.join(__DIR__, "tmp/multivariant_output.h264") | ||
| h265_out = Path.join(__DIR__, "tmp/multivariant_output.h265") | ||
| vp8_out = Path.join(__DIR__, "tmp/multivariant_output.ivf") | ||
|
|
||
| IO.puts("Input: #{input}") | ||
| IO.puts("H264 output: #{h264_out}") | ||
| IO.puts("H265 output: #{h265_out}") | ||
| IO.puts("VP8 output: #{vp8_out}") | ||
| IO.puts("") | ||
| Example.run(input, h264_out, h265_out, vp8_out) | ||
|
|
||
| IO.puts("Done.") | ||
| IO.puts(" #{h264_out} (#{File.stat!(h264_out).size} bytes)") | ||
| IO.puts(" #{h265_out} (#{File.stat!(h265_out).size} bytes)") | ||
| IO.puts(" #{vp8_out} (#{File.stat!(vp8_out).size} bytes)") |
This file contains hidden or 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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we need to update existing examples as well