Bug 442328

Summary: Find ffmpeg automatically from PATH
Product: [Applications] krita Reporter: healer.harie
Component: AnimationAssignee: Krita Bugs <krita-bugs-null>
Status: RESOLVED FIXED    
Severity: wishlist CC: alvin, knowzero
Priority: NOR    
Version First Reported In: 5.0.0-beta1   
Target Milestone: ---   
Platform: Compiled Sources   
OS: Microsoft Windows   
Latest Commit: Version Fixed/Implemented In:
Sentry Crash Report:

Description healer.harie 2021-09-12 10:05:57 UTC
SUMMARY

At the Render Animation window it can be
quite tiresome to again enter the path of ffmpeg again, to render an animation.

Would it be possible for it to automatically detect that my find my ffmpeg by going through the PATH variable in my system?

I suppose the `where` command in windows may also help.

```
FILE *fp = popen("where ffmpeg", "r");
// assert (fp != NULL);
if (NULL == fgets(ffmpeg_path, 200, fp){
  /* SPECIFY THE LOCATION OF FFMPEG MANUALLY */
}
if (ffmpeg_path[0] == '\0')
  /* SPECIFY THE LOCATION OF FFMPEG MANUALLY */
```

This is not a real code but a proof of concept. Though there may be other method better than this.

SOFTWARE/OS VERSIONS
Windows: 10
macOS: 
Linux/KDE Plasma: 
(available in About System)
KDE Plasma Version: 
KDE Frameworks Version: 
Qt Version:
Comment 1 healer.harie 2021-09-12 10:08:05 UTC
Correction*

Would it be possible for it to automatically detect my ffmpeg by going through the PATH variable in my system?
Comment 2 Alvin Wong 2021-09-12 11:10:43 UTC
Using ffprobe/ffmpeg from PATH seems like an obvious thing. I'm kind of surprised that it doesn't already work.

Note: For Windows, the suggested approach shall not be used. Instead, we can use the SearchPath API [1] .

However, regarding re-entering the path, the dialog should remember the chosen path, so there should be no need to re-enter the path every time. It only needs to be done once, and this is the behaviour I see on recent nightly builds.

[1]: https://docs.microsoft.com/en-us/windows/win32/api/processenv/nf-processenv-searchpathw
Comment 3 healer.harie 2021-09-12 15:00:46 UTC
It's strange that you mentioned that it should already work. Was this behaviour replicatable in other machine (including linux and macOS) for 5.0.0beta1?

I did have krita v4.4.7 in an other Windows machine (long ago), where I've added an additional rule of the path of ffmpeg (C:\Program Files\fftools) to the environment variable, PATH. The CMD does recognize the `ffmpeg` command, but krita don't automatically find it.

I ran krita.com, and tried to open the "Render Animation", the log contained like:
```
...
Qprocess: Destroyed while process ("C:\\Program Files\\fftools\\ffmpeg.exe") is still running.

```

It seems that somehow, krita knows ffmpeg.exe exist and its location but the FFmpeg text box is still empty.

But, if I manually execute ffmpeg.exe (by clicking the ffmpeg executable), Krita will eventually fill up the location of ffmpeg and the "Qprocess log" stops appearing. It remember this even if I restart Krita again and again, but do I restart the computer itself, is when it will be back to normal and I had to execute ffmpeg again. This does not solve the problem.

On a side note, I see that proposedPaths is written to some stream https://github.com/KDE/krita/blob/fd7ec51dd1e66fc3aa92a6021036fb711ba69003/libs/ui/animation/KisFFMpegWrapper.cpp#L365, where could I possibly find this file?
Comment 4 Alvin Wong 2021-09-12 16:28:55 UTC
Please note that I did not assert whether Krita does or does not already look for ffmpeg on PATH, as I have not checked it in any way. I just thought it would since ffmpeg being on PATH should be commonplace on Linux.

If you are still testing with 5.0 beta 1, I would suggest you test with the latest nightly (Krita Plus [1]) since it may already contain some fixes for loading the previously saved ffmpeg location.

[1]: https://binary-factory.kde.org/job/Krita_Stable_Windows_Build/
Comment 5 Know Zero 2021-09-13 20:14:24 UTC
(In reply to healer.harie from comment #3)
> It's strange that you mentioned that it should already work. Was this
> behaviour replicatable in other machine (including linux and macOS) for
> 5.0.0beta1?
> 
> I did have krita v4.4.7 in an other Windows machine (long ago), where I've
> added an additional rule of the path of ffmpeg (C:\Program Files\fftools) to
> the environment variable, PATH. The CMD does recognize the `ffmpeg` command,
> but krita don't automatically find it.
> 
> I ran krita.com, and tried to open the "Render Animation", the log contained
> like:
> ```
> ...
> Qprocess: Destroyed while process ("C:\\Program Files\\fftools\\ffmpeg.exe")
> is still running.
> 
> ```
> 
> It seems that somehow, krita knows ffmpeg.exe exist and its location but the
> FFmpeg text box is still empty.
> 
> But, if I manually execute ffmpeg.exe (by clicking the ffmpeg executable),
> Krita will eventually fill up the location of ffmpeg and the "Qprocess log"
> stops appearing. It remember this even if I restart Krita again and again,
> but do I restart the computer itself, is when it will be back to normal and
> I had to execute ffmpeg again. This does not solve the problem.
> 
> On a side note, I see that proposedPaths is written to some stream
> https://github.com/KDE/krita/blob/fd7ec51dd1e66fc3aa92a6021036fb711ba69003/
> libs/ui/animation/KisFFMpegWrapper.cpp#L365, where could I possibly find
> this file?

It's the timeout issue that should have been fixed in:

https://invent.kde.org/graphics/krita/-/commit/123c302c722376870ed6def5a873b046576882b8

Try the latest nightly build and it should work.

This is a duplicate of:
https://bugs.kde.org/show_bug.cgi?id=441435
Comment 6 healer.harie 2021-09-14 04:28:34 UTC
I download the Windows setup from build 1236 (https://binary-factory.kde.org/job/Krita_Stable_Windows_Build/1236/). Krita now automatically finds ffmpeg from PATH. 

I restarted my computer (once), but the problem doesn't persist anymore.

Thanks.