2

I have a 30-second 240fps video from my GoPro Hero10. Now I want to create a "slow-motion" out of it, which should be 1/4 speed. So the output would be 2 mins @ 60fps. (Sound should be converted, too - i know this makes this low pitch, that's ok)

After some research, I came up with this:

ffmpeg -i input.mp4 -filter_complex "[0:v]setpts=4.0*PTS[v];[0:a]atempo=0.5,atempo=0.5[a]" -map "[v]" -map "[a]" output-0.25.mp4

But after checking with ffmpeg -i output-0.25.mp4 I see, the fps is still 240 (although the length is correct, it is slo-mo, sound ok but filesize is quite big and - as said - too much fps for playback on target device).

So I searched again and came up to adding -r 60 so I end up with:

ffmpeg -i input.mp4 -filter_complex "[0:v]setpts=4.0*PTS[v];[0:a]atempo=0.5,atempo=0.5[a]" -map "[v]" -map "[a]" -r 60 output-0.25.mp4

Now the check shows also the correct fps, but it seems to be "less slo-mo" and the sound is scratchy.

What do i have to do?

All i want is "take all the original frames and stuff it into a file, which plays at 'normal speed'".

Jafix
  • 23

2 Answers2

1

There is the setpts mode and the convert to raw mode.

Using setpts would be something like this:

ffmpeg input.mkv -map_metadata -1 -filter_complex "[0:v:0]setpts=PTS*4[v];[0:a:0]atempo=0.5,atempo=0.5[a]" -map [v] -map [a] -c:v libx265 -vtag hvc1 -c:a libmp3lame -shortest "output.mp4"
  • use a good codec that reduces the file size like H.265 (libx265)
  • I suspect that because the videos metadata says 240 FPS on the original vídeo and the metadata is not deleted during the conversion the output video also shows 240 fps but is actually 60 FPS. The -map_metadata -1 option would remove the metadata.

Using the convert to raw mode would be something like this:

In this example I assume the original video is H.264 codec:

ffmpeg -i input.mp4 -map 0:v -c:v copy -bsf:v h264_mp4toannexb raw.h264
ffmpeg -fflags +genpts -r 60 -i "raw.h264" -i input.mp4 -map 0:v -map 1:a -filter:a "atempo=0.5,atempo=0.5" -c:v libx265 -vtag hvc1 "output.mp4"

In the first command the original video is converted to raw, in the second command new timestamps are generated making the video play 4x slower, adding the audio from the original video to the raw video, reducing the audio speed 4x times and finally converting the raw video to H.265 for smaller file size.

Sark
  • 506
1

Here is a solution without re-encoding the video:

  • Extract the video stream to HEVC (H.265) "raw" video stream:
    ffmpeg -y -an -i testfile.mp4 -c copy input_video.h265
  • Modify the tick_rate to 60 "ticks per second" using hevc_metadata bitstream filter:
    ffmpeg -y -i input_video.h265 -c copy -bsf:v hevc_metadata=tick_rate=60:num_ticks_poc_diff_one=1 input_video2.h265
  • Merge input_video2.h265 with the "slowed down" audio:
    ffmpeg -y -i input_video2.h265 -vn -i testfile.mp4 -map_metadata -1 -af "atempo=0.5,atempo=0.5" -c:v copy -vtag hvc1 -c:a aac -shortest "output.mp4"

The "slowed down" audio sounds strange, but I can't find a better solution than using atempo twice.

Rotem
  • 3,346