Skip to content

Disable FFmpeg logs for encoder #625

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

Merged
merged 4 commits into from
Apr 8, 2025
Merged

Conversation

NicolasHug
Copy link
Member

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
@@ -5,6 +5,7 @@
// 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 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