Browse Source

修改合成问题

rhyme 5 years ago
parent
commit
a5fbb572cc
4 changed files with 212 additions and 16 deletions
  1. 14 10
      .idea/workspace.xml
  2. 3 3
      ios/Classes/DubbingComposer.swift
  3. 7 3
      ios/Classes/SwiftDubbingLibPlugin.swift
  4. 188 0
      pubspec.lock

+ 14 - 10
.idea/workspace.xml

@@ -1,7 +1,11 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <?xml version="1.0" encoding="UTF-8"?>
 <project version="4">
 <project version="4">
   <component name="ChangeListManager">
   <component name="ChangeListManager">
-    <list default="true" id="96a4f947-f66a-4efc-b495-ae979b3315bb" name="Default Changelist" comment="" />
+    <list default="true" id="96a4f947-f66a-4efc-b495-ae979b3315bb" name="Default Changelist" comment="">
+      <change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
+      <change beforePath="$PROJECT_DIR$/ios/Classes/DubbingComposer.swift" beforeDir="false" afterPath="$PROJECT_DIR$/ios/Classes/DubbingComposer.swift" afterDir="false" />
+      <change beforePath="$PROJECT_DIR$/ios/Classes/SwiftDubbingLibPlugin.swift" beforeDir="false" afterPath="$PROJECT_DIR$/ios/Classes/SwiftDubbingLibPlugin.swift" afterDir="false" />
+    </list>
     <ignored path="$PROJECT_DIR$/.dart_tool/" />
     <ignored path="$PROJECT_DIR$/.dart_tool/" />
     <ignored path="$PROJECT_DIR$/.idea/" />
     <ignored path="$PROJECT_DIR$/.idea/" />
     <ignored path="$PROJECT_DIR$/.pub/" />
     <ignored path="$PROJECT_DIR$/.pub/" />
@@ -23,8 +27,8 @@
       <file pinned="false" current-in-tab="true">
       <file pinned="false" current-in-tab="true">
         <entry file="file://$PROJECT_DIR$/lib/dubbing_lib.dart">
         <entry file="file://$PROJECT_DIR$/lib/dubbing_lib.dart">
           <provider selected="true" editor-type-id="text-editor">
           <provider selected="true" editor-type-id="text-editor">
-            <state relative-caret-position="537">
-              <caret line="95" column="25" selection-start-line="95" selection-end-line="96" />
+            <state relative-caret-position="174">
+              <caret line="67" column="31" lean-forward="true" selection-start-line="67" selection-start-column="31" selection-end-line="67" selection-end-column="31" />
             </state>
             </state>
           </provider>
           </provider>
         </entry>
         </entry>
@@ -95,7 +99,6 @@
     </option>
     </option>
   </component>
   </component>
   <component name="ProjectFrameBounds">
   <component name="ProjectFrameBounds">
-    <option name="x" value="94" />
     <option name="y" value="23" />
     <option name="y" value="23" />
     <option name="width" value="1346" />
     <option name="width" value="1346" />
     <option name="height" value="877" />
     <option name="height" value="877" />
@@ -106,7 +109,6 @@
       <foldersAlwaysOnTop value="true" />
       <foldersAlwaysOnTop value="true" />
     </navigator>
     </navigator>
     <panes>
     <panes>
-      <pane id="Scope" />
       <pane id="ProjectPane">
       <pane id="ProjectPane">
         <subPane>
         <subPane>
           <expand>
           <expand>
@@ -129,6 +131,7 @@
         </subPane>
         </subPane>
       </pane>
       </pane>
       <pane id="PackagesPane" />
       <pane id="PackagesPane" />
+      <pane id="Scope" />
     </panes>
     </panes>
   </component>
   </component>
   <component name="PropertiesComponent">
   <component name="PropertiesComponent">
@@ -170,9 +173,10 @@
     <servers />
     <servers />
   </component>
   </component>
   <component name="ToolWindowManager">
   <component name="ToolWindowManager">
-    <frame x="94" y="23" width="1346" height="877" extended-state="0" />
+    <frame x="0" y="23" width="1346" height="877" extended-state="0" />
+    <editor active="true" />
     <layout>
     <layout>
-      <window_info active="true" content_ui="combo" id="Project" order="0" visible="true" weight="0.21702453" />
+      <window_info active="true" content_ui="combo" id="Project" order="0" visible="true" weight="0.2231595" />
       <window_info id="Captures" order="1" side_tool="true" />
       <window_info id="Captures" order="1" side_tool="true" />
       <window_info id="Structure" order="2" side_tool="true" />
       <window_info id="Structure" order="2" side_tool="true" />
       <window_info id="Image Layers" order="3" />
       <window_info id="Image Layers" order="3" />
@@ -191,7 +195,7 @@
       <window_info anchor="bottom" id="Event Log" order="7" side_tool="true" />
       <window_info anchor="bottom" id="Event Log" order="7" side_tool="true" />
       <window_info anchor="bottom" id="Flutter Performance" order="8" side_tool="true" />
       <window_info anchor="bottom" id="Flutter Performance" order="8" side_tool="true" />
       <window_info anchor="bottom" id="Version Control" order="9" weight="0.37028015" />
       <window_info anchor="bottom" id="Version Control" order="9" weight="0.37028015" />
-      <window_info anchor="bottom" id="Messages" order="10" visible="true" weight="0.329718" />
+      <window_info anchor="bottom" id="Messages" order="10" visible="true" weight="0.32939634" />
       <window_info anchor="right" id="Device File Explorer" order="0" side_tool="true" />
       <window_info anchor="right" id="Device File Explorer" order="0" side_tool="true" />
       <window_info anchor="right" id="Capture Analysis" order="1" />
       <window_info anchor="right" id="Capture Analysis" order="1" />
       <window_info anchor="right" id="Theme Preview" order="2" />
       <window_info anchor="right" id="Theme Preview" order="2" />
@@ -291,8 +295,8 @@
     </entry>
     </entry>
     <entry file="file://$PROJECT_DIR$/lib/dubbing_lib.dart">
     <entry file="file://$PROJECT_DIR$/lib/dubbing_lib.dart">
       <provider selected="true" editor-type-id="text-editor">
       <provider selected="true" editor-type-id="text-editor">
-        <state relative-caret-position="537">
-          <caret line="95" column="25" selection-start-line="95" selection-end-line="96" />
+        <state relative-caret-position="174">
+          <caret line="67" column="31" lean-forward="true" selection-start-line="67" selection-start-column="31" selection-end-line="67" selection-end-column="31" />
         </state>
         </state>
       </provider>
       </provider>
     </entry>
     </entry>

+ 3 - 3
ios/Classes/DubbingComposer.swift

@@ -29,10 +29,10 @@ class DubbingComposer {
         let composition = AVMutableComposition()
         let composition = AVMutableComposition()
         
         
         var videoTimeRange:CMTimeRange?
         var videoTimeRange:CMTimeRange?
+        let videoTrack = composition.addMutableTrack(withMediaType: AVMediaType.video, preferredTrackID: kCMPersistentTrackID_Invalid)
         
         
         //为合成器添加视频轨道
         //为合成器添加视频轨道
         if((videoUrl) != nil){
         if((videoUrl) != nil){
-           let videoTrack = composition.addMutableTrack(withMediaType: AVMediaType.video, preferredTrackID: kCMPersistentTrackID_Invalid)
             let videoAsset = AVURLAsset(url: videoUrl!, options: nil)
             let videoAsset = AVURLAsset(url: videoUrl!, options: nil)
             videoTimeRange = CMTimeRangeMake(start: CMTime.zero, duration: videoAsset.duration)
             videoTimeRange = CMTimeRangeMake(start: CMTime.zero, duration: videoAsset.duration)
             do {
             do {
@@ -50,9 +50,9 @@ class DubbingComposer {
         //添加音乐轨道
         //添加音乐轨道
         let musicTrack = composition.addMutableTrack(withMediaType: AVMediaType.audio, preferredTrackID: kCMPersistentTrackID_Invalid)
         let musicTrack = composition.addMutableTrack(withMediaType: AVMediaType.audio, preferredTrackID: kCMPersistentTrackID_Invalid)
         let musicAsset = AVURLAsset(url: musicUrl, options: nil)
         let musicAsset = AVURLAsset(url: musicUrl, options: nil)
-        let musicTimeRange = (videoTimeRange) != nil ? videoTimeRange: CMTimeRangeMake(start: CMTime.zero, duration: musicAsset.duration)
+        let musicTimeRange = videoTimeRange ?? CMTimeRangeMake(start: CMTime.zero, duration: musicAsset.duration)
         do {
         do {
-            try musicTrack?.insertTimeRange(musicTimeRange!, of: musicAsset.tracks(withMediaType: AVMediaType.audio).first!, at: CMTime.zero)
+            try musicTrack?.insertTimeRange(musicTimeRange, of: musicAsset.tracks(withMediaType: AVMediaType.audio).first!, at: CMTime.zero)
             print("创建音乐音轨成功")
             print("创建音乐音轨成功")
         }
         }
         catch {
         catch {

+ 7 - 3
ios/Classes/SwiftDubbingLibPlugin.swift

@@ -60,7 +60,7 @@ public class SwiftDubbingLibPlugin: NSObject, FlutterPlugin {
             let videoId = args!["videoId"] as! String;
             let videoId = args!["videoId"] as! String;
             let videoPath = args!["videoPath"] as! String;
             let videoPath = args!["videoPath"] as! String;
             let bgmPath = args!["bgmPath"] as! String;
             let bgmPath = args!["bgmPath"] as! String;
-            let audioPathList = args!["audioPathList"] as! [String];
+            let audioPathList = args!["audioDecodePaths"] as! [String];
             let startTimeList = args!["startTimeList"] as! [Double];
             let startTimeList = args!["startTimeList"] as! [Double];
             let pathVideoMixinDir = args!["pathVideoMixin"] as! String;
             let pathVideoMixinDir = args!["pathVideoMixin"] as! String;
             let outPath = pathVideoMixinDir + "\(videoId)_mix.mp4";
             let outPath = pathVideoMixinDir + "\(videoId)_mix.mp4";
@@ -107,9 +107,13 @@ public class SwiftDubbingLibPlugin: NSObject, FlutterPlugin {
     
     
     /// 合成
     /// 合成
     func startMixinAudio(videoPath: String?, bgmPath: String, audioPathList: [String], startTimeList: [Double], outPath: String, result: @escaping FlutterResult) {
     func startMixinAudio(videoPath: String?, bgmPath: String, audioPathList: [String], startTimeList: [Double], outPath: String, result: @escaping FlutterResult) {
-        let videoUrl:URL? = videoPath.isBlank ?URL(fileURLWithPath: videoPath!):nil
+        var videoUrl:URL?=nil
+        if(!(videoPath?.isBlank ?? true)){
+            videoUrl = URL(fileURLWithPath: videoPath!);
+        }
         let musicUrl = URL(fileURLWithPath: bgmPath)
         let musicUrl = URL(fileURLWithPath: bgmPath)
-        let composer = DubbingComposer(timeline: startTimeList, videoUrl: videoUrl!, musicUrl: musicUrl, recordsUrl: audioPathList)
+        let composer = DubbingComposer(timeline: startTimeList, videoUrl: videoUrl, musicUrl: musicUrl, recordsUrl: audioPathList)
+        
         composer.preTime = preLag
         composer.preTime = preLag
         let outputUrl = URL(fileURLWithPath: outPath)
         let outputUrl = URL(fileURLWithPath: outPath)
         DispatchQueue.global().async {
         DispatchQueue.global().async {

+ 188 - 0
pubspec.lock

@@ -0,0 +1,188 @@
+# Generated by pub
+# See https://dart.dev/tools/pub/glossary#lockfile
+packages:
+  archive:
+    dependency: transitive
+    description:
+      name: archive
+      url: "https://pub.dev"
+    source: hosted
+    version: "2.0.11"
+  args:
+    dependency: transitive
+    description:
+      name: args
+      url: "https://pub.dev"
+    source: hosted
+    version: "1.5.2"
+  async:
+    dependency: transitive
+    description:
+      name: async
+      url: "https://pub.dev"
+    source: hosted
+    version: "2.4.0"
+  boolean_selector:
+    dependency: transitive
+    description:
+      name: boolean_selector
+      url: "https://pub.dev"
+    source: hosted
+    version: "1.0.5"
+  charcode:
+    dependency: transitive
+    description:
+      name: charcode
+      url: "https://pub.dev"
+    source: hosted
+    version: "1.1.2"
+  collection:
+    dependency: transitive
+    description:
+      name: collection
+      url: "https://pub.dev"
+    source: hosted
+    version: "1.14.11"
+  convert:
+    dependency: transitive
+    description:
+      name: convert
+      url: "https://pub.dev"
+    source: hosted
+    version: "2.1.1"
+  crypto:
+    dependency: transitive
+    description:
+      name: crypto
+      url: "https://pub.dev"
+    source: hosted
+    version: "2.1.3"
+  flutter:
+    dependency: "direct main"
+    description: flutter
+    source: sdk
+    version: "0.0.0"
+  flutter_test:
+    dependency: "direct dev"
+    description: flutter
+    source: sdk
+    version: "0.0.0"
+  image:
+    dependency: transitive
+    description:
+      name: image
+      url: "https://pub.dev"
+    source: hosted
+    version: "2.1.4"
+  matcher:
+    dependency: transitive
+    description:
+      name: matcher
+      url: "https://pub.dev"
+    source: hosted
+    version: "0.12.6"
+  meta:
+    dependency: transitive
+    description:
+      name: meta
+      url: "https://pub.dev"
+    source: hosted
+    version: "1.1.8"
+  path:
+    dependency: transitive
+    description:
+      name: path
+      url: "https://pub.dev"
+    source: hosted
+    version: "1.6.4"
+  pedantic:
+    dependency: transitive
+    description:
+      name: pedantic
+      url: "https://pub.dev"
+    source: hosted
+    version: "1.8.0+1"
+  petitparser:
+    dependency: transitive
+    description:
+      name: petitparser
+      url: "https://pub.dev"
+    source: hosted
+    version: "2.4.0"
+  quiver:
+    dependency: transitive
+    description:
+      name: quiver
+      url: "https://pub.dev"
+    source: hosted
+    version: "2.0.5"
+  sky_engine:
+    dependency: transitive
+    description: flutter
+    source: sdk
+    version: "0.0.99"
+  source_span:
+    dependency: transitive
+    description:
+      name: source_span
+      url: "https://pub.dev"
+    source: hosted
+    version: "1.5.5"
+  stack_trace:
+    dependency: transitive
+    description:
+      name: stack_trace
+      url: "https://pub.dev"
+    source: hosted
+    version: "1.9.3"
+  stream_channel:
+    dependency: transitive
+    description:
+      name: stream_channel
+      url: "https://pub.dev"
+    source: hosted
+    version: "2.0.0"
+  string_scanner:
+    dependency: transitive
+    description:
+      name: string_scanner
+      url: "https://pub.dev"
+    source: hosted
+    version: "1.0.5"
+  term_glyph:
+    dependency: transitive
+    description:
+      name: term_glyph
+      url: "https://pub.dev"
+    source: hosted
+    version: "1.1.0"
+  test_api:
+    dependency: transitive
+    description:
+      name: test_api
+      url: "https://pub.dev"
+    source: hosted
+    version: "0.2.11"
+  typed_data:
+    dependency: transitive
+    description:
+      name: typed_data
+      url: "https://pub.dev"
+    source: hosted
+    version: "1.1.6"
+  vector_math:
+    dependency: transitive
+    description:
+      name: vector_math
+      url: "https://pub.dev"
+    source: hosted
+    version: "2.0.8"
+  xml:
+    dependency: transitive
+    description:
+      name: xml
+      url: "https://pub.dev"
+    source: hosted
+    version: "3.5.0"
+sdks:
+  dart: ">=2.4.0 <3.0.0"