Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to Trim Video to Match Audio Length While Merging Using FFmpeg? #1112

Open
MeetDev2602 opened this issue Feb 20, 2025 · 0 comments
Open

Comments

@MeetDev2602
Copy link

MeetDev2602 commented Feb 20, 2025

I am trying to merge a video and an audio file using FFmpeg, but I want the final output to end when the shorter of the two files ends. For example:

  • If video is 7 seconds and audio is 10 seconds, the output should be 7 seconds long.
  • If video is 10 seconds and audio is 7 seconds, the output should be 7 seconds long.

Currently, I tried using:

ffmpeg -i input.mp4-i input.mp3 -t 6 -c:v copy -c:a aac -b:a 128k -shortest output.mp4

this commend work video trim perfectly but not add audio

What I Need:

Trim the video to match the shortest duration between video and audio.

Ensure both video and audio end together without one continuing after the other.

Does this work correctly? Or is there a better way to handle this in FFmpeg?

Any suggestions or improvements are appreciated!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant