Skip to content

Combine encoding into DeviceInterface#1213

Merged
Dan-Flores merged 8 commits intometa-pytorch:mainfrom
Dan-Flores:refactor_device_interface_together
Feb 4, 2026
Merged

Combine encoding into DeviceInterface#1213
Dan-Flores merged 8 commits intometa-pytorch:mainfrom
Dan-Flores:refactor_device_interface_together

Conversation

@Dan-Flores
Copy link
Contributor

@Dan-Flores Dan-Flores commented Jan 29, 2026

This PR merges encoding into the DeviceInterface pattern.

  • The code within Encoder.cpp now always expects to have a deviceInterface_ member variable defined, and uses it to call encoding functions.
  • CUDA encoding functions were already present in CudaDeviceInterface.cpp
  • CPU encoding functions are moved out of Encoder.cpp, into CpuDeviceInterface.cpp

@pytorch-bot
Copy link

pytorch-bot bot commented Jan 29, 2026

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/meta-pytorch/torchcodec/1213

Note: Links to docs will display an error until the docs builds have been completed.

✅ No Failures

As of commit e27a05a with merge base 06d4538 (image):
💚 Looks good so far! There are no failures yet. 💚

This comment was automatically generated by Dr. CI and updates every 15 minutes.

@meta-cla meta-cla bot added the CLA Signed This label is managed by the Meta Open Source bot. label Jan 29, 2026
return std::string("CPU Device Interface.");
}

UniqueAVFrame CpuDeviceInterface::convertTensorToAVFrameForEncoding(
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CPU specific encoding implementation is removed from Encoder.cpp and added here.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just checking: this is 100% copy/pasted, correct?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, the main difference is that Encoder.h's member variables are replaced by the local variables on lines 513-518.
This made me realize we can remove those member variables from Encoder.h entirely, since they are unused.

UniqueEncodingAVFormatContext avFormatContext_;
UniqueAVCodecContext avCodecContext_;
AVStream* avStream_ = nullptr;
UniqueSwsContext swsContext_;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This member variable is deleted in favor of the swsContext_ in CpuDeviceInterface.h.

// It is here to isolate CUDA dependencies from CPU builds
// TODO Video-Encoder: Reconsider using video encoding functions in device
// interface
virtual UniqueAVFrame convertCUDATensorToAVFrameForEncoding(
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We replace convertCUDATensor... with convertTensor... to integrate into the device interface pattern.

@Dan-Flores Dan-Flores changed the title [wip] Combine encoding into DeviceInterface Combine encoding into DeviceInterface Feb 3, 2026
@Dan-Flores Dan-Flores marked this pull request as ready for review February 3, 2026 20:07
Copy link
Contributor

@NicolasHug NicolasHug left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @Dan-Flores!

return std::string("CPU Device Interface.");
}

UniqueAVFrame CpuDeviceInterface::convertTensorToAVFrameForEncoding(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just checking: this is 100% copy/pasted, correct?

@Dan-Flores Dan-Flores merged commit 65ed0d5 into meta-pytorch:main Feb 4, 2026
68 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Meta Open Source bot.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants