Small knowledge, big challenge! This paper is participating in theEssentials for programmers”Creative activities.

πŸ“– the

Good attitude, not so tired. In a good mood, all you see is beautiful scenery.

"If you can't solve a problem for a while, use this opportunity to see your limitations and put yourself out of order." As the old saying goes, it's easy to let go. If you are distracted by something, learn to disconnect. Cut out the paranoia, the trash in the community, and get rid of the negative energy. Good attitude, not so tired. In a good mood, all you see is beautiful scenery.

Recently, I was sorting out a small project, which needed the JAR of video processing. It took a long time to finish the jar, so this is to record. Hope to help you, if there is help please give a praise!


✨ downloadjarDownload itInto jave - 1.0.2. JarPut it where you can find it.

Among themInto jave - 1.0.2. JarThis dependence onmavenYou can’t use poM to import any of the following files:

Official website download portal!


πŸŽ„ recently had a small video processing requirement to get information about the length, size, format, etc. of the video based on the URL of the incoming video. Try it:

package com.cyj.resourcecenter.utils;


import it.sauronsoftware.jave.Encoder;
import lombok.extern.slf4j.Slf4j;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.nio.channels.FileChannel;
import java.util.HashMap;
import java.util.Map;

/ * * *@Description: Video processing help class *@BelongsProject: Family
 * @BelongsPackage: com.cyj.resourcecenter.utils
 * @Author: ChenYongJia
 * @CreateTime: the 2020-01-05 15:51 *@Email: [email protected]
 * @Version: 1.0 * /
@Slf4j
public class VoidUtils {

    public static void main(String[] args) {
        // Here is the file path
        File source = new File("xxxxx");
        Encoder encoder = new Encoder();
        FileChannel fc = null;
        String size = "";
        try {
            it.sauronsoftware.jave.MultimediaInfo m = encoder.getInfo(source);
            long ls = m.getDuration();
            log.info("Duration of this video :" + ls / 60000 + "Points" + (ls) / 1000 + "Second!");
            // Video frame width and height
            log.info("This video height is :{}", m.getVideo().getSize().getHeight());
            log.info("Width of this video :{}", m.getVideo().getSize().getWidth());
            log.info("This video is in the format of {}", m.getFormat());
            FileInputStream fis = new FileInputStream(source);
            fc = fis.getChannel();
            BigDecimal fileSize = new BigDecimal(fc.size());
            size = fileSize.divide(new BigDecimal(1048576), 2, RoundingMode.HALF_UP) + "MB";
            log.info("This video size is" + size);
        } catch (Exception e) {
            log.error("Video message interception is abnormal. Interception failed.", e);
        } finally {
            if (null! = fc) {try {
                    fc.close();
                } catch (IOException e) {
                    log.error("IO stream operation abnormal, interception failed", e); }}}}/ * * *@param path
     * @return Map
     */
    public static Map<String, Object> getVoideMsg(String path) {

        Map<String, Object> map = new HashMap<String, Object>();
        File file = new File(path);
        Encoder encoder = new Encoder();
        FileChannel fc = null;
        String size = "";

        if(file ! =null) {
            try {
                it.sauronsoftware.jave.MultimediaInfo m = encoder.getInfo(file);
                long ls = m.getDuration();

                FileInputStream fis = new FileInputStream(file);
                fc = fis.getChannel();
                BigDecimal fileSize = new BigDecimal(fc.size());
                size = fileSize.divide(new BigDecimal(1048576), 2, RoundingMode.HALF_UP) + "MB";

                map.put("height", m.getVideo().getSize().getHeight());
                map.put("width", m.getVideo().getSize().getWidth());
                map.put("format", m.getFormat());
            } catch (Exception e) {
                log.error("Operation abnormal, interception failed", e);
            } finally {
                if (null! = fc) {try {
                        fc.close();
                    } catch (IOException e) {
                        log.error("IO stream operation abnormal, interception failed", e); }}}}returnmap; }}Copy the code

Important: Introduce dependencies! Important: Introduce dependencies! Important: Introduce dependencies!

<! Get video length -->
<dependency>
    <groupId>it.sauronsoftware</groupId>
    <artifactId>jave</artifactId>
    <version>1.0.2</version>
    <scope>system</scope>
    <systemPath>${project. The basedir} / SRC/main/resources/lib/into jave - 1.0.2. Jar</systemPath>
</dependency>
Copy the code

Important: download after inresourcecreatelibIn it

Now because it’s an external package it’s notmavenBuilt-in needsscope ε†… system , ${project. The basedir} / SRC/main/resources/lib/into jave - 1.0.2. JarFor the projectjarThe path of the

<! Get video length -->
	<dependency>
        <groupId>it.sauronsoftware</groupId>
        <artifactId>jave</artifactId>
        <version>1.0.2</version>
        <scope>system</scope>
        <systemPath>${project. The basedir} / SRC/main/resources/lib/into jave - 1.0.2. Jar</systemPath>
    </dependency>
Copy the code

whenscope δΈΊ systemThe package will not be automatically packaged, so you need to add a parameter to the package

<build>
        <plugins>
            <! Maven plugin for SpringBoot -->
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <! Scope = system; scope = system; scope = system; scope = system;
                <configuration>
                    <includeSystemScope>true</includeSystemScope>
                </configuration>
            </plugin>
        </plugins>
        <! -- SpringBoot project package jar name -->
        <finalName>resource-center</finalName>
    </build>
Copy the code

πŸŽ‰ summary:

  • For more references, see here:The Blog of Chan Wing Kai

  • Like the small partner of the blogger can add a concern, a thumbs-up oh, continue to update hey hey!