音视频权威指南-代码仓库

代码仓库Github地址为:http://www.github.com/zhanxiaokai

代码仓库中以Android开头的都是Android的项目工程,以iOS开头的都是iOS的项目工程。

 

92 评论

  1. 我买的是kindle版,2.3.2中的编译脚本armv7和arm64貌似都无法编译,尝试了多次,都只是将部分文件copy到了脚本当前目录,后使用网上脚本是可以导出的,还没有仔细看两者间的差别,我想知道是哪个位置我操作不对,还是脚本的确有问题?

    1. Hi,如果使用静态库可以直接到github.com/zhanxiaokai仓库中去找一下,那里面确认是可以使用的。书中的编译脚本的问题可以贴出来,我看一下,回头我会把编译脚本放到github上.

      1. ./configure \
        –disable-shared \
        –disable-frontend \
        # 指定最终要运行的平台
        –host=arm-apple-darwain \
        # 指定编译好的放在哪个目录
        –prefix=”. /thin/arm64″ \
        CC=”xcrun -sdk iphoneos clang -arch arm64″ \
        CFCLAGS=”-arch arm64 -fembed-bitcode -miphoneos-version-min=8.0″ \
        LDFLAGS=”-arch arm64 -fembed-bitcode -miphoneos-version-min=8.0″
        make clean
        make -j8
        make install

        Hi,脚本如上,不知道为什么不起效果

        1. 你好,这个应该是Lame的编译脚本呀,应该是2.3.2小结中的内容。
          不是ffmpeg的。
          具体lame的仓库,你可以发邮件给我,我给你发过去。或者加我微信(KevinLoveZhan)。

  2. Android-FFmpegDecoder导入Android Studio,运行正常,点击button闪退,报错日志
    A/libc: Fatal signal 11 (SIGSEGV), code 1, fault addr 0x19c in tid 15394 (.ffmpeg_decoder)
    debuggerd: handling request: pid=15394 uid=10105 gid=10105 tid=15394

  3. configure: error: in `/Users/robin/Documents/libs/lame/lame-3.100′:
    configure: error: C compiler cannot create executables

    编译不了,大神帮忙看下,

    1. lame库的版本是否不对,可以加我微信,我把我的lame库以及编译脚本发给你。
      微信:KevinloveZhan
      另外 下周有空我会尽量把库传到github上,项目中有静态库,你可以直接拿去使用。

        1. 不好意思,还没有将shell脚本上传到github上,不过静态库与头文件可以在任何一个工程中取得,可以直接使用。

    2. –prefix改成绝对路径,再加一个CPP=xxx就可以了
      DEVELOPER=`xcode-select -print-path`

      ./configure \
      –disable-shared \
      –disable-frontend \
      –enable-static \
      –host=arm-apple-darwin \
      –prefix=”/Users/chenhong/github/lame-3.100/thin/armv7″ \
      CC=”xcrun -sdk iphoneos clang -arch armv7″ \
      CPP=”${DEVELOPER}/Toolchains/XcodeDefault.xctoolchain/usr/bin/cpp” \
      CFLAGS=”-arch armv7 -fembed-bitcode -miphoneos -version-min=7.0″ \
      LDLAGS=”-arch armv7 -fembed-bitcode -miphoneos -version-min=7.0″
      make clean
      make -j8
      make install

  4. #!/bin/bash
    NDK_ROOT=/Users/robin/Opt/android/ndk/android-ndk-r14b
    PREBUILT=$NDK_ROOT/toolchains/arm-linux-androideabi-4.9/prebuilt/darwin-x86_64
    PLATFORM=$NDK_ROOT/platforms/android-9/arch-arm

    export PATH=$PATH:$PREBUILT/bin:$PLATFORM/usr/include:
    export LDFLAGS=”-L$PLATFORM/usr/lib -L$PREBUILT/arm-linux-androideabi/lib -march=armv7-a”
    export CFLAGS=”-I$PLATFORM/usr/include -march=armv7-a -mfloat-abi=softfp -mfpu=vfp-ffast-math -O2″

    export CPPFLAGS=”$CFLAGS”
    export CFLAGS=”$CFLAGS”
    export CXXFLAGS=”$CFLAGS”
    export LDFLAGS=”$LDFLAGS”

    export AS=$PREBUILT/bin/arm-linux-androideabi-as
    export LD=$PREBUILT/bin/arm-linux-androideabi-ld
    export CXX=”$PREBUILT/bin/arm-linux-androideabi-g++ –sysroot=${PLATFORM}”
    export CC=”$PREBUILT/bin/arm-linux-androideabi-gcc –sysroot=${PLATFORM} -march=armv7-a”
    export NM=$PREBUILT/bin/arm-linux-androideabi-nm
    export STRIP=$PREBUILT/bin/arm-linux-androideabi-strip
    export RANLIB=$PREBUILT/bin/arm-linux-androideabi-ranlib
    export AR=$PREBUILT/bin/arm-linux-androideabi-ar

    ./configure –host=arm-linux \
    –disable-shared \
    –disable-frontend \
    –enable-static \
    –prefix=/Users/robin/Documents/libs/lame/lame-3.100/out

    make clean
    make -j8
    make install

  5. 您好,我看到文章第九章的时候,看到有个视频主题的效果p291页,想问下对应的代码目录是在github的哪个项目下?谢谢!

  6. AVFormatContext *formatCtx = avformat_alloc_context();
    AVIOInterruptCB int_cb = {interrupt_callback, (__bridge void *)(self)};
    formatCtx-> interrupt_callback = int_cb;
    avformat_open_input( formatCtx, path, NULL, NULL);
    avformat_find_stream_info( formatCtx, NULL);
    这段代码中的interrupt_callback编译报错,不知道是该如何实现?书中也没有说具体是在哪个项目下能找到具体实现,麻烦帮忙解答下,谢谢!

    1. 你这段代码应该属于ffmpeg拉流端的代码,所以可以在video_player项目的decoder模块找到代码,无论是Android还是iOS都可以的。

  7. FFMpegDecoder 下载 ,链接真机 6s, 运行报错
    Code Sign Error, 运行环境 xcode9, 我检查过我的 provision file 是并没有过期的,
    以下是bug 提示
    “`
    Signing Identity: “iPhone Developer: 160264075@qq.com (792896RE7P)”
    Provisioning Profile: “iOS Team Provisioning Profile: com.phuket.tour.FFmpegDecoderlzh2”
    (5089117a-cc0d-4507-b318-299661ee5fe4)

    /usr/bin/codesign –force –sign FC3EB34C821E6391D01E4481F72A2C6515509EA3 –entitlements /Users/zhihao.lv/Library/Developer/Xcode/DerivedData/FFmpegDecoder-fgaotbpolkzgvhfghjayskgykuyq/Build/Intermediates.noindex/FFmpegDecoder.build/Debug-iphoneos/FFmpegDecoder.build/FFmpegDecoder.app.xcent –timestamp=none /Users/zhihao.lv/Library/Developer/Xcode/DerivedData/FFmpegDecoder-fgaotbpolkzgvhfghjayskgykuyq/Build/Products/Debug-iphoneos/FFmpegDecoder.app

    /Users/zhihao.lv/Library/Developer/Xcode/DerivedData/FFmpegDecoder-fgaotbpolkzgvhfghjayskgykuyq/Build/Products/Debug-iphoneos/FFmpegDecoder.app: unknown error -1=ffffffffffffffff
    Command /usr/bin/codesign failed with exit code 1
    “`

  8. 第九章关于添加自定义文字,动图,是没有demo的吗?我ios的全下了一遍,打开没有看到相关代码。。。

  9. 展老师,对于第二章的例子,有没有demo?没有找到,能不能对于每章的例子,都出一个demo,然后以每章每节为文件名称。脚本也没有找到

  10. 您好,展老师!video_recorder_pro例子中,x86的静态库不全,还有arm64-v8a静态库没有。这些静态库能不能发给我,hawaiixdg@163.com。
    编译静态库的脚本的能发给我吗?

  11. 你好,为什么用 iOS 播放器的工程不能播放网络视频呢?
    代码如下:
    – (void)viewDidLoad {
    [super viewDidLoad];
    _requestHeader = [NSMutableDictionary dictionary];
    _requestHeader[MIN_BUFFERED_DURATION] = @(2.0f);
    _requestHeader[MAX_BUFFERED_DURATION] = @(4.0f);
    }

    – (IBAction)forwardPlayer:(id)sender {
    NSLog(@”forward local player page…”);
    NSString* videoFilePath = @”http://v4.music.126.net/20180313041245/a3eda1f2f55ffbf10c827ffd2eb08986/web/cloudmusic/IiEgMDFkMiAmIDEgJCAwMg==/mv/327004/1aa0f4e9dc65db3738347ec2c19cf402.mp4″;
    BOOL usingHWCodec = NO;//YES;
    ELVideoViewPlayerController *vc = [ELVideoViewPlayerController viewControllerWithContentPath:videoFilePath contentFrame:self.view.bounds usingHWCodec:usingHWCodec parameters:_requestHeader];
    [[self navigationController] pushViewController:vc animated:YES];
    }
    报错如下:
    2018-03-12 16:34:25.481332+0800 video_player_pro[894:100741] [DYMTLInitPlatform] platform initialization successful
    2018-03-12 16:34:27.420322+0800 video_player_pro[894:100628] forward local player page…
    2018-03-12 16:34:27.421889+0800 video_player_pro[894:100628] Enter VideoPlayerViewController init, url: http://v4.music.126.net/20180313041245/a3eda1f2f55ffbf10c827ffd2eb08986/web/cloudmusic/IiEgMDFkMiAmIDEgJCAwMg==/mv/327004/1aa0f4e9dc65db3738347ec2c19cf402.mp4, h/w enable: 0
    [aac @ 0x103031400] Format aac detected only with low score of 1, misdetection possible!
    [aac @ 0x102801200] get_buffer() failed
    [aac @ 0x103031400] Stream #0: not enough frames to estimate rate; consider increasing probesize
    [aac @ 0x103031400] decoding for stream 0 failed
    [aac @ 0x103031400] Estimating duration from bitrate, this may be inaccurate
    [aac @ 0x103031400] Could not find codec parameters for stream 0 (Audio: aac, 0 channels, fltp, 128 kb/s): unspecified sample rate
    Consider increasing the value for the ‘analyzeduration’ and ‘probesize’ options
    2018-03-12 16:34:28.757469+0800 video_player_pro[894:100747] Video decoder find stream info failed… find stream ErrCode is Operation not permitted
    2018-03-12 16:34:28.757657+0800 video_player_pro[894:100747] VideoDecoder decode file fail…
    2018-03-12 16:34:28.757773+0800 video_player_pro[894:100747] Enter closeFile…
    2018-03-12 16:34:28.757876+0800 video_player_pro[894:100747] Decoder decoder totalVideoFramecount is 0 decodeFrameAVGTimeMills is nan
    2018-03-12 16:34:28.758095+0800 video_player_pro[894:100747] buried point is beginOpen : [1520843667433]successOpen is [0.000]firstScreenTimeMills is [0.000]failOpen is [1.325]failOpenType is [-1.000]retryTimes is [0]duration is [0.000]
    2018-03-12 16:34:28.758185+0800 video_player_pro[894:100747] VideoDecoder Dealloc…

  12. 大神您好!我拜读到第三章的时候,下了iOS-FFmpegDecoder,跑iPhone8上,系统是ios11, 完了之后写入到沙盒的131.pcm用ffplay播放不了,报错如下:/Users/creator/Desktop/com.tour.FFmpegDecoder 2018-03-13 10:54.20.265.xcappdata/AppData/Documents/131.pcm: Invalid data found when processing input
    我只改了app唯一标识

      1. 原来播放裸数据要指定采样深度、声道数、采样频率。现在可以了播出来了,谢谢大神的指点!

      2. 大神您好!还是这个demo, 里面的accompany_decoder_controller.cpp中有:
        void AccompanyDecoderController::Init(const char* accompanyPath, const char* pcmFilePath) {
        //初始化两个decoder
        AccompanyDecoder* tempDecoder = new AccompanyDecoder();
        int accompanyMetaData[2];
        tempDecoder->getMusicMeta(accompanyPath, accompanyMetaData);
        delete tempDecoder;
        //初始化伴奏的采样率
        accompanySampleRate = accompanyMetaData[0];
        int accompanyByteCountPerSec = accompanySampleRate * CHANNEL_PER_FRAME * BITS_PER_CHANNEL / BITS_PER_BYTE;
        accompanyPacketBufferSize = (int) ((accompanyByteCountPerSec / 2) * 0.2);
        accompanyDecoder = new AccompanyDecoder();
        accompanyDecoder->init(accompanyPath, accompanyPacketBufferSize);
        pcmFile = fopen(pcmFilePath, “wb+”);
        }
        这函数里,accompanyPacketBufferSize = (int) ((accompanyByteCountPerSec / 2) * 0.2);这一句为什么要乘以2又乘以0.2呢?望大神百忙之中赐教。

  13. 展老师,书本page77中,裸创建AudioUnit,AudioComponentInstanceNew(ioUnitRef, &ioUnitInstance),第二个参数是AudioComponentInstance类型,我看您使用AudioUnit类型,这不正确吧?

  14. 请问一下,我把video_player项目移到android studio下
    这是video_player文件下的mk文件,把ChangbaPlayer.cpp移到了这里,然后ndk_build成功生成了so包,但运行后发现找不到nativie方法(java.lang.UnsatisfiedLinkError: No implementation found for boolean com.example.administrator.myapplication.video.player.ChangbaPlayer.prepare(java.lang.String, int[], int, int, boolean, float, float, int, int, android.view.Surface) 我把包名都改了,cpp里的方法路径都是对的,为啥会找不到呢,是 mk有问题吗,能否贴出android studio下编译成功的项目
    LOCAL_SRC_FILES = \
    ./libvideoplayer/common/circle_texture_queue.cpp \
    ./libvideoplayer/decoder/video_decoder.cpp \
    ./libvideoplayer/decoder/decoder_request_header.cpp \
    ./libvideoplayer/decoder/ffmpeg_video_decoder.cpp \
    ./libvideoplayer/decoder/mediacodec_video_decoder.cpp \
    ./libvideoplayer/sync/av_synchronizer.cpp \
    ./libvideoplayer/drag/av_drag_synchronizer.cpp \
    ./libvideoplayer/texture_uploader/texture_frame_uploader.cpp \
    ./libvideoplayer/texture_uploader/gpu_texture_frame_uploader.cpp \
    ./libvideoplayer/texture_uploader/yuv_texture_frame_uploader.cpp \
    ./libvideoplayer/audio_output.cpp \
    ./libvideoplayer/video_output.cpp \
    ./libvideoplayer/video_player_controller.cpp \
    ./libvideoplayer/drag/video_player_drag_controller.cpp \
    ./libvideoplayer/ChangbaPlayer.cpp

  15. 话说 X264那节 编译 不成功 总会提示有问题

    #!/bin/sh

    export AS=”gas-preprocessor.pl -arch arm — xcrun -sdk iphoneos clang”
    export CC=”xcurn -sdk iphoneos clang”
    ./configure \
    –enable-static \
    –enable-pic \
    –enable-shared \
    –host=arm-apple-darwin \
    –extra-cflags=”-arch armv7 -mios-version-min=7.0″ \
    –extra-asflags=”-arch armv7 -mios-version-min=7.0″ \
    –extra-ldflags=”-arch armv7 -mios-version-min=7.0″ \
    –prefix=”./thin/armv7″
    make clean
    make -j8
    make install

  16. 请问一下作者,如果我用MediaCodec进行编码之后,使用ffmpeg进行muxing需要如何做呢,比如头部如何写,Annexb格式需要转换成mp4格式么?

    1. 肯定需要呀,参考video_recorder代码吧,首先sps和pps需要放入到extra-data中,然后你说的这个格式需要转换(书中有说的,如何转换)。

      1. 那avformat_write_header是写的啥,使用了avformat_write_header还需要自己构造sps和pps进行操作吗,构造的sps和pps放在AVPacket的extra-data中是在编码之后还是之前填?

  17. 编译lame:
    #!/bin/bash
    NDK_ROOT=/home/chenqz/Android/Sdk/ndk-bundle
    PREBUILT=$NDK_ROOT/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64
    PLATFORM=$NDK_ROOT/platforms/android-14/arch-arm
    export PATH=$PATH:$PREBUILT/bin:$PLATFORM/usr/include:
    export LDFLAGS=”-L$PLATFORM/usr/lib -LPREBUILT/arm-linux-androideabi/lib -march armv7-a”
    export CFLAGS=”-I$PLATFORM/usr/include -march=armv7-a -mfloat-abi=softfp -mfpu=vfp -ffast-math -O2″
    export CPPFLAGS=”$CFLAGS”
    export CFLAGS=”$CFLAGS”
    export CXXFLAGS=”$CFLAGS”
    export LDFLAGS=”$LDFLAGS”
    export AS=$PREBUILT/bin/arm-linux-androideabi-as
    export LD=$PREBUILT/bin/arm-linux-androideabi-ld
    export CXX=”$PREBUILT/bin/arm-linux-androideabi-g++ –sysroot=${PLATFORM}”
    export CC=”$PREBUILT/bin/arm-linux-androideabi-gcc –sysroot=${PLATFORM}”
    export NM=$PREBUILT/bin/arm-linux-androideabi-nm
    export STRIP=$PREBUILT/bin/arm-linux-androideabi-strip
    export RANLIB=$PREBUILT/bin/arm-linux-androideabi-ranlib
    export AR=$PREBUILT/bin/arm-linux-androideabi-ar
    ./configure –host=arm-linux \
    –disable-shared \
    –disable-frontend \
    –enable-static \
    –prefix=./armv7a

    make clean
    make -j8
    make install

    错误信息:
    configure: error: expected an absolute directory name for –prefix: ./armv7a
    make: *** No rule to make target ‘clean’. Stop.
    make: *** No targets specified and no makefile found. Stop.
    make: *** No rule to make target ‘install’. Stop.

  18. 为什么github上iOS-AudioPlayer这个demo,我在按play按钮之后只播了131.aac的前几秒呢?而且还断断续续的

    1. 我也发现这个问题了,因为iOS的AudioUnit的buffer设置的太小了,同时解码的线程被阻塞了,回头我改好了传上去。

          1. 我尝试将AccompanyDecoderController的readSample函数中的pthread_cond_signal(&mCondition)的前置if判断删除,就可以一直播了,不然程序会进不去这个if判断导致不调用pthread_cond_signal(&mCondition)。另外还要将AccompanyDecoderController的accompanyPacketBufferSize变量改一下,令其大于1024而且必须是1024的整数倍数,不然播放中就会有杂音。

          2. accompanyPacketBufferSize这个变量应该设为每次audioUnit回调时所需要的pcm的字长的一半的整数倍

  19. 展老师能不能出一个安卓所以有cpu架构的编译脚本,包括加入mediacodec,fdkaac功能的,网上找了很久都没一个靠谱的

    1. 是的,不过要注意png图片去tinypng上转换一下,其实这个库比较常用,cocos2d里面也是用的这个库的。

    1. Version: Mars Release (4.5.0)
      Build id: 20150621-1200

      NDK:android-ndk-r10d

      现在项目也有在AndroidStudio的,你可以使用AndroidStudio

  20. 请问书中第37页脚本中的host是指定的是什么?
    我现在mac环境中运行此脚本同时进行x86架构的编译
    下面是我修改的脚本:
    #!/bin/bash
    NDK_ROOT=/Users/qh/Library/Android/android-ndk-r14b
    PREBUILT=$NDK_ROOT/toolchains/x86-4.9/prebuilt/darwin-x86_64
    PLATFORM=$NDK_ROOT/platforms/android-24/arch-x86
    export PATH=$PATH:$PREBUILT/bin:$PLATFORM/usr/include:

    export LDFLAGS=”-L$PLATFORM/usr/lib -L$PREBUILT/i686-linux-android/lib -march=i686″

    export CFLAGS=”-I$PLATFORM/usr/include -march=i686 -ffast-math -O2″

    export CPPFLAGS=”$CFLAGS”
    export CFLAGS=”$CFLAGS”
    export CXXFLAGS=”$CFLAGS”
    export LDLFLAGS=”$LDFLAGS”

    export AS=$PREBUILT/bin/i686-linux-android-as
    export LD=$PREBUILT/bin/i686-linux-android-ld
    export CXX=”$PREBUILT/bin/i686-linux-android-g++ –sysroot=${PLATFORM}”
    export CC=”$PREBUILT/bin/i686-linux-android-gcc –sysroot=${PLATFORM} -march=x86 ”
    export NM=$PREBUILT/bin/i686-linux-android-nm
    export STRIP=$PREBUILT/bin/i686-linux-android-strip
    export RANLIB=$PREBUILT/bin/i686-linux-android-ranlib
    export AR=$PREBUILT/bin/i686-linux-android-ar

    ./configure –host=arm-linux \
    –disable-shared \
    –disable-frontend \
    –enable-static \
    –prefix=/Users/qh/Desktop/x86

    make clean
    make -j8
    make install

    这个脚本虽然编译通过了,但是用它生成的静态库,放到Android项目中去生成so文件时
    会报一个这样的错误:
    ../../../../src/main/jni/x86/lib/libmp3lame.a(quantize.o):quantize.c:function init_xrpow_core_init: error: undefined reference to ‘init_xrpow_core_sse’
    clang++: error: linker command failed with exit code 1 (use -v to see invocation)
    ninja: build stopped: subcommand failed.

  21. 展老师好,iOS-video_player这个项目中VideoDecoder.m文件中第541行的代码如下:
    frame.duration += _videoFrame->repeat_pict * _videoTimeBase * 0.5;
    这里的_videoFrame->repeat_pict有什么用处呢?frame.duration又为什么要加上_videoFrame->repeat_pict * _videoTimeBase * 0.5呢?

    1. 这个是ffmpeg的规定写法,其实不加也没关系,并且后边也不会用到Duration这个属性。
      如果要深究的话,可以去看一下ffmpeg赋值的地方

  22. 展老师好,请问一下在Android-CameraPreviewRecorder-master这个项目中,在将RGB转YUV422的时候, 这个偏移float perHalfTexel = 0.5 / width; 纹理坐标的一半除以纹理的宽度。这里的取值不是特别理解,在片段着色器中具体的像素点和纹理坐标的对应关系又关系是怎样的呢?

  23. 展老师你好,请问一下我看到您在Android-as_video_player这个工程里使用了clang,那对应的prebuilt 库也是clang 编译的么?顺道问一下您使用的NDK 版本是多少?

    1. 对应的库不是clang编译的,还是之前使用NDK的gcc编译出来的库,版本r10之前用过,现在用的是r13

  24. 展老师您好,请问一下在软编H.264的过程中,源码是在shader中转YUV422,然后在CPU中转YUV420。可以通过GPU直接导出YUV420P吗?还是说算法复杂,效率反而更低?

  25. 展老师您好,下面这段代码是在yuy2_to_yuv420p的函数中,不是特别明白。这里neon每次读取16*4个字节的数据,然后分别在回推到y,u,v的三个指针,但是yuy2是 yuyv的排列,yuv420p是yyyy u v的排列,这里直接导回去不是就不对了吗?
    for (unsigned int i = 0; i < groups; i++) {
    const uint8x16x4_t srcYUYV = vld4q_u8(yuy2Ptr);
    uint8x16x2_t srcY;
    srcY.val[0] = srcYUYV.val[0];
    srcY.val[1] = srcYUYV.val[2];
    vst2q_u8(yPtr, srcY);
    vst1q_u8(uPtr, srcYUYV.val[1]);
    vst1q_u8(vPtr, srcYUYV.val[3]);
    yuy2Ptr += 64;
    yPtr += 32;
    uPtr += 16;
    vPtr += 16;
    }

发表评论

电子邮件地址不会被公开。 必填项已用*标注