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 support for avc3 format #90

Merged
merged 2 commits into from
Sep 22, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions lib/membrane_mp4/container/schema.ex
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,33 @@ defmodule Membrane.MP4.Container.Schema do
]
]
],
avc3: [
version: 0,
fields:
@full_box ++
[
num_of_entries: :uint32,
reserved: <<0::128>>,
width: :uint16,
height: :uint16,
horizresolution: :fp16d16,
vertresolution: :fp16d16,
reserved: <<0::32>>,
frame_count: :uint16,
compressor_name: :str256,
depth: :uint16,
reserved: <<-1::16-integer>>
],
avcC: [
black_box?: true
],
pasp: [
fields: [
h_spacing: :uint32,
v_spacing: :uint32
]
]
],
Qizot marked this conversation as resolved.
Show resolved Hide resolved
mp4a: [
fields: [
reserved: <<0::6*8>>,
Expand Down
54 changes: 28 additions & 26 deletions lib/membrane_mp4/movie_box/sample_table_box.ex
Original file line number Diff line number Diff line change
Expand Up @@ -69,35 +69,36 @@ defmodule Membrane.MP4.MovieBox.SampleTableBox do
end

defp assemble_sample_description(%H264{
stream_structure: {_avc, dcr} = structure,
stream_structure: {avc, dcr} = structure,
width: width,
height: height
})
when H264.is_avc(structure) do
[
avc1: %{
children: [
avcC: %{
content: dcr
},
pasp: %{
children: [],
fields: %{h_spacing: 1, v_spacing: 1}
}
],
fields: %{
compressor_name: <<0::size(32)-unit(8)>>,
depth: 24,
flags: 0,
frame_count: 1,
height: height,
horizresolution: {0, 0},
num_of_entries: 1,
version: 0,
vertresolution: {0, 0},
width: width
}
}
{avc,
%{
children: [
avcC: %{
content: dcr
},
pasp: %{
children: [],
fields: %{h_spacing: 1, v_spacing: 1}
}
],
fields: %{
compressor_name: <<0::size(32)-unit(8)>>,
depth: 24,
flags: 0,
frame_count: 1,
height: height,
horizresolution: {0, 0},
num_of_entries: 1,
version: 0,
vertresolution: {0, 0},
width: width
}
}}
]
end

Expand Down Expand Up @@ -234,11 +235,12 @@ defmodule Membrane.MP4.MovieBox.SampleTableBox do
sizes |> Enum.map(fn %{entry_size: size} -> size end)
end

defp unpack_sample_description(%{children: [{:avc1, %{children: boxes, fields: fields}}]}) do
defp unpack_sample_description(%{children: [{avc, %{children: boxes, fields: fields}}]})
when avc in [:avc1, :avc3] do
%H264{
width: fields.width,
height: fields.height,
stream_structure: {:avc1, boxes[:avcC].content}
stream_structure: {avc, boxes[:avcC].content}
}
end

Expand Down
5 changes: 2 additions & 3 deletions lib/membrane_mp4/track.ex
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,7 @@ defmodule Membrane.MP4.Track do

def get_encoding_info(%__MODULE__{
stream_format: %H264{
stream_structure:
{_avc, <<1, profile, compatibility, level, _rest::binary>>} = structure
stream_structure: {avc, <<1, profile, compatibility, level, _rest::binary>>} = structure
}
})
when H264.is_avc(structure) do
Expand All @@ -95,7 +94,7 @@ defmodule Membrane.MP4.Track do
level: level
}

{:avc1, map}
{avc, map}
end

def get_encoding_info(_unknown), do: nil
Expand Down