-
Notifications
You must be signed in to change notification settings - Fork 81
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
Desktop Capture Input and example #79
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's also required to add ScreenCaptureInput tests.
This project uses Github Actions for testing, but I'm not sure if it's possible to have Desktop VM (i.e. non headless) there.
Probably https://github.com/marketplace/actions/screenshots-ci-action is good start point.
src/main/java/com/github/kokorin/jaffree/ffmpeg/DesktopCaptureInput.java
Show resolved
Hide resolved
@@ -0,0 +1,59 @@ | |||
package examples.ffmpeg; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add please Apache v2 licence.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
Please note most other examples don't have a license boilerplate though...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I have to add them, my bad
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The same as to previous Apache Licence - put your credits and 2020 year
Hi, and thanks for the review.
Anyway, I will fix the license and OS right away. It might take longer to setup a test but I'll give it a go. |
I added a test for DesktopCaptureInput and it succeeds on my Windows PC:
I doubt it will succeed in the automated Github environment though, due to the headless issue you mention. Unfortunately, the page you linked seems to be only about grabbing browser output (I think what they call "desktop" is just "desktop browser" as opposed to "mobile browser"). Maybe https://github.com/marketplace/actions/gabrielbb-xvfb-action would be an option, but I have no idea how to integrate that with the test framework you have put in place. Alternately, we can leave the test in @ignore with an explanation, like for the testAlpha() method... Anyway, as mentioned above, the current implementation runs on Windows (GDI mode) and most probably on Linux, but will not yet crop the requested area on Mac and Windows (DirectShow mode), so a successful test on Linux is not an indication of overall correctness. Edit: Confirmed: automated tests fail with |
That case with adding extra arguments as ffmpeg filter seems to be too complex for Jaffree. Honestly I don't want such changes to be added to ScreenCaptureInput. Such complex behaviour is more suiteable for custom code or even separate library which will provide extra capabilities on top of the Jaffree.
The same as above. But it could be useful to add Input implementation which is capable of getting audio/video device list. |
I agree with you, better keep Jaffree simple and move complex configurations to an extra layer. Now for audio, the issue is not that much for the Input implementation to select the right device, but more about an API (probably not an Input) that would query FFmpeg and return the list of devices, the same way FFprobe returns the list of Streams in a file. Now again, support is very dependant on the platform. DirectShow (Windows) and avfoundation (Mac) support device enumeration but I don't think X11Grab (Linux) or GDIGrab (Windows alt) do. Sounds logical as they are targeted at the display... What do you think ? More generally speaking, does Jaffree expose a "low level" API that would allow a client app to build its own FFmpeg "recipe" while benefiting from the wrapping layer of Jaffree ? |
src/main/java/com/github/kokorin/jaffree/ffmpeg/DesktopCaptureInput.java
Show resolved
Hide resolved
* - Call ffmpeg to return list of devices? list of screens? | ||
*/ | ||
public class DesktopCaptureInput extends BaseInput<DesktopCaptureInput> implements Input { | ||
private final boolean WINDOWS_USE_GDI = true; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Better to introduce an enum with DIRECT_SHOW and GDI values. Also since it's not static valirable it's name should be in snakeCase.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oops, I meant it to be a static configuration.
In fact, I think it should disappear in the long run but I'm still not convinced which one is best. GDI allows cropping but DirectShow seems the way to go for audio.
If we could mix GDI for video and Directshow for audio, I think it would be perfect, but I have to test further. That would prevent other sources such as webcams however, but we're in a Desktop Capture context anyway.
If the conclusion is that we need to keep both modes, I'll add a setter and use an enum indeed.
@@ -0,0 +1,59 @@ | |||
package examples.ffmpeg; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The same as to previous Apache Licence - put your credits and 2020 year
No, there is no such FFprobe-like output parsing, but there is an option to parse ffmpeg non-progress output. Check
Well, there definitely should be some option to select device (or specific window if possible). But what to grab (device, window or whole screen) should be decided by a library user. If such option isn't supported by current platform/configuration a user should see some warning in logs. Any command line arguments should not be omitted by Jaffree since ffmpeg behaviour may change in the future.
Not sure what do you mean by low-level API. Is it |
…iguration. If not supported, calling setArea does nothing except log a warning with explanations. Save for cursor inclusion option if not supported. Also added Javadoc.
…re level on this OS/configuration.
I'll take a look at Once device retrieval is done, I think a separate "DeviceCaptureInput" class would be best suited, and maybe DesktopCaptureInput should become a subclass of it. And yeah, I agree a warning in the logs for unsupported features is the way to go. It's done now, and I also added a query method for user code to determine if the crop feature is supported or not. The example is updated accordingly and chooses between input cropping option and additional crop filter according to the OS/configuration at runtime. After digging a bit, yes, by "low level", I meant the ProcessHandler indeed. Thanks. |
By the way, am I correct that Jaffree currently only supports the standard "filter" and "complexfilter" options, but not the "per-stream" filter like '-vf' (shorthand for '-filter:v') and '-af' (or '-filter:a') ?
where the FilterStream enum could be "AUDIO" or "VIDEO" and, if specified, would replace the "-filter" prefix by "-filter:a" or "-filter:v" ? What do you think ? Kind regards, Vicne |
Seems so, but Jaffree does allow arbitrary parameters added, so currently there is a workaround.
Check I will happily aceept such PR, please don't forget about JavaDoc (I'm working on it in CHECKSTYLE branch), as well as tests. Also probably there should be more methods which accept FilterGraph. |
See #80 for "-af" and "-vf" first draft, don't hesitate to comment. |
…n in case the capture can't keep up with the requested frame rate
Thanks for merging the I'm now working on device list parsing but I have an issue with the Plus, there is a Here is my code:
and here is the output:
Any hint ? |
I also have a separate issue: when trying to stop a desktop capture using one of the 3 "Forceful stop" methods from the README.md (tried the
I then have to kill the Java process but the resulting output file is corrupt (less than 1KB). When using ffmpeg in command-line, one can exit cleanly by either hitting CTRL-C or just typing the 'q' key. I'm tempted to think this method would be much cleaner than killing the process, but I see the What would be your advice to be able to send keystrokes to a running Kind regards, Vicne |
ffmpeg prints different data to both stdout & stderr. Seems you need to read not from OutputListener, but to replace StdOutReader or StdErrReader.
That's definitely caused by force stop of ffmpeg. I haven't experimented with graceful stop. Probably you have to pass I want to thank you for your work on Jaffree and improving it. Good job! |
Oh, and if you intend to wrap up a release, could you please consider merging this PR as well ? |
I have decided to introduce develop branch to follow simplified gitflow. Please, close this PR and create another one from the same branch to develop branch. PS today I unfortunatelly had no time to integrate this changes to release. Will do my best to do it tomorrow. |
I hope I understood correctly the "create another one from the same branch to develop branch" part. |
Follow-up to issue #78