LinuxQuestions.org
Register a domain and help support LQ
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
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.

Notices

Reply
 
Search this Thread
Old 05-30-2009, 10:13 AM   #1
colucix
Moderator
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,508

Rep: Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957
How to synchronize audio and video for merging?


Hi all. I have a mute video and a audio file:
Code:
$ file video.avi audio.mp3
video.avi: RIFF (little-endian) data, AVI, 640 x 368, 23.98 fps, video: XviD
audio.mp3: MPEG ADTS, layer III, v1, 128 kbps, 48 kHz, JntStereo
I want to merge them together, but the problem is that they have different length: 40:53 the audio file, 42:44 the video. How can I synchronize them? Should I save the video at a different frame rate or should I stretch (slow) the audio? Anyone has successfully done something similar? Thank you.
 
Old 05-31-2009, 11:32 AM   #2
H_TeXMeX_H
Guru
 
Registered: Oct 2005
Location: $RANDOM
Distribution: slackware64
Posts: 12,928
Blog Entries: 2

Rep: Reputation: 1269Reputation: 1269Reputation: 1269Reputation: 1269Reputation: 1269Reputation: 1269Reputation: 1269Reputation: 1269Reputation: 1269
I remember there's an option for this in avidemux, but I don't see it in mencoder or ffmpeg documentations, not sure how it accomplishes it.
 
Old 05-31-2009, 12:03 PM   #3
tredegar
LQ 5k Club
 
Registered: May 2003
Location: London, UK
Distribution: Debian "Jessie"
Posts: 6,017

Rep: Reputation: 369Reputation: 369Reputation: 369Reputation: 369
Audacity will let you change the speed of an audio track. This will affect the pitch, but you only need about a 5% change to balance things up.
For dialogue, it probably won't matter much, but music will sound strange, depending on your degree of "tone-deafness".

Try it: Audacity -> Effects-> Change speed

I have no idea how to slow down or speed up a video file, but as H_TeXMeX_H says avidemux can probably do it.

Please let us know how you get on.
 
Old 05-31-2009, 12:46 PM   #4
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Debian sid + kde 3.5 & 4.4
Posts: 6,823

Rep: Reputation: 1948Reputation: 1948Reputation: 1948Reputation: 1948Reputation: 1948Reputation: 1948Reputation: 1948Reputation: 1948Reputation: 1948Reputation: 1948Reputation: 1948
The answer will differ depending on if you need to stretch out the audio to fit the video (the audio gets progressively more off-sync as time goes on), or if it just needs to be time-shifted in order to remove a fixed delay.

For the former I usually use sox to stretch (or compress) the audio until it's the same length as the video, and/or matches the action on the screen. The man page will explain how to do it. Sometimes it takes a lot of trial and error to get it right, if you have to sync lip movements and such. You can also use audacity, as mentioned above (except use "change tempo" instead of "change speed" to keep the pitch the same).

For the latter, ffmpeg has an -itsoffset option to alter when an input file will be started, and avidemux has a similar ability in its audio options, and again there are corresponding options in avidemux and other programs.

Last edited by David the H.; 05-31-2009 at 12:52 PM. Reason: added "change tempo" info.
 
Old 06-01-2009, 04:45 AM   #5
colucix
Moderator
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,508

Original Poster
Rep: Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957
Thank you all for your replies. I succeed by using Audacity and Avidemux. First I changed the speed of the audio track using Audacity -> Effects-> Change speed, as suggested by tredegar. After some attempts, I finally found out the exact percentage to get a good synchronization. Then I loaded the video in Avidemux and I added the audio track from Audio -> Main Track -> External MP3. Checked the result and saved the video.

@David the H. - I tried with Change Tempo, that actually is Audacity -> Effects -> Sliding Time Scale/Pitch Shift, but it took a much longer time to run, so I stuck with Change Speed due to the fact I had to do several attempts and the sound quality was still good after a change of speed of about -4 percent. Also I tried sox, but in that case the sound quality decreased a lot.

@H_TeXMeX_H - I tried to look for that effect in Avidemux but I didn't find it. Anyway, I think that Avidemux + Audacity together are a great tool to manage videos.
 
Old 06-01-2009, 09:46 AM   #6
H_TeXMeX_H
Guru
 
Registered: Oct 2005
Location: $RANDOM
Distribution: slackware64
Posts: 12,928
Blog Entries: 2

Rep: Reputation: 1269Reputation: 1269Reputation: 1269Reputation: 1269Reputation: 1269Reputation: 1269Reputation: 1269Reputation: 1269Reputation: 1269
There is a "shift" feature in avidemux:

Quote:
Checking A/V sync

At this point you want to check the audio sync. Turn on the filtered output preview mode and make sure the audio is synced, if it's not, use the Shift feature to correct this.
http://avidemux.org/admWiki/index.php?title=DVD_to_AVI

It's somewhere in the options, I don't have it installed right now, so I can't really say exactly where, but it's there.
 
Old 06-01-2009, 10:01 AM   #7
colucix
Moderator
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,508

Original Poster
Rep: Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957
Yes, the shift feature is just below the audio selection, but it shifts the audio of some milliseconds forward or backward. In my case there is not a constant shift to correct, but the audio progressively increases the shift as playback goes on. Anyway the Change Speed effect in Audacity solved the problem. Thank you.
 
  


Reply


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
Firefox / Flash Player problem: Online video will play only audio, video is white. NOoBuntuLinux Linux - Software 1 03-28-2009 12:57 AM
smplayer: video+audio stutters with pulseaudio, audio files play fine GamerX Linux - Desktop 1 02-06-2009 08:53 PM
Video Playback Audio without Video xine openSUSE bahbahthelamb Linux - Software 5 09-09-2008 09:54 AM
how can I (de-)synchronize an audio stream of a video? mamadu.bwana Linux - Software 1 11-09-2007 10:08 AM
Video Playback-speeded up audio & video howone Suse/Novell 1 10-20-2005 01:24 AM


All times are GMT -5. The time now is 07:24 AM.

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