Skip to content

Commit 6c85f63

Browse files
committed
StreamMetadata.sampleAspectRation: use AVRational instead of std::pair
1 parent c51a341 commit 6c85f63

File tree

3 files changed

+6
-7
lines changed

3 files changed

+6
-7
lines changed

src/torchcodec/_core/Metadata.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@
88

99
#include <optional>
1010
#include <string>
11-
#include <utility>
1211
#include <vector>
1312

1413
extern "C" {
1514
#include <libavcodec/avcodec.h>
1615
#include <libavutil/avutil.h>
16+
#include <libavutil/rational.h>
1717
}
1818

1919
namespace facebook::torchcodec {
@@ -46,7 +46,7 @@ struct StreamMetadata {
4646
// Video-only fields derived from the AVCodecContext.
4747
std::optional<int64_t> width;
4848
std::optional<int64_t> height;
49-
std::optional<std::pair<int, int>> sampleAspectRatio;
49+
std::optional<AVRational> sampleAspectRatio;
5050

5151
// Audio-only fields
5252
std::optional<int64_t> sampleRate;

src/torchcodec/_core/SingleStreamDecoder.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -459,9 +459,8 @@ void SingleStreamDecoder::addVideoStream(
459459

460460
streamMetadata.width = streamInfo.codecContext->width;
461461
streamMetadata.height = streamInfo.codecContext->height;
462-
streamMetadata.sampleAspectRatio = {
463-
streamInfo.codecContext->sample_aspect_ratio.num,
464-
streamInfo.codecContext->sample_aspect_ratio.den};
462+
streamMetadata.sampleAspectRatio =
463+
streamInfo.codecContext->sample_aspect_ratio;
465464
}
466465

467466
void SingleStreamDecoder::addAudioStream(

src/torchcodec/_core/custom_ops.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -603,9 +603,9 @@ std::string get_stream_json_metadata(
603603
}
604604
if (streamMetadata.sampleAspectRatio.has_value()) {
605605
map["sampleAspectRatioNum"] =
606-
std::to_string((*streamMetadata.sampleAspectRatio).first);
606+
std::to_string((*streamMetadata.sampleAspectRatio).num);
607607
map["sampleAspectRatioDen"] =
608-
std::to_string((*streamMetadata.sampleAspectRatio).second);
608+
std::to_string((*streamMetadata.sampleAspectRatio).den);
609609
}
610610
if (streamMetadata.averageFpsFromHeader.has_value()) {
611611
map["averageFpsFromHeader"] =

0 commit comments

Comments
 (0)