Skip to content

Commit

Permalink
Add support for avc3 format
Browse files Browse the repository at this point in the history
  • Loading branch information
Qizot committed Sep 22, 2023
1 parent 5b29ada commit daa8e13
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 29 deletions.
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
]
]
],
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

0 comments on commit daa8e13

Please sign in to comment.