rockcarry / fanplayer

A portable video player based on ffmpeg for windows and android platform.
GNU Lesser General Public License v3.0
606 stars 161 forks source link

android下,avcodec_open2调用失败 #54

Open HelloTodayWolrd opened 2 years ago

HelloTodayWolrd commented 2 years ago

为了能够让播放器实现硬解,重新编译了ffmpeg(加入了编译选项:--enable-hwaccel=h264_mediacodec),decoder = avcodec_find_decoder_by_name("h264_mediacodec");这一句后,获取的decoder 不为空,但是执行到avcodec_open2(player->vcodec_context, decoder, NULL),返回值小于0,执行失败,用av_strerror函数输出错误:Generic error in an external library。运行环境:华为鸿蒙OS平板。

rockcarry commented 2 years ago

ffmpeg 用的什么版本? 用仓库中编译好的 jni 测试过没,硬件解码是否正常?

HelloTodayWolrd commented 2 years ago

ffmpeg是用你的仓库下的 版本。仓库中编译好的libfanplayer_jni.so的硬解可以正常运行。为了方便调试,我把你的这个工程转成了cmake的Android工程。

HelloTodayWolrd commented 2 years ago

CMakeLists.txt文件如下:

HelloTodayWolrd commented 2 years ago
cmake_minimum_required(VERSION 3.10.2)

# Declares and names the project.

project("fanplayer")

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++11")

#add ffmpeg lib
include_directories(ffmpeg/include)
#link_directories("ffmpeg/lib")
#add soundtouch lib
include_directories(soundtouch/include)
link_directories("soundtouch/lib")
#add openssl lib
include_directories(openssl/include)
link_directories("openssl/lib")

#add src
aux_source_directory(./ SRC_DIR)
aux_source_directory(./ffplayer SRC_DIR_FFPLAYER)

add_library( # Sets the name of the library.
        native-lib

        # Sets the library as a shared library.
        SHARED

        # Provides a relative path to your source file(s).
        #native-lib.cpp
        ${SRC_DIR}
        ${SRC_DIR_FFPLAYER}
        )

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)

set(distribution_DIR ${CMAKE_SOURCE_DIR}/ffmpeg/solib)
add_library(avutil-55
        SHARED
        IMPORTED)
set_target_properties(avutil-55
        PROPERTIES IMPORTED_LOCATION
        ${CMAKE_SOURCE_DIR}/ffmpeg/solib/libavutil.so)

add_library(swresample-2
        SHARED
        IMPORTED)
set_target_properties(swresample-2
        PROPERTIES IMPORTED_LOCATION
        ${CMAKE_SOURCE_DIR}/ffmpeg/solib/libswresample.so)
add_library(avcodec-57
        SHARED
        IMPORTED)
set_target_properties(avcodec-57
        PROPERTIES IMPORTED_LOCATION
        ${CMAKE_SOURCE_DIR}/ffmpeg/solib/libavcodec.so)
add_library(avfilter-6
        SHARED
        IMPORTED)
set_target_properties(avfilter-6
        PROPERTIES IMPORTED_LOCATION
        ${CMAKE_SOURCE_DIR}/ffmpeg/solib/libavfilter.so)
add_library(swscale-4
        SHARED
        IMPORTED)
set_target_properties(swscale-4
        PROPERTIES IMPORTED_LOCATION
        ${CMAKE_SOURCE_DIR}/ffmpeg/solib/libswscale.so)
add_library(avdevice-57
        SHARED
        IMPORTED)
set_target_properties(avdevice-57
        PROPERTIES IMPORTED_LOCATION
        ${CMAKE_SOURCE_DIR}/ffmpeg/solib/libavdevice.so)
add_library(avformat-57
        SHARED
        IMPORTED)
set_target_properties(avformat-57
        PROPERTIES IMPORTED_LOCATION
        ${CMAKE_SOURCE_DIR}/ffmpeg/solib/libavformat.so)

target_link_libraries( # Specifies the target library.
        fanplayer-lib

        #android lib
        android.so
        z

        # ffmepg lib
        swresample-2
        avcodec-57
        avfilter-6
        swscale-4
        avdevice-57
        avformat-57
        avutil-55
        # Links the target library to the log library
        # included in the NDK.
        ${log-lib})
HelloTodayWolrd commented 2 years ago

我这个新的工程可以播放,但是只能软解,不知道为啥

rockcarry commented 2 years ago

ffmpeg 的版本要注意,android 要支持硬件解码只能用 n3.3.x 这个分支。n4.x.x 的 ffmpeg 对 mediacodec 硬件的支持是有问题的。