Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix warning of changing video frame properties on the fly #3318

Closed
wants to merge 1 commit into from
Closed
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
25 changes: 22 additions & 3 deletions torchaudio/csrc/ffmpeg/stream_writer/encode_process.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,22 +96,38 @@ enum AVSampleFormat get_src_sample_fmt(const std::string& src) {
".");
}

enum AVPixelFormat get_src_pix_fmt(const std::string& src) {
enum AVPixelFormat get_src_pix_fmt(
const std::string& src,
c10::optional<std::string> hw_accel) {
AVPixelFormat fmt = av_get_pix_fmt(src.c_str());
switch (fmt) {
case AV_PIX_FMT_GRAY8:
case AV_PIX_FMT_RGB24:
case AV_PIX_FMT_BGR24:
case AV_PIX_FMT_YUV444P:
return fmt;
#ifdef USE_CUDA
case AV_PIX_FMT_CUDA:
if (hw_accel.has_value()) {
return fmt;
}
#endif
default:;
}

bool is_cuda;
#ifdef USE_CUDA
if (hw_accel.has_value()) {
is_cuda = true;
}
#endif

TORCH_CHECK(
false,
"Unsupported pixel format (",
src,
") was provided. Valid values are ",
[]() -> std::string {
[is_cuda]() -> std::string {
std::vector<std::string> ret;
for (const auto& fmt :
{AV_PIX_FMT_GRAY8,
Expand All @@ -120,6 +136,9 @@ enum AVPixelFormat get_src_pix_fmt(const std::string& src) {
AV_PIX_FMT_YUV444P}) {
ret.emplace_back(av_get_pix_fmt_name(fmt));
}
if (is_cuda) {
ret.emplace_back(av_get_pix_fmt_name(AV_PIX_FMT_CUDA));
}
return c10::Join(", ", ret);
}(),
".");
Expand Down Expand Up @@ -854,7 +873,7 @@ EncodeProcess get_video_encode_process(
// so we directly get the format via FFmpeg.
const AVPixelFormat src_fmt = (disable_converter)
? av_get_pix_fmt(format.c_str())
: get_src_pix_fmt(format);
: get_src_pix_fmt(format, hw_accel);
const AVRational src_rate = av_d2q(frame_rate, 1 << 24);

// 2. Fetch codec from default or override
Expand Down