我已经设置了一个AVAssetExportSession只有2个音轨和没有视频的音轨,它就像我想要的那样播放AVPlayer- 但是当我去导出它时,唯一可用的outputFileType是AVFileTypeQuickTimeMovie- 为什么我不能选择音频格式?
当我NSLog(@"%@", [session supportedFileTypes]);得到;
[51330:c07] (
"com.apple.quicktime-movie"
)
Run Code Online (Sandbox Code Playgroud)
这是我的代码;
- (AVMutableComposition *)getComposition {
AVAsset *backingAsset = [AVAsset assetWithURL:self.urlForEightBarAudioFile];
AVAsset *vocalsAsset = [AVAsset assetWithURL:self.recorder.url];
AVMutableComposition *composition = [AVMutableComposition composition];
AVMutableCompositionTrack *compositionBackingTrack = [composition addMutableTrackWithMediaType:AVMediaTypeAudio preferredTrackID:kCMPersistentTrackID_Invalid];
AVMutableCompositionTrack *compositionVocalTrack = [composition addMutableTrackWithMediaType:AVMediaTypeAudio preferredTrackID:kCMPersistentTrackID_Invalid];
AVAssetTrack *backingAssetTrack = [backingAsset.tracks objectAtIndex:0];
AVAssetTrack *vocalsAssetTrack = [vocalsAsset.tracks objectAtIndex:0];
CMTimeRange timeRange = CMTimeRangeFromTimeToTime(kCMTimeZero, backingAsset.duration);
[compositionBackingTrack insertTimeRange:timeRange ofTrack:backingAssetTrack atTime:kCMTimeZero error:nil];
[compositionVocalTrack insertTimeRange:timeRange ofTrack:vocalsAssetTrack atTime:kCMTimeZero error:nil];
return composition;
} …Run Code Online (Sandbox Code Playgroud) 我正在使用AVMutableComposition将视频与下面的代码合并,
- (void)MergeAndSave_internal{
AVMutableComposition *composition = [AVMutableComposition composition];
AVMutableCompositionTrack *compositionVideoTrack = [composition addMutableTrackWithMediaType:AVMediaTypeVideo preferredTrackID:kCMPersistentTrackID_Invalid];
AVMutableCompositionTrack *compositionAudioTrack = [composition addMutableTrackWithMediaType:AVMediaTypeAudio preferredTrackID:kCMPersistentTrackID_Invalid];
AVMutableVideoComposition *videoComposition = [AVMutableVideoComposition videoComposition];
videoComposition.frameDuration = CMTimeMake(1,30);
videoComposition.renderScale = 1.0;
AVMutableVideoCompositionInstruction *instruction = [AVMutableVideoCompositionInstruction videoCompositionInstruction];
AVMutableVideoCompositionLayerInstruction *layerInstruction = [AVMutableVideoCompositionLayerInstruction videoCompositionLayerInstructionWithAssetTrack:compositionVideoTrack];
NSLog(@"%@",videoPathArray);
float time = 0;
CMTime startTime = kCMTimeZero;
for (int i = 0; i<videoPathArray.count; i++) {
AVURLAsset *sourceAsset = [AVURLAsset URLAssetWithURL:[NSURL fileURLWithPath:[videoPathArray objectAtIndex:i]] options:[NSDictionary dictionaryWithObject:[NSNumber numberWithBool:YES] forKey:AVURLAssetPreferPreciseDurationAndTimingKey]];
NSError *error = nil;
BOOL ok = NO;
AVAssetTrack *sourceVideoTrack = …Run Code Online (Sandbox Code Playgroud) video objective-c ios avmutablecomposition avassetexportsession
我现在正在尝试导出一个使用AVPlayer(使用URL)播放器的mp3文件,因此不必下载两次.
这是我的示例代码:
我已经尝试过每个outputFileType ......
self.exporter = [[AVAssetExportSession alloc] initWithAsset:self.asset presetName:AVAssetExportPresetPassthrough];
}
NSError *error;
NSLog(@"export.supportedFileTypes : %@",self.exporter.supportedFileTypes);
// "com.apple.quicktime-movie",
// "com.apple.m4a-audio",
// "public.mpeg-4",
// "com.apple.m4v-video",
// "public.3gpp",
// "org.3gpp.adaptive-multi-rate-audio",
// "com.microsoft.waveform-audio",
// "public.aiff-audio",
// "public.aifc-audio",
// "com.apple.coreaudio-format"
self.exporter.outputFileType = @"public.aiff-audio";
self.exporter.shouldOptimizeForNetworkUse = YES;
NSURL *a = [[NSFileManager defaultManager] URLForDirectory:NSDocumentDirectory inDomain:NSUserDomainMask appropriateForURL:nil create:YES error:&error];
NSURL *url = [a URLByAppendingPathComponent:@"filename.mp3"];
NSString *filePath = [url absoluteString];
self.exporter.outputURL = url;
if (![[NSFileManager defaultManager] fileExistsAtPath:filePath]){
[self.exporter exportAsynchronouslyWithCompletionHandler:^{
if (self.exporter.status == AVAssetExportSessionStatusCompleted)
{
if (![[NSFileManager defaultManager] fileExistsAtPath:filePath]){ …Run Code Online (Sandbox Code Playgroud) 我正在压缩视频,所以我遇到了以下导出预设
AVAssetExportPresetLowQuality
AVAssetExportPresetMediumQuality
AVAssetExportPresetHighestQuality
AVAssetExportPreset640x480
AVAssetExportPreset960x540
AVAssetExportPreset1280x720
AVAssetExportPreset1920x1080
AVAssetExportPreset3840x2160
Run Code Online (Sandbox Code Playgroud)
我已经在苹果文档中阅读了所有这些内容,并发现第二个列表在给定的固定维度上压缩但没有发现第一个列表,我很困惑,为什么它有2个列表,一个具有低,中,高质量和其他具有固定大小和哪一个更好用?
我创建了下面的合并方法(加入、联合,我不确定哪个词是正确的,我想从 2 个或更多音频中制作 1 个音频,而不是一个接一个地播放,而是一次播放每个音频)。作为输入,我有多个 .wav 格式的音频文件,并且我希望输出有 1 个 .wav 格式。
func merge(audioUrls: [NSURL], resultName : String = "result") {
let resultNameWithExtension = resultName + ".wav"
//Create AVMutableComposition Object.This object will hold our multiple AVMutableCompositionTrack.
let composition = AVMutableComposition()
//create new file to receive data
//let documentDirectoryURL = NSFileManager.defaultManager().URLsForDirectory(.DocumentDirectory, inDomains: .UserDomainMask).first!
let outputFilePath = NSTemporaryDirectory().stringByAppendingPathComponent(resultNameWithExtension)
let fileDestinationUrl = NSURL(fileURLWithPath: outputFilePath)
print(fileDestinationUrl)
StorageManager.sharedInstance.deleteFileAtPath(NSTemporaryDirectory().stringByAppendingPathComponent(resultNameWithExtension))
var avAssets: [AVURLAsset] = []
var assetTracks: [AVAssetTrack] = []
var timeRanges: [CMTimeRange] = []
for audioUrl in …Run Code Online (Sandbox Code Playgroud) - 如何删除视频中的绿线. 当播放视频2或3次时,视频中显示绿色或混合绿 - 红闪烁线,左视图或底视图或视频中的左下角.
视频裁剪方法.
-(void)cropButton
{
CGRect cropFrame = self.cropView.croppedImageFrame;
//load our movie Asset
AVAsset *asset;
asset = [AVAsset assetWithURL:[NSURL fileURLWithPath:[self.videoDataArr objectAtIndex:self.selectedIndex-1]]];
//create an avassetrack with our asset
AVAssetTrack *clipVideoTrack = [[asset tracksWithMediaType:AVMediaTypeVideo] objectAtIndex:0];
//create a video composition and preset some settings
AVMutableVideoComposition* videoComposition = [AVMutableVideoComposition videoComposition];
videoComposition.frameDuration = CMTimeMake(1, 30);
//create a video instruction
AVMutableVideoCompositionInstruction *instruction = [AVMutableVideoCompositionInstruction videoCompositionInstruction];
instruction.timeRange = CMTimeRangeMake(kCMTimeZero, asset.duration);
AVMutableVideoCompositionLayerInstruction* transformer = [AVMutableVideoCompositionLayerInstruction videoCompositionLayerInstructionWithAssetTrack:clipVideoTrack];
UIImageOrientation videoOrientation = [self getVideoOrientationFromAsset:asset];
CGAffineTransform t1 = CGAffineTransformIdentity; …Run Code Online (Sandbox Code Playgroud) 我正在使用设备麦克风录制音频,AVAudioRecorder该麦克风以.caf格式返回文件,该文件只能在 Apple 设备上播放,但不能在 Android 设备上播放。由于 Apple 不支持.mp3文件,所以我想在上传到服务器之前将其转换为.mp4格式。为.MP4是良好的只有音频?我可以转换它AVAssetExportSession吗?
以下是录音机代码:
func setupAudioRecorder ()
{
let fileMgr = FileManager.default
let dirPaths = fileMgr.urls(for:.documentDirectory,
in:.userDomainMask)
let soundFileURL = dirPaths[0].appendingPathComponent("myaudio.caf")
let recordSettings =
[AVEncoderAudioQualityKey: AVAudioQuality.min.rawValue,
AVEncoderBitRateKey: 16,
AVNumberOfChannelsKey: 2,
AVSampleRateKey: 44100.0] as [String : Any]
do {
try audioSession.setCategory(
AVAudioSessionCategoryPlayAndRecord)
} catch let error as NSError {
print("audioSession error: \(error.localizedDescription)")
}
do {
try audioRecorder = AVAudioRecorder(url: soundFileURL,
settings: recordSettings as [String : …Run Code Online (Sandbox Code Playgroud) 我正在研究视频的慢动作效果,在 iOS 11 下一切正常,但在 iOS 11 上出现以下错误:
Error Domain=AVFoundationErrorDomain Code=-11800 "The operation could not be completed" UserInfo={NSLocalizedFailureReason=An unknown error occurred (-16364), NSLocalizedDescription=The operation could not be completed, NSUnderlyingError=0x608000456620 {Error Domain=NSOSStatusErrorDomain Code=-16364 "(null)"}}
Run Code Online (Sandbox Code Playgroud)
我试图找出有关此问题的信息,但没有找到任何确切的解决方案。
下面是我的代码供参考:
- (void)applySlowMoOnAsset:(NSURL *)assetURL {
AVAsset *videoAsset = [[AVURLAsset alloc] initWithURL:assetURL options:nil];
AVMutableComposition *mixComposition = [AVMutableComposition composition];
AVMutableCompositionTrack *compositionVideoTrack = [mixComposition addMutableTrackWithMediaType:AVMediaTypeVideo
preferredTrackID:kCMPersistentTrackID_Invalid];
AVMutableCompositionTrack *compositionAudioTrack = [mixComposition addMutableTrackWithMediaType:AVMediaTypeAudio preferredTrackID:kCMPersistentTrackID_Invalid];
AVAssetTrack *videoAssetTrack = [[videoAsset tracksWithMediaType:AVMediaTypeVideo] objectAtIndex:0];
NSError *videoInsertError = nil;
BOOL videoInsertResult = [compositionVideoTrack insertTimeRange:CMTimeRangeMake(kCMTimeZero, videoAsset.duration)
ofTrack: videoAssetTrack …Run Code Online (Sandbox Code Playgroud)
我有一个音频播放器应该能够播放多种音频格式.该应用程序正在使用BASS音频库,它需要一些导出.以下是格式.除了.mov(仅音频)格式的文件外,一切正常.
关于正确解决方法的任何想法?
exportSession = [[AVAssetExportSession alloc] initWithAsset:asset presetName:AVAssetExportPresetPassthrough];
if (nil == exportSession)
@throw [NSException exceptionWithName:TSUnknownError reason:@"Couldn't create AVAssetExportSession" userInfo:nil];
if ([[assetURL pathExtension] compare:@"mp3"] == NSOrderedSame) {
[self doMp3ImportToFile:destURL completionBlock:completionBlock];
return;
}
exportSession.outputURL = destURL;
// set the output file type appropriately based on asset URL extension
if ([[assetURL pathExtension] compare:@"m4a"] == NSOrderedSame) {
exportSession.outputFileType = AVFileTypeAppleM4A;
} else if ([[assetURL pathExtension] compare:@"wav"] == NSOrderedSame) {
exportSession.outputFileType = AVFileTypeWAVE;
} else if ([[assetURL pathExtension] compare:@"aif"] == NSOrderedSame) {
exportSession.outputFileType = AVFileTypeAIFF; …Run Code Online (Sandbox Code Playgroud) 我正在使用音频文件 AVAssetExportSession但无法在保存的文件中淡出淡出效果.这是我正在使用的代码.
[[NSFileManager defaultManager] removeItemAtURL:audioFileOutput error:NULL];
AVAsset *asset = [AVAsset assetWithURL:[NSURL fileURLWithPath:file_path]];
AVAssetExportSession *exportSession = [AVAssetExportSession exportSessionWithAsset:asset
presetName:AVAssetExportPresetAppleM4A];
time = floorf(Endtime-startTime);
CMTime start = CMTimeMake(0.0*100,100);
CMTime stop = CMTimeMake(time*100,100);
CMTimeRange exportTimeRange = CMTimeRangeFromTimeToTime(start, stop);
AVMutableAudioMix *mutableAudioMix = [AVMutableAudioMix audioMix];
AVURLAsset* audio = [[AVURLAsset alloc]initWithURL:[NSURL URLWithString:file_path] options:nil];
AVAssetTrack* audioTrack = [[audio tracksWithMediaType:AVMediaTypeAudio]
objectAtIndex:0];
AVMutableAudioMixInputParameters *mixParameters = [AVMutableAudioMixInputParameters audioMixInputParametersWithTrack:audioTrack];
[mixParameters setVolumeRampFromStartVolume:1.0 toEndVolume:0.0 timeRange:exportTimeRange];
mutableAudioMix.inputParameters = @[mixParameters];
exportSession.audioMix = mutableAudioMix;
exportSession.outputURL = audioFileOutput;
exportSession.outputFileType = AVFileTypeAppleM4A;
exportSession.timeRange = exportTimeRange;
[SVProgressHUD showWithStatus:@"Saving Recording.." …Run Code Online (Sandbox Code Playgroud)