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 ?

shrw
  • 151

2 Answers2

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
Rajib
  • 3,156
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.

Rajib
  • 3,156