The filter works by changing the presentation timestamp (PTS) of each video frame. To double the speed of the video, you can use: ffmpeg -i input.mkv -filter:v "setpts=0.5*PTS" output.mkv Note that in the following examples, the audio stream is not changed, so it should ideally be disabled with -an. You can change the speed of a video stream using the setpts video filter. Note that all of these options do require re-encoding the video. This is the guidance from the ffmpeg wiki. mkvmerge -default-duration 0:12fps -fix-bitstream-timing-information 0 original-video.mp4 -o temp-video.mkvįfmpeg -i temp-video.mkv -c:v copy -c:a aac -filter:a "atempo=0.5" slow-video-with-audio.mp4 The example below assumes the source video was 24 frames/second so that audio needed to be slowed to half (0.5) speed using ffmpeg's atempo filter. If the video contains audio you can also slow that down without changing the pitch, but it is not a lossless conversion. Here is an example that changes a video to 12 frames/second: mkvmerge -default-duration 0:12fps -fix-bitstream-timing-information 0 original-video.mp4 -o temp-video.mkvįfmpeg -i temp-video.mkv -c:v copy slow-video.mp4 ![]() It requires remuxing the file to a different containter format MKV and then remuxing it back into an MP4. Lossless (video) remuxingĪs noted in the comments there is a way to do this where the video does not You can slow down a 30 fps video and audio at the same time with:įfmpeg -fflags +genpts -r 15 -i raw.h264 -i input.mp4 -map 0:v -c:v copy -map 1:a -af atempo=0.5 -movflags faststart output.I know this is an old question but none of the current answers are the recommended way anymore. With the raw bitstream method example from above, there is no need for a complex filtergraph. Using a complex filtergraph, you can speed up video and audio at the same time:įfmpeg -i input.mkv -filter_complex "setpts=0.5*PTS atempo=2.0" -map "" -map "" output.mkv The following with quadruple the audio speed:įfmpeg -i input.mkv -filter:a "atempo=2.0,atempo=2.0" -vn output.mkv If you need to, you can get around this limitation by stringing multiple atempo filters together. The atempo filter is limited to using values between 0.5 and 2.0 (so it can slow it down to no less than half the original speed, and speed up to no more than double the input). To double the speed of audio:įfmpeg -i input.mkv -filter:a "atempo=2.0" -vn output.mkv You can speed up or slow down audio with the atempo audio filter. Other options include slowmoVideo and Butterflow. This is also known as "motion interpolation" or "optical flow".įfmpeg -i input.mkv -filter:v "minterpolate='mi_mode=mci:mc_mode=aobmc:vsbmc=1:fps=120'" output.mkv You can smooth out slow/fast video with the minterpolate video filter. To slow down your video, you have to use a multiplier greater than 1:įfmpeg -i input.mkv -filter:v "setpts=2.0*PTS" output.mkv For example, to go from an input of 4 FPS to one that is sped up to 4x that (16 FPS):įfmpeg -i input.mkv -r 16 -filter:v "setpts=0.25*PTS" output.mkv You can avoid dropped frames by specifying a higher output frame rate than the input. Note that this method will drop frames to achieve the desired speed. For example, if there are two succesive frames shown at timestamps 1 and 2, and you want to speed up the video, those timestamps need to become 0.5 and 1, respectively. To double the speed of the video with the setpts filter, you can use:įfmpeg -i input.mkv -filter:v "setpts=0.5*PTS" output.mkv ![]() ![]() ![]() Then generate new timestamps while muxing to a container:įfmpeg -fflags +genpts -r 30 -i raw.h264 -c:v copy output.mp4Ĭhange the value of -r to the desired playback frame rate. Use this if you require no other changes to your input video.įirst, copy the video to a raw bitstream format.įfmpeg -i input.mp4 -map 0:v -c:v copy -bsf:v h264_mp4toannexb raw.h264įfmpeg -i input.mp4 -map 0:v -c:v copy -bsf:v hevc_mp4toannexb raw.h265 This method is lossless and apart from changing the timestamps, copies the video stream as-is. This can be done via two methods: using the setpts video filter (which requires re-encoding) or by erasing the timestamps by exporting the video to a raw bitstream format and muxing to a container while creating new timestamps. The speed of a video stream can be changed by changing the presentation timestamp (PTS) of each video frame.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |