android 录像本地网络传输保存成mp4文件优化

为了兼容使用,在之前这个基础上进行一下修改android 录像本地网络传输保存成mp4文件
后面录像要加水印,使用mediarecorder不好实现,同时mediarecorder录像保存的文件相对来说会稍微大一点.改用medicodec+mediamuxer方式。

系统修改

系统版本android7.1,低版本的MediaMuxer.java还没有FileDescriptor接口增加这个接口

1.frameworks/base/media/java/android/media/MediaMuxer.java

    public MediaMuxer(@NonNull String path, @Format int format) throws IOException {
        if (path == null) {
            throw new IllegalArgumentException("path must not be null");
        }
        if (format != OutputFormat.MUXER_OUTPUT_MPEG_4 &&
                format != OutputFormat.MUXER_OUTPUT_WEBM) {
            throw new IllegalArgumentException("format is invalid");
        }
        // Use RandomAccessFile so we can open the file with RW access;
        // RW access allows the native writer to memory map the output file.
        RandomAccessFile file = null;
        try {
            file = new RandomAccessFile(path, "rws");
            FileDescriptor fd = file.getFD();
            mNativeObject = nativeSetup(fd, format);
            mState = MUXER_STATE_INITIALIZED;
            mCloseGuard.open("release");
        } finally {
            if (file != null) {
                file.close();
            }
        }
		SystemProperties.set("ease.mp4seek.mode","false");//add by hclydao
    }
	//add by hclydao
    public MediaMuxer(@NonNull FileDescriptor fd, @Format int format) throws IOException {
        if (format != OutputFormat.MUXER_OUTPUT_MPEG_4 &&
                format != OutputFormat.MUXER_OUTPUT_WEBM) {
            throw new IllegalArgumentException("format is invalid");
        }
        // Use RandomAccessFile so we can open the file with RW access;
        // RW access allows the native writer to memory map the output file.
        mNativeObject = nativeSetup(fd, format);
        mState = MUXER_STATE_INITIALIZED;
        mCloseGuard.open("release");
		SystemProperties.set("ease.mp4seek.mode","true");
    }

增加public MediaMuxer(@NonNull FileDescriptor fd, @Format int format) 接口,然后设置了一个"ease.mp4seek.mode",这个后面用来判断是写文件,还是通过网络传输

2.frameworks/av/include/media/stagefright/MPEG4Writer.h

	void myseek(int fd, off64_t seek, int whence);
	bool            myseekMode;

增加seek操作,网络传输无法像文件那种进行回写,所以处理一下文件seek的操作,增加myseek接口
3. frameworks/av/media/libstagefright/MPEG4Writer.cpp

MPEG4Writer::MPEG4Writer(int fd)
   : mFd(dup(fd)),
     mInitCheck(mFd < 0? NO_INIT: OK),
     
  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值