SkillAgentSearch skills...

Xmplayer

一个基于ffmpeg 4.0.3的android播放器

Install / Use

/learn @passer2019/Xmplayer
About this skill

Quality Score

0/100

Supported Platforms

Universal

README

1. xmplayer

一个基于ffmpeg 4.0.3的android播放器

1.1 目录

[TOC]

1.2 计划构造一个android studio的工程,目标是可以调试C语言代码部分。

  • 运行环境:ubuntu 18.04或centos 7
  • 开发工具 android studio 3.2.1
  • android 环境: android-21 (也就是 android 5或以上,不考虑android 5以前的版本)
  • ffmpeg下载地址:https://ffmpeg.org/releases/ffmpeg-4.0.3.tar.bz2, 在https://ffmpeg.org/releases可以看到所有的发部包下载地址。
  • 基于ffplay.c构建播放器

1.3 windows下面用vs2017编译

1.3.1 准备mingw环境

这个是老的方式,也可以编译出所需要库,但建议使用后面的MSYS2的方式 可以编译出ffplay.exe

  • 下载MinGW安装器,下载地址:http://www.mingw.org/ ,对应的位置 https://osdn.net/projects/mingw/releases/68260, 可能会变。
  • 具体的地址:https://osdn.net/projects/mingw/downloads/68260/mingw-get-setup.exe/
  • 下载完成后安装,请按下列图操作,即可。(我这里默认是发装到C:\MinGW目录)
  • 注意:请不要出现中文目录,可能会有想不到的问题

1

2

3

4

5

6

7

8

9

然后等它他安装完成。

1.3.2 下载yasm

  • 下载yasm.exe,下载地址: http://yasm.tortall.net/ ;我这里只下载了32位版本了。
  • 具体地址:http://yasm.tortall.net/Download.html

a1

  • 我这里下载的是 http://www.tortall.net/projects/yasm/releases/yasm-1.3.0-win32.exe, 下载完成后,改名为yasm.exe,并复制到C:\MinGW\msys\1.0\bin目录下。

  • 这样就完成了MinGW的32位环境

1.3.3 安装vs2017

  • 这个网上大把文章,就不在这里说明了

1.3.4 配置运行环境的脚本

  • 复制一个C:/MinGW/msys/1.0/msys.batC:/MinGW/msys/1.0/msys_vs2017.bat
  • 编辑msys_vs2017.bat,并在第一行的@echo off的后面,增加下面一条语句(注意:这里的vs2017是默认安装的)
call "C:/program Files (x86)/Microsoft Visual Studio/2017/Enterprise/VC/Auxiliary/Build/vcvars32.bat"
  • 完成后,如下:
@echo off
call "C:/program Files (x86)/Microsoft Visual Studio/2017/Enterprise/VC/Auxiliary/Build/vcvars32.bat"

rem Copyright (C):  2001, 2002, 2003, 2004, 2005  Earnie Boyd
rem   mailto:earnie@users.sf.net
rem This file is part of Minimal SYStem
rem   http://www.mingw.org/msys.shtml
rem
rem File:	    msys.bat
rem Revision:	    2.4
rem Revision Date:  December 8th, 2005
... ... 余下未修改的,略去

1.3.5 Debug编译

  • 在windows文件管理器下,双击运行msys_vs2017.bat,启动依赖环境
  • 这里ffmpeg解压到c:\ffmpeg4.0.3 输入
cd c:/ffmpeg4.0.3
# 在这里可以看到configure这个文件 按照我以前的理解习惯,以为是cd /cygdrive/c/ffmpeg4.0.3 但是在这个msys则不用,用cd d:则切换到d盘,其它依赖类推

  • 进入代码目录后,就可以用configure生成所需的头文件和makefile了,这里是编译生成可调试的静态库,就不生成动态库了,也不使用汇编优化了
$ ./configure --disable-asm --enable-avdevice --enable-doc --disable-programs --enable-avresample  --disable-shared --enable-static --disable-bzlib  --enable-gray --disable-libopenjpeg --disable-iconv --disable-zlib --prefix=./vs2017_build --toolchain=msvc --arch=x86 --extra-cflags="-MDd" --extra-ldflags="/NODEFAULTLIB:libcmt" --enable-debug
$ make -j4  #我这里是4核的CPU,所以用-j4,如果是双核的则-j2,八核的则-j8
$ make install
# 如果要修改配置选项,请用 ./configure --help查找编译选项
  • 完成后,在./vs2017_build如下:

a2

  • 到这里,就完成了,所有需要的头文件和库了

1.3.6 编译ffplay

  • 这个请用下面的MSYS2环境编译
  • 请确定安装了SDL2的包 mingw-w64-i686-SDL2 然后如下操作。
cd c:/ffmpeg4.0.3
./configure --enable-shared --prefix=./vs2017_ffplay
make -j4
make install
#这样,在c:/ffmpeg4.0.3/vs2017_ffplay/bin下,就能看到 ffplay.exe
#不过,还需要手动复制一些dll 在C:\msys2\mingw32\bin\下,将SDL2.dll和libbz2-1.dll复制到ffplay.exe同一个目录下,就可以了。
ffplay d:/work/ts/cctv2.ts 
# 就可以看到有节目播出来了

1.4 MSYS2的编译环境

  • Mingw默认带的MSYS环境是1.0的版本,ffmpeg官方已经不推荐操作。 这里参考官方文档,重新定义MSYS2的编译过程。
  • 1.0版本不能编译ffplay.c,这个版本可以。
  • https://www.ffmpeg.org/platform.html#Windows 官方参考文档 <4 Windows>

官方文档目录截图

1.4.1 下载MSYS2,并安装

  • 下载地址:https://www.msys2.org/
  • 安装,默认安装就可以了(我这里选择的是32位版本,i686),没有什么
# Update the package database and core system packages(更新包数据库和核心包)
pacman -Syu

# normal msys2 packages
# pacman -S make pkgconf diffutils  
# 官方提供的pkgconf不存在,试出了pkg-config这个可以安装 
pacman -S make pkg-config diffutils yasm

# mingw-w64 packages and toolchains
# 下面这个是64位版本
# pacman -S mingw-w64-x86_64-nasm mingw-w64-x86_64-gcc mingw-w64-x86_64-SDL2
# 下面这个是32位版本,我这时用的是32位版本,同时这里也安装了ffplay编译,需要的SDL2
pacman -S mingw-w64-i686-nasm mingw-w64-i686-gcc mingw-w64-i686-SDL2
  • 然后在生成编译生成一个msys_vs2017.bat的文件,在C:\msys2目录,也就是msys2_shell.cmd所在的目录 具体内容:
set MSYS2_PATH_TYPE=inherit
call "C:/program Files (x86)/Microsoft Visual Studio/2017/Enterprise/VC/Auxiliary/Build/vcvars32.bat"
msys2_shell.cmd -mingw32
  • 将C:\msys2\usr\bin\link.exe改一下名,因为会和vc的link.exe重名

  • 最后,就可以照着上面的“Debug编译”来编译了

1.5 创建vs2017的工程

1.5.1 创建工程

a3

并新建一个文件main.cpp a4

a5

#include <stdio.h>
int main(int argc, char * argv[]) {
	printf("hello ffmpeg!");
	return 0;
}

1.5.2 增加依赖头文件

c:\ffmpeg-4.0.3\vs2017_build\include (视实际情况变化) a6 a7 a8

1.5.3 增加库文件目录

c:\ffmpeg-4.0.3\vs2017_build\lib(视实际情况变化) a9 aa

1.5.4 增加库文件

依赖的库:libavcodec.a;libavdevice.a;libavfilter.a;libavformat.a;libavutil.a;libswresample.a;libswscale.a ab ac

1.5.5 修改main.cpp如下

#include <stdio.h>
extern "C"
{
	#include <libavformat/avformat.h>
	#include <libavutil/dict.h>
}
int main(int argc, char * argv[]) {
	avformat_network_init();
	printf("hello ffmpeg!");
	return 0;
}

1.5.6 LNK2019 错误

  • 如下图所示,这个是缺少依赖库造成的, ad

  • 主要是缺少Bcrypt.lib;Ws2_32.lib;Secur32.lib这三个库 af ae

  • 最后 ========== 生成: 成功 1 个,失败 0 个,最新 0 个,跳过 0 个 ==========

到这里生成完后,就可以用这个版本进行调试了,并可以断点进入。

2. 附录

2.1 ./configure --help

具体的编译选项,请视实际要求调整

Usage: configure [options]
Options: [defaults in brackets after descriptions]

Help options:
  --help                   print this message
  --quiet                  Suppress showing informative output
  --list-decoders          show all available decoders
  --list-encoders          show all available encoders
  --list-hwaccels          show all available hardware accelerators
  --list-demuxers          show all available demuxers
  --list-muxers            show all available muxers
  --list-parsers           show all available parsers
  --list-protocols         show all available protocols
  --list-bsfs              show all available bitstream filters
  --list-indevs            show all available input devices
  --list-outdevs           show all available output devices
  --list-filters           show all available filters

Standard options:
  --logfile=FILE           log tests and output to FILE [ffbuild/config.log]
  --disable-logging        do not log configure debug information
  --fatal-warnings         fail if any configure warning is generated
  --prefix=PREFIX          install in PREFIX [/usr/local]
  --bindir=DIR             install binaries in DIR [PREFIX/bin]
  --datadir=DIR            install data files in DIR [PREFIX/share/ffmpeg]
  --docdir=DIR             install documentation in DIR [PREFIX/share/doc/ffmpeg]
  --libdir=DIR             install libs in DIR [PREFIX/lib]
  --shlibdir=DIR           install shared libs in DIR [LIBDIR]
  --incdir=DIR             install includes in DIR [PREFIX/include]
  --mandir=DIR             install man page in DIR [PREFIX/share/man]
  --pkgconfigdir=DIR       install pkg-config files in DIR [LIBDIR/pkgconfig]
  --enable-rpath           use rpath to allow installing libraries in paths
                           not part of the dynamic linker search path
                           use rpath when linking programs (USE WITH CARE)
  --install-name-dir=DIR   Darwin directory name for installed targets

Licensing options:
  --enable-gpl             allow use of GPL code, the resulting libs
                           and binaries will be under GPL [no]
  --enable-version3        upgrade (L)GPL to version 3 [no]
  --enable-nonfree         allow use of nonfree code, the resulting libs
                           and binaries will be unredistributable [no]

Configuration options:
  --disable-static         do not build static libraries [no]
  --enable-shared          build shared libraries [no]
  --enable-small           optimize for size instead of speed
  --disable-runtime-cpudetect disable detecting CPU capabilities at runtime (smaller binary)
  --enable-gray            enable full grayscale support (slower color)
  --disable-swscale-alpha  disable alpha channel support in swscale
  --disable-all            disable building components, libraries and programs
  --disable-autodetect     disable automatically detected external libraries [no]

Program options:
  --disable-programs       do not build command line programs
  --disable-ffmpeg         disable ffmpeg build
  --disable-ffplay         disable ffplay build
  --disable-ffprobe        disable ffprobe build

Documentation options:
  --disable-doc            do not build documentation
  --disable-htmlpages      do not build HTML documentation pages
  --disable-manpages       do not build man documentation pages
  --disable-podpages       do not build POD documentation pages
  --disable-txtpages       do not build text documentation pages

Component options:
  --disable-avdevice       disable libavdevice build
  --disable-avcodec        disable libavcodec build
  --disable-avformat       disable libavformat build
  --disable-swresample     disable libswresample build
  --disable-swscale        disable libswscale build
  --disable-postproc       disable libpostproc build
  --disable-avfilter       disable libavfilter build
  --enable-avresample      enable libavresample build (deprecated) [no]
  --disable-pthreads       disable pthreads [autodetect]
  --disable-w32threads     disable Win32 threads [autodetect]
  --disable-os2threads     disable OS/2 threads [autodetect]
  --disable-network        disable network support [no]
  --disable-dct            disable DCT code
  --disable-dwt            disable DWT code
  --disable-error-resilience disable error resilience code
  --disable-lsp            disable LSP code
  --disable-lzo            disable LZO decoder code
  --disable-mdct           disable MDCT code
  --disable-rdft           disable RDFT code
  --disable-fft            disable FFT code
  --disable-faan           disable floating point AAN (I)DCT code
  --disable-pixelutils     disable pixel ut
View on GitHub
GitHub Stars10
CategoryDevelopment
Updated3y ago
Forks5

Languages

C

Security Score

60/100

Audited on Jul 9, 2022

No findings