Skip to content
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

Add encoder #29

Merged
merged 6 commits into from
Jan 27, 2025
Merged

Add encoder #29

merged 6 commits into from
Jan 27, 2025

Conversation

gBillal
Copy link
Collaborator

@gBillal gBillal commented Jan 21, 2025

A first version of a video encoder (h264 and hevc).
@mickel8 you can start reviewing it in case you have a different architecture in mind.

@mickel8
Copy link
Member

mickel8 commented Jan 21, 2025

Awesome! I will try to take a look tomorrow

Copy link
Member

@mickel8 mickel8 left a comment

Choose a reason for hiding this comment

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

Looks good! Btw. if you have more features in your mind I can also add you as admin to this repo to speedup the process of adding new features

@@ -0,0 +1,19 @@
defmodule Xav.Packet do
Copy link
Member

Choose a reason for hiding this comment

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

Maybe it would be better to go for Frame and RawFrame? WDYT? I have networking background and for me packet is strictly related to network protocols.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I'm trying to follow ffmpeg naming, even for the fields. RawFrame will also work.

@doc """
Create a new encoder.

It accepts the following options:\n#{NimbleOptions.docs(@video_encoder_schema)}
Copy link
Member

Choose a reason for hiding this comment

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

Would be nice to either use NimbleOptions everywhere or nowhere. Alternatively we can make an update in another PR

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes I'll do that too, I want just to focus on the encoder for now. I'll update the converter and the other modules if needed.

Copy link
Member

Choose a reason for hiding this comment

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

Nice docs 👍

lib/encoder.ex Outdated Show resolved Hide resolved
lib/encoder.ex Outdated Show resolved Hide resolved
lib/encoder.ex Outdated Show resolved Hide resolved
c_src/xav/utils.c Outdated Show resolved Hide resolved
c_src/xav/utils.c Outdated Show resolved Hide resolved
c_src/xav/xav_encoder.c Outdated Show resolved Hide resolved
c_src/xav/encoder.h Outdated Show resolved Hide resolved
c_src/xav/xav_encoder.c Show resolved Hide resolved
@gBillal
Copy link
Collaborator Author

gBillal commented Jan 24, 2025

Looks good! Btw. if you have more features in your mind I can also add you as admin to this repo to speedup the process of adding new features

For now, after the encoder, I want to look at the subject of hardware accelerated encoding/decoding.
Make me an admin. Sure why not.

@gBillal gBillal marked this pull request as ready for review January 26, 2025 08:58
@mickel8
Copy link
Member

mickel8 commented Jan 27, 2025

@gBillal you should have write permissions. In particular, feel free to merge PR without my revie


defp to_packets(result) do
Enum.map(result, fn {data, dts, pts, keyframe?} ->
%Xav.Packet{data: data, dts: dts, pts: pts, keyframe?: keyframe?}
Copy link
Member

Choose a reason for hiding this comment

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

I wonder whether to return a list of packets or merge them all into a single packet/frame?

Do you know why ffmpeg outputs multiple packets? How are they divided?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Actually we cannot merge them together. A packet represent a single video frame (in the case of audio it may be multiple samples in the same packet), a packet has properties specific to a single frame (pts, dts and keyframe?). Also some containers/decoders requires a single packet as the unit to work on with.

Copy link
Member

Choose a reason for hiding this comment

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

Is this then expected that encoding a single raw frame can result in multiple output packets?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes it's possible, usually the encoder will buffer packets to output them in decoding order which may be different than presentation order.

I think it's also better code wise, the same code is used for encoding and flushing and it's easier to include the encoder in elixir streams/enum rather than handling nil or {:ok, packet}.

Copy link
Member

Choose a reason for hiding this comment

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

Perfect, thanks! If you have time, it would be nice to mention this in the docs

@gBillal
Copy link
Collaborator Author

gBillal commented Jan 27, 2025

@gBillal you should have write permissions. In particular, feel free to merge PR without my revie

Yes I have access but I cannot push a hex package or should I leave release creation to you ?

@gBillal gBillal merged commit c43f710 into elixir-webrtc:master Jan 27, 2025
@gBillal gBillal deleted the encoder branch January 27, 2025 18:14
@mickel8
Copy link
Member

mickel8 commented Jan 27, 2025

Yeah, let's leave it to me or ping me when it's needed

@mickel8 mickel8 mentioned this pull request Feb 4, 2025
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