Is it possible to edit the volume and pan of a video track and export it to a standalone video with this information?

I am recording a video in my application. When a video is being recorded, I want the user to view the recording using the controls to change the volume and pan the audio track. To watch the video, I use AVMutableComposition and add AVAsset from the local URL of the recorded file and use the composition as AVPlayerItem to play through AVPlayer . I do this because I want to add volume and panoramas (") (") to the soundtracks in the composition, and then export the entire composition.

Playback works fine, but I can't find a way to add such “filters” (to change the volume or pan of AVAssetTrack or anything else at that level). So far, I have been able to change the volume during playback using this:

  NSMutableArray *audioParam = [NSMutableArray array]; AVMutableAudioMixInputParameters *audioInputParams = [AVMutableAudioMixInputParameters audioMixInputParameters]; [audioInputParams setVolume:volumeSlider.value atTime:kCMTimeZero]; [audioInputParams setTrackID:[audioTrack trackID]]; [audioParam addObject:audioInputParams]; AVMutableAudioMix *audioMix = [AVMutableAudioMix audioMix]; [audioMix setInputParameters:audioParam]; [playerItem setAudioMix:audioMix]; 

Here, I believe, I am only changing the presentation of the composition, not the composition itself. When the user is satisfied with the volume level and panning, he should click “Accept” and I will export the composition to a separate movie file (IE this will not affect the composition if I change the player’s volume in this way).

Is there a way to add the original movie to AVComposition, change the volume / pan of the sound and export to a new file with new information?

I am also, as already mentioned, looking for this to pan an audio stereo or monaural track, but I cannot find anything. The only mention of panning in Apple Docs is the use of AVAudioPlayer , which I cannot use as it is a video file. Also, changing the pan in the player will not do anything good, as I explained using the volume. Is there no way to change the panning through AVAsset , AVAssetTrack , AVComposition or something like that?

I thought that I would have to do it manually, reducing the volume of each channel for a stereo audio track, but I also can not find a way to do this.

Simply put, I’m looking for a way to change the volume level and pan (left / right) of the audio track of one video (previously mentioned video during preview / playback), and then you can export this video to a new video file, which will then have this new information about volume and panorama as source information.

Example:

1. Record a video.

2. Preview the video.

3. Set the panning sound to the left (audio in the left channel only) and Volume up to 20%

4. Export video with new information

5. If I upload this video file to the Internet now, and someone downloads it to any device / computer, it will only have sound in the left speaker, and it will be quite low.

+6
source share
1 answer

Since you want these parameters (volume and panorama) to be applied to your output, most likely you will want to create an AVMutableComposition and then an AVAssetExportSession to spit everything out as you expect.

To handle panning, I usually deal with recording audio or recording in AVMutableComposition, simply by quickly multiplying by sampling any channel, if necessary. It depends on how your application is structured where you can do it.

To get the volume control, you can set the volume of each AVMutableCompositionTrack or AVAssetTrack added to your AVComposition, or you can apply AVMutableAudioMix to the AVAssetExportSession property of the audio engine. When you export, it will be exported using the mentioned audio mix. This will “print” your volume changes, so you don’t have to change them during playback.

AudioMix is ​​good because it allows you to fade, etc.

0
source

All Articles