我在java中使用xugglu来切换输入MP3文件的比特率,将其存储在输出文件中。我举了一个例子,我在网上找到了将文件加载到阅读器并添加一个编写器作为监听器。有谁知道我怎么能修改比特率?
以下是我一直在使用的代码:
import com.xuggle.mediatool.IMediaReader;
import com.xuggle.mediatool.IMediaViewer;
import com.xuggle.mediatool.IMediaWriter;
import com.xuggle.mediatool.ToolFactory;
import org.slf4j.LoggerFactory;
public class TranscodingExample {
private static final String inputFilename = "/home/user/Desktop/file_changed.mp3";
private static final String outputFilename = "/home/user/Desktop/file_changed.flv";
public static void main(String[] args) {
// create a media reader
IMediaReader mediaReader =
ToolFactory.makeReader(inputFilename);
// create a media writer
IMediaWriter mediaWriter =
ToolFactory.makeWriter(outputFilename, mediaReader);
// add a writer to the reader, to create the output file
mediaReader.addListener(mediaWriter);
// create a media viewer with stats enabled
IMediaViewer mediaViewer = ToolFactory.makeViewer(true);
// add a viewer to the reader, to see the decoded media
mediaReader.addListener(mediaViewer);
// read and decode packets from the source file and
// and dispatch decoded audio and video to the writer
while (mediaReader.readPacket() == null) ;
}
}
EDIT-1:
我无法真正解决这个问题,所以我只是在Java应用程序中使用了一个linux命令。您可以找到对代码here的引用。我使用的命令是:
ffmpeg -i in.mp3 -b 112k out.mp3
它将mp3转换为新的比特率等于112k。