ffmpeg ,有 170 M +,
每次调试 UI, run 一下,还要把他的二进制包打进去,
开发的时候,经常怀疑人生
要是编译的时候,把他也带进去,
时间就更长了
采用按需的技术策略,
开发的时候,没使用他,就把他删了,
用到他的代码部分,不用更改就好了
保证删了不影响使用代码,
let file = song.replacingOccurrences(of:".mp3", with: "") + ".raw"
if FileManager.default.fileExists(atPath: file) == false{
let command = "-i \(song) -f s16le -acodec pcm_s16le -ac 1 -ar 44100 \(file)"
let result = MobileFFmpeg.execute(command)
switch result {
case RETURN_CODE_SUCCESS:
print("命令执行 completed successfully.\n")
case RETURN_CODE_CANCEL:
print("命令执行 cancelled by user.\n")
default:
print("命令执行 failed with rc=\(result) and output=\(String(describing: MobileFFmpegConfig.getLastCommandOutput())).\n")
}
}
Mock 一下,就好了。 做一下模拟实现
-
开发用 FakeImport 文件,
-
生成打包用 RealImport 文件,再把 ffmpeg 添加回去
FakeImport.h 里面
#import <Foundation/Foundation.h>
extern int const RETURN_CODE_SUCCESS;
extern int const RETURN_CODE_CANCEL;
@interface MobileFFmpeg : NSObject
+ (int)execute:(NSString*)command;
@end
@interface MobileFFmpegConfig : NSObject
+ (NSString*)getLastCommandOutput;
@end
FakeImport.m 里面
#import "FakeImport.h"
int const RETURN_CODE_SUCCESS = 3;
int const RETURN_CODE_CANCEL = 5;
@implementation MobileFFmpeg
+ (int)execute:(NSString*)command{
return 0;
}
@end
@implementation MobileFFmpegConfig
+ (NSString*)getLastCommandOutput{
return @"";
}
@end
RealImport.h 文件里面,
#import "MobileFFmpegConfig.h"
#import "MobileFFmpeg.h"