I am trying to convert a audio (mp3) file to a video file (ideally flv or anything that youtube will accept). Looking around on here I thought that JAVE might be able to do the job and have been playing around with it but most of the support is about extracting the audio from a video rather than the other way around. I was guessing that I might need a blank image or something to form the pictures part of the video but can't seem to work it out. Thanks for any and all help!
My current code looks like :
File source = new File("voicetomstest.mp3");
File target = new File("target.flv");
AudioAttributes audio = new AudioAttributes();
audio.setCodec("libmp3lame");
audio.setBitRate(new Integer(64000));
audio.setChannels(new Integer(1));
audio.setSamplingRate(new Integer(22050));
VideoAttributes video = new VideoAttributes();
video.setCodec("flv");
video.setBitRate(new Integer(160000));
video.setFrameRate(new Integer(15));
video.setSize(new VideoSize(400, 300));
EncodingAttributes attrs = new EncodingAttributes();
attrs.setFormat("flv");
attrs.setAudioAttributes(audio);
attrs.setVideoAttributes(video);
Encoder encoder = new Encoder();
encoder.encode(source, target, attrs);
And currently has the following error
Apr 01, 2018 3:13:34 PM testvoice2video.TestVoice2Video main
SEVERE: null
it.sauronsoftware.jave.InputFormatException
at it.sauronsoftware.jave.Encoder.parseMultimediaInfo(Encoder.java:659)
at it.sauronsoftware.jave.Encoder.encode(Encoder.java:840)
at it.sauronsoftware.jave.Encoder.encode(Encoder.java:713)
at testvoice2video.TestVoice2Video.main(TestVoice2Video.java:74)
where line 74 is "encoder.encode(source, target, attrs);"
I don't work with this code, but it appears to me from looking at the Encoder.parseMultiMediaInfo() source code that the InputFormatException thrown at line 659 is a result of not being able to create a MultimediaInfo file from your target. It's looking for this regexp at the beginning of the target:
^\\s*Input #0, (\\w+).+$\\s*"
The target file is opened as an ffmpeg executable, where various arguments are then added as per your attributes. I don't know what ffmpeg argument results in a "Input #0" type header but I have to assume it's the
...
ffmpeg.addArgument("-i");
ffmpeg.addArgument(source.getAbsolutePath());
...
Are you sure your source file is being found?
Related
I have been trying to set the album art of a mp3 file using the mp3agic library in java. The following code snippet is what i used to do so. Unfortunately this isnt working. The saved image file does not contain the album art nor the set title. Also, the program compiles with no error.
File img = new File("img.jpg");
imgLink[1]="http://"+imgLink[1];
URL url = new URL(imgLink[1]);
FileUtils.copyURLToFile(url, img);
byte[] bytes = new byte[(int) img.length()];
id3v2Tag.setTitle("Something");
id3v2Tag.setAlbumImage(bytes, "image/jpg");
mp3file.save("something.mp3");
Any help regarding this issue would be much appreciated.
The above code works. It wasn't showing properly on the folder I was working with. When I opened the file with iTunes it showed up. It's probably some fault with windows.
I am trying to convert video to audio . That is why , I am using the following code :
File source = new File("E:\\Shunno - Khachar Bhitor Ochin Pakhi.mp4");
File target = new File("E:\\output.mp3");
AudioAttributes audio = new AudioAttributes();
audio.setCodec("libmp3lame");
audio.setBitRate(new Integer(128000));
audio.setChannels(new Integer(2));
audio.setSamplingRate(new Integer(44100));
EncodingAttributes attrs = new EncodingAttributes();
attrs.setFormat("mp3");
attrs.setAudioAttributes(audio);
Encoder encoder = new Encoder();
try
{
encoder.encode(source, target, attrs);
}
catch (IllegalArgumentException | EncoderException e)
{
}
But I am getting the following error :
Sep 26, 2016 11:28:29 AM it.sauronsoftware.jave.DefaultFFMPEGLocator copyFile
SEVERE: Could not get native library for ffmpeg-amd64.exe
Exception in thread "main" java.lang.RuntimeException: Cannot retrieve native file ffmpeg-amd64.exe
at it.sauronsoftware.jave.DefaultFFMPEGLocator.copyFile(DefaultFFMPEGLocator.java:139)
at it.sauronsoftware.jave.DefaultFFMPEGLocator.<init>(DefaultFFMPEGLocator.java:80)
at it.sauronsoftware.jave.Encoder.<init>(Encoder.java:105)
at Convert.main(Convert.java:29)
How can I solve this error ? Please help me .
The error is very clear: ffmpeg cannot been found.
Since you hard coded some windows path here is the windows binary of ffmpeg. I suggest to download the x64 static version. Since that is just one file you need to care about.
If you need it for another platform check the download site.
Within the zip file in the subdirectory bin where the binary ffmpeg.exe is located. Now you need to renamed it to ffmpeg-amd64.exe since the library expects that name. Now you need to copy the file to a directory of your path variable e.g. C:\windows\system32. I suggest not to use that directory, but this is the simplest way. Better put it somewhere else and modify your path variable. There are dozens of explanations so just google them if you want how do achieve that.
So I'm trying to write a simple program that will change the type of an image from a .png to a .tiff using jmagick in java. I followed a tutorial that i found online for different image formats located Here. The program compiles successfully but when I run it I get this message:
Process finished with exit code -1073740940 (0xC0000374)
This is my code:
System.out.println("I'm at 0");
String inputfileName = "C:\\Users\\MySelf\\IdeaProjects\\tess4jTest\\p1.png"; //Input PNG file
ImageInfo info = new ImageInfo(inputfileName); //Get PNG file into ImageInfo object
MagickImage magick_converter = new MagickImage(info); //Create MagickImage object
System.out.println("I'm at 1")
String outputfile = "C:\\Users\\emctiern\\IdeaProjects\\tess4jTest\\p01.tiff"; //Output File name
magick_converter.setFileName(outputfile); //set output file format
magick_converter.writeImage(info); //do the conversion
System.out.println("I'm at 2");
My code never actually reaches the print 1 and 2, I think it might be that its not sure where to get the file from, That's why I entered the the full file path. In the tutorial I followed they just had the image name and nothing else.
Thanks in advance
I have an mp3 file that i am trying to play from a source package in eclipse (java) for some reason it plays fine when i run it in eclipse but when i try to play it from a .jar it doesn't play. The images show up fine but the sound doesn't, i think i may have to recode the sound file like an image file but i'm not sure how here's the code for the Image:
JLabel TextBox = new JLabel(new ImageIcon(Toolkit.getDefaultToolkit().getImage(getClass().getResource("/Images/TextBox.png"))));
and the Sound
Player player = Manager.createPlayer(new MediaLocator(getClass().getClassLoader().getResource("Sounds/Bonsai.mp3")));
thanks in advance!
Try getting the resource as a Stream. You can retrieve a file this way.
InputStream fis =
ClassLoader.getSystemClassLoader().getResourceAsStream("/Sounds/bonsai.mp3");
p = new Player(fis);
p.play();
The:
getClass().getClassLoader().getResource(....)
does indeed return a URL. But MediaLocator can not use URL's from the form jar:file:/
I recommend to copy the file from the jar to a "Temp" filesystem and the stream it from there.
You can always delete it when you done, if that is needed.
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