JavaCV + FFmpeg 播放音视频

JavaCV + FFmpeg 播放音视频

FFmpeg documentation
bytedeco/javacv - GitHub
参考资料:
FFmpeg简易播放器的实现3-音频播放
雷霄骅(leixiaohua1020)的专栏 FFmpeg


1、导入JavaCV库

gradle下面这种会导入javacv-platform所有包,非常耗时:https://repo.maven.apache.org/maven2/org/bytedeco/

xml 复制代码
dependencies {
  implementation group: 'org.bytedeco', name: 'javacv-platform', version: '1.5.9'
}

1.1 使用ffmpeg必要库



https://repo.maven.apache.org/maven2/org/bytedeco/

xml 复制代码
ext {
    javacvVersion = '1.5.9'
    ffmpegVersion = '6.0'
    windowsVersion = 'windows-x86_64'
}
dependencies {
    implementation "org.bytedeco:javacpp:${javacvVersion}"
    implementation "org.bytedeco:javacpp:${javacvVersion}:${windowsVersion}"
    implementation "org.bytedeco:javacv:${javacvVersion}"
    implementation "org.bytedeco:ffmpeg:${ffmpegVersion}-${javacvVersion}"
    implementation "org.bytedeco:ffmpeg:${ffmpegVersion}-${javacvVersion}:${windowsVersion}"
}

1.2 简单FFmpeg命令

  • ffmpeg -i input.avi -hide_banner
java 复制代码
String url = "C:\\Users\\Administrator\\Desktop\\input.avi";
// 解封装上下文
AVFormatContext pFormatCtx = new AVFormatContext(null);
if (null == pFormatCtx) {
    XLog.e("获取解封装上下文失败");
    return;
}

// 打开流媒体
if (avformat_open_input(pFormatCtx, url, null, null) != 0) {
    XLog.e("打开媒体失败");
    return;
}

// 读取流媒体数据,以获得流的信息
if (avformat_find_stream_info(pFormatCtx, (PointerPointer<Pointer>) null) < 0) {
    XLog.e("获得媒体流信息失败");
    return;
}

// 控制台打印流媒体信息
av_dump_format(pFormatCtx, 0, (BytePointer) null, 0);
  • ffplay "Let Me Down Slowly.mp3" -hide_banner 工具播放音乐

待续~~~~

在 java 中使用 ffmpeg 的四个阶段
Java版流媒体编解码和图像处理(JavaCPP+FFmpeg)

相关推荐
Drifter_yh22 分钟前
【黑马点评】Redisson 分布式锁核心原理剖析
java·数据库·redis·分布式·spring·缓存
莫寒清2 小时前
Spring MVC:@RequestParam 注解详解
java·spring·mvc
没有医保李先生2 小时前
字节对齐的总结
java·开发语言
甲枫叶4 小时前
【claude】Claude Code正式引入Git Worktree原生支持:Agent全面实现并行独立工作
java·人工智能·git·python·ai编程
六件套是我4 小时前
无法访问org.springframeword.beans.factory.annotation.Value
java·开发语言·spring boot
LYS_06184 小时前
C++学习(5)(函数 指针 引用)
java·c++·算法
forestsea4 小时前
Spring Cloud Alibaba 2025.1.0.0 正式发布:拥抱 Spring Boot 4.0 与 Java 21+ 的新时代
java·spring boot·后端
IT枫斗者4 小时前
IntelliJ IDEA 2025.3史诗级更新:统一发行版+Spring Boot 4支持,这更新太香了!
java·开发语言·前端·javascript·spring boot·后端·intellij-idea
forestsea4 小时前
Spring Boot 4.0 + JDK 25 + GraalVM:下一代云原生Java应用架构
java·spring boot·云原生