All Downloads are FREE. Search and download functionalities are using the official Maven repository.

ws.schild.jave.utils.Utils Maven / Gradle / Ivy

Go to download

The JAVE (Java Audio Video Encoder) library is Java wrapper on the ffmpeg project. Developers can take take advantage of JAVE2 to transcode audio and video files from a format to another. In example you can transcode an AVI file to a MPEG one, you can change a DivX video stream into a (youtube like) Flash FLV one, you can convert a WAV audio file to a MP3 or a Ogg Vorbis one, you can separate and transcode audio and video tracks, you can resize videos, changing their sizes and proportions and so on. Many other formats, containers and operations are supported by JAVE2.

There is a newer version: 3.5.0
Show newest version
/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package ws.schild.jave.utils;

import java.text.DecimalFormat;

/** @author a.schild */
public class Utils {

  /**
   * * https://www.ffmpeg.org/ffmpeg-utils.html#time-duration-syntax
   *
   * 

Build a time/duration string based on the milisenconds passed in milis [-][HH:]MM:SS[.m...] * or [-]S+[.m...] * * @param milis number of miliseconds, can be negative too * @return String to be used for specifying positions in the video/audio file */ public static String buildTimeDuration(long milis) { DecimalFormat df2 = new DecimalFormat("00"); DecimalFormat df3 = new DecimalFormat("000"); long milisPart = Math.abs(milis) % 1000; long seconds = Math.abs(milis) / 1000; long secondsPart = seconds % 60; long minutes = seconds / 60; long minutesPart = minutes % 60; long hours = minutes / 60; StringBuilder retVal = new StringBuilder(); if (milis < 0) { retVal.append("-"); } if (hours != 0) { retVal.append(df2.format(hours)).append(":"); } if (minutesPart != 0 || hours != 0) { retVal.append(df2.format(minutesPart)).append(":"); } retVal.append(df2.format(secondsPart)); if (milisPart != 0) { retVal.append(".").append(df3.format(milisPart)); } return retVal.toString(); } /** * Escape all special characters []=;, to be safe to use in command line * * @param argumentIn input argument to escape * @return escaped string */ public static String escapeArgument(String argumentIn) { String retVal = argumentIn.replace("[", "\\["); retVal = retVal.replace("]", "\\]"); retVal = retVal.replace("=", "\\="); retVal = retVal.replace(":", "\\:"); retVal = retVal.replace(",", "\\,"); return retVal; } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy