4

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

I want to place it between specified location ..


EDIT

Here is the full command with output :

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%

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 ?

5
  • 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.
    – llogan
    Feb 13, 2014 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, 2014 at 16:55
  • Sir, i am new in this area .. and got to do this .. please give some commands of what you are talking
    – shrw
    Feb 16, 2014 at 6:32
  • I am hearing from left and then same from right. Is this increasing the length of the video
    – shrw
    Feb 16, 2014 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, 2014 at 16:33

2 Answers 2

8

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
7
  • works, the day i will get 15 reps .. i will vote this up .. thanks
    – shrw
    Feb 17, 2014 at 8:51
  • 1
    Great- nice to know it works. Can you accept the answer with a tick mark?
    – Rajib
    Feb 17, 2014 at 9:40
  • sorry a newbie !
    – shrw
    Feb 17, 2014 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.
    – gcstr
    Nov 3, 2014 at 1:08
  • 2
    @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, 2014 at 16:41
1

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.

3
  • 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
    – shrw
    Feb 13, 2014 at 15:18
  • 1
    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, 2014 at 16:05
  • tried this but video is expanded ..
    – shrw
    Feb 14, 2014 at 16:49

Not the answer you're looking for? Browse other questions tagged .