Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
3 changes: 3 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,9 @@ set(MP4V2_SOURCE_FILES
src/atom_amr.cpp
src/atom_avc1.cpp
src/atom_avcC.cpp
src/atom_hvc1.cpp
src/atom_hev1.cpp
src/atom_hvcC.cpp
src/atom_chpl.cpp
src/atom_colr.cpp
src/atom_d263.cpp
Expand Down
47 changes: 47 additions & 0 deletions include/mp4v2/track.h
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,53 @@ void MP4AddH264PictureParameterSet(
const uint8_t* pPict,
uint16_t pictLen );

/** Add an HEVC (H265) video track.
*
* This function adds an HEVC video track to the file. The track uses
* the 'hvc1' sample entry type.
*
* @param hFile handle of file to add track to.
* @param timeScale the timescale of the track.
* @param sampleDuration the default sample duration.
* @param width the video width in pixels.
* @param height the video height in pixels.
* @param general_profile_idc the HEVC profile indicator.
* @param general_level_idc the HEVC level indicator.
* @param sampleLenFieldSizeMinusOne the size of the NAL unit length
* field minus one. Valid values are 0, 1, and 3, corresponding
* to NAL unit lengths of 1, 2, and 4 bytes.
*
* @return the track ID of the new track, or MP4_INVALID_TRACK_ID on failure.
*/
MP4V2_EXPORT
MP4TrackId MP4AddHEVCVideoTrack(
MP4FileHandle hFile,
uint32_t timeScale,
MP4Duration sampleDuration,
uint16_t width,
uint16_t height,
uint8_t general_profile_idc,
uint8_t general_level_idc,
uint8_t sampleLenFieldSizeMinusOne );

/** Add an HEVC (H265) video track with hev1 sample entry.
*
* Similar to MP4AddHEVCVideoTrack but uses 'hev1' sample entry type.
* Use hev1 when parameter sets may appear in-band (within samples).
*
* @see MP4AddHEVCVideoTrack for parameter documentation.
*/
MP4V2_EXPORT
MP4TrackId MP4AddHEV1VideoTrack(
MP4FileHandle hFile,
uint32_t timeScale,
MP4Duration sampleDuration,
uint16_t width,
uint16_t height,
uint8_t general_profile_idc,
uint8_t general_level_idc,
uint8_t sampleLenFieldSizeMinusOne );

MP4V2_EXPORT
void MP4SetH263Vendor(
MP4FileHandle hFile,
Expand Down
2 changes: 1 addition & 1 deletion libplatform/config.h.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
builds, but we use MP4V2_EXPORTS instead. */
#ifdef DLL_EXPORT
# define MP4V2_EXPORTS
#else
#elif !defined(MP4V2_USE_STATIC_LIB)
# define MP4V2_USE_STATIC_LIB
#endif

Expand Down
86 changes: 86 additions & 0 deletions src/atom_hev1.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
/*
* The contents of this file are subject to the Mozilla Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* Contributor(s):
* Chema Gonzalez <chemag@gmail.com>
*/

#include "src/impl.h"

namespace mp4v2 {
namespace impl {

///////////////////////////////////////////////////////////////////////////////

MP4Hev1Atom::MP4Hev1Atom(MP4File &file)
: MP4Atom(file, "hev1")
{
AddReserved(*this, "reserved1", 6); /* 0 */

AddProperty( /* 1 */
new MP4Integer16Property(*this, "dataReferenceIndex"));

AddReserved(*this, "reserved2", 16); /* 2 */

AddProperty( /* 3 */
new MP4Integer16Property(*this, "width"));
AddProperty( /* 4 */
new MP4Integer16Property(*this, "height"));

AddReserved(*this, "reserved3", 14); /* 5 */

MP4StringProperty* pProp =
new MP4StringProperty(*this, "compressorName");
pProp->SetFixedLength(32);
pProp->SetCountedFormat(true);
pProp->SetValue("HEVC Coding");
AddProperty(pProp); /* 6 */

AddReserved(*this, "reserved4", 4); /* 7 */

ExpectChildAtom("hvcC", Required, OnlyOne);
ExpectChildAtom("btrt", Optional, OnlyOne);
ExpectChildAtom("colr", Optional, OnlyOne);
ExpectChildAtom("pasp", Optional, OnlyOne);
}

void MP4Hev1Atom::Generate()
{
MP4Atom::Generate();

((MP4Integer16Property*)m_pProperties[1])->SetValue(1);

// property reserved3 has non-zero fixed values
static uint8_t reserved3[14] = {
0x00, 0x48, 0x00, 0x00,
0x00, 0x48, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x01,
};
m_pProperties[5]->SetReadOnly(false);
((MP4BytesProperty*)m_pProperties[5])->
SetValue(reserved3, sizeof(reserved3));
m_pProperties[5]->SetReadOnly(true);

// property reserved4 has non-zero fixed values
static uint8_t reserved4[4] = {
0x00, 0x18, 0xFF, 0xFF,
};
m_pProperties[7]->SetReadOnly(false);
((MP4BytesProperty*)m_pProperties[7])->
SetValue(reserved4, sizeof(reserved4));
m_pProperties[7]->SetReadOnly(true);
}

///////////////////////////////////////////////////////////////////////////////

}
} // namespace mp4v2::impl
86 changes: 86 additions & 0 deletions src/atom_hvc1.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
/*
* The contents of this file are subject to the Mozilla Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* Contributor(s):
* Chema Gonzalez <chemag@gmail.com>
*/

#include "src/impl.h"

namespace mp4v2 {
namespace impl {

///////////////////////////////////////////////////////////////////////////////

MP4Hvc1Atom::MP4Hvc1Atom(MP4File &file)
: MP4Atom(file, "hvc1")
{
AddReserved(*this, "reserved1", 6); /* 0 */

AddProperty( /* 1 */
new MP4Integer16Property(*this, "dataReferenceIndex"));

AddReserved(*this, "reserved2", 16); /* 2 */

AddProperty( /* 3 */
new MP4Integer16Property(*this, "width"));
AddProperty( /* 4 */
new MP4Integer16Property(*this, "height"));

AddReserved(*this, "reserved3", 14); /* 5 */

MP4StringProperty* pProp =
new MP4StringProperty(*this, "compressorName");
pProp->SetFixedLength(32);
pProp->SetCountedFormat(true);
pProp->SetValue("HEVC Coding");
AddProperty(pProp); /* 6 */

AddReserved(*this, "reserved4", 4); /* 7 */

ExpectChildAtom("hvcC", Required, OnlyOne);
ExpectChildAtom("btrt", Optional, OnlyOne);
ExpectChildAtom("colr", Optional, OnlyOne);
ExpectChildAtom("pasp", Optional, OnlyOne);
}

void MP4Hvc1Atom::Generate()
{
MP4Atom::Generate();

((MP4Integer16Property*)m_pProperties[1])->SetValue(1);

// property reserved3 has non-zero fixed values
static uint8_t reserved3[14] = {
0x00, 0x48, 0x00, 0x00,
0x00, 0x48, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x01,
};
m_pProperties[5]->SetReadOnly(false);
((MP4BytesProperty*)m_pProperties[5])->
SetValue(reserved3, sizeof(reserved3));
m_pProperties[5]->SetReadOnly(true);

// property reserved4 has non-zero fixed values
static uint8_t reserved4[4] = {
0x00, 0x18, 0xFF, 0xFF,
};
m_pProperties[7]->SetReadOnly(false);
((MP4BytesProperty*)m_pProperties[7])->
SetValue(reserved4, sizeof(reserved4));
m_pProperties[7]->SetReadOnly(true);
}

///////////////////////////////////////////////////////////////////////////////

}
} // namespace mp4v2::impl
Loading