Support LQ: Use code LQ3 and save $3 on Domain Registration
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, 09: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 10:17 PM.
Old 06-21-2012, 11:52 PM   #2
Senior Member
Registered: Jan 2005
Location: Melbourne, Australia
Distribution: Debian Jessie (Fluxbox WM)
Posts: 1,380
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-22-2012, 12:44 AM   #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 01:55 PM
ffmpeg grabbing audio and video glvorange Linux - Newbie 2 10-01-2011 10:56 AM
ffmpeg, trying to demux VOB, subtitles show up in video stream Meson Linux - Software 1 01-29-2010 09:41 AM
LXer: End-to-end video podcast production with Kino and FFmpeg LXer Syndicated Linux News 0 03-25-2008 10:40 PM
how can I (de-)synchronize an audio stream of a video? mamadu.bwana Linux - Software 1 11-09-2007 11:08 AM

All times are GMT -5. The time now is 07:08 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