a-schild / jave2

The JAVE (Java Audio Video Encoder) library is Java wrapper on the ffmpeg project
GNU General Public License v3.0
1.2k stars 246 forks source link

Cannot run program "/tmp/jave/ffmpeg-amd64-3.0.1": error=26, Text file busy #238

Closed AIAlexander closed 10 months ago

AIAlexander commented 10 months ago

Hi, I encountered this error when using a thread pool to parallelly use ffmpeg commands for capturing screenshots from different videos. Here is Maven:

<dependency>
     <groupId>ws.schild</groupId>
     <artifactId>jave-all-deps</artifactId>
     <version>3.0.1</version>
</dependency>

code:

List<Video> videos = new ArrayList<>;
CountDownLatch latch = new CountDownLatch(videos.size());
Executor executor = CustomExecutor();
for (Video v : videos) {
    executor.run(() -> {
        try {
           ProcessWrapper p = new DefaultFFMPEGLocator().createExecutor();
           p.addArgument("-ss");
           ........
           p.execute();
        } catch(Exception e) {
            e.printStackTrace();
        } finally {
            latch.countDown();
        }
    })
}

Is it not allowed to use ffmpeg commands with multiple threads simultaneously? Thanks for the help!

a-schild commented 10 months ago

The code should work concurrently, but I think you are using it incorrectly.

Can you please modify your code, so that

Inside the DefaultFFMPEGLocator we have a semaphore on the class instance, and when you create multiple DefaultFFMPEGLocator instances they won't share the semaphore

AIAlexander commented 10 months ago

Thank you! I will try it