How to compress video file to 3gp or mp4 in java? - java

i am having a video file which i need to convert to 3gp, mp4 using java.
is there any library to do this or any sample ?
if any of you have done or know the sample please guide me to do the above or provide me the example.
thanks

If you MUST use Java, check Java Media Framework.
http://www.oracle.com/technetwork/java/javase/tech/index-jsp-140239.html

Use a tool like ffmpeg (ffmpeg.org) or mconvert (from MPlayer) or VLC. You can call them from Java using the ProcessBuilder or Commons Exec.

You may have look at pandastream. But it is a web service.

Compressing video in java you can use IVCompressor
is very easy to use
for more details go https://techgnious.github.io/IVCompressor/
simple code
<dependency>
<groupId>io.github.techgnious</groupId>
<artifactId>IVCompressor</artifactId>
<version>1.0.1</version>
</dependency>
public static void main(String[] args) throws VideoException, IOException {
IVCompressor compressor = new IVCompressor();
IVSize customRes = new IVSize();
customRes.setWidth(400);
customRes.setHeight(300);
File file = new File("D:/Testing/20.mp4");
compressor.reduceVideoSizeAndSaveToAPath(file,VideoFormats.MP4,ResizeResolution.R480P,"D:/Testing/Custome");
}

Related

How to find file size in scala?

I'm writing a scala script, that need to know a size of a file. How do I do this correctly?
In Python I would do
os.stat('somefile.txt').st_size
and in Scala?
There is no way to do this using the Scala standard libraries. Without resorting to external libraries, you can use the Java File.length() method do do this. In Scala, this would look like:
import java.io.File
val someFile = new File("somefile.txt")
val fileSize = someFile.length
If you want something Scala-specific, you can use an external framework like scalax.io or rapture.io
java.nio.file.Files.size
from api:
public static long size(Path path) throws IOException
Returns the size of a file (in bytes)
import java.io.File;
val file:File = new File("your file path");
file.length()

JAAD stopping other providers from working

I'm using JAAD with SPI to play m4a files through JavaSound, which I have working fine.
However, I'd like to support a number of formats in this way - but whenever I try and play another format, JAAD seems to try to deal with it and then fail (obviously because it only deals with AAC.)
I'm assuming this is a bug in JAAD, since all the other SPI libraries play fine with each other. Is there a nice way to work around it until it's fixed, or is there another AAC library that works with Javasound which I can use?
There is a workaround using jaad created by Michael Berry: this is the url
https://code.google.com/p/quelea-projection/source/browse/Quelea/src/org/quelea/sound/AudioTrack.java?spec=svn0352523f49cf20d41d1a7dc098af1db38000cc6d&r=0352523f49cf20d41d1a7dc098af1db38000cc6d
Since it took me a while to find berry150's code, here is the solution:
First, you have to order the jars in the classpath so that JLayer, MP3SPI and Tritonous Share are loaded before JAAD. Then for getting the AudioInputStream, use the following code:
if (getAudioFormat().equals(".mp3")) {
audioStream = AudioSystem.getAudioInputStream(file); // Obtains an audio input stream of the song
}
else if (getAudioFormat().equals(".m4a")){
audioStream = new AACAudioFileReader().getAudioInputStream(file);
}
So what happens is that if the audio is mp3, the getAudioStreamMethod() from Javasound will be called first since its JAR was loaded first. If the audio is .m4a, a new instance of the ACCAudioFileReader() is created and the getAudioInputStream() of the JAAD library is called.

could not get audio input stream from input URL

I am trying to run a sound file in Java using this code:
public class Audio3
{
public static void main(String[] args) throws Exception
{
URL soundFile =new URL(
"http://everyayah.com/data/Ghamadi_40kbps/audhubillah.mp3");
AudioInputStream ais = AudioSystem.getAudioInputStream(soundFile);
AudioPlayer.player.start(ais);
}
}
I am getting this exception
javax.sound.sampled.UnsupportedAudioFileException:
could not get audio input stream from input URL
Any idea what could be the reason?
According to the JavaSound info. page.
MP3 decoding support
The Java Sound API does not support many formats of sampled sound internally. In a 1.6.0_24 Oracle JRE getAudioFileTypes() will generally return {WAVE, AU, AIFF}. An MP3 decoder at least, is close by. The mp3plugin.jar of the Java Media Framework supports decoding MP3s.
I can vouch for that information since I've successfully loaded MP3s using Java Sound and the MP3 SPI (& also wrote the info. page ;) ). The JMF installer download is becoming hard to find, but you can get the mp3plugin.jar direct from where I put it for use in JWS apps.

How to write FLAC files in java

I have a requirement to write FLAC files in java. Earlier I was writing the audio input into a WAV file and then converting it to FLAC file using a external converter
I was looking into JFlac to find any API through which I can write FLAC files. I found that AudioFileFormat.TYPE in java supports only the following file formats - AIFC, AIFF, SND, AU, WAVE .
I would like to have a method where I can capture the audio from the microphone and, using an API such as Audiosystem.write, write it to a FLAC file instead of WAV file.
Please suggest a method or an API that can solve my problem.
You can use this lib. Here is a simple example using version 0.2.3 (javaFlacEncoder-0.2.3-all.tar.gz). Extract the dowloaded file, and then import javaFlacEncoder-0.2.3.jar to your project. For more documentation, see here:
package fr.telecomParisTech;
import java.io.File;
import javaFlacEncoder.FLAC_FileEncoder;
public class SoundConverter {
/**
* #param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
FLAC_FileEncoder flacEncoder = new FLAC_FileEncoder();
File inputFile = new File("hello.wav");
File outputFile = new File("hello.flac");
flacEncoder.encode(inputFile, outputFile);
System.out.println("Done");
}
}
You can write audio stream directly to a FLAC file with javaflacencoder:
AudioSystem.write(audioInputStream, FLACFileWriter.FLAC, new File("E:\\temp.flac"));
If you want to change sample rates,
use ffmpeg
like this
ffmpeg -i sourcefile.wav -ar 16000 targetfile.flac

Converting into FLV using Java

does anybody know how to convert any kind of video format into flv using java, i have been searching for a java api for converting video but it seems that there is no such thing but there might be a way to do it, i mean to make something like youtube service does converting the videos, but using java, i need a web application that can show videos into FLv Format but to be uploaded in any format, if somebody has made something like this please let me know how or any idea,
thanks.
Using xuggler, here is a simple piece of code to do exactly what you asked for:
public class AnyMediaConverter {
public void main(String[] args) {
//assumes the following: arg0 is input file and arg1 is output file
IMediaReader reader = ToolFactory.makeReader(args[0]);
IMediaWriter writer = ToolFactory.makeWriter(args[1], reader);
writer.open();
writer.setForceInterleave(true);
IContainerFormat outFormat = IContainerFormat.make();
outFormat.setOutputFormat("flv", args[1], null);
IContainer container = writer.getContainer();
container.open(args[1], IContainer.Type.WRITE, outFormat);
writer.addVideoStream(0, 0, ICodec.findEncodingCodecByName("flv"), 320, 240);
writer.addAudioStream(1, 0, ICodec.findEncodingCodecByName("libmp3lame"), 2, 44100);
reader.addListener(writer);
while (reader.readPacket() == null);
}
}
now try doing that in JMF or FMJ or whatever (if you want a headache)
None in Java comes directly to mind, even Java's own media framework JMF doesn't support FLV, but you may find this overview of Open Source Flash Projects useful. If any non-Java commandline tool turns out to be useful for you, then you could execute it from inside Java using Runtime#exec() (tutorial here) or preferably ProcessBuilder (tutorial here).
There is a wrapper for ffmpeg that plugs into JMF: Fobs4JMF

Categories

Resources