Android ffmpeg 音频的解码和播放

本文详细介绍了如何在Android平台上利用FFmpeg进行音频解码,并通过反射调用AudioTrack和OpenSL ES实现播放。文章涵盖了解码流程,包括注册组件、打开音频文件、获取解码器等步骤,并提供了Java层和JNI层的代码示例。
摘要由CSDN通过智能技术生成

Android ffmpeg 音频的解码和播放

FFmpeg在音视频开发的地位不必多说,它已经是行业的一个品牌标杆。本篇文章探讨使用FFmpeg进行音频解码,然后反射调用android系统自带的AudioTrack和OpenSL ES两种播放方式。

首先谈下FFmpeg解码流程,步骤包括:注册组件、分配FormatContext、打开音频文件、获取输入文件信息、获取音频流索引位置、获取音频解码器、打开解码器、循环读取待解码数据、解码完一帧送去播放器播放。
代码如下:

# For more information about using CMake with Android Studio, read the
# documentation: https://d.android.com/studio/projects/add-native-code.html

# Sets the minimum version of CMake required to build the native library.

cmake_minimum_required(VERSION 3.4.1)


add_definitions(-std=c++11)

find_library( # Sets the name of the path variable.
              log-lib

              # Specifies the name of the NDK library that
              # you want CMake to locate.
              log )

find_library( # Sets the name of the path variable.
            android-lib

            # Specifies the name of the NDK library that
            # you want CMake to locate.
            android )

set(distribution_DIR ${CMAKE_SOURCE_DIR}/libs/armeabi)

add_library( avutil
             SHARED
             IMPORTED )

set_target_properties( avutil
                       PROPERTIES IMPORTED_LOCATION
                       ${distribution_DIR}/libavutil-54.so )

add_library( swresample
             SHARED
             IMPORTED )

set_target_properties( swresample
                       PROPERTIES IMPORTED_LOCATION
                       ${distribution_DIR}/libswresample-1.so)

add_library( avcodec
             SHARED
             IMPORTED )

set_target_properties( avcodec
                       PROPERTIES IMPORTED_LOCATION
                       ${distribution_DIR}/libavcodec-56.so)

add_library( avformat
             SHARED
             IMPORTED )

set_target_properties( avformat
                       PROPERTIES IMPORTED_LOCATION
                       ${distribution_DIR}/libavformat-56.so)

add_library( swscale
             SHARED
             IMPORTED )

set_target_properties( swscale
                       PROPERTIES IMPORTED_LOCATION
                       ${distribution_DIR}/libswscale-3.so)

add_library( postproc
             SHARED
             IMPORTED )

set_target_properties( postproc
                       PROPERTIES IMPORTED_LOCATION
                       ${distribution_DIR}/libpostproc-53.so)

add_library( avfilter
             SHARED
             IMPORTED )

set_target_properties( avfilter
                       PROPERTIES IMPORTED_L
  • 2
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值