Jump to content
Tuts 4 You

Do you know any frame rate calculator?


Recommended Posts

Hi guys,

I'am looking for any tool to calc a video frame rate from a new audio stream lenght.Just found nothing yet also nothing I could use with ffmpeg how to stretch a video stream lenght into audio stream lenght.

So the task is pretty simple.

1.) I have a video with a lenght of 1 minute and a frame rate of 25 fps

2.) I have a audio with a lenght higher or lower than 1 minute = both stream lenghts differ

3.) Now I wanna  match both streams into same lenght of the audio lenght (audio must keep original lenght)

I thought there would be any ffmpeg command to do this task but found nothing (only how to speedup audio or video).When I do use VirtualDub/2 I can load a video and see its frame rate X.Now I can add a audio stream with any lenght Y and make both same I can use the frame rate adjustment option in VD called "change so video and audio durations match" to stretch the video to audio lenght what changes the video frame rate to higher or lower rate.So this I wanna do with ffmpeg.Does anyone know how without to calc a new frame rate manually before or checking this in VD etc?

Otherwise I would like to find any small tool with thos calc options to set video frame rate of original video & a time X to calc out the needed frame rate I have to use to match the video to audio lenght.On internet I just found some bitrate calc but nothing for this task yet.

Calculation would be like this....(I think so / just testet a little around)

AllFrames / Default_FPS = TimeLenght
300       / 29,970      = 10,010 seconds

Default_FPS * TimeLenght  / NewTimeLenght   NewFrameRate
29,970      * 10,010 sec  / 60 sec          = 4,999995

...and in this case my new frame rate would be 4.999 to stretch the video exactly to 1 minute duration.

As I said,I would really prefer to find any ffmpeg command to do this in a simple way without to calc the new frame rate manually I have to use.Or having a small tool I can enter some datas to calc out the new rate etc.Maybe anyone does know any command or tool I could check out.

PS: I could code a tool too for this but I have again some float calc problems (dont remember anymore about this).


Link to comment
Share on other sites

You're overcomplicating things. You have video that has 300 frames. You need it to last 60 seconds. Necessary frame rate is 300/60=5 frames per second.

Who would want to write a specific tool that does one division operation? Certainly not me. :)



  • Like 1
Link to comment
Share on other sites

Hi kao,

hmmm.Looks more simple now.I think I did stroll anywhere else. :) I really don't know why I always do think so different.Maybe simple solutions aren't my thing and I don't see them or whatever.Good ok, using a calculator with the right formula could be ok in that case.


Link to comment
Share on other sites

I think this should do it...

ffmpeg -y -i input.mp4 -vf "setpts=1.25*PTS" -r 30 output.mp4

Changing the -r value to match your needed framerate


  • Like 1
Link to comment
Share on other sites


I tried this setpts already but isn't what I'am looking for.Also in this case I need to re-encode the video too what is normaly not needed just to change the frame rate value like you can do in VirtualDub and export the video in direct copy mode.Strange that this not works in ffmpeg anyhow like this maybe....

ffmpeg -i "video_audio.mp4" -matchvideo2audiolenght -c copy output.mp4

...ffmpeg could check the audio stream in this video (or new audio stream if set) to get the audio lenght like 1 minute for example and changing the original framerate of the video to X to stretch the video to the same lenght of 1 minute and output as new file.In this case I wouldnt need to find out the new framerate of video I have to use manually and using it to extract first the h264 video stream then changing the framerate to X and muxing both streams h264 & audio stream together back into mp4 container.Its a bad detour you know.All this steps I can do with ffmpeg manually just using demux / mux methods = without re-encoding.

I made a short video to show my manually steps I have to do with ffmpeg so far to get it work but its a detour style.I dont know whether this steps can be done automatically anyhow with ffmpeg you know.On internet I found nothing yet.Maybe you or anyone who works with ffmpeg more than me can watch quickly my video and tell me how this can be done without a detour etc.If you know or find a better method for this then just tell me.



Link to comment
Share on other sites

I have used ffmpeg but mostly the basics so sadly dont have any further solutions

I like the look of the app you created 😀

It looks a boring task to do what you are doing, it seems your app has the functionality to do it via ffmpeg but just needs some extra functions to combine all the tasks


Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Create New...