1

I have a problem. I have recorded my videos separately, and then added sound to it. Sometimes, sound is longer or less in duration compared to video duration. Usually sound is longer, sometimes around 20 seconds. To me, when running on my PC through flv or some Windows Media player, that is not problem, since after video is over, last capture of video stays displayed (like an image), and sounds is still executing, and video ends after sound is over. So everything is ok at my PC when running it like .flv or .mp4 file. But, when I upload that on Google drive or some other place on web (that is, when I run it in my browser for viewing after upload), I see my video is cutted to the lenght of the video duration (so my sound is cutted). I understand that this is because of different duration sizes of sound and video.

Now I need a command with ffmpeg that can make my video to be extened to my sound duration. I would like not to reencode my videos with sound again (in sense that I would need to put my mp3 file in ffmpeg command) if I don't need (since I have many videos and sound is already inserted in them), but just to re-encode video with some ffmpeg command to extend video lenght to sound lenght.

I have watched this (not sure at the momen if this would even help me): https://superuser.com/questions/801547/ffmpeg-add-audio-but-keep-video-length-the-same-not-shortest

But with this approach, you have to reencode video with sound (mp3 or similar) file first.

Can it be done, and what would be command, or commands for it? (And if only way is to re-encode it with mp3 file, what would be command for it?)

Edit: I don't want to cut my sound, I need to hold last frame till my sound is over. Currently last frame is holded only when viewing on my PC, when I upload that, clip is cutted immediately when video stops.

  • 1
    You could make a still image of the last frame then concatenate it with the video and loop it until you get to the end of the audio. – stib Dec 21 '17 at 8:18
  • stib, I understand, but making still image and concatenation is too much job (specially if there are many videos). That is why I am asking if there is a way to more elegantly adjust it with ffmpeg. – DarioBB Dec 21 '17 at 8:55
  • You can do it all with ffmpeg, so if there are many videos you could automate it. – stib Dec 21 '17 at 10:20
  • I can't reproduce this behaviour at Youtube. Media plays till the audio stream concludes. – Gyan Dec 21 '17 at 10:26
  • stib, any example? I really researched a lot, and find nothing that helps me. Mulvya, I never mentioned youtube, and my sound is recorded separaretly in these videos. Sound is added directly copying (without re-encoding). If you upload that kind of video with different sound lenght on Google drive for example, it will cut it. I think youtube will do the same, you just haven't had video with my example. – DarioBB Dec 21 '17 at 10:30
1

You can hack this using mp4fpsmod (direct link to Win binary; C++ source at https://github.com/nu774/mp4fpsmod).

First step is to extract the timestamps of the existing video

mp4fpsmod -p vid_tc.txt vid.mp4

This will produce a text file like this

# timecode format v2
0
40
80
120
... 
4880
4920
4960

Each line contains the timestamp of frame #N in milliseconds.

In this example, each frame is 40 milliseconds long and the last frame is shown at 4960 ms and hence the video stream is 5 seconds long.

Now suppose your audio is 11.34 seconds == 11340 ms long. Edit the last timecode to something just under 11340, like 11320.

# timecode format v2
0
40
80
120
... 
4880
4920
11320

and then run

mp4fpsmod -x -T keep -t vid_tc.txt -o vid_new.mp4 vid.mp4

This will create a new file vid_new.mp4, which you can upload. The duration shown in desktop players or tools can be wrong, but playback should be as desired, except that the last frame is shown along with the end of the audio. This skips re-encoding and is quick. You can add -i and skip -o vid_new.mp4 if you want to edit the timecode in-place in existing file i.e.

mp4fpsmod -x -T keep -t vid_tc.txt -i vid.mp4

but I don't recommend it.

  • Thank you, I will try it. Will this maybe ruin quality of video my video since this isn't ffmpeg? Everything should stay as it was for me - resolution, quality, etc. And second, if I want to remove problem with how duration is shown in desktop players you mentioned, what would be the way? Re-encode it with mp3 file? P.s. I've found this, but I haven't tried it yet, maybe this would be (correct answer on this link) what I am searching for If I don't want to involve mp3 file directly?: superuser.com/questions/871084/… – DarioBB Dec 21 '17 at 12:12
  • 1
    There's no re-encoding so there's no quality change. The answer at SU won't help if the audio is longer. – Gyan Dec 21 '17 at 12:44
  • Thank you Mulvya. I will try it. Just one more question - you've mentioned it has to be set under 11340 in example. You've set it to 11320. Could it work properly if it is set only to 11339? And what would happened if is set for example, to 9000? I guess that setting number to low could ruin ending? – DarioBB Dec 21 '17 at 15:04
  • 1
    Any number just lower than the audio length is fine. So 11339 is fine. The idea is to increase length so 9000 won't work for an audio stream of 11.34 seconds. – Gyan Dec 21 '17 at 15:45
  • All right. And just wondering, can mp4fpmod get mp3 file length or it is just working with video files? If that is the case, I'll have to or either read it manually (really not problem) or get precise info through ffmpeg stackoverflow.com/questions/10437750/… – DarioBB Dec 21 '17 at 16:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.