Skip to content

Commit adc6299

Browse files
Dan-FloresDaniel Flores
andauthored
Resolve clang-tidy lints in VideoEncoder (#897)
Co-authored-by: Daniel Flores <[email protected]>
1 parent 4a842f9 commit adc6299

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

src/torchcodec/_core/Encoder.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -598,8 +598,8 @@ void VideoEncoder::initializeEncoder(
598598
// TODO-VideoEncoder: Remove assumption that tensor in NCHW format
599599
auto sizes = frames_.sizes();
600600
inPixelFormat_ = AV_PIX_FMT_GBRP;
601-
inHeight_ = sizes[2];
602-
inWidth_ = sizes[3];
601+
inHeight_ = static_cast<int>(sizes[2]);
602+
inWidth_ = static_cast<int>(sizes[3]);
603603

604604
// Use specified dimensions or input dimensions
605605
// TODO-VideoEncoder: Allow height and width to be set
@@ -664,7 +664,7 @@ void VideoEncoder::encode() {
664664
getFFMPEGErrorStringFromErrorCode(status));
665665

666666
AutoAVPacket autoAVPacket;
667-
int numFrames = frames_.sizes()[0];
667+
int numFrames = static_cast<int>(frames_.sizes()[0]);
668668
for (int i = 0; i < numFrames; ++i) {
669669
torch::Tensor currFrame = frames_[i];
670670
UniqueAVFrame avFrame = convertTensorToAVFrame(currFrame, i);

src/torchcodec/_core/Encoder.h

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,16 @@ class VideoEncoder {
125125
public:
126126
~VideoEncoder();
127127

128+
// Rule of Five requires that we define copy and move
129+
// constructors and assignment operators.
130+
// Both are deleted because we have unique_ptr members
131+
VideoEncoder(const VideoEncoder&) = delete;
132+
VideoEncoder& operator=(const VideoEncoder&) = delete;
133+
134+
// Move assignment operator deleted since we have a const member
135+
VideoEncoder(VideoEncoder&&) = default;
136+
VideoEncoder& operator=(VideoEncoder&&) = delete;
137+
128138
VideoEncoder(
129139
const torch::Tensor& frames,
130140
int frameRate,
@@ -143,7 +153,7 @@ class VideoEncoder {
143153

144154
UniqueEncodingAVFormatContext avFormatContext_;
145155
UniqueAVCodecContext avCodecContext_;
146-
int streamIndex_;
156+
int streamIndex_ = -1;
147157
UniqueSwsContext swsContext_;
148158

149159
const torch::Tensor frames_;

0 commit comments

Comments
 (0)