Skip to content

Add encoder#2

Merged
varsill merged 17 commits into
initial_implementationfrom
add_encoder
Jan 9, 2026
Merged

Add encoder#2
varsill merged 17 commits into
initial_implementationfrom
add_encoder

Conversation

@varsill
Copy link
Copy Markdown
Collaborator

@varsill varsill commented Dec 12, 2025

This PR:

@varsill varsill mentioned this pull request Dec 12, 2025
@varsill varsill requested a review from mat-hek December 16, 2025 16:34
@varsill varsill marked this pull request as ready for review December 17, 2025 09:13
Comment thread lib/encoder.ex Outdated
Comment on lines +37 to +38
| {:variable_bitrate, Membrane.VKVideo.Encoder.VariableBitrate.t()}
| {:constant_bitrate, Membrane.VKVideo.Encoder.ConstantBitrate.t()},
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
| {:variable_bitrate, Membrane.VKVideo.Encoder.VariableBitrate.t()}
| {:constant_bitrate, Membrane.VKVideo.Encoder.ConstantBitrate.t()},
| {:variable_bitrate, __MODULE__.VariableBitrate.t()}
| {:constant_bitrate, __MODULE__.ConstantBitrate.t()},

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Comment thread lib/encoder/constant_bitrate.ex Outdated
Comment on lines +6 to +7
@type t :: %__MODULE__{bitrate: non_neg_integer(), virtual_buffer_size_ms: non_neg_integer()}
defstruct [:bitrate, :virtual_buffer_size_ms]
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If there are no default values for the fields, add @enforce_keys. Also, add some description for the fields, especially virtual_buffer_size_ms

Comment thread lib/encoder.ex Outdated
Comment on lines +29 to +30
Framerate of the stream expressed in number of frames per second.
If nil, the framerate will be read from the stream format's structure.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it only for the sake of rate control, I'd mention it in the description and probably call it approx_framerate or alike

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Comment thread lib/encoder.ex Outdated
Comment on lines +64 to +67
Membrane.Logger.warning("""
Framerate received within stream format: #{inspect(stream_format.framerate)} was overriden by the value provided via options:
#{inspect(state.framerate)}
""")
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it's worth issuing a warning in such case. Also, there's code duplication with the other clause that seems easily avoidable

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Comment thread test/encoder_test.exs Outdated
Comment on lines +119 to +125
# assert_sink_playing(pid, :sink)
#
# assert_sink_stream_format(
# pid,
# :sink,
# %Membrane.H264{width: 1280, height: 720, alignment: :au, stream_structure: :annexb}
# )
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

some leftovers here

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Comment thread native/vkvideo_encoder/src/lib.rs Outdated
Comment on lines +94 to +95
let device = adapter
.create_device(wgpu::Features::empty(), wgpu::Limits::default())
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what about the device server?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It requires putting everything into a single NIF so I am implementing it separately here: #3

Comment thread lib/encoder.ex
%Membrane.Buffer{
payload: encoded_frame.payload,
pts: pts,
dts: buffer.dts
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does the decoder support B frames? If so, it should output DTS, if not, we should use PTS

Copy link
Copy Markdown
Collaborator Author

@varsill varsill Dec 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The encoder doesn't support B-frames.
If it would, it should be enough to put the incoming buffer DTS/PTS as the output DTS (if I get it right, if the decoder was to output DTS, it would do it in the same manner as I do it here 🤔 ).

@varsill varsill requested a review from mat-hek December 22, 2025 14:56
Comment thread lib/encoder.ex Outdated
Comment on lines +68 to +69
|> put_in([:width], stream_format.width)
|> put_in([:height], stream_format.height)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why use put_in instead of map update syntax?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It takes 2 lines less then :D

Comment thread lib/encoder.ex Outdated
alignment: :au,
width: state.width,
height: state.height,
framerate: state.framerate
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if we should ever set the framerate to approx_framerate specified via options

Comment thread lib/encoder.ex Outdated
description: """
Framerate of the stream expressed in number of frames per second.
It's only used by the rate control mechanism and therefore it does not need to be an exact
value. If nil, the framerate will be read from the stream format's structure.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what if none is given?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as discuss, we will warn and fallback to 30 fps

varsill and others added 3 commits December 23, 2025 11:59
* Puts encoder and decoder into a single NIF

* Make Resource an Enum

* Fix function names

* Add device server (#4)

* Add create_device

* Fix the resource

* Add Device server and destroy function

--- 
Co-authored-by: Jerzy Wilczek <jerzy.wilczek@swmansion.com>
@varsill varsill requested a review from mat-hek January 8, 2026 13:05
@varsill varsill merged commit 9d097e9 into initial_implementation Jan 9, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants