All Products
Search
Document Center

Video recording

Last Updated: Aug 01, 2019

Step 1: Copy SDK files

  • Copy the files highlighted in red into your project, as shown in the following figure.Snip20181025_2.png

Step 2: Copy business code files

Copy the following three parts of code files into your project:

  • Basic code and public components that the project is dependent on

    Copy the files highlighted in red into your project, as shown in the following figure.Copy files for recording

Name Description
AlivcBeaitufySettingsPanel The face filter component.
Categories The categories required by the project.
Config The configuration files of the project.
Helpers The helper classes required by the project.
Utilites The four utility classes required by the project.

To correctly display the original icons of the face filter component, you need to copy the corresponding image resources from the NewLive folder in the image folder Assets.xcassets of the demo. In addition, the text of the face filter is localized and displayed in English by default. If you want to display the text in Chinese, you need to localize the configuration and copy the localized characters from the root directory/demo/AliyunVideoClient_Entrance/Resources directory.

  • Basic code and public components that the short video SDK is dependent on

    Copy the files highlighted in red into your project, as shown in the following figure.Copy files for recording

Name Description
AlivcShortVideoCommonFile The public components that the short video SDK is dependent on in its basic, standard, and professional editions.
Common The business components for the professional edition of the short video SDK.
AlivcShortVideoFaceUnity The dependent files for the advanced face filter of FaceUnity.
AlivcShortVideoResource The resources required by the short video SDK.

Resource folders are referenced as folder references, as shown in the following figure.WX20181019-225713@2x.png

Add these folders to your project following instructions, as shown in the following figure.WX20181019-230720@2x.png

In addition, comment out the following two lines of code in the AliyunCompositionViewController.m file: #import "AlivcShortVideoPublishManager.h" and [[AlivcShortVideoPublishManager shared]saveResources:(NSArray *)saveAVURLAssetArray];.

  • Code of the video recording module

    Copy the files highlighted in red into your project, as shown in the following figure.Copy recording code

VideoRecord: the business code of video recording.

Step 3: Configure the PCH file

Add the following reference to a .pch file in your project:

  1. #import "AlivcMacro.h"
  2. #import "AlivcImage.h"

If your project does not contain a .pch file, you can copy the PrefixHeader.pch file from the demo. Keep the preceding reference in the .pch file and choose TARGETS > Build Settings to configure the PCH file, as shown in the following figure.WX20181020-002351@2x.png

Prefix Header: Enter the directory of the PrefixHeader.pch file in your project, for example, $(SRCROOT)/Your own directory/PrefixHeader.pch.

Step 4: Set up the project environment

  1. Open the project and select the target. Choose General > Embedded Binaries. Click + and then Add Other… to import the alivcffmpeg.framework and AliyunVideoSDKPro.framework files.

  2. Open the project and select the target. Choose General > Linked Frameworks and Libraries. Click + to add the following system libraries:

    • libz.tbd
    • ImageIO.framework
    • CoreMedia.framework
    • CoreVideo.framework
    • VideoToolBox.framework
    • MediaPlayer.framework
    • OpenAL.framework
    • libc++.tbd
    • libsqlite3.tbd
    • libiconv.tbd

    The following figure provides a screenshot.Screenshot 2018-10-15 18.15.40.png

  3. Choose Build Settings > Build Options. Set Enable Bitcode to No.

  4. Choose Build Settings > Linking > Other Linker Flags. Add the $(inherited) and -ObjC options.

  5. Configure the Info.plist file.

    Open the Info.plist file of your project and add the following fields:

    • Privacy - Camera Usage Description
    • Privacy - Microphone Usage Description
    • Privacy - Photo Library Usage Description
    • Privacy - Photo Library Additions Usage Description
    • Privacy - Media Library Usage Description

Add the App Transport Security Settings option. Add its child attribute Allow Arbitrary Loads and set its value to Yes to enable HTTP requests.You can also add the following code to the source code of the Info.plist file:

  1. <key>NSAppleMusicUsageDescription</key>
  2. <string></string>
  3. <key>NSPhotoLibraryAddUsageDescription</key>
  4. <string></string>
  5. <key>NSPhotoLibraryUsageDescription</key>
  6. <string></string>
  7. <key>NSMicrophoneUsageDescription</key>
  8. <string></string>
  9. <key>NSCameraUsageDescription</key>
  10. <string></string>
  11. <key>NSAppTransportSecurity</key>
  12. <dict>
  13. <key>NSAllowsArbitraryLoads</key>
  14. <true/>
  15. </dict>

Step 5: Integrate CocoaPods

  • Add the following reference to a Podfile:
  1. pod 'MBProgressHUD', '~> 1.1.0'
  2. pod 'AFNetworking', '~> 3.0'
  3. pod 'SDWebImage', '~> 4.0'
  4. pod 'FMDB', '~> 2.5'
  5. pod 'JSONModel'
  6. pod 'LXReorderableCollectionViewFlowLayout'
  7. pod 'Nama-lite', '5.3.0'
  8. pod 'ZipArchive','1.4.0'
  9. pod 'AlivcConan', '0.9.0' # The dependent data tracking of the short video SDK.
  • On a physical device where your project is run, run the cd command to go to the directory of the Podfile and run the pod install command.

Step 6: Compile the sample code for the recording feature

  1. #import "AliyunMediaConfig.h"
  2. #import "AlivcShortVideoRoute.h"
  3. // Obtains the routing information.
  4. AlivcShortVideoRoute *alivcRoute = [AlivcShortVideoRoute shared];
  5. // Sets parameters.
  6. AliyunMediaConfig *recordMediaConfig = [AliyunMediaConfig defaultConfig];
  7. // The minimum duration.
  8. recordMediaConfig.minDuration = 2.0;
  9. // The maximum duration.
  10. recordMediaConfig.maxDuration = 15;
  11. // The aspect ratio of the video.
  12. float videoOutputRatio = 9.0f / 16.0f;
  13. // The resolution.
  14. float videoOutputWidth = recordMediaConfig.outputSize.width;
  15. // The size of the video, which must be an even integer.
  16. CGFloat height = ceilf(videoOutputWidth / videoOutputRatio);
  17. // The output size of the video.
  18. recordMediaConfig.outputSize = CGSizeMake(videoOutputWidth, height);
  19. [alivcRoute registerMediaConfig:recordMediaConfig];
  20. // Registers a callback event for the completion of recording.
  21. [alivcRoute registerRecordFinishBlock:^(NSString * _Nonnull outputPath) {
  22. NSLog(@"Storage path of the recorded video: %@",outputPath);
  23. // Performs other operations required after short video processing.
  24. }];
  25. // Obtains a view controller for the feature.
  26. UIViewController *control = [alivcRoute alivcViewControllerWithType:AlivcViewControlRecord];
  27. // Hides the built-in navigation bar with a custom unified style in the functional module.
  28. [self.navigationController setNavigationBarHidden:YES animated:YES];
  29. // If you fail to be redirected to the custom page, check whether UINavigationController is configured in your code.
  30. [self.navigationController pushViewController:control animated:YES];

Additional information

Activate a short video SDK license

  • After you buy a short video SDK package, send your application name, order number, bundle ID, package name, and signature to videosdk@service.aliyun.com. Alibaba Cloud will activate a short video SDK license for you. The signature is an MD5 hash value in lowercase without colons (:).
  • You do not need to integrate the license into the SDK. You only need to ensure that the bundle ID, package name, and signature that you provided are the same as those in your project. During testing, you can use the bundle ID, package name, and signature in the demo to experience the Alibaba Cloud short video SDK.
  • You can use one package of the basic or standard edition in only one application (up to 10 shadow applications) and one package of the professional edition in three applications at most (up to 10 shadow applications).
  • The advanced face filter is available only in the professional edition of the short video SDK. It is provided and charged by the third party FaceUnity. You can apply for the trial use of the advanced face filter of FaceUnity. Alibaba Cloud will send a certificate to you by email.

Enable the advanced face filter

The short video solution integrates the advanced face filter of FaceUnity. To use this advanced face filter, you only need to replace the relevant authpack certificate file with a FaceUnity certificate.

Obtain a FaceUnity certificate

You can send an email to apply for trial use and specify the advanced face filter of FaceUnity in the email. Alibaba Cloud will send a certificate to you by email.Email: videosdk@service.aliyun.com.Email content: Provide your application name, bundle ID, package name, and signature. The signature is an MD5 hash value in lowercase without colons (:).

After the application email is sent, you can receive an authpack.h file. Use this file to replace the authpack.h file in your project. Ensure that the bundle ID is consistent in the two files.

  • For more information about the core code for integrating the FaceUnity SDK into the recording module of the short video solution, see the FaceUnityManager class in the demo.
  • The advanced face filter is available only in the professional edition of the short video SDK.
  • For more information about how to completely integrate the FaceUnity SDK, see the procedure for integrating the FaceUnity SDK into the short video SDK at https://github.com/Faceunity/FUAliShortVideoDemo.