Skip to content

Conversation

@NicolasHug
Copy link
Contributor

And let the user define the log level through TORCHCODEC_FFMPEG_LOG_LEVEL, like in the decoder.

@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Meta Open Source bot. label Apr 7, 2025
// LICENSE file in the root directory of this source tree.

#include "src/torchcodec/_core/FFMPEGCommon.h"
#include <cstdlib>
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we need <cstring> to get std::strcmp (https://en.cppreference.com/w/cpp/string/byte/strcmp); see the errors in CI. It only sees strcmp from the C headers.

But, I think we can actually just make things simpler and avoid manipulating C-style strings:

int logLevel = AV_LOG_QUIET;
const char* logLevelPtr = std::getenv("TORCHCODEC_FFMPEG_LOG_LEVEL");
if (logLevelPtr != nullPtr) {
  std::string logLevelEnv(logLevelPtr);
  if (logLevelEnv == "QUIET") {
    logLevel = AV_LOG_QUIET;
  }
  else if (logLevelEnv == "PANIC") {
    logLevel = AV_LOG_PANIC;
  }
  ...
}

There's a marginal cost in copying the string, but we execute this code once at startup, and we should prefer C++ string operations over C-style string operations.

@NicolasHug NicolasHug merged commit 697176e into meta-pytorch:main Apr 8, 2025
46 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.

3 participants