使用ffmpeg将mp4文件转为h264文件或者264文件

使用如下命令:

ffmpeg -i test.mp4 -c copy test.h264

或者

ffmpeg -i test.mp4 -c h264 test.h264
  • 3
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
以下是使用Java创建FFmpeg进程将文件编码为H.264 / H.265的示例代码: ```java import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; public class FFmpegEncoder { private static final String FFmpeg_PATH = "path/to/ffmpeg"; // FFmpeg的路径 private static final String INPUT_FILE_PATH = "path/to/input/file"; // 输入文件的路径 private static final String OUTPUT_FILE_PATH = "path/to/output/file"; // 输出文件的路径 private static final String CODEC = "libx264"; // 使用H.264编码器 // private static final String CODEC = "libx265"; // 使用H.265编码器 public static void main(String[] args) { String command = FFmpeg_PATH + " -i " + INPUT_FILE_PATH + " -c:v " + CODEC + " " + OUTPUT_FILE_PATH; Process process = null; try { process = Runtime.getRuntime().exec(command); // 创建FFmpeg进程 InputStream inputStream = process.getInputStream(); BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream)); String line; while ((line = reader.readLine()) != null) { // 输出FFmpeg进程的输出信息 System.out.println(line); } int exitCode = process.waitFor(); // 等待FFmpeg进程完成 System.out.println("FFmpeg process exited with code " + exitCode); } catch (IOException e) { e.printStackTrace(); } catch (InterruptedException e) { e.printStackTrace(); } finally { if (process != null) { process.destroy(); // 销毁FFmpeg进程 } } } } ``` 在上面的示例代码中,我们可以指定要使用的编码器,使用`libx264`表示使用H.264编码器,使用`libx265`表示使用H.265编码器。我们可以根据需要进行更改。在执行FFmpeg进程时,我们使用`Runtime.getRuntime().exec()`方法创建进程。然后,我们使用`process.getInputStream()`获取进程的输出流,并使用`BufferedReader`读取输出流中的内容。最后,我们使用`process.waitFor()`等待FFmpeg进程完成,并获取其退出代码。最后,我们使用`process.destroy()`销毁进程以释放资源。 注意:在上面的示例代码中,我们假设您已经正确安装了FFmpeg并将其添加到了系统的环境变量中。如果您的FFmpeg路径与示例代码中的路径不同,请相应地更改路径。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值