LinuxQuestions.org
Help answer threads with 0 replies.
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 09-28-2014, 08:56 AM   #1
gael33
Member
 
Registered: Feb 2009
Location: Scotland
Distribution: Linux Mint 18.3 Cinnamon 64 bit
Posts: 316

Rep: Reputation: 20
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.
 
Old 09-28-2014, 12:42 PM   #2
Pearlseattle
Member
 
Registered: Aug 2007
Location: Zurich, Switzerland
Distribution: Gentoo
Posts: 995

Rep: Reputation: 128Reputation: 128
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... .
 
Old 09-28-2014, 05:34 PM   #3
teckk
Senior Member
 
Registered: Oct 2004
Distribution: FreeBSD Arch
Posts: 2,410

Rep: Reputation: 566Reputation: 566Reputation: 566Reputation: 566Reputation: 566Reputation: 566
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.
Old 09-28-2014, 06:05 PM   #4
gael33
Member
 
Registered: Feb 2009
Location: Scotland
Distribution: Linux Mint 18.3 Cinnamon 64 bit
Posts: 316

Original Poster
Rep: Reputation: 20
Quote:
Originally Posted by teckk View Post
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?
 
Old 09-29-2014, 05:53 AM   #5
ondoho
LQ Addict
 
Registered: Dec 2013
Posts: 12,879
Blog Entries: 9

Rep: Reputation: 3514Reputation: 3514Reputation: 3514Reputation: 3514Reputation: 3514Reputation: 3514Reputation: 3514Reputation: 3514Reputation: 3514Reputation: 3514Reputation: 3514
Quote:
Originally Posted by gael33 View Post
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.
 
Old 09-29-2014, 06:49 AM   #6
gael33
Member
 
Registered: Feb 2009
Location: Scotland
Distribution: Linux Mint 18.3 Cinnamon 64 bit
Posts: 316

Original Poster
Rep: Reputation: 20
Quote:
Originally Posted by ondoho View Post
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
 
Old 09-29-2014, 03:51 PM   #7
teckk
Senior Member
 
Registered: Oct 2004
Distribution: FreeBSD Arch
Posts: 2,410

Rep: Reputation: 566Reputation: 566Reputation: 566Reputation: 566Reputation: 566Reputation: 566
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.
Code:
./offset.sh
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.
 
Old 09-29-2014, 07:38 PM   #8
Pearlseattle
Member
 
Registered: Aug 2007
Location: Zurich, Switzerland
Distribution: Gentoo
Posts: 995

Rep: Reputation: 128Reputation: 128
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.
 
  


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
Aligning output using tabs frater Programming 3 11-01-2012 07:13 AM
Aligning sectors for an SSD? DanceMan Linux - Hardware 9 08-06-2010 03:20 AM
Aligning output in C++ R00ts Programming 13 02-14-2006 01:51 PM
aligning torsmo kurrupt Linux - Software 1 06-28-2005 03:34 PM
Video without sound; sound without video - in Debian, KDE with SB Live headisdead Linux - Hardware 0 06-20-2004 08:43 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 04:13 AM.

Main Menu
Advertisement
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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration