In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces how to use Java to achieve video to audio batch conversion, the article is very detailed, has a certain reference value, interested friends must read it!
The implementation of this function requires the use of a third-party jar package jave,JAVE is an encapsulation tool for java to call FFmpeg.
Add the following dependencies to the spring boot project pom file
Ws.schild jave-core 3.1.1 ws.schild jave-nativebin-win64 3.1.1 Ws.schild jave-nativebin-linux64 3.1.1
Java single-class implementation code, copied to the Spring boot project, using the idea editor main method to run.
Import ws.schild.jave.Encoder;import ws.schild.jave.EncoderException;import ws.schild.jave.MultimediaObject;import ws.schild.jave.encode.AudioAttributes;import ws.schild.jave.encode.EncodingAttributes; import java.io.File;import java.util.Arrays; public class VideoToAudio {/ / Audio format private static String outputFormat= "mp3" to be output / * obtain the converted file name * @ param sourceFilePath: source video file path * @ return * / public static String getNewFileName (String sourceFilePath) {File source = new File (sourceFilePath); String fileName=source.getName () .substring (0, source.getName () .lastIndexOf (".")); return fileName+ "." + outputFormat } / * convert audio format * @ param sourceFilePath: source video file path * @ param targetFilePath: destination music file path * @ return * / public static void transform (String sourceFilePath, String targetFilePath) {File source = new File (sourceFilePath); File target = new File (targetFilePath); / / set audio attribute AudioAttributes audio = new AudioAttributes () Audio.setCodec (null); / / set transcoding properties EncodingAttributes attrs = new EncodingAttributes (); attrs.setOutputFormat (outputFormat); attrs.setAudioAttributes (audio); try {/ / Audio conversion format class Encoder encoder = new Encoder (); MultimediaObject mediaObject=new MultimediaObject (source); encoder.encode (mediaObject, target, attrs) System.out.println ("conversion completed...");} catch (EncoderException e) {e.printStackTrace () }} / * batch convert audio format * @ param sourceFolderPath: source video folder path * @ param targetFolderPath: destination music folder path * @ return * / public static void batchTransform (String sourceFolderPath, String targetFolderPath) {File sourceFolder = new File (sourceFolderPath) If (sourceFolder.list () .forEach (e-> {transform (sourceFolderPath+ "\" + e, targetFolderPath+ "\" + getNewFileName (e));}} public static void main (String [] args) {batchTransform ("C:\ Users\ tarzan\ Desktop\ video", "C:\ Users\ tarzan\ Desktop\ audio") }} above are all the contents of the article "how to use Java to convert video to audio in batch". Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.