How to add padding silence for MP4 container?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

How to add padding silence for MP4 container?

Francois Visagie
Hi All,

 

I'm trying to help someone who needs to delay his audio stream by 2s: he got
given a .mp4 file containing only video and a .aac file with audio which he
needs to mux together delaying the audio by 2s.

 

This works perfectly for MKV:

 

                ffmpeg -i invideo.mp4 -itsoffset 00:00:02.000 -i inaudio.aac
-codec:v copy -codec:a copy out.mkv

 

However, he'd prefer the MP4 container format. Although the ffmpeg command
completes perfectly, no player on my machine respects the MP4 timestamps and
I've seen this reported elsewhere also.

 

So instead of using timestamps with MP4, is there a way to tell ffmpeg to
insert 2s of silence at the beginning of the audio?

 

Many thanks,

Francois

 

Francois Visagie

 

 

T: +27 (83) 326-4358

F: +27 (86) 511-3490

E: [hidden email]

 

 

_______________________________________________
ffmpeg-user mailing list
[hidden email]
http://ffmpeg.org/mailman/listinfo/ffmpeg-user
Reply | Threaded
Open this post in threaded view
|

Re: How to add padding silence for MP4 container?

Tom Horsley
> So instead of using timestamps with MP4, is there a way to tell ffmpeg to
> insert 2s of silence at the beginning of the audio?

I don't know about using ffmpeg itself, but I fiddle with audio
sync problems all the time and I use sox to generate silence
when I need it. For example:

sox -n -r 48000 -c 2 -e signed-integer -b 16 quiet.wav trim 0 2.0

That will generate 2 seconds of silence in a 16 bit stereo PCM
.wav file format. You can then concatenate that with another audio
file like so:

sox quiet.wav main.wav delayed.wav

I've only ever done this with uncompressed PCM files, don't know
if audio compression might introduce other problems. I tend to
do the mp3 or aac compression as the last step when muxing the
audio and video together with ffmpeg.

See all my trails and tribulations archiving TV shows off my
TiVo (and correcting audio sync) at:

http://home.comcast.net/~tomhorsley/game/ffmpeg.html
_______________________________________________
ffmpeg-user mailing list
[hidden email]
http://ffmpeg.org/mailman/listinfo/ffmpeg-user
Reply | Threaded
Open this post in threaded view
|

Re: How to add padding silence for MP4 container?

Paul B Mahol
In reply to this post by Francois Visagie
On 5/25/13, Francois Visagie <[hidden email]> wrote:

> Hi All,
>
>
>
> I'm trying to help someone who needs to delay his audio stream by 2s: he
> got
> given a .mp4 file containing only video and a .aac file with audio which he
> needs to mux together delaying the audio by 2s.
>
>
>
> This works perfectly for MKV:
>
>
>
>                 ffmpeg -i invideo.mp4 -itsoffset 00:00:02.000 -i
> inaudio.aac
> -codec:v copy -codec:a copy out.mkv
>
>
>
> However, he'd prefer the MP4 container format. Although the ffmpeg command
> completes perfectly, no player on my machine respects the MP4 timestamps
> and
> I've seen this reported elsewhere also.
>
>
>
> So instead of using timestamps with MP4, is there a way to tell ffmpeg to
> insert 2s of silence at the beginning of the audio?

ffmpeg -i input -af aresample=firts_pts=X

where X is 2 * sample_rate of your audio stream.

you can't use -codec:a copy to insert real silence.

>
>
>
> Many thanks,
>
> Francois
>
>
>
> Francois Visagie
>
>
>
>
>
> T: +27 (83) 326-4358
>
> F: +27 (86) 511-3490
>
> E: [hidden email]
>
>
>
>
>
> _______________________________________________
> ffmpeg-user mailing list
> [hidden email]
> http://ffmpeg.org/mailman/listinfo/ffmpeg-user
>
_______________________________________________
ffmpeg-user mailing list
[hidden email]
http://ffmpeg.org/mailman/listinfo/ffmpeg-user
Reply | Threaded
Open this post in threaded view
|

Re: How to add padding silence for MP4 container?

Liam Condron-Farnos
In reply to this post by Tom Horsley
On 25 May 2013 13:45, Tom Horsley <[hidden email]> wrote:
>> So instead of using timestamps with MP4, is there a way to tell ffmpeg to
>> insert 2s of silence at the beginning of the audio?
>
> I don't know about using ffmpeg itself, but I fiddle with audio
> sync problems all the time and I use sox to generate silence
> when I need it. For example:

To generate silence with ffmpeg, use the aevalsrc audio filter

http://ffmpeg.org/ffmpeg-all.html#aevalsrc

Then, you can use either the concat demuxer (for which you'll have to
generate the sound separately, ad then prepend it to your existing
audio in two distinct commands) or the concat filter (requires
re-encoding, but will allow you to work with a single ffmpeg command).

ffmpeg -filter_complex 'aevalsrc=0:d=2' silence.aac
ffmpeg -f concat -i <(for f in silence.aac audio.aac; do echo file
"'$f'"; done) -c copy out-audio.aac

OR:

ffmpeg -i audio.aac  -filter_complex
'aevalsrc=0:d=2[slug];[slug][0]concat=n=2:v=0:a=1[out]' -map '[out]'
-c:a libfdk_aac -vbr 3 out-audio.aac

(change depending on the AAC encoder you have)

http://ffmpeg.org/trac/ffmpeg/wiki/How to concatenate (join, merge) media files
_______________________________________________
ffmpeg-user mailing list
[hidden email]
http://ffmpeg.org/mailman/listinfo/ffmpeg-user
Reply | Threaded
Open this post in threaded view
|

Re: How to add padding silence for MP4 container?

Paul B Mahol
On 5/25/13, Liam Condron-Farnos <[hidden email]> wrote:

> On 25 May 2013 13:45, Tom Horsley <[hidden email]> wrote:
>>> So instead of using timestamps with MP4, is there a way to tell ffmpeg
>>> to
>>> insert 2s of silence at the beginning of the audio?
>>
>> I don't know about using ffmpeg itself, but I fiddle with audio
>> sync problems all the time and I use sox to generate silence
>> when I need it. For example:
>
> To generate silence with ffmpeg, use the aevalsrc audio filter
>
> http://ffmpeg.org/ffmpeg-all.html#aevalsrc
>
> Then, you can use either the concat demuxer (for which you'll have to
> generate the sound separately, ad then prepend it to your existing
> audio in two distinct commands) or the concat filter (requires
> re-encoding, but will allow you to work with a single ffmpeg command).
>
> ffmpeg -filter_complex 'aevalsrc=0:d=2' silence.aac
> ffmpeg -f concat -i <(for f in silence.aac audio.aac; do echo file
> "'$f'"; done) -c copy out-audio.aac
>
> OR:
>
> ffmpeg -i audio.aac  -filter_complex
> 'aevalsrc=0:d=2[slug];[slug][0]concat=n=2:v=0:a=1[out]' -map '[out]'
> -c:a libfdk_aac -vbr 3 out-audio.aac
>
> (change depending on the AAC encoder you have)
>
> http://ffmpeg.org/trac/ffmpeg/wiki/How to concatenate (join, merge) media
> files

That is veeery complicated way to do something when there is very fast
and easy way.
_______________________________________________
ffmpeg-user mailing list
[hidden email]
http://ffmpeg.org/mailman/listinfo/ffmpeg-user
Reply | Threaded
Open this post in threaded view
|

Re: How to add padding silence for MP4 container?

Paul B Mahol
In reply to this post by Paul B Mahol
On 5/25/13, Paul B Mahol <[hidden email]> wrote:

> On 5/25/13, Francois Visagie <[hidden email]> wrote:
>> Hi All,
>>
>>
>>
>> I'm trying to help someone who needs to delay his audio stream by 2s: he
>> got
>> given a .mp4 file containing only video and a .aac file with audio which
>> he
>> needs to mux together delaying the audio by 2s.
>>
>>
>>
>> This works perfectly for MKV:
>>
>>
>>
>>                 ffmpeg -i invideo.mp4 -itsoffset 00:00:02.000 -i
>> inaudio.aac
>> -codec:v copy -codec:a copy out.mkv
>>
>>
>>
>> However, he'd prefer the MP4 container format. Although the ffmpeg
>> command
>> completes perfectly, no player on my machine respects the MP4 timestamps
>> and
>> I've seen this reported elsewhere also.
>>
>>
>>
>> So instead of using timestamps with MP4, is there a way to tell ffmpeg to
>> insert 2s of silence at the beginning of the audio?
>
> ffmpeg -i input -af aresample=firts_pts=X
>
> where X is 2 * sample_rate of your audio stream.
>
> you can't use -codec:a copy to insert real silence.

Well, you actually can, and that is "complicated" way, that others
have mentioned.

Note that in such case: creating silence, encoding silence into aac,
and than concatenating
silence and audio into another stream without transcoding, you can not
have always exact
precision, so 2s delay may be possible or may not (i never tried so dunno).
_______________________________________________
ffmpeg-user mailing list
[hidden email]
http://ffmpeg.org/mailman/listinfo/ffmpeg-user
Reply | Threaded
Open this post in threaded view
|

Re: How to add padding silence for MP4 container?

Francois Visagie
> -----Original Message-----
> From: [hidden email] [mailto:ffmpeg-user-
> [hidden email]] On Behalf Of Paul B Mahol
> Sent: 25 May 2013 15:28
> To: FFmpeg user questions
> Subject: Re: [FFmpeg-user] How to add padding silence for MP4 container?
>
> On 5/25/13, Paul B Mahol <[hidden email]> wrote:
> > On 5/25/13, Francois Visagie <[hidden email]> wrote:
> >> Hi All,
> >>
> >>
> >>
> >> I'm trying to help someone who needs to delay his audio stream by 2s:
he
> >> got
> >> given a .mp4 file containing only video and a .aac file with audio
which

> >> he
> >> needs to mux together delaying the audio by 2s.
> >>
> >>
> >>
> >> This works perfectly for MKV:
> >>
> >>
> >>
> >>                 ffmpeg -i invideo.mp4 -itsoffset 00:00:02.000 -i
> >> inaudio.aac
> >> -codec:v copy -codec:a copy out.mkv
> >>
> >>
> >>
> >> However, he'd prefer the MP4 container format. Although the ffmpeg
> >> command
> >> completes perfectly, no player on my machine respects the MP4
> timestamps
> >> and
> >> I've seen this reported elsewhere also.
> >>
> >>
> >>
> >> So instead of using timestamps with MP4, is there a way to tell ffmpeg
to

> >> insert 2s of silence at the beginning of the audio?
> >
> > ffmpeg -i input -af aresample=firts_pts=X
> >
> > where X is 2 * sample_rate of your audio stream.
> >
> > you can't use -codec:a copy to insert real silence.
>
> Well, you actually can, and that is "complicated" way, that others
> have mentioned.
>
> Note that in such case: creating silence, encoding silence into aac,
> and than concatenating
> silence and audio into another stream without transcoding, you can not
> have always exact
> precision, so 2s delay may be possible or may not (i never tried so
dunno).

Thanks for all the inputs, much appreciated!

> _______________________________________________
> ffmpeg-user mailing list
> [hidden email]
> http://ffmpeg.org/mailman/listinfo/ffmpeg-user

_______________________________________________
ffmpeg-user mailing list
[hidden email]
http://ffmpeg.org/mailman/listinfo/ffmpeg-user