Welcome to the most active Linux Forum on the web.
Go Back > Forums > Linux Forums > Linux - Software
User Name
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.


  Search this Thread
Old 06-04-2012, 08:54 PM   #1
LQ Newbie
Registered: Apr 2012
Posts: 4

Rep: Reputation: Disabled
ffmpeg mixing audio/video - trying to end vid after video stream completes

I am using ffmpeg to mix a video and an audio file.

I am trying to end output file after the input video stream completes.

ffmpeg -shortest -i out.ogv -sameq -i audio.mp3 tester.avi
I was using -shortest but then my video was sometimes chopped when I had a short audio file. I want to let the full video finish and just chop the audio whenever the video finishes.

Sometimes audio will be shorter than the video, sometimes longer.

I know I can specify a manual stop time, but I would rather not have to do this.


Last edited by joejoe99; 06-04-2012 at 09:17 PM.
Old 06-21-2012, 10:52 PM   #2
Senior Member
Registered: Jan 2005
Location: Melbourne, Australia
Distribution: Debian Stretch (Fluxbox WM)
Posts: 1,389
Blog Entries: 52

Rep: Reputation: 355Reputation: 355Reputation: 355Reputation: 355
I don't know of an ffmpeg argument to do what you want, but if you need to script it, you could use ffprobe to test the durations of each first:
[[ $(ffprobe "$1" 2>&1) =~ Duration:\ ([^,]*) ]]; DV="${BASH_REMATCH[1]}"
[[ $(ffprobe "$2" 2>&1) =~ Duration:\ ([^,]*) ]]; DA="${BASH_REMATCH[1]}"
SHORTEST=''; if [[ "$DV" < "$DA" ]]; then SHORTEST='-shortest'; fi
ffmpeg $SHORTEST -i "$1" -sameq -i "$2" "$3"
Or simply use ffprobe to automatically set the output duration to the video file duration:
ffmpeg -t $([[ $(ffprobe "out.ogv" 2>&1) =~ Duration:\ ([^,]*) ]]; echo "${BASH_REMATCH[1]}") -i out.ogv -sameq -i audio.mp3 tester.avi
Old 06-21-2012, 11:44 PM   #3
LQ Newbie
Registered: Apr 2012
Posts: 4

Original Poster
Rep: Reputation: Disabled

Biggest thanks!

Thats great! Ill do what you suggest and use ffprobe to set the output duration to the vid.

Awesome thanks for showing how to do that. Best back to you! jj99


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Using FFmpeg to record from TV Card - Video is OK but no audio linux-freak Linux - General 1 01-07-2012 12:55 PM
ffmpeg grabbing audio and video glvorange Linux - Newbie 2 10-01-2011 09:56 AM
ffmpeg, trying to demux VOB, subtitles show up in video stream Meson Linux - Software 1 01-29-2010 08:41 AM
LXer: End-to-end video podcast production with Kino and FFmpeg LXer Syndicated Linux News 0 03-25-2008 09:40 PM
how can I (de-)synchronize an audio stream of a video? mamadu.bwana Linux - Software 1 11-09-2007 10:08 AM > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 07:13 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration