File torchvision-revert-pr8408.patch of Package python-torchvision-stable

commit e631f37ea0292a673b4222e596b30a9d698b8496
Author: Oleksandr Ostrenko <oleksandr.ostrenko@gmail.com>
Date:   Sat Aug 9 10:04:07 2025 +0200

    Revert "Add compatibility with FFMPEG 7.0 (#8408)"
    
    This reverts commit 375cfdf5675d0b6dbebe4d49ffcd0a6d50081715.

diff --git a/torchvision/csrc/io/decoder/audio_sampler.cpp b/torchvision/csrc/io/decoder/audio_sampler.cpp
index d46b93d..e26d788 100644
--- a/torchvision/csrc/io/decoder/audio_sampler.cpp
+++ b/torchvision/csrc/io/decoder/audio_sampler.cpp
@@ -48,23 +48,6 @@ bool AudioSampler::init(const SamplerParameters& params) {
     return false;
   }
 
-#if LIBAVUTIL_VERSION_INT >= AV_VERSION_INT(57, 28, 100)
-  SwrContext* swrContext_ = NULL;
-  AVChannelLayout channel_out;
-  AVChannelLayout channel_in;
-  av_channel_layout_default(&channel_out, params.out.audio.channels);
-  av_channel_layout_default(&channel_in, params.in.audio.channels);
-  int ret = swr_alloc_set_opts2(
-      &swrContext_,
-      &channel_out,
-      (AVSampleFormat)params.out.audio.format,
-      params.out.audio.samples,
-      &channel_in,
-      (AVSampleFormat)params.in.audio.format,
-      params.in.audio.samples,
-      0,
-      logCtx_);
-#else
   swrContext_ = swr_alloc_set_opts(
       nullptr,
       av_get_default_channel_layout(params.out.audio.channels),
@@ -75,7 +58,6 @@ bool AudioSampler::init(const SamplerParameters& params) {
       params.in.audio.samples,
       0,
       logCtx_);
-#endif
   if (swrContext_ == nullptr) {
     LOG(ERROR) << "Cannot allocate SwrContext";
     return false;
diff --git a/torchvision/csrc/io/decoder/audio_stream.cpp b/torchvision/csrc/io/decoder/audio_stream.cpp
index 9d7354e..0f6c57e 100644
--- a/torchvision/csrc/io/decoder/audio_stream.cpp
+++ b/torchvision/csrc/io/decoder/audio_stream.cpp
@@ -6,36 +6,26 @@
 namespace ffmpeg {
 
 namespace {
-static int get_nb_channels(const AVFrame* frame, const AVCodecContext* codec) {
-#if LIBAVUTIL_VERSION_INT >= AV_VERSION_INT(57, 28, 100)
-  return frame ? frame->ch_layout.nb_channels : codec->ch_layout.nb_channels;
-#else
-  return frame ? frame->channels : codec->channels;
-#endif
-}
-
 bool operator==(const AudioFormat& x, const AVFrame& y) {
   return x.samples == static_cast<size_t>(y.sample_rate) &&
-      x.channels == static_cast<size_t>(get_nb_channels(&y, nullptr)) &&
-      x.format == y.format;
+      x.channels == static_cast<size_t>(y.channels) && x.format == y.format;
 }
 
 bool operator==(const AudioFormat& x, const AVCodecContext& y) {
   return x.samples == static_cast<size_t>(y.sample_rate) &&
-      x.channels == static_cast<size_t>(get_nb_channels(nullptr, &y)) &&
-      x.format == y.sample_fmt;
+      x.channels == static_cast<size_t>(y.channels) && x.format == y.sample_fmt;
 }
 
 AudioFormat& toAudioFormat(AudioFormat& x, const AVFrame& y) {
   x.samples = y.sample_rate;
-  x.channels = get_nb_channels(&y, nullptr);
+  x.channels = y.channels;
   x.format = y.format;
   return x;
 }
 
 AudioFormat& toAudioFormat(AudioFormat& x, const AVCodecContext& y) {
   x.samples = y.sample_rate;
-  x.channels = get_nb_channels(nullptr, &y);
+  x.channels = y.channels;
   x.format = y.sample_fmt;
   return x;
 }
@@ -64,15 +54,9 @@ int AudioStream::initFormat() {
   if (format_.format.audio.samples == 0) {
     format_.format.audio.samples = codecCtx_->sample_rate;
   }
-#if LIBAVUTIL_VERSION_INT >= AV_VERSION_INT(57, 28, 100)
-  if (format_.format.audio.channels == 0) {
-    format_.format.audio.channels = codecCtx_->ch_layout.nb_channels;
-  }
-#else
   if (format_.format.audio.channels == 0) {
     format_.format.audio.channels = codecCtx_->channels;
   }
-#endif
   if (format_.format.audio.format == AV_SAMPLE_FMT_NONE) {
     format_.format.audio.format = codecCtx_->sample_fmt;
   }
openSUSE Build Service is sponsored by