[英]Java - Write Video and Audio at the same time to FFmpeg
你好开发者,
我目前正在开发一种工具,可以通过使用Java Process执行FFmpeg并向其提供视频帧来呈现视频。
我目前使用以下FFmpeg命令: ffmpeg -y -f rawvideo -pix_fmt rgb24 -s %WIDTH%x%HEIGHT% -r %FPS% -i - -an -c:v libx264 -preset ultrafast -pix_fmt yuv420p "%FILENAME%.mp4"
,其中占位符显然被实际值替换。
我用来初始化FFmpeg的代码:
//commandArgs is a list of command line arguments for FFmpeg
List<String> command = new ArrayList<String>();
command.add("ffmpeg");
command.addAll(commandArgs);
process = new ProcessBuilder(command).directory(outputFolder).start();
OutputStream exportLogOut = new FileOutputStream("export.log");
new StreamPipe(process.getInputStream(), exportLogOut).start();
new StreamPipe(process.getErrorStream(), exportLogOut).start();
outputStream = process.getOutputStream();
channel = Channels.newChannel(outputStream);
然后,我有以下方法将包含视频帧的ByteBuffer写入FFmpeg:
public void consume(ByteBuffer buf) {
try {
channel.write(buf);
ByteBufferPool.release(buf);
} catch(Exception e) {
e.printStackTrace();
}
}
现在,我的问题是,我将如何继续将同步音频数据写入输出文件? 我假设我需要使用多个管道,当然我将不得不修改我的命令行参数,但我需要帮助:
1) what kind of Audio Data do I need to feed FFmpeg with?
2) how do I feed Audio and Video in one go?
3) how do I keep Audio and Video synchronized?
在此先感谢您的帮助!
问候,CrushedPixel
看一下https://github.com/artclarke/humble-video ,它是java中ffmpeg的包装器。 您可以将视频/音频流以编码方式添加到编码器中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.