0

I'm trying to have apply slow motion effect to a series of videos. And further those videos will be scaled, padded and cross-faded. Following is the command I'm using to apply slow motion.

ffmpeg -i 1.mp4 -filter_complex "
[0:v]trim=0:5,setpts=PTS-STARTPTS[tv1];
[0:v]trim=5:7,setpts=PTS-STARTPTS[tv2];
[0:v]trim=start=7,setpts=PTS-STARTPTS[tv3];
[tv2]setpts=PTS*2[slow];
[tv1][slow][tv3]concat=n=3:v=1:a=0[out]" -map [out] -c:v libx264 test.mp4

I have two questions.

  1. Referring to [tv2] though it is trimmed and applied the slow motion effect starting from 5th second actually it apply the effect from 4th second. What is the reason for this?

Following is the command I'm using for other processing right after concatenate in the above command.

[concat0]scale=iw*min(1280/iw\,720/ih):ih*min(1280/iw\,720/ih),pad=1280:720:(1280-iw*min(1280/iw\,720/ih))/2:(720-ih*min(1280/iw\,720/ih))/2,format=pix_fmts=yuva420p,fade=t=out:st=16:d=2:alpha=1,setpts=expr=PTS-STARTPTS+10/TB[va0];

There I need to specify the setpts and I'm using the cumulative duration of the videos before the current video. Here is the complete command I'm using for it.

  1. How can I calculate the duration of the video after applying the slow motion effect? For instance what would be the increment of the duration of video result from the 1st command I mentioned here in seconds or even microseconds?

1 Answer 1

0

Question 1 - The command is incomplete because you don't take into account the audio track, you changed the PTS only in the video track. To see the difference just try this:

# no-good, starts from 4th second audio with a frozen video frame
ffmpeg -i in.mp4 -vf trim=5:7 out.mp4
#
# works as expected, both audio and video start at 5th second
ffmpeg -i in.mp4 -vf trim=5:7 -af atrim=5:7 out.mp4

Question 2 - This too won't work as expected for the same reason, but once you fix the previous issue here's a not-very-elegant yet effective trick to correlate the "before" and "after" times:

# overlay the input video with a timer, pulled to the right 200 pixels
ffmpeg -i in.mp4 -f lavfi -i testsrc=n=3 -vf overlay=x=200 in-with-time.mp4
#
# do all your manipulation, and finaly overlay with another timer at x=0
ffmpeg -i in-with-time.mp4 -f lavfi -i testsrc=n=3 -filter_complex "..stuff...,overlay[out]" out.mp4

This provides you per frame the original and resulting time at 1 millisecond accuracy.

6
  • Thanks for the explanation. For the first point, I don't need the original audio in the output file so it is better to add -an. For the second point, I needed a mathematical calculation to get the duration. Commented Jun 4, 2015 at 6:45
  • To calculate you have to show how you feed [concat0], how [out] maps to it. This can influence the baseline for calculating the PTS. Is it done in the same CLI call or as a second pass? Is there anything else in between? The reference you gave to the other question shows a different scenario. Commented Jun 4, 2015 at 11:04
  • Assume the answer I'm getting from my calculation is "tt". Then I used for PTS calculations like tt/TB. Is this wrong? I'm sorry, I'm new to ffmpeg. (the reference i mentioned is the command i'm using and i added those slomo effect to it) Commented Jun 5, 2015 at 7:09
  • Well first of all, if you're new to ffmpeg then you shouldn't have posted answers here and to your previous question, particularly without verifying that the answers are correct. Second, part of trying to help is figuring whether your assumptions are right, after all, my assumption is that you have a real need to get something to work, and I gave some of my time to help you in that. So, until you remove your previous answers which might confuse someone with a similar problem who reads them, and until you provide a clear picture of your issue, I don't quite see how I can be of any help. Commented Jun 5, 2015 at 9:40
  • 1
    Deleted my answer as per your request. The answers I'm posting are generated from the IRC chat of ffmpeg. And also they are tested on my problem context. Just to let yourself clear. Commented Jun 7, 2015 at 4:31

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.