Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I have got few input sources and i want to place the audio at specific location in the output

Currently the complex filter expression is cutting the original audio and placing it at same location

[1:a]atrim=end=4,asetpts=PTS-STARTPTS[aud1]

I want to place it between specified location ..


EDIT

Here is the full command with output :

ffmpeg -i /tmp/a.mp4 -i /tmp/1.wav  -i /tmp/2.wav  -filter_complex " [0:a]atrim=0:4.489,asetpts=PTS-STARTPTS[aud1];[1:a]atrim=end=3.717,asetpts=PTS-STARTPTS[bud2];[bud2]adelay=4489[aud2];[0:a]atrim=8.206:16,asetpts=PTS-STARTPTS[bud3];[bud3]adelay=8206[aud3];[2:a]atrim=end=4.5,asetpts=PTS-STARTPTS[bud4];[bud4]adelay=16000[aud4];[aud1][aud2][aud3][aud4]concat=n=4:v=0:a=1[aout]" -map 0:v -map "[aout]" -c:v copy  /tmp/out.mp4



ffmpeg version N-60489-g03911c4 Copyright (c) 2000-2014 the FFmpeg developers
  built on Feb 10 2014 05:14:06 with gcc 4.6 (Debian 4.6.3-1)
  configuration: --prefix=/root/ffmpeg-static/32bit --arch=x86_32 --extra-cflags='-m32 -I/root/ffmpeg-static/32bit/include -static' --extra-ldflags='-m32 -L/root/ffmpeg-static/32bit/lib -static' --extra-libs='-lxml2 -lexpat -lfreetype' --enable-static --disable-shared --disable-ffserver --disable-doc --enable-bzlib --enable-zlib --enable-postproc --enable-runtime-cpudetect --enable-libx264 --enable-gpl --enable-libtheora --enable-libvorbis --enable-libmp3lame --enable-gray --enable-libass --enable-libfreetype --enable-libopenjpeg --enable-libspeex --enable-libvo-aacenc --enable-libvo-amrwbenc --enable-version3 --enable-libvpx
  libavutil      52. 63.101 / 52. 63.101
  libavcodec     55. 50.100 / 55. 50.100
  libavformat    55. 31.100 / 55. 31.100
  libavdevice    55.  8.100 / 55.  8.100
  libavfilter     4.  1.102 /  4.  1.102
  libswscale      2.  5.101 /  2.  5.101
  libswresample   0. 17.104 /  0. 17.104
  libpostproc    52.  3.100 / 52.  3.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '/tmp/a.mp4':
  Metadata:
    major_brand     : mp42
    minor_version   : 0
    compatible_brands: isommp42
    creation_time   : 2014-02-12 09:37:39
  Duration: 00:00:30.98, start: 0.000000, bitrate: 524 kb/s
    Stream #0:0(und): Video: h264 (Constrained Baseline) (avc1 / 0x31637661), yuv420p, 640x360 [SAR 1:1 DAR 16:9], 426 kb/s, 25 fps, 25 tbr, 25 tbn, 50 tbc (default)
    Metadata:
      handler_name    : VideoHandler
    Stream #0:1(und): Audio: aac (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 95 kb/s (default)
    Metadata:
      creation_time   : 2014-02-12 09:37:39
      handler_name    : IsoMedia File Produced by Google, 5-11-2011
Guessed Channel Layout for  Input Stream #1.0 : stereo
Input #1, wav, from '/tmp/1.wav':
  Duration: 00:00:08.79, bitrate: 1536 kb/s
    Stream #1:0: Audio: pcm_s16le ([1][0][0][0] / 0x0001), 48000 Hz, stereo, s16, 1536 kb/s
Guessed Channel Layout for  Input Stream #2.0 : stereo
Input #2, wav, from '/tmp/2.wav':
  Duration: 00:00:12.46, bitrate: 1536 kb/s
    Stream #2:0: Audio: pcm_s16le ([1][0][0][0] / 0x0001), 48000 Hz, stereo, s16, 1536 kb/s
Output #0, mp4, to '/tmp/out.mp4':
  Metadata:
    major_brand     : mp42
    minor_version   : 0
    compatible_brands: isommp42
    encoder         : Lavf55.31.100
    Stream #0:0(und): Video: h264 ([33][0][0][0] / 0x0021), yuv420p, 640x360 [SAR 1:1 DAR 16:9], q=2-31, 426 kb/s, 25 fps, 12800 tbn, 25 tbc (default)
    Metadata:
      handler_name    : VideoHandler
    Stream #0:1: Audio: aac (libvo_aacenc) ([64][0][0][0] / 0x0040), 44100 Hz, stereo, s16, 128 kb/s (default)
Stream mapping:
  Stream #0:1 (aac) -> atrim
  Stream #0:1 (aac) -> atrim
  Stream #1:0 (pcm_s16le) -> atrim
  Stream #2:0 (pcm_s16le) -> atrim
  Stream #0:0 -> #0:0 (copy)
  concat -> Stream #0:1 (libvo_aacenc)
Press [q] to stop, [?] for help
[output stream 0:1 @ 0xa8cee60] 100 buffers queued in output stream 0:1, something may be wrong.
frame=  774 fps=572 q=-1.0 Lsize=    2404kB time=00:00:49.21 bitrate= 400.1kbits/s    
video:1611kB audio:770kB subtitle:0 data:0 global headers:0kB muxing overhead 0.996036%

The problem is that the voice is not getting placed properly. And the video timeline is increased a lot. I am trying to place audio music in the original video.

PROBLEM

A 30 second video was made 46 second(and audio was incorrectly placed) .. even though the audios were laid only within the video range. I hearing from the left and then same from right?? Is this increasing the length of video ?

share|improve this question

closed as unclear what you're asking by LordNeckbeard, Kevin Panko, David, Joe Taylor, Dave Feb 27 at 10:12

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question.If this question can be reworded to fit the rules in the help center, please edit the question.

    
Do you want to replace any existing audio with the new audio or mix them? Please always include the complete ffmpeg command and the complete ffmpeg console output. –  LordNeckbeard Feb 13 at 18:40
    
I believe you are laying several audio tracks on the video, each at different times. So as in a video edit timeline, you need several tracks. Instead, you are taking several audio files and 'concat'ing them, that is joining them. The length is increasing because of the join, and the result is probably placed at the beginning anyway. The effect of the offset is now erased. –  Rajib Feb 15 at 16:55
    
Sir, i am new in this area .. and got to do this .. please give some commands of what you are talking –  naveen23 Feb 16 at 6:32
    
I am hearing from left and then same from right. Is this increasing the length of the video –  naveen23 Feb 16 at 13:14
    
Naveen, Please explain what you wish to achieve a little more clearly. You want to place several audio files on a video track at different points in time? See my new answer which I am guessing is what you want to achieve, only with lesser number of inputs. –  Rajib Feb 16 at 16:33

2 Answers 2

Say you want to lay Audio tracks on to a video file at various points. The Audio tracks that you use will be cut and trimmed at various points. In the following example, one audio is from the video file itself, and there is a second one from from a purely audio file- a wav file. The video file is videoandaudio.mov and the audio is audio_only.wav.

The atrim filter "cuts" the audio channels. The adelay filter places the audio at various points. The amix filter mixes those audios into a single mixed output. The aformat filter ensures consistency. Especially for flv you need sampling not more than 44100Hz.

In the example the audio of the video file is used upto 20 seconds. The second audio actually starts at 10000 milliseconds, which is earlier than the end of the audio (20 seconds) but this illustrative example purposely shows that amix can handle that. After that the second audio kicks in and goes till we trim the end at 240 seconds. The flv1 coder is again illustrative only- you can use anything. Be sure to use nice bitrates and other parameters for the video. For audio you can't do a-acodec copy if you use filtergraph so I am showing with PCM.

ffmpeg -i videoandaudio.mov -i audio_only.wav  -filter_complex "[0:a]aformat=sample_fmts=fltp:sample_rates=44100:channel_layouts=mono,atrim=end=20[aud1];[1:a]aformat=sample_fmts=fltp:sample_rates=44100:channel_layouts=mono,atrim=end=240[bud2];[bud2]adelay=10000[aud2];[aud1][aud2]amix=inputs=2"  -map 0:v -c:v flv1 -pix_fmt yuv420p -c:a pcm_s16le out.flv
share|improve this answer
    
works, the day i will get 15 reps .. i will vote this up .. thanks –  naveen23 Feb 17 at 8:51
    
Great- nice to know it works. Can you accept the answer with a tick mark? –  Rajib Feb 17 at 9:40
    
sorry a newbie ! –  naveen23 Feb 17 at 10:10
1  
It works, but the same audio gets duplicated. The first starts at the beginning of the video, and the delayed one starts after the specified time. –  goo Nov 3 at 1:08
1  
@goo You need to set the adelay for each channel. So if the audio file you're delaying is stereo, you'd need to do something like adelay=5000|5000. What you're probably hearing is the right channel at the beginning and then the delayed left channel. –  blim8183 Nov 20 at 16:41

You need the adelay filter in a chain. See this documentation.

To delay the output of one pad, if it is [aud1] use that as input to the adelay filter at the end of the chain:

[1:a]atrim=end=4,asetpts=PTS-STARTPTS[aud1];[aud1]adelay=2000[delayedaudio]    

The delay is in milliseconds.

share|improve this answer
    
can we use ... [1:a]atrim=end=4,asetpts=PTS-STARTPTS,adelay=2000[aud1] OR [1:a]atrim=end=4,adelay=2000[aud1] ... are those valid statements –  naveen23 Feb 13 at 15:18
    
You could try and see. The reason I suggested using the out-in pads is because you are using complex filters anyway and a chain is a safe way to go. Without the pads the filters will process the audio in succession- in theory this looks like the same effect in this case, but ffmpeg often throws up things that I fail to see at first glance. –  Rajib Feb 13 at 16:05
    
tried this but video is expanded .. –  naveen23 Feb 14 at 16:49

Not the answer you're looking for? Browse other questions tagged or ask your own question.