<p>You can hack this using <a href="https://sites.google.com/site/qaacpage/cabinet/mp4fpsmod_0.25.zip?attredirects=0&amp;d=1" rel="nofollow noreferrer">mp4fpsmod</a> (direct link to Win binary; C++ source at <a href="https://github.com/nu774/mp4fpsmod" rel="nofollow noreferrer">https://github.com/nu774/mp4fpsmod</a>).</p>

<p>First step is to extract the timestamps of the existing video</p>

<pre><code>mp4fpsmod -p vid_tc.txt vid.mp4
</code></pre>

<p>This will produce a text file like this</p>

<pre><code># timecode format v2
0
40
80
120
... 
4880
4920
4960
</code></pre>

<p>Each line contains the timestamp of frame #N in milliseconds.</p>

<p>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.</p>

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

<pre><code># timecode format v2
0
40
80
120
... 
4880
4920
11320
</code></pre>

<p>and then run</p>

<pre><code>mp4fpsmod -x -T keep -t vid_tc.txt -o vid_new.mp4 vid.mp4
</code></pre>

<p>This will create a new file <code>vid_new.mp4</code>, 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 <code>-i</code> and skip <code>-o vid_new.mp4</code> if you want to edit the timecode in-place in existing file i.e. </p>

<pre><code>mp4fpsmod -x -T keep -t vid_tc.txt -i vid.mp4
</code></pre>

<p>but I don't recommend it.</p>

CC BY-SA 3.0
2017-12-21T12:12:49.823Z
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?: https://superuser.com/questions/871084/ffmpeg-extract-audio-with-exact-frame-length-of-video?rq=1
DarioBB
CC BY-SA 3.0
2017-12-21T12:44:15.453Z
There's no re-encoding so there's no quality change. The answer at SU won't help if the audio is longer.
Gyan
CC BY-SA 3.0
2017-12-21T15:04:56.157Z
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
CC BY-SA 3.0
2017-12-21T15:45:04.283Z
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
CC BY-SA 3.0
2017-12-21T16:12:31.940Z
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 
https://stackoverflow.com/questions/10437750/how-to-get-the-real-actual-duration-of-an-mp3-file-vbr-or-cbr-server-side
DarioBB
CC BY-SA 3.0
2017-12-21T16:18:12.593Z
mp4fpsmod only looks at video streams.
Gyan
CC BY-SA 3.0
2017-12-21T23:07:07.120Z
I have tried it. It doesent work at all. Absolutely nothing from it. Everything is the same after the upload.
DarioBB
CC BY-SA 3.0
2017-12-22T04:56:35.753Z
Share the file, if you can.
Gyan
CC BY-SA 4.0
2020-03-23T06:36:11.823Z
Thank you for this answer. The resulting video doesn't play properly in mkv. I doubled the video length, but mkv thinks the video is 3 times as long. But after uploading to Youtube, it works perfectly!
nyanpasu64
CC BY-SA 3.0
2017-12-21T11:08:54.270Z
2017-12-21T11:08:54.270Z
Gyan
<p>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. <strong>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.</strong> 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 <strong>my video is cutted to the lenght of the video duration (so my sound is cutted)</strong>. I understand that this is because of different duration sizes of sound and video.</p>

<p>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.</p>

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

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

<p>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?)</p>

<p><strong>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.</strong></p>

CC BY-SA 3.0
2017-12-21T08:18:42.037Z
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
CC BY-SA 3.0
2017-12-21T08:55:29.680Z
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
CC BY-SA 3.0
2017-12-21T10:20:59.753Z
You can do it all with ffmpeg, so if there are many videos you could automate it.
stib
CC BY-SA 3.0
2017-12-21T10:26:36.110Z
I can't reproduce this behaviour at Youtube. Media plays till the audio stream concludes.
Gyan
CC BY-SA 3.0
2017-12-21T10:30:47.007Z
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
<video><ffmpeg><encoding>
FFmpeg - how to adjust video (clip) duration to sound duration if sound is longer, possible without re-encoding it with mp3 file?
DarioBB
# FFmpeg - how to adjust video (clip) duration to sound duration if sound is longer, possible without re-encoding it with mp3 file?

(Asked by: username_0 on 2017-12-21)

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.**

**Tags:** video, ffmpeg, encoding

> **Comments:**
> **username_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.  
> **username_0**: username_1, 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.  
> **username_1**: You can do it all with ffmpeg, so if there are many videos you could automate it.  
> **username_2**: I can't reproduce this behaviour at Youtube. Media plays till the audio stream concludes.  
> **username_0**: username_1, 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.  

---

## 1 answers

### Answer by username_2 on 2017-12-21. Score: 2

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.

> **Comments:**
> **username_0**: 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?: https://superuser.com/questions/871084/ffmpeg-extract-audio-with-exact-frame-length-of-video?rq=1  
> **username_2**: There's no re-encoding so there's no quality change. The answer at SU won't help if the audio is longer.  
> **username_0**: 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?  
> **username_2**: 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.  
> **username_0**: 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  https://stackoverflow.com/questions/10437750/how-to-get-the-real-actual-duration-of-an-mp3-file-vbr-or-cbr-server-side  
> **username_2**: mp4fpsmod only looks at video streams.  
> **username_0**: I have tried it. It doesent work at all. Absolutely nothing from it. Everything is the same after the upload.  
> **username_2**: Share the file, if you can.  
> **username_3**: Thank you for this answer. The resulting video doesn't play properly in mkv. I doubled the video length, but mkv thinks the video is 3 times as long. But after uploading to Youtube, it works perfectly!  

---

