Simplified screen capture: record video of only what appears within the layers of a UIView?
Asked Answered
W

1

3

This SO answer addresses how to do a screen capture of a UIView. We need something similar, but instead of a single image, the goal is to produce a video of everything appearing within a UIView over 60 seconds -- conceptually like recording only the layers of that UIView, ignoring other layers.

Our video app superimposes layers on whatever the user is recording, and the ultimate goal is to produce a master video merging those layers with the original video. However, using AVVideoCompositionCoreAnimationTool to merge layers with the original video is very, very, very slow: exporting a 60-second video takes 10-20 seconds.

What we found is combining two videos (i.e., only using AVMutableComposition without AVVideoCompositionCoreAnimationTool) is very fast: ~ 1 second. The hope is to create an independent video of the layers and then combine that with the original video only using AVMutableComposition.

An answer in Swift is ideal but not required.

Worldly answered 22/1, 2016 at 22:4 Comment(3)
Can you expand on the fast AVMutableComposition-only combine? How fast? What do you mean by "combine" in this case?Arcade
In our testing merging videos with only AVMutableComposition meant a 60-second video could finish exporting in ~ 1 second (as opposed to 10-20 seconds with AVVideoCompositionCoreAnimationTool. The code merged videos by inserting videos into AVMutableCompositionTrack with insertTimeRange. Any suggestions? @RhythmicFistmanWorldly
@Worldly I might be asking similar question to yours. Did you end up resolving the issue you had? Here is my question, is it what you were trying to achieve as well? #50498171Caltrop
A
1

It sounds like your "fast" merge doesn't involve (re)-encoding frames, i.e. it's trivial and basically a glorified file concatenation, which is why it's getting 60x realtime. I asked about that because your "very slow" export is from 3-6 times realtime, which actually isn't that terrible (at least it wasn't on older hardware).

Encoding frames with an AVAssetWriter should give you an idea of the fastest possible non-trivial export and this may reveal that on modern hardware you could halve or quarter your export times.

This is a long way of saying that there might not be that much more performance to be had. If you think about the typical iOS video encoding use case, which would probably be recording 1920p @ 120 fps or 240 fps, your encoding at ~6x realtime @ 30fps is in the ballpark of what your typical iOS device "needs" to be able to do.

There are optimisations available to you (like lower/variable framerates), but these may lose you the convenience of being able to capture CALayers.

Arcade answered 23/1, 2016 at 0:45 Comment(1)
Thanks for the detailed answer. Since it seems like the glorified concatenation is the only way to achieve super fast times, this goes back to the original question of whether it's possible to create a video of the contents of a single UIView, not the entire screen. Because then we could do the "fast merge" and effectively reduce export time. Is it possible to record video from a single UIView without AVVideoCompositionCoreAnimationTool?Worldly

© 2022 - 2024 — McMap. All rights reserved.