Skip to content

Commit

Permalink
Use aspect ratio from mpeg2 video bitstream if known
Browse files Browse the repository at this point in the history
  • Loading branch information
philipnbbc committed Apr 22, 2024
1 parent 5212eb2 commit d73b650
Show file tree
Hide file tree
Showing 9 changed files with 30 additions and 1 deletion.
2 changes: 2 additions & 0 deletions include/bmx/mxf_helper/MPEG2LGMXFDescriptorHelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@


#include <bmx/mxf_helper/PictureMXFDescriptorHelper.h>
#include <bmx/essence_parser/MPEG2EssenceParser.h>



Expand Down Expand Up @@ -66,6 +67,7 @@ class MPEG2LGMXFDescriptorHelper : public PictureMXFDescriptorHelper

virtual mxfpp::FileDescriptor* CreateFileDescriptor(mxfpp::HeaderMetadata *header_metadata);
virtual void UpdateFileDescriptor();
void UpdateFileDescriptor(MPEG2EssenceParser *essence_parser);

public:
MXFFrameLayout GetFrameLayout() const;
Expand Down
3 changes: 3 additions & 0 deletions include/bmx/writer_helper/MPEG2LGWriterHelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
#include <vector>

#include <bmx/essence_parser/MPEG2EssenceParser.h>
#include <bmx/mxf_helper/MPEG2LGMXFDescriptorHelper.h>



Expand All @@ -55,6 +56,7 @@ class MPEG2LGWriterHelper
MPEG2LGWriterHelper();
~MPEG2LGWriterHelper();

void SetDescriptorHelper(MPEG2LGMXFDescriptorHelper *descriptor_helper);
void SetFlavour(Flavour flavour);

public:
Expand Down Expand Up @@ -85,6 +87,7 @@ class MPEG2LGWriterHelper
uint32_t GetBitRate() const { return mBitRate; }

private:
MPEG2LGMXFDescriptorHelper *mDescriptorHelper;
Flavour mFlavour;

MPEG2EssenceParser mEssenceParser;
Expand Down
1 change: 1 addition & 0 deletions src/as02/AS02MPEG2LGTrack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ AS02MPEG2LGTrack::AS02MPEG2LGTrack(AS02Clip *clip, uint32_t track_index, Essence
{
mTrackNumber = MXF_MPEG_PICT_TRACK_NUM(0x01, MXF_MPEG_PICT_FRAME_WRAPPED_EE_TYPE, 0x00);
mEssenceElementKey = VIDEO_ELEMENT_KEY;
mWriterHelper.SetDescriptorHelper(dynamic_cast<MPEG2LGMXFDescriptorHelper*>(mDescriptorHelper));

mIndexStartPosition = 0;
}
Expand Down
1 change: 1 addition & 0 deletions src/avid_mxf/AvidMPEG2LGTrack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ using namespace mxfpp;
AvidMPEG2LGTrack::AvidMPEG2LGTrack(AvidClip *clip, uint32_t track_index, EssenceType essence_type, File *file)
: AvidPictureTrack(clip, track_index, essence_type, file)
{
mWriterHelper.SetDescriptorHelper(dynamic_cast<MPEG2LGMXFDescriptorHelper*>(mDescriptorHelper));
mWriterHelper.SetFlavour(MPEG2LGWriterHelper::AVID_FLAVOUR);

mTrackNumber = MXF_AVID_MPEG_PICT_TRACK_NUM;
Expand Down
11 changes: 11 additions & 0 deletions src/mxf_helper/MPEG2LGMXFDescriptorHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,17 @@ void MPEG2LGMXFDescriptorHelper::UpdateFileDescriptor()
}
}

void MPEG2LGMXFDescriptorHelper::UpdateFileDescriptor(MPEG2EssenceParser *essence_parser)
{
UpdateFileDescriptor();

GenericPictureEssenceDescriptor *picture_descriptor = dynamic_cast<GenericPictureEssenceDescriptor*>(mFileDescriptor);
BMX_ASSERT(picture_descriptor);

if (essence_parser->HaveKnownAspectRatio())
picture_descriptor->setAspectRatio(essence_parser->GetAspectRatio());
}

MXFFrameLayout MPEG2LGMXFDescriptorHelper::GetFrameLayout() const
{
return SUPPORTED_ESSENCE[mEssenceIndex].frame_layout;
Expand Down
1 change: 1 addition & 0 deletions src/mxf_op1a/OP1AMPEG2LGTrack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ OP1AMPEG2LGTrack::OP1AMPEG2LGTrack(OP1AFile *file, uint32_t track_index, uint32_
{
mTrackNumber = MXF_MPEG_PICT_TRACK_NUM(0x01, MXF_MPEG_PICT_FRAME_WRAPPED_EE_TYPE, 0x00);
mEssenceElementKey = VIDEO_ELEMENT_KEY;
mWriterHelper.SetDescriptorHelper(dynamic_cast<MPEG2LGMXFDescriptorHelper*>(mDescriptorHelper));
}

OP1AMPEG2LGTrack::~OP1AMPEG2LGTrack()
Expand Down
1 change: 1 addition & 0 deletions src/rdd9_mxf/RDD9MPEG2LGTrack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ RDD9MPEG2LGTrack::RDD9MPEG2LGTrack(RDD9File *file, uint32_t track_index, uint32_
{
mPictureDescriptorHelper = dynamic_cast<PictureMXFDescriptorHelper*>(mDescriptorHelper);
BMX_ASSERT(mPictureDescriptorHelper);
mWriterHelper.SetDescriptorHelper(dynamic_cast<MPEG2LGMXFDescriptorHelper*>(mDescriptorHelper));
mValidator = 0;

mPictureDescriptorHelper->SetAspectRatio(ASPECT_RATIO_16_9);
Expand Down
9 changes: 9 additions & 0 deletions src/writer_helper/MPEG2LGWriterHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ using namespace bmx;

MPEG2LGWriterHelper::MPEG2LGWriterHelper()
{
mDescriptorHelper = 0;
mFlavour = DEFAULT_FLAVOUR;
mPosition = 0;
mPrevKeyFramePosition = -1;
Expand Down Expand Up @@ -84,6 +85,11 @@ MPEG2LGWriterHelper::~MPEG2LGWriterHelper()
{
}

void MPEG2LGWriterHelper::SetDescriptorHelper(MPEG2LGMXFDescriptorHelper *descriptor_helper)
{
mDescriptorHelper = descriptor_helper;
}

void MPEG2LGWriterHelper::SetFlavour(Flavour flavour)
{
mFlavour = flavour;
Expand Down Expand Up @@ -222,6 +228,9 @@ void MPEG2LGWriterHelper::ProcessFrame(const unsigned char *data, uint32_t size)
mKeyFrameTemporalReference = mTemporalReference;
}

if (mPosition == 0 && mDescriptorHelper)
mDescriptorHelper->UpdateFileDescriptor(&mEssenceParser);

mPosition++;
}

Expand Down
2 changes: 1 addition & 1 deletion test/avid_mxf/test_mpeg2lg.cmake
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Test creating an Avid MXF file containing AVC video and 2 PCM tracks
# Test creating an Avid MXF file containing MPEG2 video and 2 PCM tracks

include("${TEST_SOURCE_DIR}/test_common.cmake")

Expand Down

0 comments on commit d73b650

Please sign in to comment.