Skip to content

web ui ffmpeg error in windows (and fix) #2

Closed

Description

@laresistenciadelbit

When importing a wav file to the ui I get the message:

[in#0 @ 000001cbba4a5480] Error opening input: Invalid argument
Error opening input file 'T:\wintmp\zonos2-1.audio'.
Error opening input files: Invalid argument
spk: ffmpeg failed (rc=-22, 0 samples) for T:\wintmp\zonos2-1.audio

The problem is this line from the spk-encoder.cpp file:

std::string cmd = "ffmpeg -v error -i '" + std::string(path) +
                      "' -ac 1 -ar " + std::to_string(m.sr) + " -f f32le -";

The character ' is valid for linux shell but not for windows.
The fix (ai told me) is to use a different management for the windows ffmpeg call remplacing the problematic line with:

    // Use double quotes on Windows (cmd.exe doesn't understand single quotes) and single
    // quotes on POSIX shells. Also escape any embedded double-quotes in the path on Windows.
#ifdef _WIN32
    std::string escaped(path);
    {
        std::string r;
        r.reserve(escaped.size() + 4);
        for (char c : escaped) { if (c == '"') r += '"'; r += c; }
        escaped = std::move(r);
    }
    std::string cmd = "ffmpeg -v error -i \"" + escaped +
                      "\" -ac 1 -ar " + std::to_string(m.sr) + " -f f32le -";
#else
    std::string cmd = "ffmpeg -v error -i '" + std::string(path) +
                      "' -ac 1 -ar " + std::to_string(m.sr) + " -f f32le -";
#endif

aaand... recompile it again, and failing again because of the next line:

FILE * pp = popen(cmd.c_str(), "r");

which needs to be opened as binary:

FILE * pp = popen(cmd.c_str(), "rb");

With this two changes it worked for me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions