3

I want to save videos in slow motion through my android app.I tried to convert videos into slow motion by changing frame rate.

I used the following commands,first command is dumping 30 frames per second from videos to a temp directory, and then second command is using these images to create a video with reduced or faster frame rate and then i am deleting all the images from temp directory.

ffmpeg -i input_file.mp4 -r 30/1 img%03d.png

ffmpeg -framerate 15/1 -i img%03d.png -r 30 -pix_fmt yuv420p out4.mp4

But this is a very slow operation. It is taking like forever even for small videos.

I even tried to change PTS(presentation time stamp) of videos, but it is not working properly on android phones using this command:

ffmpeg -i input.mkv -filter:v "setpts=2.0*PTS" output.mkv

as suggested here: https://trac.ffmpeg.org/wiki/How%20to%20speed%20up%20/%20slow%20down%20a%20video

Can anybody suggest me how can i make it fast. Is it necessary to save frames to a temp directory, can i pass the output of ffmpeg process to another ffmpeg process executing concurrently through some method.

Is there any other ffmpeg command to save the videos in slow motion?

nkalra0123
  • 2,281
  • 16
  • 17
  • 1
    Your first method is not encouraged. See [here](http://blog.grio.com/2012/01/fast-and-slow-motion-video-with-ffmpeg.html) for more details. Also include the full console output for the second method which adjust `setpts` and which is important for us to guide you. What do you exactly mean by "not working properly"? – Chamath Jul 09 '15 at 06:14
  • By not working properly i mean audio is not in sync in processed video,it is not getting slowed down, If i remove audio by using filter -an , video is getting slow properly – nkalra0123 Aug 17 '15 at 16:13
  • Your approach will not slow down the audio tempo as expected. It is just for video. Use [atempo](https://ffmpeg.org/ffmpeg-all.html#atempo) to adjust the audio speed accordingly. – Chamath Aug 27 '15 at 10:35

1 Answers1

1

You just need to use below command to create slow motion video using ffmpeg-

String[] complexCommand = {"-y", "-i", inputFileAbsolutePath, "-filter_complex", "[0:v]setpts=2.0*PTS[v];[0:a]atempo=0.5[a]", "-map", "[v]", "-map", "[a]", "-b:v", "2097k", "-r", "60", "-vcodec", "mpeg4", outputFileAbsolutePath};

Check out this post on my blog for complete tutorial

Android Developer
  • 9,157
  • 18
  • 82
  • 139