类 VideoUtil

java.lang.Object
com.tlcsdm.core.util.VideoUtil

public class VideoUtil extends Object
视频处理工具类,利用 ws.schild:jave2 处理.

默认情况下,jave2在执行时,会把ffmpeg可执行文件释放到"java.io.tmpdir"临时目录下,但在tomcat等容器下执行时,如果启用tomcat的用户,与 java应用的执行用户不同,可能会存在无写入权限的问题。遇到这种情况,可以先用代码把java.io.tmpdir这个系统变量,指到其它有权限的目录, 执行完后,再还原回来


 String oldTmpDir = System.getProperty("java.io.tmpdir");
         try {
             System.setProperty("java.io.tmpdir", "有权限写入的新临时目录");
         }  finally {
             System.setProperty("java.io.tmpdir", oldTmpDir);
         }
 

作者:
unknowIfGuestInDream
  • 字段详细资料

    • ALLOW_IMG_FORMAT

      static final String ALLOW_IMG_FORMAT
      支持的视频文件后缀.
      另请参阅:
    • NEW_VIDOE_WATER_NAME_PRE_STR

      static final String NEW_VIDOE_WATER_NAME_PRE_STR
      水印视频名字拼接.
      另请参阅:
    • NEW_SC_NAME_PRE_STR

      static final String NEW_SC_NAME_PRE_STR
      视频截图文件名拼接. eg:原视频 test.mp4 截图名称 test_sc1.jpg 、test_sc10.jpg
      另请参阅:
  • 构造器详细资料

    • VideoUtil

      private VideoUtil()
  • 方法详细资料

    • addWatermark

      public static String addWatermark(String sourceUrl, String targetUrl, String waterIconPath) throws ws.schild.jave.EncoderException
      视频加图片水印.
      参数:
      sourceUrl - 源视频绝对路径
      targetUrl - 水印视频绝对路径
      waterIconPath - 水印图文件绝对路径
      抛出:
      ws.schild.jave.EncoderException
    • readVideoLength

      public static int readVideoLength(String sourceUrl) throws ws.schild.jave.EncoderException
      获取视频时长 返回秒.
      参数:
      sourceUrl - 原视频绝对路径
      抛出:
      ws.schild.jave.EncoderException
    • durationFormatToString

      public static String durationFormatToString(BigDecimal duration)
      将视频时长转换成"00:00:00.000"的字符串格式.
      参数:
      duration - 视频时长(单位:秒)
    • getVideoPicByTime

      public static String getVideoPicByTime(String sourceUrl, String targetPath, List<Integer> secondsList) throws ws.schild.jave.EncoderException
      视频截取指定时间的图片.
      参数:
      sourceUrl - 原视频绝对路径 eg:C:/Users/Desktop/test.mp4
      targetPath - 截图路径 eg:C:/Users/Desktop/
      secondsList - 截取的秒 列表 eg:[1,10,20] 截取 第1秒,第10秒,第20秒
      抛出:
      ws.schild.jave.EncoderException
    • getVideoInfo

      public static ws.schild.jave.info.MultimediaInfo getVideoInfo(String videoPath)
      获取视频信息.
    • checkIsVideo

      public static boolean checkIsVideo(String sourceUrl)
      校验文件是否是视频文件.
      参数:
      sourceUrl - 视频绝对路径
    • video2Mp3

      public static boolean video2Mp3(String videoPath, String audioPath)
      视频文件转音频文件.
      参数:
      videoPath - 视频文件
      audioPath - 音频结果文件
    • video2Wav

      public static boolean video2Wav(String videoPath, String targetWavPath)
      从和视频中提取音频wav.
      参数:
      videoPath - 视频文件
      targetWavPath - wav结果文件
    • concatVideo

      public static boolean concatVideo(String srcPath, String targetPath, String... videos)
      Jave2连接视频. 耗时短
    • concatVideoWithCommand

      public static boolean concatVideoWithCommand(String srcPath, String targetPath, String... videos)
      ffmpeg命令连接视频. 多个视频拼接(耗时长)
    • cut

      public static boolean cut(String srcPath, String targetPath, Float offset, Float duration)
      切割视频.
      参数:
      srcPath - 音频源文件路径
      targetPath - 音频结果路径
      offset - 起始时间(秒)
      duration - 切片的音频长度(秒)