Wargus / war1gus

Importer and scripts for Warcraft: Orcs and Humans
GNU General Public License v2.0
101 stars 14 forks source link

[macOS] Path issue with War1gus ffmpeg conversion tool #418

Closed shinra-electric closed 3 months ago

shinra-electric commented 1 year ago

A recent PR in Stratagus moves the data & config files to~/Library/Application\ Support/ folder. This fixes launching Wargus and War1gus from the app bundle directly. (No need to launch from terminal anymore).

However, when using the extraction tool for War1gus, ffmpeg does not save some video conversions.

The error message is: /Users/user/Library/Application: No such file or directory

It looks like it is not recognising the escaping slash in the directory name.

Here are two logs: War1gus broken.txt war1gus working.txt

Edit: I should mention that it is just SOME videos that are affected. The rest of the data is extracted correctly.

shinra-electric commented 1 year ago

I edited my original post to add successful and broken logs.

You can see that the issues start at line 1707.

In the working one is trying to get data from a mylist.txt file: Input #0, concat, from '/Users/user/Library/Stratagus/data.War1gus/videos/mylist.txt':

But in the broken one it can't find this file because it is not parsing the escaping \ in the Application Support folder correctly: /Users/user/Library/Application: No such file or directory

shinra-electric commented 1 year ago

I went through the files and only the following files will fail to convert: cave.ogv hintro.ogv ointro.ogv title.ogv

Edit: Going by this, I think the issue is somewhere in the MuxAllIntroVideos() function

shinra-electric commented 9 months ago

Just retested and this issue is still there.

I'm pretty sure the solution is just to enclose the appropriate var in quotation marks (which will allow using paths with spaces in them), but I can't find which is the correct variable...

shinra-electric commented 3 months ago

@Jarod42 If you'd be able to point me in the right direction, I'll make a PR to try and fix this. It should be an easy fix, but I can't find where the appropriate path variable is...

Jarod42 commented 3 months ago

I found "Application\ Support" in stratagus repo in stratagus\gameheaders\stratagus-game-launcher.h stratagus\src\stratagus\parameters.cpp I think it should simply be "Application Support"... You probably should have warning for "\ " as space is not a valid escape sequence... So not the fix we are looking for.

You can see that the issues start at line 1707.

It is even more likely the source:

in war1gus repo: war1gus\war1tool.cpp:1832

    const char* cmd1v = "ffmpeg -y -f concat -safe 0 -i %s "

should probably be

    const char* cmd1v = "ffmpeg -y -f concat -safe 0 -i \"%s\" "

and all other cmd in fact

    const char* cmd1a = "ffmpeg -y -f concat -safe 0 -i \"%s\" "
shinra-electric commented 3 months ago

Hmm, I edited the \"%s\" in the six cmd but it didn't affect anything...

shinra-electric commented 3 months ago

I found "Application\ Support" in stratagus repo in stratagus\gameheaders\stratagus-game-launcher.h stratagus\src\stratagus\parameters.cpp I think it should simply be "Application Support"... You probably should have warning for "\ " as space is not a valid escape sequence... So not the fix we are looking for.

I don't think this is the issue, because War1gus/Wargus/Stargus can all find the Application Support folder. I'll try removing the \ on the off-chance it helps with something...

Edit: Removing the \ didn't make any noticeable difference. War1gus could still find the app support folder, video muxing still failed.

Jarod42 commented 3 months ago

You still have "/Users/user/Library/Application: No such file or directory"? How did you run war1tool?

shinra-electric commented 3 months ago

You still have "/Users/user/Library/Application: No such file or directory"? How did you run war1tool?

I get:

[AVFormatContext @ 0x151606650] Unable to choose an output format for '/Users/user/Library/Application'; use a standard extension for the filename or specify the format manually.
[out#0 @ 0x6000028f09c0] Error initializing the muxer for /Users/user/Library/Application: Invalid argument
Error opening output file /Users/user/Library/Application.
Error opening output files: Invalid argument

I'm running war1tool not through the command line, just by opening the app. It says no data found on launch (correct, I'm deleting the data each time) and asks me to find an installer.

The GoG installer exe is not recognised, but I use innoextract on it and then point war1tool to DATA.WAR.

Almost all of the war1tool steps are working, it just seems to be the muxing that is not. If you look at previous ffmpeg actions, they all correctly identify the App Support folder. I should probably also mention that wartool works correctly as well.

Here is an updated terminal output: war1tool output.txt

Edit: Errors start at line 1710

Jarod42 commented 3 months ago

output parameters also need quoting: 1833:

    const char* cmd1v = "ffmpeg -y -f concat -safe 0 -i \"%s\" "
        "-codec:v huffyuv \"%s/%s/hintro_v.avi\"";
shinra-electric commented 3 months ago

I'm getting there, but the final .ogv is not getting saved.

Here is the latest output:

Terminal Saved Output.txt

So you can see that the first steps are successful, but the last step fails.

These are the adjustments I made (just for hintro:

// Castle sequence
    // const char* cmd1v = "ffmpeg -y -i %s/%s/hintro1.avi -i %s/%s/hintro2.avi "
    //  "-filter_complex '[0:0][1:0]concat=n=2:v=1:a=0[out]' "
    //  "-map '[out]' -codec:v huffyuv %s/%s/hintro_v.avi";
    mylist = fopen(listfile, "w");
    #ifdef WIN32
    fprintf(mylist, "file '%s'\n", "hintro1.avi");
    fprintf(mylist, "file '%s'\n", "hintro2.avi");
    #else
    fprintf(mylist, "file '%s/%s/%s'\n", Dir, VIDEO_PATH, "hintro1.avi");
    fprintf(mylist, "file '%s/%s/%s'\n", Dir, VIDEO_PATH, "hintro2.avi");
    #endif
    fclose(mylist);
    const char* cmd1v = "ffmpeg -y -f concat -safe 0 -i \"%s\" "
        "-codec:v huffyuv \"%s/%s/hintro_v.avi\"";
    snprintf(cmd, STATIC_CMD_SIZE - 1, cmd1v, listfile, Dir, VIDEO_PATH);
    system(cmd);

    // const char* cmd1a = "ffmpeg -y -f concat -safe 0 -i -i %s/%s/intro_1.wav -i %s/%s/intro_2.wav "
    //  "-filter_complex '[0:0][1:0]concat=n=2:v=0:a=1[out]' "
    //  "-map '[out]' %s/%s/hintro_a.wav";
    mylist = fopen(listfileSound, "w");
    #ifdef WIN32
    fprintf(mylist, "file '%s'\n", "intro_1.wav");
    fprintf(mylist, "file '%s'\n", "intro_2.wav");
    #else
    fprintf(mylist, "file '%s/%s/%s'\n", Dir, SOUND_PATH, "intro_1.wav");
    fprintf(mylist, "file '%s/%s/%s'\n", Dir, SOUND_PATH, "intro_2.wav");
    #endif
    fclose(mylist);
    const char* cmd1a = "ffmpeg -y -f concat -safe 0 -i \"%s\" "
        " \"%s/%s/hintro_a.wav\"";
    snprintf(cmd, STATIC_CMD_SIZE - 1, cmd1a, listfileSound, Dir, SOUND_PATH);
    system(cmd);

    const char* cmd1 = "ffmpeg -y -i \"%s/%s/hintro_v.avi\" -i \"%s/%s/hintro_a.wav\" "
        "-codec:v libtheora -qscale:v 31 -pix_fmt yuv420p -vb 4000k -codec:a libvorbis -qscale:a 15 \"%s/%s/hintro.ogv\"";
    snprintf(cmd, STATIC_CMD_SIZE - 1, cmd1, Dir, VIDEO_PATH, Dir, SOUND_PATH, Dir, VIDEO_PATH);
    system(cmd);

So the last place where there is an issue should be :

    const char* cmd1 = "ffmpeg -y -i \"%s/%s/hintro_v.avi\" -i \"%s/%s/hintro_a.wav\" "
        "-codec:v libtheora -qscale:v 31 -pix_fmt yuv420p -vb 4000k -codec:a libvorbis -qscale:a 15 \"%s/%s/hintro.ogv\"";
    snprintf(cmd, STATIC_CMD_SIZE - 1, cmd1, Dir, VIDEO_PATH, Dir, SOUND_PATH, Dir, VIDEO_PATH);
    system(cmd);

But I can't see an issue in there...

Jarod42 commented 3 months ago

I suggest to create a (Draft) PR with your changes. Might be simpler to follow the changes, and spot missing ones.

From what I see from log, there are still some missing quotes...

shinra-electric commented 3 months ago

https://github.com/shinra-electric/war1gus/tree/war1tool-path

Your help is appreciated 😅

shinra-electric commented 3 months ago

Fixed by #450