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
30
votes
2 answers

Get the accurate duration of a video

I'm making a player and I want to list all files and in front of all files I want to present the duration of the video. The only problem is that I'm not getting the right video duration, sometimes it return a duration completely wrong. I've tried…
Mr. James
  • 456
  • 1
  • 5
  • 12
28
votes
4 answers

iOS 7 AVPlayer AVPlayerItem duration incorrect in iOS 7

I have the following code in my app: NSURL *url = [NSURL fileURLWithPath: [self.DocDir stringByAppendingPathComponent: self.FileName] isDirectory: NO]; self.avPlayer = [AVPlayer playerWithURL: url]; Float64 duration =…
Matt Wolfe
  • 8,924
  • 8
  • 60
  • 77
24
votes
1 answer

How can I add a watermark in a captured video on iOS

I was wondering if anybody can tell me how I can achieve this. If been thinking of a couple of solutions: Create individual images from the captured video and later merge them per image and after that create a new AVAsset... Sounds a bit…
Michiel Timmerman
  • 353
  • 1
  • 3
  • 11
18
votes
3 answers

AVAssetExportSession failed with unknown error -12780 for specific video

I have a problem tracing the underlying issue behind my asset export session failure. The issue is for one video only, and I believe the problem is in its audio track, since I successfully exported the asset without the audio track (only the video…
17
votes
1 answer

Applying a CIFilter to a Video File and Saving it

Is there any fast, lightweight-as-possible way to apply a CIFilter to a video? Before it's mentioned, I have looked at GPUImage - it looks like very powerful magic code, but it's really overkill for what I'm trying to do. Essentially, I would like…
Jojodmo
  • 23,357
  • 13
  • 65
  • 107
16
votes
2 answers

Only First Track Playing of AVMutableComposition()

New Edit Below I have already referenced AVMutableComposition - Only Playing First Track (Swift) but it is not providing the answer to what I am looking for. I have a AVMutableComposition(). I am trying to apply MULTIPLE AVCompositionTrack, of a…
impression7vx
  • 1,728
  • 1
  • 20
  • 50
16
votes
6 answers

How to get the size (KB) of a Video AVAsset

I would like to get an AVAsset video file size, not the video's resolution, but the file weight in KB. A solution would be to calculate an estimated filesize from the duration and the estimatedDataRate, but this seems to be a lot just to get a…
TheSquad
  • 7,385
  • 8
  • 40
  • 79
15
votes
5 answers

AVAssetExportSession giving me a green border on right and bottom of output video

Here's the code: AVAssetExportSession *exporter = [[AVAssetExportSession alloc] initWithAsset:mixComposition presetName:AVAssetExportPresetHighestQuality]; exporter.outputURL = outputUrl; exporter.outputFileType =…
13
votes
6 answers

Convert PHAsset (video) to AVAsset, synchronously

I need to use the AVAsset object, in order to play it using AVPlayer and AVPlayerLayer. I started using the Photos framework since AssetsLibrary is deprecated. Now I got to the point where I have an array of PHAsset objects and I need to convert…
Objectif
  • 364
  • 1
  • 4
  • 12
12
votes
0 answers

Exporting Asset to Filesystem via AVAssetExportSession always fails - Swift 3

I want to export a .mp4-video stored in an AVPlayerItem to the filesystem. If that succeeds, I want to get it into a NSData-variable (but that is not part of the question, just wanted to tell you why I want to store it into the Filesystem in the…
Marcel
  • 121
  • 8
12
votes
2 answers

How to fix video orientation issue in iOS

I am working with an app in which user picks video from Photos and uploads it to server. As my server is .Net server , the video gets rotated. I know the reason of problem is probably same as was in case of image (you may refer my earlier answer…
HarshIT
  • 4,583
  • 2
  • 30
  • 60
11
votes
2 answers

Sample accurate extraction of chunks of audio using AVFoundation

Problem I am looking to extract sample-accurate ranges of LPCM audio from audio tracks within video files. Currently, I'm looking to achieve this using AVAssetReaderTrackOutput against an AVAssetTrack delivered from reading a AVURLAsset. Despite…
Dan
  • 1,258
  • 1
  • 10
  • 22
10
votes
1 answer

How to detect selected Media is Time-Lapse, Slow-Motion or .mp4

Creating an application for image and video processing, where app requirement is set device Orientation according to selected video content orientation from the gallery. So I have used some line of code to get selected media current orientation…
Sumit singh
  • 2,398
  • 1
  • 15
  • 30
10
votes
1 answer

How do I know when generateCGImagesAsynchronously has completely finished?

I have a requirement to take a video, convert each frame to and image and save these images to disk. I'd like to use AVAssetImageGenerator for efficiency's sake, and have code similar to the following: The issue is that I don't know when all image…
terrafirma9
  • 362
  • 2
  • 15
9
votes
2 answers

AVAsset Orientation/Rotation issue

Tried to use Ray great tutorial to fix the orientation issue. left - how the video should look(portrait), right - unwanted rotated result Code used func setUpVideoNew() { let originalVideoTrack =…
Roi Mulia
  • 5,626
  • 11
  • 54
  • 105
1
2 3
26 27