快速解决Android平台移植ffmpeg的一些问题

时间:2021-12-08 07:58:21

it行业是一个踩在巨人肩膀上前进的行业,否则做的事情不一定有意义,所以我也是基于havlenapetr移植的ffmpeg基础上做了些改进,他做的主要贡献有:

1. 移植了ffmpeg并将与媒体相关的结构体在java层重新进行了封装,方便应用程序在java层直接操作ffmpeg api,如各种媒体格式转码及播放,如图1所示

2. 模仿android的mediaplayer类实现了ffmpeg的播放接口,如setdatasource(),setdisplay(),start(), stop(),pause()等,缺点是没有实现seek功能。

3. 实现了一个简单播放器功能,抛弃掉ffmpeg自带的ffplay播放器,他重新实现了音视频的分离播放和同步处理等播放器应有的功能。

快速解决Android平台移植ffmpeg的一些问题

图1 ffmpeg的java层封装

基于android移植ffmpeg的意义在于:

1.解决了android媒体框架opencore的多媒体支持不足,虽然说android平台的软解功耗大,但是从pc机的发展历史看,android的视频处理以后也会走以硬解为主,软解为辅的路线。

2. 解决android平台直播的问题,虽然android支持rtsp/rtp的直播方案,但是这种方案主要是普遍用在电信设备上,基于互联网的海量视频服务提供者还是以http live streaming方案为主,测试时可以用ffmpeg将直播流打包成分段的ts流(如10秒钟),然后组织成m3u8文件实现完整的直播方案,而且互联网的直播内容还有很多是基于mms协议的,视频格式是wmv,要聚集这些内容都是离不开ffmpeg软解的。

移植步骤:

1. 下载havlenaptr移植的ffmpeg(https://github.com/havlenapetr/ffmpeg/zipball/debug).

2.  基于ndk编译下载的ffmpeg,出现的编译问题主要是文件的存放路径不对,修改jni目录下的android.mk文件,增加头文件目录$(local_path)/../include/android,修改vector.h文件为:

#include <cutils/log.h>
#include <utils/vectorimpl.h>
#include <utils/typehelpers.h>

3.utils目录下缺少typehelpers.h,添加该文件:

复制代码 代码如下:

/*
 *  typehelpers.h
 * 
 *  copyright 2005 the android open source project
 *
 */
#ifndef android_type_helpers_h
#define android_type_helpers_h
#include <new>
#include <stdint.h>
#include <string.h>
#include <sys/types.h>
// ---------------------------------------------------------------------------
namespace android {
/*
 * types traits
 */

template <typename t> struct trait_trivial_ctor  { enum { value = false }; };
template <typename t> struct trait_trivial_dtor  { enum { value = false }; };
template <typename t> struct trait_trivial_copy  { enum { value = false }; };
template <typename t> struct trait_trivial_assign{ enum { value = false }; };
template <typename t> struct trait_pointer     { enum { value = false }; };   
template <typename t> struct trait_pointer<t*> { enum { value = true }; };
#define android_basic_types_traits( t )                                       /
    template<> struct trait_trivial_ctor< t >  { enum { value = true }; };    /
    template<> struct trait_trivial_dtor< t >  { enum { value = true }; };    /
    template<> struct trait_trivial_copy< t >  { enum { value = true }; };    /
    template<> struct trait_trivial_assign< t >{ enum { value = true }; };
#define android_type_traits( t, ctor, dtor, copy, assign )                    /
    template<> struct trait_trivial_ctor< t >  { enum { value = ctor }; };    /
    template<> struct trait_trivial_dtor< t >  { enum { value = dtor }; };    /
    template<> struct trait_trivial_copy< t >  { enum { value = copy }; };    /
    template<> struct trait_trivial_assign< t >{ enum { value = assign }; };
template <typename type>
struct traits {
    enum {
        is_pointer          = trait_pointer<type>::value,
        has_trivial_ctor    = is_pointer || trait_trivial_ctor<type>::value,
        has_trivial_dtor    = is_pointer || trait_trivial_dtor<type>::value,
        has_trivial_copy    = is_pointer || trait_trivial_copy<type>::value,
        has_trivial_assign  = is_pointer || trait_trivial_assign<type>::value  
    };
};
template <typename t, typename u>
struct aggregate_traits {
    enum {
        is_pointer          = false,
        has_trivial_ctor    = traits<t>::has_trivial_ctor && traits<u>::has_trivial_ctor,
        has_trivial_dtor    = traits<t>::has_trivial_dtor && traits<u>::has_trivial_dtor,
        has_trivial_copy    = traits<t>::has_trivial_copy && traits<u>::has_trivial_copy,
        has_trivial_assign  = traits<t>::has_trivial_assign && traits<u>::has_trivial_assign
    };
};
// ---------------------------------------------------------------------------
/*
 * basic types traits
 */

android_basic_types_traits( void );
android_basic_types_traits( bool );
android_basic_types_traits( char );
android_basic_types_traits( unsigned char );
android_basic_types_traits( short );
android_basic_types_traits( unsigned short );
android_basic_types_traits( int );
android_basic_types_traits( unsigned int );
android_basic_types_traits( long );
android_basic_types_traits( unsigned long );
android_basic_types_traits( long long );
android_basic_types_traits( unsigned long long );
android_basic_types_traits( float );
android_basic_types_traits( double );
// ---------------------------------------------------------------------------

/*
 * compare and order types
 */
template<typename type> inline
int strictly_order_type(const type& lhs, const type& rhs) {
    return (lhs < rhs) ? 1 : 0;
}
template<typename type> inline
int compare_type(const type& lhs, const type& rhs) {
    return strictly_order_type(rhs, lhs) - strictly_order_type(lhs, rhs);
}
/*
 * create, destroy, copy and assign types...
 */

template<typename type> inline
void construct_type(type* p, size_t n) {
    if (!traits<type>::has_trivial_ctor) {
        while (n--) {
            new(p++) type;
        }
    }
}
template<typename type> inline
void destroy_type(type* p, size_t n) {
    if (!traits<type>::has_trivial_dtor) {
        while (n--) {
            p->~type();
            p++;
        }
    }
}
template<typename type> inline
void copy_type(type* d, const type* s, size_t n) {
    if (!traits<type>::has_trivial_copy) {
        while (n--) {
            new(d) type(*s);
            d++, s++;
        }
    } else {
        memcpy(d,s,n*sizeof(type));
    }
}
template<typename type> inline
void assign_type(type* d, const type* s, size_t n) {
    if (!traits<type>::has_trivial_assign) {
        while (n--) {
            *d++ = *s++;
        }
    } else {
        memcpy(d,s,n*sizeof(type));
    }
}
template<typename type> inline
void splat_type(type* where, const type* what, size_t n) {
    if (!traits<type>::has_trivial_copy) {
        while (n--) {
            new(where) type(*what);
            where++;
        }
    } else {
         while (n--) {
             *where++ = *what;
        }
    }
}
template<typename type> inline
void move_forward_type(type* d, const type* s, size_t n = 1) {
    if (!traits<type>::has_trivial_copy || !traits<type>::has_trivial_dtor) {
        d += n;
        s += n;
        while (n--) {
            --d, --s;
            if (!traits<type>::has_trivial_copy) {
                new(d) type(*s);
            } else {
                *d = *s;
            }
            if (!traits<type>::has_trivial_dtor) {
                s->~type();
            }
        }
    } else {
        memmove(d,s,n*sizeof(type));
    }
}
template<typename type> inline
void move_backward_type(type* d, const type* s, size_t n = 1) {
    if (!traits<type>::has_trivial_copy || !traits<type>::has_trivial_dtor) {
        while (n--) {
            if (!traits<type>::has_trivial_copy) {
                new(d) type(*s);
            } else {
                *d = *s;
            }
            if (!traits<type>::has_trivial_dtor) {
                s->~type();
            }
            d++, s++;
        }
    } else {
        memmove(d,s,n*sizeof(type));
    }
}
// ---------------------------------------------------------------------------
/*
 * a key/value pair
 */
template <typename key, typename value>
struct key_value_pair_t {
    key     key;
    value   value;
    key_value_pair_t() { }
    key_value_pair_t(const key_value_pair_t& o) : key(o.key), value(o.value) { }
    key_value_pair_t(const key& k, const value& v) : key(k), value(v)  { }
    key_value_pair_t(const key& k) : key(k) { }
    inline bool operator < (const key_value_pair_t& o) const {
        return strictly_order_type(key, o.key);
    }
};
template<>
template <typename k, typename v>
struct trait_trivial_ctor< key_value_pair_t<k, v> >
{ enum { value = aggregate_traits<k,v>::has_trivial_ctor }; };
template<>
template <typename k, typename v>
struct trait_trivial_dtor< key_value_pair_t<k, v> >
{ enum { value = aggregate_traits<k,v>::has_trivial_dtor }; };
template<>
template <typename k, typename v>
struct trait_trivial_copy< key_value_pair_t<k, v> >
{ enum { value = aggregate_traits<k,v>::has_trivial_copy }; };
template<>
template <typename k, typename v>
struct trait_trivial_assign< key_value_pair_t<k, v> >
{ enum { value = aggregate_traits<k,v>::has_trivial_assign};};
// ---------------------------------------------------------------------------
}; // namespace android
// ---------------------------------------------------------------------------
#endif // android_type_helpers_h


4.编译中出现 make: *** no rule to make target `/cygdrive/e/workspace/myffmpeg/obj/local/armeabi/libjniaudio.so', needed by `/cygdrive/e/workspace/myffmpeg/obj/local/armeabi/libmediaplayer.a'.  stop. 需要把下载的ffmpeg中的libjniaudio.so和libjnivideo.so放到错误中指定的目录下。

 

5. 编译成功后运行的结果如下:

 快速解决Android平台移植ffmpeg的一些问题    快速解决Android平台移植ffmpeg的一些问题

当点击媒体文件播放时,发现画面显示不正常,如下所示:

快速解决Android平台移植ffmpeg的一些问题

调试后发现mediaplayer.cpp中没有像android自带播放器一样实现onvideosizechangedlistener的回调函数,当播放视图(surfaceview)创建后没有根据实际播放的视频大小做调整,而且画面没有居中显示,所以我在此基础上做了如下改进

1. 实现onvideosizechangedlistener接口,通知播放界面调整大小

2. 播放界面剧中显示,等比率缩放视频大小。

3. 实现seek功能

 

3.1 要实现getcurrentposition(), 因为拖动时传过来的是时间millisecond3.2 把milli second转化成timestamp掉用av_seek...3.3 在idecoder类里面加入flush函数,实际上就是seek的时候把队列里的avpacket清除掉3.4 通过av_gettime()函数作为外部参考时钟,实现音视频同步,需要hurryup和实现drop frame的处理。

下面是调整后播放flv(h264+aac)格式(分辨率为320*240,25帧/s)的结果,软解播放达到平均22帧/s

快速解决Android平台移植ffmpeg的一些问题  快速解决Android平台移植ffmpeg的一些问题

其它wmv,ts流,avi等格式均可播放,但是音质效果需要改进。

最近的进展情况:

1. 实现ffmpeg播放的回调接口,可以通知界面刷新状态,如去掉缓冲提示等。 

复制代码 代码如下:

public interface iffmpegplayer {
     public void onplay();
     public void onstop();
     public void onrelease();
     public void onerror(string msg, exception e);
    }


2. 定制话播放控制栏界面,效果如下:

 

快速解决Android平台移植ffmpeg的一些问题

替换ffmpeg自带的控制栏界面

如何支持http网络播放,需要config.h里enable相关选项,我的配置参考如下:

复制代码 代码如下:

/* automatically generated by configure - do not modify! */
#ifndef ffmpeg_config_h
#define ffmpeg_config_h
#define ffmpeg_configuration "--target-os=linux --arch=armv41 --enable-cross-compile --cc=/home/petr/projects/android_api/ndk/android-ndk-1.6_r1/build/prebuilt/linux-x86/arm-eabi-4.2.1/bin/arm-eabi-gcc --cross-prefix=/home/petr/projects/android_api/ndk/android-ndk-1.6_r1/build/prebuilt/linux-x86/arm-eabi-4.2.1/bin/arm-eabi- --nm=/home/petr/projects/android_api/ndk/android-ndk-1.6_r1/build/prebuilt/linux-x86/arm-eabi-4.2.1/bin/arm-eabi-nm --extra-cflags='-fpic -dandroid' --enable-static --disable-shared --disable-asm --disable-yasm --prefix=/home/ffmpeg-android-bin --extra-ldflags='-wl,-t,/home/petr/projects/android_api/ndk/android-ndk-1.6_r1/build/prebuilt/linux-x86/arm-eabi-4.2.1/arm-eabi/lib/ldscripts/armelf.x -wl,-rpath-link=/home/petr/projects/android_api/ndk/android-ndk-1.6_r1/build/platforms/android-4/arch-arm/usr/lib -l/home/petr/projects/android_api/ndk/android-ndk-1.6_r1/build/platforms/android-4/arch-arm/usr/lib -nostdlib /home/petr/projects/android_api/ndk/android-ndk-1.6_r1/build/prebuilt/linux-x86/arm-eabi-4.2.1/lib/gcc/arm-eabi/4.2.1/crtbegin.o /home/petr/projects/android_api/ndk/android-ndk-1.6_r1/build/prebuilt/linux-x86/arm-eabi-4.2.1/lib/gcc/arm-eabi/4.2.1/crtend.o -lc -lm -ldl'"
#define ffmpeg_license "lgpl version 2.1 or later"
#define ffmpeg_datadir "/home/ffmpeg-android-bin/share/ffmpeg"
#define cc_type "gcc"
#define cc_version __version__
#define restrict restrict
#define asmalign(zerobits) ".p2align " #zerobits "/n/t"
#define extern_prefix ""
#define extern_asm
#define arch_alpha 0
#define arch_arm 0
#define arch_avr32 0
#define arch_avr32_ap 0
#define arch_avr32_uc 0
#define arch_bfin 0
#define arch_ia64 0
#define arch_m68k 0
#define arch_mips 0
#define arch_mips64 0
#define arch_parisc 0
#define arch_ppc 0
#define arch_ppc64 0
#define arch_s390 0
#define arch_sh4 0
#define arch_sparc 0
#define arch_sparc64 0
#define arch_tomi 0
#define arch_x86 0
#define arch_x86_32 0
#define arch_x86_64 0
#define have_altivec 0
#define have_amd3dnow 0
#define have_amd3dnowext 0
#define have_armv5te 0
#define have_armv6 0
#define have_armv6t2 0
#define have_armvfp 0
#define have_iwmmxt 0
#define have_mmi 0
#define have_mmx 0
#define have_mmx2 0
#define have_neon 0
#define have_ppc4xx 0
#define have_sse 0
#define have_ssse3 0
#define have_vis 0
#define have_bigendian 0
#define have_beosthreads 0
#define have_os2threads 0
#define have_pthreads 0
#define have_w32threads 0
#define have_alsa_asoundlib_h 0
#define have_altivec_h 0
#define have_arpa_inet_h 0
#define have_attribute_may_alias 1
#define have_attribute_packed 1
#define have_bswap 0
#define have_closesocket 0
#define have_cmov 0
#define have_conio_h 0
#define have_dcbzl 0
#define have_dev_bktr_ioctl_bt848_h 0
#define have_dev_bktr_ioctl_meteor_h 0
#define have_dev_ic_bt8xx_h 0
#define have_dev_video_meteor_ioctl_meteor_h 0
#define have_dev_video_bktr_ioctl_bt848_h 0
#define have_dlfcn_h 0
#define have_dlopen 1
#define have_dos_paths 0
#define have_ebp_available 0
#define have_ebx_available 0
#define have_exp2 0
#define have_exp2f 0
#define have_fast_64bit 0
#define have_fast_clz 1
#define have_fast_cmov 0
#define have_fast_unaligned 0
#define have_fork 1
#define have_getaddrinfo 1
#define have_gethrtime 0
#define have_getprocessmemoryinfo 0
#define have_getprocesstimes 0
#define have_getrusage 0
#define have_struct_rusage_ru_maxrss 0
#define have_inet_aton 1
#define have_inline_asm 1
#define have_isatty 1
#define have_ldbrx 0
#define have_libdc1394_1 0
#define have_libdc1394_2 0
#define have_local_aligned_16 0
#define have_local_aligned_8 0
#define have_log2 0
#define have_log2f 0
#define have_loongson 0
#define have_lrint 0
#define have_lrintf 0
#define have_lzo1x_999_compress 0
#define have_machine_ioctl_bt848_h 0
#define have_machine_ioctl_meteor_h 0
#define have_malloc_h 0
#define have_memalign 1
#define have_mkstemp 1
#define have_pld 1
#define have_posix_memalign 0
#define have_round 0
#define have_roundf 0
#define have_sdl 0
#define have_sdl_video_size 0
#define have_setmode 0
#define have_socklen_t 1
#define have_soundcard_h 0
#define have_poll_h 0
#define have_setrlimit 0
#define have_strerror_r 1
#define have_struct_addrinfo 1
#define have_struct_ipv6_mreq 0
#define have_struct_sockaddr_in6 0
#define have_struct_sockaddr_sa_len 0
#define have_struct_sockaddr_storage 1
#define have_symver 1
#define have_symver_gnu_asm 1
#define have_symver_asm_label 0
#define have_sys_mman_h 0
#define have_sys_resource_h 0
#define have_sys_select_h 0
#define have_sys_soundcard_h 0
#define have_sys_videoio_h 0
#define have_ten_operands 0
#define have_termios_h 0
#define have_threads 0
#define have_truncf 0
#define have_vfp_args 1
#define have_virtualalloc 0
#define have_winsock2_h 0
#define have_xform_asm 0
#define have_yasm 0
#define config_bsfs 1
#define config_decoders 1
#define config_demuxers 1
#define config_encoders 1
#define config_filters 1
#define config_hwaccels 0
#define config_indevs 1
#define config_muxers 1
#define config_outdevs 0
#define config_parsers 1
#define config_protocols 1
#define config_aandct 1
#define config_avcodec 1
#define config_avdevice 0
#define config_avfilter 0
#define config_avfilter_lavf 0
#define config_avformat 1
#define config_avisynth 0
#define config_bzlib 0
#define config_dct 1
#define config_doc 0
#define config_dwt 1
#define config_dxva2 0
#define config_fastdiv 1
#define config_ffmpeg 1
#define config_ffplay 0
#define config_ffprobe 1
#define config_ffserver 0
#define config_fft 1
#define config_golomb 1
#define config_gpl 0
#define config_gprof 0
#define config_gray 0
#define config_h264dsp 1
#define config_hardcoded_tables 0
#define config_libdc1394 0
#define config_libdirac 0
#define config_libfaac 0
#define config_libgsm 0
#define config_libmp3lame 0
#define config_libnut 0
#define config_libopencore_amrnb 0
#define config_libopencore_amrwb 0
#define config_libopenjpeg 0
#define config_librtmp 0
#define config_libschroedinger 0
#define config_libspeex 0
#define config_libtheora 0
#define config_libvorbis 0
#define config_libvpx 0
#define config_libx264 0
#define config_libxvid 0
#define config_lpc 1
#define config_lsp 1
#define config_mdct 1
#define config_memalign_hack 0
#define config_mlib 0
#define config_mpegaudio_hp 1
#define config_network 1
#define config_nonfree 0
#define config_pic 0
#define config_postproc 0
#define config_powerpc_perf 0
#define config_rdft 1
#define config_runtime_cpudetect 0
#define config_shared 0
#define config_small 0
#define config_sram 0
#define config_static 1
#define config_swscale 1
#define config_swscale_alpha 1
#define config_vaapi 0
#define config_vdpau 0
#define config_version3 0
#define config_x11grab 0
#define config_zlib 0
#define config_avutil 1
#define config_gplv3 0
#define config_lgplv3 0
#define config_aasc_decoder 1
#define config_amv_decoder 1
#define config_anm_decoder 1
#define config_asv1_decoder 1
#define config_asv2_decoder 1
#define config_aura_decoder 1
#define config_aura2_decoder 1
#define config_avs_decoder 1
#define config_bethsoftvid_decoder 1
#define config_bfi_decoder 1
#define config_bink_decoder 1
#define config_bmp_decoder 1
#define config_c93_decoder 1
#define config_cavs_decoder 1
#define config_cdgraphics_decoder 1
#define config_cinepak_decoder 1
#define config_cljr_decoder 1
#define config_cscd_decoder 1
#define config_cyuv_decoder 1
#define config_dnxhd_decoder 1
#define config_dpx_decoder 1
#define config_dsicinvideo_decoder 1
#define config_dvvideo_decoder 1
#define config_dxa_decoder 0
#define config_eacmv_decoder 1
#define config_eamad_decoder 1
#define config_eatgq_decoder 1
#define config_eatgv_decoder 1
#define config_eatqi_decoder 1
#define config_eightbps_decoder 1
#define config_eightsvx_exp_decoder 1
#define config_eightsvx_fib_decoder 1
#define config_escape124_decoder 1
#define config_ffv1_decoder 1
#define config_ffvhuff_decoder 1
#define config_flashsv_decoder 0
#define config_flic_decoder 1
#define config_flv_decoder 1
#define config_fourxm_decoder 1
#define config_fraps_decoder 1
#define config_frwu_decoder 1
#define config_gif_decoder 1
#define config_h261_decoder 1
#define config_h263_decoder 1
#define config_h263i_decoder 1
#define config_h264_decoder 1
#define config_h264_vdpau_decoder 0
#define config_huffyuv_decoder 1
#define config_idcin_decoder 1
#define config_iff_byterun1_decoder 1
#define config_iff_ilbm_decoder 1
#define config_indeo2_decoder 1
#define config_indeo3_decoder 1
#define config_indeo5_decoder 1
#define config_interplay_video_decoder 1
#define config_jpegls_decoder 1
#define config_kgv1_decoder 1
#define config_kmvc_decoder 1
#define config_loco_decoder 1
#define config_mdec_decoder 1
#define config_mimic_decoder 1
#define config_mjpeg_decoder 1
#define config_mjpegb_decoder 1
#define config_mmvideo_decoder 1
#define config_motionpixels_decoder 1
#define config_mpeg_xvmc_decoder 0
#define config_mpeg1video_decoder 1
#define config_mpeg2video_decoder 1
#define config_mpeg4_decoder 1
#define config_mpeg4_vdpau_decoder 0
#define config_mpegvideo_decoder 1
#define config_mpeg_vdpau_decoder 0
#define config_mpeg1_vdpau_decoder 0
#define config_msmpeg4v1_decoder 1
#define config_msmpeg4v2_decoder 1
#define config_msmpeg4v3_decoder 1
#define config_msrle_decoder 1
#define config_msvideo1_decoder 1
#define config_mszh_decoder 1
#define config_nuv_decoder 1
#define config_pam_decoder 1
#define config_pbm_decoder 1
#define config_pcx_decoder 1
#define config_pgm_decoder 1
#define config_pgmyuv_decoder 1
#define config_pictor_decoder 1
#define config_png_decoder 0
#define config_ppm_decoder 1
#define config_ptx_decoder 1
#define config_qdraw_decoder 1
#define config_qpeg_decoder 1
#define config_qtrle_decoder 1
#define config_r210_decoder 1
#define config_rawvideo_decoder 1
#define config_rl2_decoder 1
#define config_roq_decoder 1
#define config_rpza_decoder 1
#define config_rv10_decoder 1
#define config_rv20_decoder 1
#define config_rv30_decoder 1
#define config_rv40_decoder 1
#define config_sgi_decoder 1
#define config_smacker_decoder 1
#define config_smc_decoder 1
#define config_snow_decoder 1
#define config_sp5x_decoder 1
#define config_sunrast_decoder 1
#define config_svq1_decoder 1
#define config_svq3_decoder 1
#define config_targa_decoder 1
#define config_theora_decoder 1
#define config_thp_decoder 1
#define config_tiertexseqvideo_decoder 1
#define config_tiff_decoder 1
#define config_tmv_decoder 1
#define config_truemotion1_decoder 1
#define config_truemotion2_decoder 1
#define config_tscc_decoder 0
#define config_txd_decoder 1
#define config_ulti_decoder 1
#define config_v210_decoder 1
#define config_v210x_decoder 1
#define config_vb_decoder 1
#define config_vc1_decoder 1
#define config_vc1_vdpau_decoder 0
#define config_vcr1_decoder 1
#define config_vmdvideo_decoder 1
#define config_vmnc_decoder 1
#define config_vp3_decoder 1
#define config_vp5_decoder 1
#define config_vp6_decoder 1
#define config_vp6a_decoder 1
#define config_vp6f_decoder 1
#define config_vqa_decoder 1
#define config_wmv1_decoder 1
#define config_wmv2_decoder 1
#define config_wmv3_decoder 1
#define config_wmv3_vdpau_decoder 0
#define config_wnv1_decoder 1
#define config_xan_wc3_decoder 1
#define config_xl_decoder 1
#define config_yop_decoder 1
#define config_zlib_decoder 0
#define config_zmbv_decoder 0
#define config_aac_decoder 1
#define config_ac3_decoder 1
#define config_alac_decoder 1
#define config_als_decoder 1
#define config_amrnb_decoder 1
#define config_ape_decoder 1
#define config_atrac1_decoder 1
#define config_atrac3_decoder 1
#define config_binkaudio_dct_decoder 1
#define config_binkaudio_rdft_decoder 1
#define config_cook_decoder 1
#define config_dca_decoder 1
#define config_dsicinaudio_decoder 1
#define config_eac3_decoder 1
#define config_flac_decoder 1
#define config_imc_decoder 1
#define config_mace3_decoder 1
#define config_mace6_decoder 1
#define config_mlp_decoder 1
#define config_mp1_decoder 1
#define config_mp1float_decoder 1
#define config_mp2_decoder 1
#define config_mp2float_decoder 1
#define config_mp3_decoder 1
#define config_mp3float_decoder 1
#define config_mp3adu_decoder 1
#define config_mp3adufloat_decoder 1
#define config_mp3on4_decoder 1
#define config_mp3on4float_decoder 1
#define config_mpc7_decoder 1
#define config_mpc8_decoder 1
#define config_nellymoser_decoder 1
#define config_qcelp_decoder 1
#define config_qdm2_decoder 1
#define config_ra_144_decoder 1
#define config_ra_288_decoder 1
#define config_shorten_decoder 1
#define config_sipr_decoder 1
#define config_smackaud_decoder 1
#define config_sonic_decoder 1
#define config_truehd_decoder 1
#define config_truespeech_decoder 1
#define config_tta_decoder 1
#define config_twinvq_decoder 1
#define config_vmdaudio_decoder 1
#define config_vorbis_decoder 1
#define config_wavpack_decoder 1
#define config_wmapro_decoder 1
#define config_wmav1_decoder 1
#define config_wmav2_decoder 1
#define config_wmavoice_decoder 1
#define config_ws_snd1_decoder 1
#define config_pcm_alaw_decoder 1
#define config_pcm_bluray_decoder 1
#define config_pcm_dvd_decoder 1
#define config_pcm_f32be_decoder 1
#define config_pcm_f32le_decoder 1
#define config_pcm_f64be_decoder 1
#define config_pcm_f64le_decoder 1
#define config_pcm_mulaw_decoder 1
#define config_pcm_s8_decoder 1
#define config_pcm_s16be_decoder 1
#define config_pcm_s16le_decoder 1
#define config_pcm_s16le_planar_decoder 1
#define config_pcm_s24be_decoder 1
#define config_pcm_s24daud_decoder 1
#define config_pcm_s24le_decoder 1
#define config_pcm_s32be_decoder 1
#define config_pcm_s32le_decoder 1
#define config_pcm_u8_decoder 1
#define config_pcm_u16be_decoder 1
#define config_pcm_u16le_decoder 1
#define config_pcm_u24be_decoder 1
#define config_pcm_u24le_decoder 1
#define config_pcm_u32be_decoder 1
#define config_pcm_u32le_decoder 1
#define config_pcm_zork_decoder 1
#define config_interplay_dpcm_decoder 1
#define config_roq_dpcm_decoder 1
#define config_sol_dpcm_decoder 1
#define config_xan_dpcm_decoder 1
#define config_adpcm_4xm_decoder 1
#define config_adpcm_adx_decoder 1
#define config_adpcm_ct_decoder 1
#define config_adpcm_ea_decoder 1
#define config_adpcm_ea_maxis_xa_decoder 1
#define config_adpcm_ea_r1_decoder 1
#define config_adpcm_ea_r2_decoder 1
#define config_adpcm_ea_r3_decoder 1
#define config_adpcm_ea_xas_decoder 1
#define config_adpcm_g726_decoder 1
#define config_adpcm_ima_amv_decoder 1
#define config_adpcm_ima_dk3_decoder 1
#define config_adpcm_ima_dk4_decoder 1
#define config_adpcm_ima_ea_eacs_decoder 1
#define config_adpcm_ima_ea_sead_decoder 1
#define config_adpcm_ima_iss_decoder 1
#define config_adpcm_ima_qt_decoder 1
#define config_adpcm_ima_smjpeg_decoder 1
#define config_adpcm_ima_wav_decoder 1
#define config_adpcm_ima_ws_decoder 1
#define config_adpcm_ms_decoder 1
#define config_adpcm_sbpro_2_decoder 1
#define config_adpcm_sbpro_3_decoder 1
#define config_adpcm_sbpro_4_decoder 1
#define config_adpcm_swf_decoder 1
#define config_adpcm_thp_decoder 1
#define config_adpcm_xa_decoder 1
#define config_adpcm_yamaha_decoder 1
#define config_dvbsub_decoder 1
#define config_dvdsub_decoder 1
#define config_pgssub_decoder 1
#define config_xsub_decoder 1
#define config_libdirac_decoder 0
#define config_libgsm_decoder 0
#define config_libgsm_ms_decoder 0
#define config_libopencore_amrnb_decoder 0
#define config_libopencore_amrwb_decoder 0
#define config_libopenjpeg_decoder 0
#define config_libschroedinger_decoder 0
#define config_libspeex_decoder 0
#define config_libvpx_decoder 0
#define config_asv1_encoder 1
#define config_asv2_encoder 1
#define config_bmp_encoder 1
#define config_dnxhd_encoder 1
#define config_dvvideo_encoder 1
#define config_ffv1_encoder 1
#define config_ffvhuff_encoder 1
#define config_flashsv_encoder 0
#define config_flv_encoder 1
#define config_gif_encoder 1
#define config_h261_encoder 1
#define config_h263_encoder 1
#define config_h263p_encoder 1
#define config_huffyuv_encoder 1
#define config_jpegls_encoder 1
#define config_ljpeg_encoder 1
#define config_mjpeg_encoder 1
#define config_mpeg1video_encoder 1
#define config_mpeg2video_encoder 1
#define config_mpeg4_encoder 1
#define config_msmpeg4v1_encoder 1
#define config_msmpeg4v2_encoder 1
#define config_msmpeg4v3_encoder 1
#define config_pam_encoder 1
#define config_pbm_encoder 1
#define config_pcx_encoder 1
#define config_pgm_encoder 1
#define config_pgmyuv_encoder 1
#define config_png_encoder 0
#define config_ppm_encoder 1
#define config_qtrle_encoder 1
#define config_rawvideo_encoder 1
#define config_roq_encoder 1
#define config_rv10_encoder 1
#define config_rv20_encoder 1
#define config_sgi_encoder 1
#define config_snow_encoder 1
#define config_svq1_encoder 1
#define config_targa_encoder 1
#define config_tiff_encoder 1
#define config_v210_encoder 1
#define config_wmv1_encoder 1
#define config_wmv2_encoder 1
#define config_zlib_encoder 0
#define config_zmbv_encoder 0
#define config_aac_encoder 1
#define config_ac3_encoder 1
#define config_alac_encoder 1
#define config_flac_encoder 1
#define config_mp2_encoder 1
#define config_nellymoser_encoder 1
#define config_ra_144_encoder 1
#define config_sonic_encoder 1
#define config_sonic_ls_encoder 1
#define config_vorbis_encoder 1
#define config_wmav1_encoder 1
#define config_wmav2_encoder 1
#define config_pcm_alaw_encoder 1
#define config_pcm_f32be_encoder 1
#define config_pcm_f32le_encoder 1
#define config_pcm_f64be_encoder 1
#define config_pcm_f64le_encoder 1
#define config_pcm_mulaw_encoder 1
#define config_pcm_s8_encoder 1
#define config_pcm_s16be_encoder 1
#define config_pcm_s16le_encoder 1
#define config_pcm_s24be_encoder 1
#define config_pcm_s24daud_encoder 1
#define config_pcm_s24le_encoder 1
#define config_pcm_s32be_encoder 1
#define config_pcm_s32le_encoder 1
#define config_pcm_u8_encoder 1
#define config_pcm_u16be_encoder 1
#define config_pcm_u16le_encoder 1
#define config_pcm_u24be_encoder 1
#define config_pcm_u24le_encoder 1
#define config_pcm_u32be_encoder 1
#define config_pcm_u32le_encoder 1
#define config_pcm_zork_encoder 1
#define config_roq_dpcm_encoder 1
#define config_adpcm_adx_encoder 1
#define config_adpcm_g726_encoder 1
#define config_adpcm_ima_qt_encoder 1
#define config_adpcm_ima_wav_encoder 1
#define config_adpcm_ms_encoder 1
#define config_adpcm_swf_encoder 1
#define config_adpcm_yamaha_encoder 1
#define config_dvbsub_encoder 1
#define config_dvdsub_encoder 1
#define config_xsub_encoder 1
#define config_libdirac_encoder 0
#define config_libfaac_encoder 0
#define config_libgsm_encoder 0
#define config_libgsm_ms_encoder 0
#define config_libmp3lame_encoder 0
#define config_libopencore_amrnb_encoder 0
#define config_libschroedinger_encoder 0
#define config_libtheora_encoder 0
#define config_libvorbis_encoder 0
#define config_libvpx_encoder 0
#define config_libx264_encoder 0
#define config_libxvid_encoder 0
#define config_h263_vaapi_hwaccel 0
#define config_h264_dxva2_hwaccel 0
#define config_h264_vaapi_hwaccel 0
#define config_mpeg2_dxva2_hwaccel 0
#define config_mpeg2_vaapi_hwaccel 0
#define config_mpeg4_vaapi_hwaccel 0
#define config_vc1_dxva2_hwaccel 0
#define config_vc1_vaapi_hwaccel 0
#define config_wmv3_dxva2_hwaccel 0
#define config_wmv3_vaapi_hwaccel 0
#define config_aac_parser 1
#define config_ac3_parser 1
#define config_cavsvideo_parser 1
#define config_dca_parser 1
#define config_dirac_parser 1
#define config_dnxhd_parser 1
#define config_dvbsub_parser 1
#define config_dvdsub_parser 1
#define config_h261_parser 1
#define config_h263_parser 1
#define config_h264_parser 1
#define config_mjpeg_parser 1
#define config_mlp_parser 1
#define config_mpeg4video_parser 1
#define config_mpegaudio_parser 1
#define config_mpegvideo_parser 1
#define config_pnm_parser 1
#define config_vc1_parser 1
#define config_vp3_parser 1
#define config_vp8_parser 1
#define config_aac_adtstoasc_bsf 1
#define config_chomp_bsf 1
#define config_dump_extradata_bsf 1
#define config_h264_mp4toannexb_bsf 1
#define config_imx_dump_header_bsf 1
#define config_mjpega_dump_header_bsf 1
#define config_mp3_header_compress_bsf 1
#define config_mp3_header_decompress_bsf 1
#define config_mov2textsub_bsf 1
#define config_noise_bsf 1
#define config_remove_extradata_bsf 1
#define config_text2movsub_bsf 1
#define config_aac_demuxer 1
#define config_ac3_demuxer 1
#define config_aea_demuxer 1
#define config_aiff_demuxer 1
#define config_amr_demuxer 1
#define config_anm_demuxer 1
#define config_apc_demuxer 1
#define config_ape_demuxer 1
#define config_asf_demuxer 1
#define config_ass_demuxer 1
#define config_au_demuxer 1
#define config_avi_demuxer 1
#define config_avisynth_demuxer 0
#define config_avs_demuxer 1
#define config_bethsoftvid_demuxer 1
#define config_bfi_demuxer 1
#define config_bink_demuxer 1
#define config_c93_demuxer 1
#define config_caf_demuxer 1
#define config_cavsvideo_demuxer 1
#define config_cdg_demuxer 1
#define config_daud_demuxer 1
#define config_dirac_demuxer 1
#define config_dnxhd_demuxer 1
#define config_dsicin_demuxer 1
#define config_dts_demuxer 1
#define config_dv_demuxer 1
#define config_dxa_demuxer 1
#define config_ea_demuxer 1
#define config_ea_cdata_demuxer 1
#define config_eac3_demuxer 1
#define config_ffm_demuxer 1
#define config_filmstrip_demuxer 1
#define config_flac_demuxer 1
#define config_flic_demuxer 1
#define config_flv_demuxer 1
#define config_fourxm_demuxer 1
#define config_gsm_demuxer 1
#define config_gxf_demuxer 1
#define config_h261_demuxer 1
#define config_h263_demuxer 1
#define config_h264_demuxer 1
#define config_idcin_demuxer 1
#define config_iff_demuxer 1
#define config_image2_demuxer 1
#define config_image2pipe_demuxer 1
#define config_ingenient_demuxer 1
#define config_ipmovie_demuxer 1
#define config_iss_demuxer 1
#define config_iv8_demuxer 1
#define config_ivf_demuxer 1
#define config_lmlm4_demuxer 1
#define config_m4v_demuxer 1
#define config_matroska_demuxer 1
#define config_mjpeg_demuxer 1
#define config_mlp_demuxer 1
#define config_mm_demuxer 1
#define config_mmf_demuxer 1
#define config_mov_demuxer 1
#define config_mp3_demuxer 1
#define config_mpc_demuxer 1
#define config_mpc8_demuxer 1
#define config_mpegps_demuxer 1
#define config_mpegts_demuxer 1
#define config_mpegtsraw_demuxer 1
#define config_mpegvideo_demuxer 1
#define config_msnwc_tcp_demuxer 1
#define config_mtv_demuxer 1
#define config_mvi_demuxer 1
#define config_mxf_demuxer 1
#define config_nc_demuxer 1
#define config_nsv_demuxer 1
#define config_nut_demuxer 1
#define config_nuv_demuxer 1
#define config_ogg_demuxer 0
#define config_oma_demuxer 1
#define config_pcm_alaw_demuxer 1
#define config_pcm_mulaw_demuxer 1
#define config_pcm_f64be_demuxer 1
#define config_pcm_f64le_demuxer 1
#define config_pcm_f32be_demuxer 1
#define config_pcm_f32le_demuxer 1
#define config_pcm_s32be_demuxer 1
#define config_pcm_s32le_demuxer 1
#define config_pcm_s24be_demuxer 1
#define config_pcm_s24le_demuxer 1
#define config_pcm_s16be_demuxer 1
#define config_pcm_s16le_demuxer 1
#define config_pcm_s8_demuxer 1
#define config_pcm_u32be_demuxer 1
#define config_pcm_u32le_demuxer 1
#define config_pcm_u24be_demuxer 1
#define config_pcm_u24le_demuxer 1
#define config_pcm_u16be_demuxer 1
#define config_pcm_u16le_demuxer 1
#define config_pcm_u8_demuxer 1
#define config_pva_demuxer 1
#define config_qcp_demuxer 1
#define config_r3d_demuxer 1
#define config_rawvideo_demuxer 1
#define config_rl2_demuxer 1
#define config_rm_demuxer 1
#define config_roq_demuxer 1
#define config_rpl_demuxer 1
#define config_rtsp_demuxer 0
#define config_sdp_demuxer 0
#define config_segafilm_demuxer 1
#define config_shorten_demuxer 1
#define config_siff_demuxer 1
#define config_smacker_demuxer 1
#define config_sol_demuxer 1
#define config_sox_demuxer 1
#define config_str_demuxer 1
#define config_swf_demuxer 1
#define config_thp_demuxer 1
#define config_tiertexseq_demuxer 1
#define config_tmv_demuxer 1
#define config_truehd_demuxer 1
#define config_tta_demuxer 1
#define config_txd_demuxer 1
#define config_vc1_demuxer 1
#define config_vc1t_demuxer 1
#define config_vmd_demuxer 1
#define config_voc_demuxer 1
#define config_vqf_demuxer 1
#define config_w64_demuxer 1
#define config_wav_demuxer 1
#define config_wc3_demuxer 1
#define config_wsaud_demuxer 1
#define config_wsvqa_demuxer 1
#define config_wv_demuxer 1
#define config_xa_demuxer 1
#define config_yop_demuxer 1
#define config_yuv4mpegpipe_demuxer 1
#define config_libnut_demuxer 0
#define config_ac3_muxer 1
#define config_adts_muxer 1
#define config_aiff_muxer 1
#define config_amr_muxer 1
#define config_asf_muxer 1
#define config_ass_muxer 1
#define config_asf_stream_muxer 1
#define config_au_muxer 1
#define config_avi_muxer 1
#define config_avm2_muxer 1
#define config_crc_muxer 1
#define config_daud_muxer 1
#define config_dirac_muxer 1
#define config_dnxhd_muxer 1
#define config_dts_muxer 1
#define config_dv_muxer 1
#define config_eac3_muxer 1
#define config_ffm_muxer 1
#define config_filmstrip_muxer 1
#define config_flac_muxer 1
#define config_flv_muxer 1
#define config_framecrc_muxer 1
#define config_framemd5_muxer 1
#define config_gif_muxer 1
#define config_gxf_muxer 1
#define config_h261_muxer 1
#define config_h263_muxer 1
#define config_h264_muxer 1
#define config_image2_muxer 1
#define config_image2pipe_muxer 1
#define config_ipod_muxer 1
#define config_m4v_muxer 1
#define config_md5_muxer 1
#define config_matroska_muxer 1
#define config_matroska_audio_muxer 1
#define config_mjpeg_muxer 1
#define config_mlp_muxer 1
#define config_mmf_muxer 1
#define config_mov_muxer 1
#define config_mp2_muxer 1
#define config_mp3_muxer 1
#define config_mp4_muxer 1
#define config_mpeg1system_muxer 1
#define config_mpeg1vcd_muxer 1
#define config_mpeg1video_muxer 1
#define config_mpeg2dvd_muxer 1
#define config_mpeg2svcd_muxer 1
#define config_mpeg2video_muxer 1
#define config_mpeg2vob_muxer 1
#define config_mpegts_muxer 1
#define config_mpjpeg_muxer 1
#define config_mxf_muxer 1
#define config_mxf_d10_muxer 1
#define config_null_muxer 1
#define config_nut_muxer 1
#define config_ogg_muxer 0
#define config_pcm_alaw_muxer 1
#define config_pcm_mulaw_muxer 1
#define config_pcm_f64be_muxer 1
#define config_pcm_f64le_muxer 1
#define config_pcm_f32be_muxer 1
#define config_pcm_f32le_muxer 1
#define config_pcm_s32be_muxer 1
#define config_pcm_s32le_muxer 1
#define config_pcm_s24be_muxer 1
#define config_pcm_s24le_muxer 1
#define config_pcm_s16be_muxer 1
#define config_pcm_s16le_muxer 1
#define config_pcm_s8_muxer 1
#define config_pcm_u32be_muxer 1
#define config_pcm_u32le_muxer 1
#define config_pcm_u24be_muxer 1
#define config_pcm_u24le_muxer 1
#define config_pcm_u16be_muxer 1
#define config_pcm_u16le_muxer 1
#define config_pcm_u8_muxer 1
#define config_psp_muxer 1
#define config_rawvideo_muxer 1
#define config_rm_muxer 1
#define config_roq_muxer 1
#define config_rtp_muxer 1
#define config_rtsp_muxer 0
#define config_sox_muxer 1
#define config_spdif_muxer 1
#define config_swf_muxer 1
#define config_tg2_muxer 1
#define config_tgp_muxer 1
#define config_truehd_muxer 1
#define config_vc1t_muxer 1
#define config_voc_muxer 1
#define config_wav_muxer 1
#define config_webm_muxer 1
#define config_yuv4mpegpipe_muxer 1
#define config_libnut_muxer 0
#define config_aspect_filter 1
#define config_crop_filter 1
#define config_format_filter 1
#define config_noformat_filter 1
#define config_null_filter 1
#define config_pad_filter 1
#define config_pixelaspect_filter 1
#define config_scale_filter 1
#define config_slicify_filter 1
#define config_unsharp_filter 1
#define config_vflip_filter 1
#define config_buffer_filter 1
#define config_nullsrc_filter 1
#define config_nullsink_filter 1
#define config_file_protocol 1
#define config_gopher_protocol 0
#define config_http_protocol 1
#define config_mmst_protocol 0
#define config_pipe_protocol 1
#define config_rtmp_protocol 0
#define config_rtmpt_protocol 1
#define config_rtmpe_protocol 1
#define config_rtmpte_protocol 1
#define config_rtmps_protocol 1
#define config_rtp_protocol 0
#define config_tcp_protocol 1
#define config_udp_protocol 1
#define config_concat_protocol 1
#define config_alsa_indev 0
#define config_bktr_indev 0
#define config_dv1394_indev 1
#define config_jack_indev 0
#define config_oss_indev 0
#define config_v4l2_indev 0
#define config_v4l_indev 0
#define config_vfwcap_indev 0
#define config_x11_grab_device_indev 0
#define config_libdc1394_indev 0
#define config_alsa_outdev 0
#define config_oss_outdev 0
#endif /* ffmpeg_config_h */


ffmpeg自带的播放器ffplay对音视频的处理方法总结:

 

1. 如果声音是cbr的(也就是固定码率),就以音频的时间戳为基准

2. 如果视频时cbr,就以视频的时间戳为基准

3. 如果都是vbr的,就参考外部时钟,通过av_gettime()获取微妙集的时钟。

ffmpeg通过avstream结构的time_base(有理数由分子和分母组成)可以获取一个参考时间单位,所有音视频流的timestamp都是基于这个时间单位顺序递增,比如time_base.num=1,time_base.den=90000,表示把1秒分成90000等份,音视频的pts和dts值就表示有多少个1/90000等份,更简单一点假设time_base.num=1,time_base.den=1000,就表示1秒分成1000等份,相当于1毫秒,那时间戳就表示是以毫秒为单位的,再做音视频处理时候,如果解码的速度比按照时间戳显示的速度快,那就简单不用丟帧(drop frame)处理,当解码速度很慢时(比如手机设备),就需要丢帧处理,是每两帧丟一帧数据,还是每3帧丟掉一帧数据,就需要根据延时显示程度来计算丢帧的比率

havlenapetr最新的ffmpeg可以直接编译通过,不过有个bug,就是播放完毕后,video_decoder线程不能退出,主要原因是阻塞在packet队列的queue->get函数里,这里处理逻辑需要考虑两种情况:

1. avpacket队列里没有音视频帧数据时,解码线程挂起进入等待状态,有新的avpacket加入队列时激活解码线程

2. 如果文件读取到末尾,queue->get直接返回-1,解码线程发现队列空时直接退出