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 |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
 |
09-28-2014, 07:56 AM
|
#1
|
Member
Registered: Feb 2009
Location: Scotland
Distribution: Linux Mint 21.3 Cinnamon 64 bit
Posts: 346
Rep:
|
Aligning sound to video ... how?
I have a MP4 short video from a wedding the video is crystal clear but the sound is out of alignment by about 6 secs.
Does anyone know of a program that I could use to bring the sound back into alignment with the video?
I have had a look at Pitivi and Openshot and I cannot figure out how to use them (I'm not stupid, I'm just getting on in years).
Any help will be appreciated,
Thanks.
|
|
|
09-28-2014, 11:42 AM
|
#2
|
Senior Member
Registered: Aug 2007
Location: Zurich, Switzerland
Distribution: Gentoo
Posts: 1,001
Rep: 
|
You probably just want to remux it so as to not lose quality, right?
if yes then there are probably a lot of tools that can do it, e.g. mmg (part of mkvtoolnix) (but the output container format will then be mkv instead of mp4), avidemux, etc... .
|
|
|
09-28-2014, 04:34 PM
|
#3
|
LQ Guru
Registered: Oct 2004
Distribution: Arch
Posts: 5,392
|
If you are serious I will show you how to do that. My examples will be with mplayer and ffmpeg, but you can use what you wish.
You will first need to determine exactly how far out of sync the audio and video is. You could do that with mplayer. Play the video while pressing the + or - keys watching the on screen display until you have the audio video in sync. Note how far out of sync it is. Then dump the audio to a file, dump the video to another file. Then put them back together while syncing the A-V. Also find out what audio codec the video has.
Read the output of
Code:
ffmpeg -i yourfile.mp4
I'll use .aac as an example with an out of sync by 6.1 seconds.
Code:
ffmpeg -i yourfile.mp4 -vn -c:a copy outaud.aac
Code:
ffmpeg -i yourfile.mp4 -an -c:v copy outvid.mp4
Then put them back together with an offset and copying the input. Use positive or negative offset depending on which way you need to go. You may need a little trial and error to get the sync exact. You can delay the audio or the video. -itsoffset comes before the file that wish to offset.
Code:
ffmpeg -i outvid.mp4 -itsoffset 6.1 -i outaud.aac -c copy Newfile.mp4
Look at man ffmpeg
https://trac.ffmpeg.org/wiki/TitleIndex
https://www.ffmpeg.org/ffmpeg.html
http://linux.die.net/man/1/ffmpeg
After you have made an attempt to solve it, and have a Newfile.mp4, and need more help...ask.
|
|
1 members found this post helpful.
|
09-28-2014, 05:05 PM
|
#4
|
Member
Registered: Feb 2009
Location: Scotland
Distribution: Linux Mint 21.3 Cinnamon 64 bit
Posts: 346
Original Poster
Rep:
|
Quote:
Originally Posted by teckk
If you are serious I will show you how to do that. My examples will be with mplayer and ffmpeg, but you can use what you wish.
You will first need to determine exactly how far out of sync the audio and video is. You could do that with mplayer. Play the video while pressing the + or - keys watching the on screen display until you have the audio video in sync. Note how far out of sync it is. Then dump the audio to a file, dump the video to another file. Then put them back together while syncing the A-V. Also find out what audio codec the video has.
Read the output of
Code:
ffmpeg -i yourfile.mp4
I'll use .aac as an example with an out of sync by 6.1 seconds.
Code:
ffmpeg -i yourfile.mp4 -vn -c:a copy outaud.aac
Code:
ffmpeg -i yourfile.mp4 -an -c:v copy outvid.mp4
Then put them back together with an offset and copying the input. Use positive or negative offset depending on which way you need to go. You may need a little trial and error to get the sync exact. You can delay the audio or the video. -itsoffset comes before the file that wish to offset.
Code:
ffmpeg -i outvid.mp4 -itsoffset 6.1 -i outaud.aac -c copy Newfile.mp4
Look at man ffmpeg
https://trac.ffmpeg.org/wiki/TitleIndex
https://www.ffmpeg.org/ffmpeg.html
http://linux.die.net/man/1/ffmpeg
After you have made an attempt to solve it, and have a Newfile.mp4, and need more help...ask.
|
I really do appreciate all that information, but as pensioner/silver surfer with not a lot of techie know-how I would be frightened to even attempt that.
I noticed that VLC player can adjust sound sync ... is it possible to use that program and save the adjusted file?
|
|
|
09-29-2014, 04:53 AM
|
#5
|
LQ Addict
Registered: Dec 2013
Posts: 19,872
|
Quote:
Originally Posted by gael33
frightened to even attempt that.
|
why on earth?
are you frightened to use your keyboard instead of your mouse?
just copy the file(s) to a dedicated folder, open a terminal in that folder and try it. if it doesn't work, remove the folder. there.
|
|
|
09-29-2014, 05:49 AM
|
#6
|
Member
Registered: Feb 2009
Location: Scotland
Distribution: Linux Mint 21.3 Cinnamon 64 bit
Posts: 346
Original Poster
Rep:
|
Quote:
Originally Posted by ondoho
why on earth?
are you frightened to use your keyboard instead of your mouse?
just copy the file(s) to a dedicated folder, open a terminal in that folder and try it. if it doesn't work, remove the folder. there.
|
Okay, I'll give it a go later 
|
|
|
09-29-2014, 02:51 PM
|
#7
|
LQ Guru
Registered: Oct 2004
Distribution: Arch
Posts: 5,392
|
Oh course if you were a Linux geek you might make a bash script to automate all of that. There are 50 ways to do this, something like:
offset.sh
Code:
#! /usr/bin/env bash
while true; do
echo "Enter path of video file you wish to change."
read vid
echo "How much offset do you want? | Examples 6.1, -6.2"
read oset
#Seperate the audio video here.
ffmpeg -i $vid -vn -c:a copy outaud.aac &&
ffmpeg -i $vid -an -c:v copy outvid.mp4 &&
#Put them back together with offset here..
ffmpeg -i outvid.mp4 -itsoffset $oset -i outaud.aac -c copy -bsf:a aac_adtstoasc Output.mp4 &&
#If good quit, if not repeat.
read -p "Play the video Output.mp4, is it good y or n " yn
case $yn in
[Yy]* ) rm outaud.aac; rm outvid.mp4; exit;;
[Nn]* ) echo "Try again"; rm Output.mp4 ;;
esac
done
Make that script executable
Code:
chmod u+x offset.sh
Then execute it.
Answer the prompts.
If you can't get enough offset that way then make one offset positive and the other negative. 6 seconds is a lot.
Change line 17 to
Code:
ffmpeg -itsoffset -4 outvid.mp4 -itsoffset $oset -i outaud.aac -c copy -bsf:a aac_adtstoasc Output.mp4 &&
Don't say that you can't do it. Dive in. That script doesn't affect your original file.
|
|
|
09-29-2014, 06:38 PM
|
#8
|
Senior Member
Registered: Aug 2007
Location: Zurich, Switzerland
Distribution: Gentoo
Posts: 1,001
Rep: 
|
If you don't try at least teckk's example you'll be permanently banned on a planetary level from executing anything on a console and additionally you'll get extra "Are you sure?" and "Are you really sure?" prompts when executing any GUI command e.g. paste&delete&save&undo.

|
|
|
All times are GMT -5. The time now is 10:32 AM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|