java
主页 > 软件编程 > java >

java如何获取视频文件的编解码器代码

2024-05-04 | 佚名 | 点击:

引入jar包:

1

2

3

4

5

<dependency>

            <groupId>org.bytedeco</groupId>

            <artifactId>javacv-platform</artifactId>

            <version>1.5.9</version>

        </dependency>

测试类

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

package com.jd.brand.approve.controller.approve;

 

import org.bytedeco.ffmpeg.global.avcodec;

import org.bytedeco.javacv.FFmpegFrameGrabber;

 

import java.io.File;

 

public class VideoDecoder {//HEVC,AAC

 

    public static void main(String[] args) {

        String videoPath = "/Users/xuhaojie/Desktop/视频.mp4"; // 视频文件路径

 

        try {

            final FFmpegFrameGrabber fFmpegFrameGrabber = new FFmpegFrameGrabber(videoPath);

            fFmpegFrameGrabber.start();

            final int videoCodec = fFmpegFrameGrabber.getVideoCodec();

            final String videoCodecName = fFmpegFrameGrabber.getVideoCodecName();

            System.out.println("h264:" + avcodec.AV_CODEC_ID_H264);

            System.out.println("h265:" + avcodec.AV_CODEC_ID_H265);

            System.out.println("hevc:" + avcodec.AV_CODEC_ID_HEVC);

            System.out.println(videoCodec);

        } catch (Exception e) {

            e.printStackTrace();

        }

    }

}

执行结果

Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '/Users/xuhaojie/Desktop/视频.mp4':
  Metadata:
    major_brand     : mp42
    minor_version   : 1
    compatible_brands: isommp41mp42
    creation_time   : 2024-01-11T05:42:21.000000Z
  Duration: 00:00:15.00, start: 0.000000, bitrate: 5703 kb/s
  Stream #0:0[0x1](zho): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 124 kb/s (default)
    Metadata:
      creation_time   : 2024-01-11T05:42:21.000000Z
      handler_name    : Core Media Audio
      vendor_id       : [0][0][0][0]
  Stream #0:1[0x2](und): Video: hevc (Main 10) (hvc1 / 0x31637668), yuv420p10le(tv, bt709, progressive), 768x1366 [SAR 1:1 DAR 384:683], 5460 kb/s, 25 fps, 25 tbr, 25k tbn (default)
    Metadata:
      creation_time   : 2024-01-11T05:42:21.000000Z
      handler_name    : Core Media Video
      vendor_id       : [0][0][0][0]
h264:27
h265:173
hevc:173
173

原文链接:
相关文章
最新更新