当前仓库属于关闭状态,部分功能使用受限,详情请查阅 仓库状态说明
17 Star 37 Fork 35

OpenHarmony-TPC/mp4parser
关闭

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
Apache-2.0

mp4parser

简介

一个读取、写入操作音视频文件编辑的工具。

编译运行

1、通过IDE工具下载依赖SDK,Tools->SDK Manager->Openharmony SDK 把native选项勾上下载,API版本>=10

2、开发板选择RK3568,ROM下载地址. 选择开发板类型是rk3568,请使用最新的版本

3、下载源码

git clone https://gitee.com/openharmony-tpc/mp4parser.git --recurse-submodules

4、项目依赖FFmpeg库,关于FFmpeg的编译:FFmpeg源码基于版本号:n4.3.8.

FFmpeg依赖

1、修改编译之前需要在交叉编译中支持编译x86_64架构,可以参考adpater_architecture.md文档。

2、FFmpeg:FFmpeg版本(n4.3.8):FFmpeg源码链接, 可以在交叉编译出库文件和头文件

​ 编译之前需要先修改HPKBUILD文件中FFmpeg的版本为n4.3.8。

pkgver=n6.0 
//修改为
pkgver=n4.3.8

3.下载FFmpeg的n4.3.8,执行以下命令获取对应的sha512值,替换SHA512SUM文件的内容。

sha512num FFmpeg-n4.3.8.zip

4.在cpp目录下新增third_party目录和在library下新增libs目录,并将编译生成的FFmpeg库拷贝到该目录下,如下图所示

img.png

下载安装

ohpm install @ohos/mp4parser

OpenHarmony ohpm 环境配置等更多内容,请参考如何安装 OpenHarmony ohpm 包

X86模拟器配置

使用模拟器运行应用/服务

使用说明

视频合成

  import {MP4Parser} from "@ohos/mp4parser";
  import {ICallBack} from "@ohos/mp4parser";

    /**
     * 视频合成
     */
  private videoMerge() {
    let getLocalDirPath = getContext(this).cacheDir+"/";
    let that = this;
    let filePathOne = getLocalDirPath + "qqq.mp4";
    let filePathTwo = getLocalDirPath + "www.mp4";
    let outMP4 = getLocalDirPath + "mergeout.mp4";
    var callBack: ICallBack = {
      callBackResult(code: number) {
        that.btnText = "视频合成点击执行"
        that.imageWidth = 0
        that.imageHeight = 0
        if (code == 0) {
          AlertDialog.show({ message: $r('app.string.ok') })
        }
        else {
          AlertDialog.show({ message: $r('app.string.failed') })
        }
      }
    }
    MP4Parser.videoMerge(filePathOne, filePathTwo, outMP4, callBack);
  }

视频裁剪

import {MP4Parser} from "@ohos/mp4parser";
import {ICallBack} from "@ohos/mp4parser";


  /**
   * 视频裁剪
   */
   private videoClip() {
    let getLocalDirPath = getContext(this).cacheDir+"/";
    let that=this;
    let sTime = "00:00:10";
    let eTime = "00:00:20";
    let sourceMP4 = getLocalDirPath+"qqq.mp4";
    let outMP4 = getLocalDirPath+"clipout.mp4";
    var callBack: ICallBack = {
      callBackResult(code: number) {
        that.btnText="视频裁剪点击执行"
        that.imageWidth=0
        that.imageHeight=0
        if (code == 0) {
          AlertDialog.show({ message: $r('app.string.ok') })
        }
        else {
          AlertDialog.show({ message: $r('app.string.failed') })
        }
      }
    }
    MP4Parser.videoClip(sTime, eTime, sourceMP4, outMP4, callBack);
  }

音频合成

import {MP4Parser} from "@ohos/mp4parser";
import {ICallBack} from "@ohos/mp4parser";


    /**
   * 音频合成
   */
   private audioMerge() {
    let getLocalDirPath = getContext(this).cacheDir+"/";
    let that = this;
    let filePathOne = getLocalDirPath + "a.mp3";
    let filePathTwo = getLocalDirPath + "b.mp3";
    let outPath = getLocalDirPath + "mergeout.mp3";
    var callBack: ICallBack = {
      callBackResult(code: number) {
        console.log("mp4parser-->audioMerge--->end");
        that.btnText = "音频合成点击执行"
        that.imageWidth = 0
        that.imageHeight = 0
        if (code == 0) {
          AlertDialog.show({ message: $r('app.string.ok') })
        }
        else {
          AlertDialog.show({ message: $r('app.string.failed') })
        }
      }
    }
    MP4Parser.audioMerge(filePathOne, filePathTwo, outPath, callBack);
  }

音频裁剪

import {MP4Parser} from "@ohos/mp4parser";
import {ICallBack} from "@ohos/mp4parser";


   /**
     * 音频裁剪
     */
   private audioClip() {
    let getLocalDirPath = getContext(this).cacheDir+"/";
    let that = this;
    let sTime = "00:00:00";
    let eTime = "00:00:10";
    let sourcePath = getLocalDirPath + "a.mp3";
    let outPath = getLocalDirPath + "clipout.mp3";
    var callBack: ICallBack = {
      callBackResult(code: number) {
        that.btnText = "音频裁剪点击执行"
        that.imageWidth = 0
        that.imageHeight = 0
        if (code == 0) {
          AlertDialog.show({ message: $r('app.string.ok') })
        }
        else {
          AlertDialog.show({ message: $r('app.string.failed') })
        }
      }
    }
    MP4Parser.audioClip(sTime, eTime, sourcePath, outPath, callBack);
  }

视频批量合成

import {MP4Parser} from "@ohos/mp4parser";
import {ICallBack} from "@ohos/mp4parser";

  /**
   * 视频批量合成
   */
   private videoMultMerge() {
    let that = this;
    let getLocalDirPath = getContext(this).cacheDir+"/";
    let filePath = getLocalDirPath + "mergeList.txt";
    let outMP4 = getLocalDirPath + "mergeout3.mp4";
    var callBack: ICallBack = {
      callBackResult(code: number) {
        that.btnText2 = "视频合成点击执行"
        that.imageWidth = 0
        that.imageHeight = 0
        if (code == 0) {
          AlertDialog.show({ message: $r('app.string.ok') })
        }
        else {
          AlertDialog.show({ message: $r('app.string.failed') })
        }
      }
    }
    MP4Parser.videoMultMerge(filePath, outMP4, callBack);
  }

音频批量合成

import {MP4Parser} from "@ohos/mp4parser";
import {ICallBack} from "@ohos/mp4parser";

  /**
   * 音频批量合成
   */
  private audioMultMerge() {
    let getLocalDirPath = getContext(this).cacheDir+"/";
    let that = this;
    let filePath = getLocalDirPath + "mergewavList.txt";
    let outPath = getLocalDirPath + "mergeout3.wav";
    var callBack: ICallBack = {
      callBackResult(code: number) {
        that.btnText2 = "音频合成点击执行"
        that.imageWidth = 0
        that.imageHeight = 0
        if (code == 0) {
          AlertDialog.show({ message: $r('app.string.ok') })
        }
        else {
          AlertDialog.show({ message: $r('app.string.failed') })
        }
      }
    }
    MP4Parser.audioMultMerge(filePath, outPath, callBack);
  }

视频取帧

import {ICallBack, IFrameCallBack, MP4Parser} from "@ohos/mp4parser";

  private getFrameAtTimeRang() {
    let getLocalDirPath = getContext(this).cacheDir + "/";
    let sourceMP4 = getLocalDirPath + "www.mp4";
    let that = this;
    var callBack: ICallBack = {
      callBackResult(code: number) {
        if (code == 0) {
          var frameCallBack: IFrameCallBack = {
            async callBackResult(data: ArrayBuffer, timeUs: number) {
              const imageSource = image.createImageSource(data)
              that.imagePixelMap = await imageSource.createPixelMap()
            }
          }
          MP4Parser.getFrameAtTimeRang("1000000", "9000000", MP4Parser.OPTION_CLOSEST, frameCallBack);
        }
      }
    }
    MP4Parser.setDataSource(sourceMP4, callBack);
  }

调用FFmpeg指令

 let context = AbilityDelegatorRegistry.getAbilityDelegator().getAppContext()
    let getLocalDirPath = context.cacheDir + "/";
    let sTime = "00:00:01";
    let eTime = "00:00:02";
    let sourceMP4 = getLocalDirPath + "testvideo.mp4";
    let outMP4 = getLocalDirPath + "out.mp4";
    let callBack: ICallBack = {
        callBackResult(code: number) {
          expect(0).assertEqual(code)
          done()
        }
    }
    MP4Parser.ffmpegCmd("ffmpeg -y -i " + sourceMP4 + " -ss " + sTime + " -c copy -to " + eTime + " " + outMP4, callBack)

接口说明

import {MP4Parser} from "@ohos/mp4parser";

  1. 视频合成 MP4Parser.videoMerge()
  2. 视频裁剪 MP4Parser.videoClip()
  3. 批量视频合成 MP4Parser.videoMultMerge()
  4. 音频合成 MP4Parser.audioMerge()
  5. 音频裁剪 MP4Parser.audioClip()
  6. 音频批量合成 MP4Parser.audioMultMerge()
  7. 设置视频源 MP4Parser.setDataSource()
  8. 视频取帧 MP4Parser.getFrameAtTimeRang()
  9. 停止取帧 MP4Parser.stopGetFrame()
  10. 调用FFmpeg指令 MP4Parser.ffmpegCmd()

约束与限制

在下述版本验证通过:

DevEco Studio版本: 4.0 Release(4.0.3.413), SDK: (4.0.10.3) DevEco Studio 版本: 4.1 Canary(4.1.3.317),OpenHarmony SDK: API11 (4.1.0.36) DevEco Studio: NEXT Beta1-5.0.3.806, SDK: API12 Release (5.0.0.66)

目录结构

|---- mp4parser  
|     |---- entry  # 示例代码文件夹
|     |---- library  # mp4parser库文件夹
|           |---- MP4Parser.ets  # 对外接口
|     |---- README.MD  # 安装使用方法                    

贡献代码

使用过程中发现任何问题都可以提 Issue 给组件,当然,也非常欢迎发 PR 共建。

开源协议

本项目基于 Apache License 2.0 ,请自由地享受和参与开源。

Copyright (c) 2020-present. xch168 Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

简介

暂无描述 展开 收起
Apache-2.0
取消

发行版 (10)

全部
2个月前

贡献者

全部

近期动态

不能加载更多了
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/openharmony-tpc/mp4parser.git
git@gitee.com:openharmony-tpc/mp4parser.git
openharmony-tpc
mp4parser
mp4parser
master

搜索帮助