objc2_av_foundation/generated/AVAssetWriter.rs
1//! This file has been automatically generated by `objc2`'s `header-translator`.
2//! DO NOT EDIT
3use core::ffi::*;
4use core::ptr::NonNull;
5use objc2::__framework_prelude::*;
6#[cfg(feature = "objc2-core-media")]
7use objc2_core_media::*;
8use objc2_foundation::*;
9#[cfg(feature = "objc2-uniform-type-identifiers")]
10use objc2_uniform_type_identifiers::*;
11
12use crate::*;
13
14/// These constants are returned by the AVAssetWriter status property to indicate whether it can successfully write samples to its output file.
15///
16///
17/// Indicates that the status of the asset writer is not currently known.
18///
19/// Indicates that the asset writer is successfully writing samples to its output file.
20///
21/// Indicates that the asset writer has successfully written all samples following a call to finishWriting.
22///
23/// Indicates that the asset writer can no longer write samples to its output file because of an error. The error is described by the value of the asset writer's error property.
24///
25/// Indicates that the asset writer can no longer write samples because writing was canceled with the cancelWriting method.
26///
27/// See also [Apple's documentation](https://developer.apple.com/documentation/avfoundation/avassetwriterstatus?language=objc)
28// NS_ENUM
29#[repr(transparent)]
30#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
31pub struct AVAssetWriterStatus(pub NSInteger);
32impl AVAssetWriterStatus {
33 #[doc(alias = "AVAssetWriterStatusUnknown")]
34 pub const Unknown: Self = Self(0);
35 #[doc(alias = "AVAssetWriterStatusWriting")]
36 pub const Writing: Self = Self(1);
37 #[doc(alias = "AVAssetWriterStatusCompleted")]
38 pub const Completed: Self = Self(2);
39 #[doc(alias = "AVAssetWriterStatusFailed")]
40 pub const Failed: Self = Self(3);
41 #[doc(alias = "AVAssetWriterStatusCancelled")]
42 pub const Cancelled: Self = Self(4);
43}
44
45unsafe impl Encode for AVAssetWriterStatus {
46 const ENCODING: Encoding = NSInteger::ENCODING;
47}
48
49unsafe impl RefEncode for AVAssetWriterStatus {
50 const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
51}
52
53extern_class!(
54 /// AVAssetWriter provides services for writing media data to a new file,
55 ///
56 ///
57 /// Instances of AVAssetWriter can write media to new files in formats such as the QuickTime movie file format or the MPEG-4 file format. AVAssetWriter has support for automatic interleaving of media data for multiple concurrent tracks. Source media data can be obtained from instances of AVAssetReader for one or more assets or from other sources outside of AVFoundation.
58 ///
59 /// Instances of AVAssetWriter can re-encode media samples as they are written. Instances of AVAssetWriter can also optionally write metadata collections to the output file.
60 ///
61 /// A single instance of AVAssetWriter can be used once to write to a single file. Clients that wish to write to files multiple times must use a new instance of AVAssetWriter each time.
62 ///
63 /// See also [Apple's documentation](https://developer.apple.com/documentation/avfoundation/avassetwriter?language=objc)
64 #[unsafe(super(NSObject))]
65 #[derive(Debug, PartialEq, Eq, Hash)]
66 pub struct AVAssetWriter;
67);
68
69extern_conformance!(
70 unsafe impl NSObjectProtocol for AVAssetWriter {}
71);
72
73impl AVAssetWriter {
74 extern_methods!(
75 #[unsafe(method(init))]
76 #[unsafe(method_family = init)]
77 pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
78
79 #[unsafe(method(new))]
80 #[unsafe(method_family = new)]
81 pub unsafe fn new() -> Retained<Self>;
82
83 #[cfg(feature = "AVMediaFormat")]
84 /// Returns an instance of AVAssetWriter configured to write to a file in a specified container format.
85 ///
86 ///
87 /// Parameter `URL`: The location of the file to be written. The URL must be a file URL.
88 ///
89 /// Parameter `fileType`: A UTI indicating the format of the file to be written.
90 ///
91 /// Parameter `outError`: On return, if initialization of the AVAssetWriter fails, points to an NSError describing the nature of the failure.
92 ///
93 /// Returns: An instance of AVAssetWriter.
94 ///
95 ///
96 /// Writing will fail if a file already exists at the specified URL.
97 ///
98 /// UTIs for container formats that can be written are declared in AVMediaFormat.h.
99 #[unsafe(method(assetWriterWithURL:fileType:error:_))]
100 #[unsafe(method_family = none)]
101 pub unsafe fn assetWriterWithURL_fileType_error(
102 output_url: &NSURL,
103 output_file_type: &AVFileType,
104 ) -> Result<Retained<Self>, Retained<NSError>>;
105
106 #[cfg(feature = "AVMediaFormat")]
107 /// Creates an instance of AVAssetWriter configured to write to a file in a specified container format.
108 ///
109 ///
110 /// Parameter `URL`: The location of the file to be written. The URL must be a file URL.
111 ///
112 /// Parameter `fileType`: A UTI indicating the format of the file to be written.
113 ///
114 /// Parameter `outError`: On return, if initialization of the AVAssetWriter fails, points to an NSError describing the nature of the failure.
115 ///
116 /// Returns: An instance of AVAssetWriter.
117 ///
118 ///
119 /// Writing will fail if a file already exists at the specified URL.
120 ///
121 /// This method throws an exception if the output file type is not declared in AVMediaFormat.h.
122 #[unsafe(method(initWithURL:fileType:error:_))]
123 #[unsafe(method_family = init)]
124 pub unsafe fn initWithURL_fileType_error(
125 this: Allocated<Self>,
126 output_url: &NSURL,
127 output_file_type: &AVFileType,
128 ) -> Result<Retained<Self>, Retained<NSError>>;
129
130 #[cfg(feature = "objc2-uniform-type-identifiers")]
131 /// Creates an instance of AVAssetWriter configured to output segment data in a specified container format.
132 ///
133 ///
134 /// Parameter `outputContentType`: A UTType indicating the format of the segment data to be output.
135 ///
136 /// Returns: An instance of AVAssetWriter.
137 ///
138 ///
139 /// Clients that want to receive segment data through the -assetWriter:didOutputSegmentData:segmentType:segmentReport: or -assetWriter:didOutputSegmentData:segmentType: delegate method should use this initializer instead of -initWithURL:fileType:error:.
140 ///
141 /// Clients may use +typeWithIdentifier: with a UTI to create an instance of UTType. See
142 /// <UniformTypeIdentifiers
143 /// /UTType.h>.
144 ///
145 /// This method throws an exception if the output content type UTI for container format is not declared in AVMediaFormat.h.
146 #[unsafe(method(initWithContentType:))]
147 #[unsafe(method_family = init)]
148 pub unsafe fn initWithContentType(
149 this: Allocated<Self>,
150 output_content_type: &UTType,
151 ) -> Retained<Self>;
152
153 /// The location of the file for which the instance of AVAssetWriter was initialized for writing.
154 ///
155 /// You may use [[UTType typeWithIdentifier:outputFileType] preferredFilenameExtension] to obtain an appropriate path extension for the outputFileType you have specified. For more information, see
156 /// <UniformTypeIdentifiers
157 /// /UTType.h>.
158 #[unsafe(method(outputURL))]
159 #[unsafe(method_family = none)]
160 pub unsafe fn outputURL(&self) -> Retained<NSURL>;
161
162 #[cfg(feature = "AVMediaFormat")]
163 /// The UTI of the file format of the file for which the instance of AVAssetWriter was initialized for writing.
164 #[unsafe(method(outputFileType))]
165 #[unsafe(method_family = none)]
166 pub unsafe fn outputFileType(&self) -> Retained<AVFileType>;
167
168 #[cfg(feature = "AVMediaFormat")]
169 /// The media types for which inputs can be added to the receiver.
170 ///
171 ///
172 /// Some media types may not be accepted within the file format with which an AVAssetWriter was initialized.
173 #[unsafe(method(availableMediaTypes))]
174 #[unsafe(method_family = none)]
175 pub unsafe fn availableMediaTypes(&self) -> Retained<NSArray<AVMediaType>>;
176
177 /// The status of writing samples to the receiver's output file.
178 ///
179 ///
180 /// The value of this property is an AVAssetWriterStatus that indicates whether writing is in progress, has completed successfully, has been canceled, or has failed. Clients of AVAssetWriterInput objects should check the value of this property after appending samples fails to determine why no more samples could be written. This property is thread safe.
181 #[unsafe(method(status))]
182 #[unsafe(method_family = none)]
183 pub unsafe fn status(&self) -> AVAssetWriterStatus;
184
185 /// If the receiver's status is AVAssetWriterStatusFailed, this describes the error that caused the failure.
186 ///
187 ///
188 /// The value of this property is an NSError that describes what caused the receiver to no longer be able to write to its output file. If the receiver's status is not AVAssetWriterStatusFailed, the value of this property is nil. This property is thread safe.
189 #[unsafe(method(error))]
190 #[unsafe(method_family = none)]
191 pub unsafe fn error(&self) -> Option<Retained<NSError>>;
192
193 #[cfg(feature = "AVMetadataItem")]
194 /// A collection of metadata to be written to the receiver's output file.
195 ///
196 ///
197 /// The value of this property is an array of AVMetadataItem objects representing the collection of top-level metadata to be written in the output file.
198 ///
199 /// This property cannot be set after writing has started.
200 #[unsafe(method(metadata))]
201 #[unsafe(method_family = none)]
202 pub unsafe fn metadata(&self) -> Retained<NSArray<AVMetadataItem>>;
203
204 #[cfg(feature = "AVMetadataItem")]
205 /// Setter for [`metadata`][Self::metadata].
206 ///
207 /// This is [copied][objc2_foundation::NSCopying::copy] when set.
208 #[unsafe(method(setMetadata:))]
209 #[unsafe(method_family = none)]
210 pub unsafe fn setMetadata(&self, metadata: &NSArray<AVMetadataItem>);
211
212 /// Specifies whether the output file should be written in way that makes it more suitable for playback over a network
213 ///
214 ///
215 /// When the value of this property is YES, the output file will be written in such a way that playback can start after only a small amount of the file is downloaded.
216 ///
217 /// This property cannot be set after writing has started.
218 #[unsafe(method(shouldOptimizeForNetworkUse))]
219 #[unsafe(method_family = none)]
220 pub unsafe fn shouldOptimizeForNetworkUse(&self) -> bool;
221
222 /// Setter for [`shouldOptimizeForNetworkUse`][Self::shouldOptimizeForNetworkUse].
223 #[unsafe(method(setShouldOptimizeForNetworkUse:))]
224 #[unsafe(method_family = none)]
225 pub unsafe fn setShouldOptimizeForNetworkUse(&self, should_optimize_for_network_use: bool);
226
227 /// Specifies a directory that is suitable for containing temporary files generated during the process of writing an asset.
228 ///
229 ///
230 /// AVAssetWriter may need to write temporary files when configured in certain ways, such as when performsMultiPassEncodingIfSupported is set to YES on one or more of its inputs. This property can be used to control where in the filesystem those temporary files are created. All temporary files will be deleted when asset writing is completed, is canceled, or fails.
231 ///
232 /// When the value of this property is nil, the asset writer will choose a suitable location when writing temporary files. The default value is nil.
233 ///
234 /// This property cannot be set after writing has started. The asset writer will fail if a file cannot be created in this directory (for example, due to insufficient permissions).
235 #[unsafe(method(directoryForTemporaryFiles))]
236 #[unsafe(method_family = none)]
237 pub unsafe fn directoryForTemporaryFiles(&self) -> Option<Retained<NSURL>>;
238
239 /// Setter for [`directoryForTemporaryFiles`][Self::directoryForTemporaryFiles].
240 ///
241 /// This is [copied][objc2_foundation::NSCopying::copy] when set.
242 #[unsafe(method(setDirectoryForTemporaryFiles:))]
243 #[unsafe(method_family = none)]
244 pub unsafe fn setDirectoryForTemporaryFiles(
245 &self,
246 directory_for_temporary_files: Option<&NSURL>,
247 );
248
249 #[cfg(feature = "AVAssetWriterInput")]
250 /// The inputs from which the asset writer receives media data.
251 ///
252 /// The value of this property is an NSArray containing concrete instances of AVAssetWriterInput. Inputs can be added to the receiver using the addInput: method.
253 #[unsafe(method(inputs))]
254 #[unsafe(method_family = none)]
255 pub unsafe fn inputs(&self) -> Retained<NSArray<AVAssetWriterInput>>;
256
257 #[cfg(feature = "AVMediaFormat")]
258 /// Tests whether output settings for a specific media type are supported by the receiver's file format.
259 ///
260 ///
261 /// Parameter `outputSettings`: The output settings that are to be tested.
262 ///
263 /// Parameter `mediaType`: The media type for which the output settings are to be tested. Media types are defined in AVMediaFormat.h.
264 ///
265 /// Returns: A BOOL indicating whether the given output settings can be used for the given media type.
266 ///
267 ///
268 /// This method determines whether the output settings for the specified media type can be used with the receiver's file format. For example, video compression settings that specify H.264 compression are not compatible with file formats that cannot contain H.264-compressed video.
269 ///
270 /// Attempting to add an input with output settings and a media type for which this method returns NO will cause an exception to be thrown.
271 ///
272 /// # Safety
273 ///
274 /// `output_settings` generic should be of the correct type.
275 #[unsafe(method(canApplyOutputSettings:forMediaType:))]
276 #[unsafe(method_family = none)]
277 pub unsafe fn canApplyOutputSettings_forMediaType(
278 &self,
279 output_settings: Option<&NSDictionary<NSString, AnyObject>>,
280 media_type: &AVMediaType,
281 ) -> bool;
282
283 #[cfg(feature = "AVAssetWriterInput")]
284 /// Tests whether an input can be added to the receiver.
285 ///
286 ///
287 /// Parameter `input`: The AVAssetWriterInput object to be tested.
288 ///
289 /// Returns: A BOOL indicating whether the input can be added to the receiver.
290 ///
291 ///
292 /// An input that accepts media data of a type that is not compatible with the receiver, or with output settings that are not compatible with the receiver, cannot be added.
293 #[unsafe(method(canAddInput:))]
294 #[unsafe(method_family = none)]
295 pub unsafe fn canAddInput(&self, input: &AVAssetWriterInput) -> bool;
296
297 #[cfg(feature = "AVAssetWriterInput")]
298 /// Adds an input to the receiver.
299 ///
300 ///
301 /// Parameter `input`: The AVAssetWriterInput object to be added.
302 ///
303 ///
304 /// Inputs are created with a media type and output settings. These both must be compatible with the receiver.
305 ///
306 /// Inputs cannot be added after writing has started.
307 ///
308 /// This method throws an exception if any of the following conditions are satisfied:
309 /// - the input's media type is not allowed for this asset writer
310 /// - writing uncompressed video in a specific format
311 /// - passthrough* to files (other than AVFileTypeQuickTimeMovie) is missing a format hint in the AVAssetWriterInput initializer
312 /// - passthrough* is not supported for this media/file type combination (for example, AVFileTypeWAVE only supports AVMediaTypeAudio)
313 ///
314 /// Passthrough is indicated when the input's output settings are nil.
315 #[unsafe(method(addInput:))]
316 #[unsafe(method_family = none)]
317 pub unsafe fn addInput(&self, input: &AVAssetWriterInput);
318
319 /// Prepares the receiver for accepting input and for writing its output to its output file.
320 ///
321 ///
322 /// Returns: A BOOL indicating whether writing successfully started.
323 ///
324 ///
325 /// This method must be called after all inputs have been added and other configuration properties have been set in order to tell the receiver to prepare for writing. After this method is called, clients can start writing sessions using startSessionAtSourceTime: and can write media samples using the methods provided by each of the receiver's inputs.
326 ///
327 /// If writing cannot be started, this method returns NO. Clients can check the values of the status and error properties for more information on why writing could not be started.
328 ///
329 /// On iOS, if the status of an AVAssetWriter is AVAssetWriterStatusWriting when the client app goes into the background, its status will change to AVAssetWriterStatusFailed and appending to any of its inputs will fail. You may want to use -[UIApplication beginBackgroundTaskWithExpirationHandler:] to avoid being interrupted in the middle of a writing session and to finish writing the data that has already been appended. For more information about executing code in the background, see the iOS Application Programming Guide.
330 #[unsafe(method(startWriting))]
331 #[unsafe(method_family = none)]
332 pub unsafe fn startWriting(&self) -> bool;
333
334 #[cfg(feature = "objc2-core-media")]
335 /// Initiates a sample-writing session for the receiver.
336 ///
337 ///
338 /// Parameter `startTime`: The starting asset time for the sample-writing session, in the timeline of the source samples.
339 ///
340 ///
341 /// Sequences of sample data appended to the asset writer inputs are considered to fall within "sample-writing sessions", initiated with this method. Accordingly, this method must be called after writing has started (using -startWriting) but before any sample data is appended to the receiver's inputs.
342 ///
343 /// Each writing session has a start time which, where allowed by the file format being written, defines the mapping from the timeline of source samples to the timeline of the written file. In the case of the QuickTime movie file format, the first session begins at movie time 0, so a sample appended with timestamp T will be played at movie time (T-startTime). Samples with timestamps earlier than startTime will still be added to the output file but will be edited out (i.e. not presented during playback). If the earliest appended sample for an input has a timestamp later than than startTime, an empty edit will be inserted to preserve synchronization between tracks of the output asset.
344 ///
345 /// To end the session started by use of this method, use -endSessionAtSourceTime: or -finishWritingWithCompletionHandler:. It is an error to invoke -startSessionAtSourceTime: twice in a row without invoking -endSessionAtSourceTime: in between.
346 ///
347 /// NOTE: Multiple sample-writing sessions are currently not supported. It is an error to call -startSessionAtSourceTime: a second time after calling -endSessionAtSourceTime:.
348 #[unsafe(method(startSessionAtSourceTime:))]
349 #[unsafe(method_family = none)]
350 pub unsafe fn startSessionAtSourceTime(&self, start_time: CMTime);
351
352 #[cfg(feature = "objc2-core-media")]
353 /// Concludes a sample-writing session.
354 ///
355 ///
356 /// Parameter `endTime`: The ending asset time for the sample-writing session, in the timeline of the source samples.
357 ///
358 ///
359 /// Call this method to complete a session started with -startSessionAtSourceTime:.
360 ///
361 /// The endTime defines the moment on the timeline of source samples at which the session ends. In the case of the QuickTime movie file format, each sample-writing session's startTime...endTime pair corresponds to a period of movie time into which the session's samples are inserted. Samples with timestamps that are later than the session end time will still be added to the written file but will be edited out (i.e. not presented during playback). So if the first session has duration D1 = endTime - startTime, it will be inserted into the written file at time 0 through D1; the second session would be inserted into the written file at time D1 through D1+D2, etc. It is legal to have a session with no samples; this will cause creation of an empty edit of the prescribed duration.
362 ///
363 /// It is not mandatory to call -endSessionAtSourceTime:; if -finishWritingWithCompletionHandler: is called without first invoking -endSessionAtSourceTime:, the session's effective end time will be the latest end timestamp of the session's appended samples (i.e. no samples will be edited out at the end).
364 ///
365 /// It is an error to append samples outside of a sample-writing session. To append more samples after invoking -endSessionAtSourceTime:, you must first start a new session using -startSessionAtSourceTime:.
366 ///
367 /// NOTE: Multiple sample-writing sessions are currently not supported. It is an error to call -startSessionAtSourceTime: a second time after calling -endSessionAtSourceTime:.
368 ///
369 /// This method throws an exception if the session is ended without first starting it.
370 #[unsafe(method(endSessionAtSourceTime:))]
371 #[unsafe(method_family = none)]
372 pub unsafe fn endSessionAtSourceTime(&self, end_time: CMTime);
373
374 /// Cancels the creation of the output file.
375 ///
376 ///
377 /// If the status of the receiver is "failed" or "completed," -cancelWriting is a no-op. Otherwise, this method will block until writing is canceled.
378 ///
379 /// If an output file was created by the receiver during the writing process, -cancelWriting will delete the file.
380 ///
381 /// This method should not be called concurrently with -[AVAssetWriterInput appendSampleBuffer:] or -[AVAssetWriterInputPixelBufferAdaptor appendPixelBuffer:withPresentationTime:].
382 #[unsafe(method(cancelWriting))]
383 #[unsafe(method_family = none)]
384 pub unsafe fn cancelWriting(&self);
385
386 /// Completes the writing of the output file.
387 ///
388 ///
389 /// Returns: A BOOL indicating whether writing successfully finished.
390 ///
391 ///
392 /// This method is deprecated. Use finishWritingWithCompletionHandler: instead.
393 ///
394 /// This method will block until writing is finished. When this method returns successfully, the file being written by the receiver is complete and ready to use.
395 ///
396 /// Because this method is blocking and can take a long time to execute (especially with shouldOptimizeForNetworkUse set to YES), it should not be called from the main thread. Doing so can cause the finishWriting operation to fail.
397 ///
398 /// If writing cannot be finished, this method returns NO. Clients can check the values of the status and error properties for more information on why writing could not be finished.
399 ///
400 /// This method should not be called concurrently with -[AVAssetWriterInput appendSampleBuffer:] or -[AVAssetWriterInputPixelBufferAdaptor appendPixelBuffer:withPresentationTime:].
401 #[deprecated]
402 #[unsafe(method(finishWriting))]
403 #[unsafe(method_family = none)]
404 pub unsafe fn finishWriting(&self) -> bool;
405
406 #[cfg(feature = "block2")]
407 /// Marks all unfinished inputs as finished and completes the writing of the output file.
408 ///
409 ///
410 /// This method returns immediately and causes its work to be performed asynchronously.
411 ///
412 /// When the writing of the output file is finished, or if a failure or a cancellation occurs in the meantime, the specified handler will be invoked to indicate completion of the operation. To determine whether the operation succeeded, your handler can check the value of AVAssetWriter.status. If the status is AVAssetWriterStatusFailed, AVAsset.error will contain an instance of NSError that describes the failure.
413 ///
414 /// To guarantee that all sample buffers are successfully written, ensure all calls to -[AVAssetWriterInput appendSampleBuffer:] or -[AVAssetWriterInputPixelBufferAdaptor appendPixelBuffer:withPresentationTime:] have returned before invoking this method.
415 ///
416 /// # Safety
417 ///
418 /// `handler` block must be sendable.
419 #[unsafe(method(finishWritingWithCompletionHandler:))]
420 #[unsafe(method_family = none)]
421 pub unsafe fn finishWritingWithCompletionHandler(
422 &self,
423 handler: &block2::DynBlock<dyn Fn()>,
424 );
425 );
426}
427
428/// AVAssetWriterFileTypeSpecificProperties.
429impl AVAssetWriter {
430 extern_methods!(
431 #[cfg(feature = "objc2-core-media")]
432 /// For file types that support movie fragments, specifies the frequency at which movie fragments should be written.
433 ///
434 ///
435 /// When movie fragments are used, a partially written asset whose writing is unexpectedly interrupted can be successfully opened and played up to multiples of the specified time interval. The default value of this property is kCMTimeInvalid, which indicates that movie fragments should not be used.
436 ///
437 /// When using movie fragments, for best writing performance to external storage devices, set the movieFragmentInterval to 10 seconds or greater.
438 ///
439 /// This property cannot be set after writing has started.
440 #[unsafe(method(movieFragmentInterval))]
441 #[unsafe(method_family = none)]
442 pub unsafe fn movieFragmentInterval(&self) -> CMTime;
443
444 #[cfg(feature = "objc2-core-media")]
445 /// Setter for [`movieFragmentInterval`][Self::movieFragmentInterval].
446 #[unsafe(method(setMovieFragmentInterval:))]
447 #[unsafe(method_family = none)]
448 pub unsafe fn setMovieFragmentInterval(&self, movie_fragment_interval: CMTime);
449
450 #[cfg(feature = "objc2-core-media")]
451 /// For file types that support movie fragments, specifies the interval at which initial movie fragment should be written.
452 ///
453 ///
454 /// This property is irrelevant if the movieFragmentInterval property is not set. The default value is kCMTimeInvalid, which indicates that the interval for initial movie fragment is same as the one specified by movieFragmentInterval property.
455 ///
456 /// This property cannot be set after writing has started.
457 #[unsafe(method(initialMovieFragmentInterval))]
458 #[unsafe(method_family = none)]
459 pub unsafe fn initialMovieFragmentInterval(&self) -> CMTime;
460
461 #[cfg(feature = "objc2-core-media")]
462 /// Setter for [`initialMovieFragmentInterval`][Self::initialMovieFragmentInterval].
463 #[unsafe(method(setInitialMovieFragmentInterval:))]
464 #[unsafe(method_family = none)]
465 pub unsafe fn setInitialMovieFragmentInterval(
466 &self,
467 initial_movie_fragment_interval: CMTime,
468 );
469
470 /// For file types that support movie fragments, specifies the initial movie fragment sequence number.
471 ///
472 ///
473 /// The value must be equal to or greater than 1.
474 ///
475 /// The default value is 1.
476 ///
477 /// Note that if you combine movie fragments produced by an instance of AVAssetWriter with additional movie fragments, produced either by a different instance of AVAssetWriter or by some other means, it is necessary to ensure that movie fragment sequence numbers increase monotonically across the entire combined collection, in temporal order.
478 ///
479 /// This property cannot be set after writing has started.
480 #[unsafe(method(initialMovieFragmentSequenceNumber))]
481 #[unsafe(method_family = none)]
482 pub unsafe fn initialMovieFragmentSequenceNumber(&self) -> NSInteger;
483
484 /// Setter for [`initialMovieFragmentSequenceNumber`][Self::initialMovieFragmentSequenceNumber].
485 #[unsafe(method(setInitialMovieFragmentSequenceNumber:))]
486 #[unsafe(method_family = none)]
487 pub unsafe fn setInitialMovieFragmentSequenceNumber(
488 &self,
489 initial_movie_fragment_sequence_number: NSInteger,
490 );
491
492 /// For file types that support fragmented MPEG-4, specifies whether the movie fragments should be produced in way that makes them suitable for combining with movie fragments produced by one or more other instances of AVAssetWriter into a single fragment stream of uniform encoding.
493 ///
494 ///
495 /// The default value is NO.
496 ///
497 /// When multiple instances of AVAssetWriter are used to produce distinct streams that complement each other, for example to create HLS encoding or bitrate variants, it’s not necessary to set this property to YES.
498 ///
499 /// This property cannot be set after writing has started.
500 #[unsafe(method(producesCombinableFragments))]
501 #[unsafe(method_family = none)]
502 pub unsafe fn producesCombinableFragments(&self) -> bool;
503
504 /// Setter for [`producesCombinableFragments`][Self::producesCombinableFragments].
505 #[unsafe(method(setProducesCombinableFragments:))]
506 #[unsafe(method_family = none)]
507 pub unsafe fn setProducesCombinableFragments(&self, produces_combinable_fragments: bool);
508
509 #[cfg(feature = "objc2-core-media")]
510 /// For file types that support movie fragments, provides a hint of the final duration of the file to be written
511 ///
512 ///
513 /// The value of this property must be a nonnegative, numeric CMTime. Alternatively, if the value of this property is an invalid CMTime (e.g. kCMTimeInvalid), no overall duration hint will be written to the file. The default value is kCMTimeInvalid.
514 ///
515 /// This property is currently ignored if movie fragments are not being written. Use the movieFragmentInterval property to enable movie fragments.
516 ///
517 /// This property cannot be set after writing has started.
518 #[unsafe(method(overallDurationHint))]
519 #[unsafe(method_family = none)]
520 pub unsafe fn overallDurationHint(&self) -> CMTime;
521
522 #[cfg(feature = "objc2-core-media")]
523 /// Setter for [`overallDurationHint`][Self::overallDurationHint].
524 #[unsafe(method(setOverallDurationHint:))]
525 #[unsafe(method_family = none)]
526 pub unsafe fn setOverallDurationHint(&self, overall_duration_hint: CMTime);
527
528 #[cfg(feature = "objc2-core-media")]
529 /// For file types that contain a 'moov' atom, such as QuickTime Movie files, specifies the asset-level time scale to be used.
530 ///
531 ///
532 /// The default value is 0, which indicates that the receiver should choose a convenient value, if applicable.
533 ///
534 /// This property cannot be set after writing has started.
535 #[unsafe(method(movieTimeScale))]
536 #[unsafe(method_family = none)]
537 pub unsafe fn movieTimeScale(&self) -> CMTimeScale;
538
539 #[cfg(feature = "objc2-core-media")]
540 /// Setter for [`movieTimeScale`][Self::movieTimeScale].
541 #[unsafe(method(setMovieTimeScale:))]
542 #[unsafe(method_family = none)]
543 pub unsafe fn setMovieTimeScale(&self, movie_time_scale: CMTimeScale);
544 );
545}
546
547/// AVAssetWriterInputGroups.
548impl AVAssetWriter {
549 extern_methods!(
550 #[cfg(feature = "AVMediaSelectionGroup")]
551 /// Tests whether an input group can be added to the receiver.
552 ///
553 ///
554 /// Parameter `inputGroup`: The AVAssetWriterInputGroup object to be tested.
555 ///
556 /// Returns: A BOOL indicating whether the input group can be added to the receiver.
557 ///
558 ///
559 /// If outputFileType specifies a container format that does not support mutually exclusive relationships among tracks, or if the specified instance of AVAssetWriterInputGroup contains inputs with media types that cannot be related, the group cannot be added to the AVAssetWriter.
560 ///
561 /// This method throws an exception if any of the following conditions are satisfied:
562 /// - this writer's output file type does not support mutually exclusive relationships among tracks (allowed types are AVFileTypeQuickTimeMovie, AVFileTypeAppleM4A, AVFileTypeAppleM4V, AVFileType3GPP, AVFileTypeMPEG4)
563 /// - any AVAssetWriterInput in the input group is also present in an input group already added
564 #[unsafe(method(canAddInputGroup:))]
565 #[unsafe(method_family = none)]
566 pub unsafe fn canAddInputGroup(&self, input_group: &AVAssetWriterInputGroup) -> bool;
567
568 #[cfg(feature = "AVMediaSelectionGroup")]
569 #[unsafe(method(addInputGroup:))]
570 #[unsafe(method_family = none)]
571 pub unsafe fn addInputGroup(&self, input_group: &AVAssetWriterInputGroup);
572
573 #[cfg(feature = "AVMediaSelectionGroup")]
574 /// The instances of AVAssetWriterInputGroup that have been added to the AVAssetWriter.
575 ///
576 ///
577 /// The value of this property is an NSArray containing concrete instances of AVAssetWriterInputGroup. Input groups can be added to the receiver using the addInputGroup: method.
578 #[unsafe(method(inputGroups))]
579 #[unsafe(method_family = none)]
580 pub unsafe fn inputGroups(&self) -> Retained<NSArray<AVAssetWriterInputGroup>>;
581 );
582}
583
584extern_class!(
585 /// [Apple's documentation](https://developer.apple.com/documentation/avfoundation/avassetwriterinputgroup?language=objc)
586 #[unsafe(super(AVMediaSelectionGroup, NSObject))]
587 #[derive(Debug, PartialEq, Eq, Hash)]
588 #[cfg(feature = "AVMediaSelectionGroup")]
589 pub struct AVAssetWriterInputGroup;
590);
591
592#[cfg(feature = "AVMediaSelectionGroup")]
593extern_conformance!(
594 unsafe impl NSCopying for AVAssetWriterInputGroup {}
595);
596
597#[cfg(feature = "AVMediaSelectionGroup")]
598unsafe impl CopyingHelper for AVAssetWriterInputGroup {
599 type Result = Self;
600}
601
602#[cfg(feature = "AVMediaSelectionGroup")]
603extern_conformance!(
604 unsafe impl NSObjectProtocol for AVAssetWriterInputGroup {}
605);
606
607#[cfg(feature = "AVMediaSelectionGroup")]
608impl AVAssetWriterInputGroup {
609 extern_methods!(
610 #[unsafe(method(init))]
611 #[unsafe(method_family = init)]
612 pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
613
614 #[unsafe(method(new))]
615 #[unsafe(method_family = new)]
616 pub unsafe fn new() -> Retained<Self>;
617
618 #[cfg(feature = "AVAssetWriterInput")]
619 #[unsafe(method(assetWriterInputGroupWithInputs:defaultInput:))]
620 #[unsafe(method_family = none)]
621 pub unsafe fn assetWriterInputGroupWithInputs_defaultInput(
622 inputs: &NSArray<AVAssetWriterInput>,
623 default_input: Option<&AVAssetWriterInput>,
624 ) -> Retained<Self>;
625
626 #[cfg(feature = "AVAssetWriterInput")]
627 #[unsafe(method(initWithInputs:defaultInput:))]
628 #[unsafe(method_family = init)]
629 pub unsafe fn initWithInputs_defaultInput(
630 this: Allocated<Self>,
631 inputs: &NSArray<AVAssetWriterInput>,
632 default_input: Option<&AVAssetWriterInput>,
633 ) -> Retained<Self>;
634
635 #[cfg(feature = "AVAssetWriterInput")]
636 /// The inputs grouped together by the receiver.
637 ///
638 ///
639 /// The value of this property is an NSArray containing concrete instances of AVAssetWriterInput.
640 #[unsafe(method(inputs))]
641 #[unsafe(method_family = none)]
642 pub unsafe fn inputs(&self) -> Retained<NSArray<AVAssetWriterInput>>;
643
644 #[cfg(feature = "AVAssetWriterInput")]
645 /// The input designated at the defaultInput of the receiver.
646 ///
647 ///
648 /// The value of this property is a concrete instance of AVAssetWriterInput.
649 #[unsafe(method(defaultInput))]
650 #[unsafe(method_family = none)]
651 pub unsafe fn defaultInput(&self) -> Option<Retained<AVAssetWriterInput>>;
652 );
653}
654
655/// AVAssetWriterSegmentation.
656impl AVAssetWriter {
657 extern_methods!(
658 #[cfg(feature = "objc2-core-media")]
659 /// Specifies preferred segment interval.
660 ///
661 ///
662 /// The default value is kCMTimeInvalid, which means that the receiver will choose an appropriate default value. The value can be set to positive numeric or kCMTimeIndefinite.
663 /// If the value is kCMTimeIndefinite, every time a client calls -flushSegment the receiver outputs a segment data.
664 ///
665 /// This property cannot be set after writing has started.
666 #[unsafe(method(preferredOutputSegmentInterval))]
667 #[unsafe(method_family = none)]
668 pub unsafe fn preferredOutputSegmentInterval(&self) -> CMTime;
669
670 #[cfg(feature = "objc2-core-media")]
671 /// Setter for [`preferredOutputSegmentInterval`][Self::preferredOutputSegmentInterval].
672 #[unsafe(method(setPreferredOutputSegmentInterval:))]
673 #[unsafe(method_family = none)]
674 pub unsafe fn setPreferredOutputSegmentInterval(
675 &self,
676 preferred_output_segment_interval: CMTime,
677 );
678
679 #[cfg(feature = "objc2-core-media")]
680 /// Specifies start time of initial segment.
681 ///
682 ///
683 /// A numeric time must be set if the value of preferredOutputSegmentInterval property is positive numeric. If not, this property is irrelevant.
684 ///
685 /// This property cannot be set after writing has started.
686 #[unsafe(method(initialSegmentStartTime))]
687 #[unsafe(method_family = none)]
688 pub unsafe fn initialSegmentStartTime(&self) -> CMTime;
689
690 #[cfg(feature = "objc2-core-media")]
691 /// Setter for [`initialSegmentStartTime`][Self::initialSegmentStartTime].
692 #[unsafe(method(setInitialSegmentStartTime:))]
693 #[unsafe(method_family = none)]
694 pub unsafe fn setInitialSegmentStartTime(&self, initial_segment_start_time: CMTime);
695
696 #[cfg(feature = "AVMediaFormat")]
697 /// Specifies a file type profile for the specified file type.
698 ///
699 ///
700 /// The default value is nil, which means that the receiver will choose an appropriate default profile based on the specified file type.
701 ///
702 /// Clients that want to receive segment data that is suitable for streaming through the -assetWriter:didOutputSegmentData:segmentType:segmentReport: or -assetWriter:didOutputSegmentData:segmentType: delegate method should set AVFileTypeProfileMPEG4AppleHLS, or AVFileTypeProfileMPEG4CMAFCompliant to require output that is specifically compliant with CMAF format, with AVFileTypeMPEG4 file type.
703 ///
704 /// File type profiles are declared in AVMediaFormat.h.
705 ///
706 /// This property cannot be set after writing has started.
707 #[unsafe(method(outputFileTypeProfile))]
708 #[unsafe(method_family = none)]
709 pub unsafe fn outputFileTypeProfile(&self) -> Option<Retained<AVFileTypeProfile>>;
710
711 #[cfg(feature = "AVMediaFormat")]
712 /// Setter for [`outputFileTypeProfile`][Self::outputFileTypeProfile].
713 ///
714 /// This is [copied][objc2_foundation::NSCopying::copy] when set.
715 #[unsafe(method(setOutputFileTypeProfile:))]
716 #[unsafe(method_family = none)]
717 pub unsafe fn setOutputFileTypeProfile(
718 &self,
719 output_file_type_profile: Option<&AVFileTypeProfile>,
720 );
721
722 /// An object that implements one or more of the methods in the AVAssetWriterDelegate protocol.
723 ///
724 ///
725 /// This property cannot be set after writing has started.
726 #[unsafe(method(delegate))]
727 #[unsafe(method_family = none)]
728 pub unsafe fn delegate(
729 &self,
730 ) -> Option<Retained<ProtocolObject<dyn AVAssetWriterDelegate>>>;
731
732 /// Setter for [`delegate`][Self::delegate].
733 ///
734 /// This is a [weak property][objc2::topics::weak_property].
735 #[unsafe(method(setDelegate:))]
736 #[unsafe(method_family = none)]
737 pub unsafe fn setDelegate(
738 &self,
739 delegate: Option<&ProtocolObject<dyn AVAssetWriterDelegate>>,
740 );
741
742 /// Closes the current segment and outputs it to the -assetWriter:didOutputSegmentData:segmentType:segmentReport: or -assetWriter:didOutputSegmentData:segmentType: delegate method.
743 ///
744 ///
745 /// This method throws an exception if the delegate method to output segment data is not implemented, or if the value of the preferredOutputSegmentInterval property is not kCMTimeIndefinite.
746 #[unsafe(method(flushSegment))]
747 #[unsafe(method_family = none)]
748 pub unsafe fn flushSegment(&self);
749 );
750}
751
752extern_protocol!(
753 /// [Apple's documentation](https://developer.apple.com/documentation/avfoundation/avassetwriterdelegate?language=objc)
754 pub unsafe trait AVAssetWriterDelegate: NSObjectProtocol + Send + Sync {
755 #[cfg(feature = "AVAssetSegmentReport")]
756 /// A method invoked when a segment data is output.
757 ///
758 ///
759 /// Parameter `writer`: An AVAssetWriter instance.
760 ///
761 /// Parameter `segmentData`: An instance of NSData containing a segment data.
762 ///
763 /// Parameter `segmentType`: A segment type of the segment data. Segment types are declared in AVAssetSegmentReport.h.
764 ///
765 /// Parameter `segmentReport`: An AVAssetSegmentReport instance.
766 ///
767 ///
768 /// If this method is implemented, normal file writing will be suppressed. The instance of AVAssetWriter must be initialized by -initWithContentType: initializer.
769 /// Then, clients append media data to AVAssetWriterInputs added to the receiver, call -markAsFinished for each input to mark the input as finished and call -finishWritingWithCompletionHandler: to finish writing as is the case in normal file writing.
770 ///
771 /// Do not use the movieFragmentInterval or shouldOptimizeForNetworkUse properties, as these properties are ignored in this mode of operation.
772 ///
773 /// Clients that need to reference the NSData outside of the scope of this method must retain or copy it and then release it when they are finished with it.
774 ///
775 /// The segmentReport provides information on the segment data. If there is no information available to report, the segmentReport may be nil.
776 /// Clients that do not need information on consecutive segment data should implement the -assetWriter:didOutputSegmentData:segmentType: method instead of this one for greater efficiency, as this will signal the receiver to skip the preparation of segment reports.
777 /// See more detailed description of AVAssetSegmentReport in AVAssetSegmentReport.h.
778 ///
779 /// If the file type is AVFileTypeMPEG4 and the outputFileTypeProfile is AVFileTypeProfileMPEG4AppleHLS or AVFileTypeProfileMPEG4CMAFCompliant, when the segmentType is AVAssetSegmentTypeInitialization, the segment contains a 'moov' atom that does not contain any sample tables other than the sample descriptions, and is suitable for use as an initialization segment for the following segment data sequences.
780 /// When the segmentType is AVAssetSegmentTypeSeparable, the segment contains a 'moof' atom that contains one 'moof' atom followed by one 'mdat' atom.
781 ///
782 /// 1. If the value of preferredOutputSegmentInterval property is positive numeric, when (a sample's output PTS - InitialSegmentStartTime) >= (interval * N) (N = 1, 2, 3...), the receiver waits for next sync sample and outputs a segment data that includes all samples appended since the previous interval to the delegate method when the sync sample appears, so that the next segment can start with the sync sample.
783 /// In this configuration, passthrough (by passing nil to output settings for AVAssetWriterInputs) and compression are available. The media type of input can be AVMediaTypeVideo or AVMediaTypeAudio.
784 /// Only one input of each media type can be added for compression and when (a sample's PTS - InitialSegmentStartTime) >= (interval * N) (N = 1, 2, 3...), the sample will be forced to be encoded as sync sample so that the current segment will be closed immediately.
785 /// For passthrough, only one input can be added.
786 ///
787 /// 2. If the value of preferredOutputSegmentInterval property is kCMTimeIndefinite, every time a client calls -flushSegment the receiver outputs a segment data that includes all samples appended since the previous call to the delegate method.
788 /// The delegate method may be called asynchronously, on a different thread from the one that calls -flushSegment.
789 /// In this configuration, only passthrough is available. The media type of input can be AVMediaTypeVideo or AVMediaTypeAudio.
790 /// Only one input of each media type can be added.
791 /// The client should call -flushSegment prior to a sync sample so that the next segment can start with the sync sample. Otherwise, it is an error.
792 #[optional]
793 #[unsafe(method(assetWriter:didOutputSegmentData:segmentType:segmentReport:))]
794 #[unsafe(method_family = none)]
795 unsafe fn assetWriter_didOutputSegmentData_segmentType_segmentReport(
796 &self,
797 writer: &AVAssetWriter,
798 segment_data: &NSData,
799 segment_type: AVAssetSegmentType,
800 segment_report: Option<&AVAssetSegmentReport>,
801 );
802
803 #[cfg(feature = "AVAssetSegmentReport")]
804 /// A method invoked when a segment data is output.
805 ///
806 ///
807 /// Parameter `writer`: An AVAssetWriter instance.
808 ///
809 /// Parameter `segmentData`: An instance of NSData containing a segment data.
810 ///
811 /// Parameter `segmentType`: A segment type of the segment data. Segment types are declared in AVAssetSegmentReport.h.
812 ///
813 ///
814 /// The usage of this method is same as -assetWriter:didOutputSegmentData:segmentType:segmentReport: except that this method does not deliver AVAssetSegmentReport.
815 ///
816 /// If clients implement the -assetWriter:didOutputSegmentData:segmentType:segmentReport: method, that method is called instead of this one.
817 #[optional]
818 #[unsafe(method(assetWriter:didOutputSegmentData:segmentType:))]
819 #[unsafe(method_family = none)]
820 unsafe fn assetWriter_didOutputSegmentData_segmentType(
821 &self,
822 writer: &AVAssetWriter,
823 segment_data: &NSData,
824 segment_type: AVAssetSegmentType,
825 );
826 }
827);