Making a real slow motion video that slows things down

I create this application for my and removable videos at a speed of 120 and 240 frames per second.

When I watch these videos on my mac, I see these markers below the timeline.

enter image description here

These markers are editable and represent an area that is in slow motion. Thus, the video starts at the normal frame rate, enters into slow motion and returns to the normal frame rate at the end. I do not put these markers there, iOS. In this case, I wonder if there is a way to remove them and make the video completely slow.

I just initialize AVAssetWriter as usual for video without slowdown.

In addition, I noticed that these slow-motion videos are not very slow, but they are slow-motion recipes that play correctly on iOS and Mac devices using QuickTime X. Even QuickTime 7 does not play them correctly.

In any case, to make this thing a real slow motion that can be played on any player, on any computer?

+5
source share
1 answer

Your slow-motion video files are actually only high-frame video files. iOS slows down the playback speed to show extra frames in slow motion. The problem is that other players play at a playback speed of 1, so to make the effect portable, you need to change the timestamps of the frame view.

Maybe you can do it with AVMutableComposition , but I prefer to use more wysiwyg AVAssetReader / AVAssetWriter . Something like this for every frame in the input file:

 if let inSampleBuffer = readerOutput.copyNextSampleBuffer() { let inTimeStamp = CMSampleBufferGetPresentationTimeStamp(inSampleBuffer) let outTimeStamp = CMTimeMultiplyByFloat64(inTimeStamp, 30.0/240) // slow 240 fps down to 30fps (8x slowmo) var outSampleBuffer: CMSampleBuffer? var outTimingInfo = CMSampleTimingInfo(duration: kCMTimeInvalid, presentationTimeStamp: outTimeStamp, decodeTimeStamp: kCMTimeInvalid) if CMSampleBufferCreateCopyWithNewTiming(kCFAllocatorDefault, inSampleBuffer, 1, &outTimingInfo, &outSampleBuffer) == noErr { writerInput.appendSampleBuffer(outSampleBuffer!) } } else { // finished } 
+2
source

Source: https://habr.com/ru/post/1266790/


All Articles