Search code examples
amazon-web-servicesspring-bootffmpegamazon-elastic-beanstalkbytedeco-javacv

Process vide files to take screen grabs in java spring boot


I am using JavaCV library with ffmpeg bindings to process video files and taking screen grabs at specific frames. Adding JavaCV library dependency to my spring project increases the size of my jar file from around 90Mb > 1+ Gb. This is a big issue becuase my project is deployed on AWS elastic beanstalk that accepts a max size of 500 Mb for a jar file.

Need help to resolve this issue with the jar file or else any other alternate library that could do this.

What I tried: I have removed all accept the abosultely necessary dependencies in my project to reduce the jar size. I have also tried to find alternate solutions but couldnt get anything. My pom file looks like

<dependencies>
        <!-- <dependency>
            <groupId>org.apache.tika</groupId>
            <artifactId>tika-core</artifactId>
            <version>1.27</version>
        </dependency>
        <dependency>
            <groupId>org.apache.tika</groupId>
            <artifactId>tika-parsers</artifactId>
            <version>1.27</version>
        </dependency> -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>
        <dependency>
            <groupId>com.google.oauth-client</groupId>
            <artifactId>google-oauth-client</artifactId>
            <version>1.32.1</version>
        </dependency>
        <dependency>
            <groupId>com.google.http-client</groupId>
            <artifactId>google-http-client</artifactId>
            <version>1.32.1</version>
        </dependency>
        <!-- Thanks for using https://jar-download.com -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-oauth2-client</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
        <!-- <dependency>
            <groupId>org.bytedeco</groupId>
            <artifactId>javacv-platform</artifactId>
            <version>1.5.9</version>
        </dependency> -->
        <dependency>
            <groupId>org.bytedeco</groupId>
            <artifactId>javacv</artifactId>
            <version>1.5.9</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-validation</artifactId>
        </dependency>
        <dependency>
            <groupId>org.apache.commons</groupId>
            <artifactId>commons-csv</artifactId>
            <version>1.10.0</version>
        </dependency>
        <dependency>
            <groupId>io.jsonwebtoken</groupId>
            <artifactId>jjwt</artifactId>
            <version>0.9.1</version>
        </dependency>
        <!-- mysql driver -->
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-devtools</artifactId>
        </dependency>
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-configuration-processor</artifactId>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>com.amazonaws</groupId>
            <artifactId>aws-java-sdk-s3</artifactId>
            <version>1.12.550</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/commons-io/commons-io -->
        <dependency>
            <groupId>commons-io</groupId>
            <artifactId>commons-io</artifactId>
            <version>2.6</version>
        </dependency>
        <!-- APACHE POI Dependency for excel -->
        <!-- <dependency>
            <groupId>org.apache.poi</groupId>
            <artifactId>poi</artifactId>
            <version>4.1.2</version>
        </dependency> -->
        <!--        <dependency>
            <groupId>org.apache.poi</groupId>
            <artifactId>poi-ooxml</artifactId>
            <version>4.1.2</version>
        </dependency> -->
        <dependency>
            <groupId>com.github.ozlerhakan</groupId>
            <artifactId>poiji</artifactId>
            <version>3.0.3</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-aws</artifactId>
            <version>2.2.6.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-aws-messaging</artifactId>
            <version>2.2.6.RELEASE</version>
        </dependency>
    </dependencies>```

Solution

  • I was able to resolve my issue by excluding the libraries I didn't need in the pom file.

    <dependency>
                <groupId>org.bytedeco</groupId>
                <artifactId>javacv</artifactId>
                <version>1.5.9</version>
                <exclusions>
                    <exclusion>
                        <groupId>org.bytedeco</groupId>
                        <artifactId>flandmark-platform</artifactId>
                    </exclusion>
                    <exclusion>
                        <groupId>org.bytedeco</groupId>
                        <artifactId>artoolkitplus-platform</artifactId>
                    </exclusion>
                    <exclusion>
                        <groupId>org.bytedeco</groupId>
                        <artifactId>opencv</artifactId>
                    </exclusion>
                    <exclusion>
                        <groupId>org.bytedeco</groupId>
                        <artifactId>opencv-platform</artifactId>
                    </exclusion>
                    <exclusion>
                        <groupId>org.bytedeco</groupId>
                        <artifactId>videoinput-platform</artifactId>
                    </exclusion>
                    <exclusion>
                        <groupId>org.bytedeco</groupId>
                        <artifactId>videoinput</artifactId>
                    </exclusion>
                    <exclusion>
                        <groupId>org.bytedeco</groupId>
                        <artifactId>artoolkitplus</artifactId>
                    </exclusion>
                    <exclusion>
                        <groupId>org.bytedeco</groupId>
                        <artifactId>librealsense2-platform</artifactId>
                    </exclusion>
                    <exclusion>
                        <groupId>org.bytedeco</groupId>
                        <artifactId>librealsense2</artifactId>
                    </exclusion>
                    <exclusion>
                        <groupId>org.bytedeco</groupId>
                        <artifactId>librealsense</artifactId>
                    </exclusion>
                    <exclusion>
                        <groupId>org.bytedeco</groupId>
                        <artifactId>libfreenect2-platform</artifactId>
                    </exclusion>
                    <exclusion>
                        <groupId>org.bytedeco</groupId>
                        <artifactId>libfreenect-platform</artifactId>
                    </exclusion>
                    <exclusion>
                        <groupId>org.bytedeco</groupId>
                        <artifactId>openblas-platform</artifactId>
                    </exclusion>
                    <exclusion>
                        <groupId>org.bytedeco</groupId>
                        <artifactId>leptonica-platform</artifactId>
                    </exclusion>
                    <exclusion>
                        <groupId>org.bytedeco</groupId>
                        <artifactId>librealsense-platform</artifactId>
                    </exclusion>
                    <exclusion>
                        <groupId>org.bytedeco</groupId>
                        <artifactId>libdc1394</artifactId>
                    </exclusion>
                    <exclusion>
                        <groupId>org.bytedeco</groupId>
                        <artifactId>flycapture</artifactId>
                    </exclusion>
                    <exclusion>
                        <groupId>org.bytedeco</groupId>
                        <artifactId>openblas</artifactId>
                    </exclusion>
                    <exclusion>
                        <groupId>org.bytedeco</groupId>
                        <artifactId>leptonica</artifactId>
                    </exclusion>
                    <exclusion>
                        <groupId>org.bytedeco</groupId>
                        <artifactId>flandmark</artifactId>
                    </exclusion>
                    <exclusion>
                        <groupId>org.bytedeco</groupId>
                        <artifactId>librealsense2</artifactId>
                    </exclusion>
                    <exclusion>
                        <groupId>org.bytedeco</groupId>
                        <artifactId>libfreenect2</artifactId>
                    </exclusion>
                    <exclusion>
                        <groupId>org.bytedeco</groupId>
                        <artifactId>libdc1394-platform</artifactId>
                    </exclusion>
                    <exclusion>
                        <groupId>org.bytedeco</groupId>
                        <artifactId>libfreenect</artifactId>
                    </exclusion>
                    <exclusion>
                        <groupId>org.bytedeco</groupId>
                        <artifactId>tesseract</artifactId>
                    </exclusion>
                    <exclusion>
                        <groupId>org.bytedeco</groupId>
                        <artifactId>tesseract-platform</artifactId>
                    </exclusion>
                    <exclusion>
                        <groupId>org.bytedeco</groupId>
                        <artifactId>flycapture-platform</artifactId>
                    </exclusion>
                    <exclusion>
                        <groupId>org.bytedeco</groupId>
                        <artifactId>javacv-platform</artifactId>
                    </exclusion>
                    <exclusion>
                        <groupId>org.bytedeco</groupId>
                        <artifactId>javacpp-platform</artifactId>
                    </exclusion>
                
                    <exclusion>
                        <groupId>org.bytedeco</groupId>
                        <artifactId>javacpp-presets</artifactId>
                    </exclusion>
                </exclusions>
            </dependency>
    

    Reference: Can i select the only packages I used within my maven dependecies to export a runnable jar in eclipse?