Questions tagged [avasset]

AVAsset is an abstract class to represent timed audiovisual media such as videos and sounds. Each asset contains a collection of tracks that are intended to be presented or processed together, each of a uniform media type, including but not limited to audio, video, text, closed captions, and subtitles.

An AVAsset object defines the collective properties of the tracks that comprise the asset. (You can access the instances of AVAssetTrack representing tracks of the collection, so you can examine each of these independently if you need to.) You often instantiate an asset using a concrete subclass of AVAsset; for example, you can initialize an instance of AVURLAsset using an URL that refers to an audiovisual media file, such as a QuickTime movie file or an MP3 file (amongst other types). You can also instantiate an asset using other concrete subclasses that extend the basic model for audiovisual media in useful ways, as AVComposition does for temporal editing. To assemble audiovisual constructs from one or more source assets, you can insert assets into instances of AVMutableComposition.

You often instantiate an asset using AVURLAsset—a concrete subclass of AVAsset—with URLs that refer to audiovisual media resources, such as streams (including HTTP live streams), QuickTime movie files, MP3 files, and files of other types. You can also instantiate an asset using other concrete subclasses that extend the basic model for audiovisual media in useful ways, as AVComposition does for temporal editing.

Properties of assets as a whole are defined by AVAsset. Additionally, references to instances of AVAssetTrack representing tracks of the collection can be obtained, so that each of these can be examined independently.

Because of the nature of timed audiovisual media, upon successful initialization of an asset some or all of the values for its keys may not be immediately available. The value of any key can be requested at any time, and asset will always return its value synchronously, although it may have to block the calling thread in order to do so. In order to avoid blocking, you can register your interest in particular keys and to become notified when their values become available. For further details, see AVAsynchronousKeyValueLoading.

To play an instance of AVAsset, initialize an instance of AVPlayerItem with it, use the player item to set up its presentation state (such as whether only a limited timeRange of the asset should be played, etc.), and provide the player item to an AVPlayer object according to whether the item is to be played by itself or together with a collection of other items.

Click Here for Apple documentation.

399 questions
9
votes
3 answers

Extract video portion from Live Photo

Has anyone figured out how to extract the video portion from a Live Photo? I'm working on an app to convert Live Photos into a GIF, and the first step is to get the video file from the Live Photo. It seems like it should be possible, because if you…
JYeh
  • 4,273
  • 3
  • 27
  • 40
9
votes
4 answers

How do I implement AVAssetImageGenerator.copyCGImageAtTime in swift

Thus far I have the following let assetUrl = NSURL.URLWithString(self.targetVideoString) let asset: AVAsset = AVAsset.assetWithURL(assetUrl) as AVAsset let imageGenerator = AVAssetImageGenerator(asset: asset); let time : CMTime =…
user379468
  • 3,989
  • 10
  • 50
  • 68
9
votes
4 answers

AVAssetReaderOutput copyNextSampleBuffer hangs when encoding video w/ audio on device

After implementing the solution to encoding video (with audio) in this question, Video Encoding using AVAssetWriter - CRASHES, I found that the code works correctly in the iPhone Simulator. Unfortunately, certain videos fail to encode their audio…
jlw
  • 3,166
  • 1
  • 19
  • 24
8
votes
1 answer

Is there any difference between using AVPlayer, AVPlayerItem, and AVPlayerAsset?

I found the three ways to play video with URL. let url = "some url" // first way AVPlayer(url: url) // second way let playerItem = AVPlayerItem(url: url) AVPlayer(playerItem: playerItem) // third way let asset = AVAsset(url: url) let playerItem =…
user12208004
  • 1,704
  • 3
  • 15
  • 37
8
votes
1 answer

What is the correct time range to use when sequencing AVAssets?

I'm working on a project that requires sequencing a large number (problem is visible at n = 30 or fewer) of short (1-5 second) AVAssets. All of the reference material and sample projects I can find points to using the range CMTimeRange(start: .zero,…
jefflovejapan
  • 2,047
  • 3
  • 20
  • 34
8
votes
2 answers

iOS 8 album art cover

Since iOS 8, all the data arrays for album art from iPad & iPhone devices returns a null array. I can get album art or cover art when pulling from a local file(NSBundle), but any songs on purchased from iTunes or on the device itself returns empty.…
Tae Re
  • 163
  • 1
  • 8
8
votes
1 answer

AVAsset "tracksWithMediaType" returns an empty array

These is the beginning o a method I am using to merge videos together -(void) mergeVideosAndAudio:(AVAsset *)audioAsset{ //Load Video Assets NSError *error; NSArray *dirFiles; if ((dirFiles = [[NSFileManager defaultManager]…
Kaitis
  • 628
  • 9
  • 21
8
votes
0 answers

IOS - How to write AVAsset to file?

I am working with an app now that streams data from a web url. I am able to implement the streaming using AVAsset and AVPlayer as its player. Now, what I want to do is to save the streamed bytes from AVAsset to a music file in local. It's basically…
8
votes
2 answers

How to trim the video file and convert to 15 seconds video with iOS SDK?

I want to trim a video file. I want to just pick the video from a gallery and convert it to a 15-second video. If I use normal trimming with picker view controller, it does not specify a time and just shows the frames, but I need to be fixed for 15…
Ramkumar Paulraj
  • 1,841
  • 2
  • 20
  • 40
8
votes
1 answer

How to repeat audio track if video duration in longer than audio duration

I am mixing an audio and video file using AVMutableComposition. Below is my code for that: enter code here AVMutableComposition* mixComposition = [AVMutableComposition composition]; NSString *bundleDirectory = [[NSBundle mainBundle] bundlePath]; …
coder1010
  • 412
  • 5
  • 15
8
votes
1 answer

How can I extract metadata from mp3 file in ios development

I am working on an ios music player with cloud storage. I need to extract the music information such as title, artist, artwork. I have an action called playit which plays and pauses the mp3 file. It should also populate some UILables and UIImage…
user951297
7
votes
1 answer

Request AVAsset using iCloud PHAsset returns an AVAsset with no VideoTracks

Recently, started noticing some assets were not being displayed when importing them from the photo library. The assets in questions are stored in iCloud and are not cached on the device. I believe it is an iOS 14 issue, since I have never…
Swift Rabbit
  • 1,370
  • 3
  • 14
  • 29
7
votes
3 answers

How to convert Data to AVAsset?

Is there a way to convert Data to AVAsset/AVURLAsset or better AVPlayerItem? I found an answer that converts Data to PHAsset and requires saving it first to the desk. Is there a better way?
Elsammak
  • 1,102
  • 10
  • 26
7
votes
1 answer

How to get file Url of Slow motion video from Asset?

I am getting file url of normal video, but slow motion video asset type is AVComposition. I am try with AVAssetExportSession But it consuming large time. PHVideoRequestOptions *options=[[PHVideoRequestOptions alloc] init]; options.version =…
7
votes
1 answer

PHCacheImageManager.requestAVAsset(forVideo:...) returns nil AVAsset

I'm using [PHCachingImageManager] to cache videos in a collection view. I can display the images generated with the cache manager, but pulling AVAssets isn't working. I try to get an AVAsset by using the .requestAVAsset(forVideo:...) method but the…
A L
  • 516
  • 6
  • 16
1
2
3
26 27