3

Looking to edit a blip out of the beginning of a video/audio file:

  • How can I use ffmpeg to only edit the first two seconds of the clip so that there's no longer that blip in the audio?

  • How do I ensure that all 7 audio tracks are affected by the audio filter?

  • How do I ensure that all 7 are also present in my output file in the same input specs?

Complete output:

ffmpeg -i ~/Downloads/in.mov  -vcodec copy -acodec pcm_s24le -q:a 0 -af "volume=enable='between(t,0,3)':volume=0"  ~/Downloads/out2.mov
ffmpeg version 2.6.1 Copyright (c) 2000-2015 the FFmpeg developers
  built with Apple LLVM version 6.0 (clang-600.0.57) (based on LLVM 3.5svn)
  configuration: --prefix=/usr/local/Cellar/ffmpeg/2.6.1 --enable-shared --enable-pthreads --enable-gpl --enable-version3 --enable-hardcoded-tables --enable-avresample --cc=clang --host-cflags= --host-ldflags= --enable-libx264 --enable-libmp3lame --enable-libvo-aacenc --enable-libxvid --enable-vda
  libavutil      54. 20.100 / 54. 20.100
  libavcodec     56. 26.100 / 56. 26.100
  libavformat    56. 25.101 / 56. 25.101
  libavdevice    56.  4.100 / 56.  4.100
  libavfilter     5. 11.102 /  5. 11.102
  libavresample   2.  1.  0 /  2.  1.  0
  libswscale      3.  1.101 /  3.  1.101
  libswresample   1.  1.100 /  1.  1.100
  libpostproc    53.  3.100 / 53.  3.100
Guessed Channel Layout for  Input Stream #0.1 : mono
Guessed Channel Layout for  Input Stream #0.2 : mono
Guessed Channel Layout for  Input Stream #0.3 : mono
Guessed Channel Layout for  Input Stream #0.4 : mono
Guessed Channel Layout for  Input Stream #0.5 : mono
Guessed Channel Layout for  Input Stream #0.6 : mono
Guessed Channel Layout for  Input Stream #0.7 : stereo
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '~/Downloads/in.mov':
  Metadata:
    major_brand     : qt  
    minor_version   : 537199360
    compatible_brands: qt  
    creation_time   : 2014-01-16 18:02:27
  Duration: 00:00:06.44, start: 0.000000, bitrate: 119128 kb/s
    Stream #0:0(eng): Video: prores (apch / 0x68637061), yuv422p10le(bt709), 1920x1080, 109843 kb/s, SAR 1:1 DAR 16:9, 29.97 fps, 29.97 tbr, 2997 tbn, 2997 tbc (default)
    Metadata:
      creation_time   : 2014-01-16 18:02:27
      handler_name    : Apple Alias Data Handler
      encoder         : Apple ProRes 422 (HQ)
      timecode        : 01:00:00;00
    Stream #0:1(eng): Audio: pcm_s24le (in24 / 0x34326E69), 48000 Hz, 1 channels, s32 (24 bit), 1152 kb/s (default)
    Metadata:
      creation_time   : 2014-01-16 18:02:27
      handler_name    : Apple Alias Data Handler
    Stream #0:2(eng): Audio: pcm_s24le (in24 / 0x34326E69), 48000 Hz, 1 channels, s32 (24 bit), 1152 kb/s (default)
    Metadata:
      creation_time   : 2014-01-16 18:02:27
      handler_name    : Apple Alias Data Handler
    Stream #0:3(eng): Audio: pcm_s24le (in24 / 0x34326E69), 48000 Hz, 1 channels, s32 (24 bit), 1152 kb/s (default)
    Metadata:
      creation_time   : 2014-01-16 18:02:27
      handler_name    : Apple Alias Data Handler
    Stream #0:4(eng): Audio: pcm_s24le (in24 / 0x34326E69), 48000 Hz, 1 channels, s32 (24 bit), 1152 kb/s (default)
    Metadata:
      creation_time   : 2014-01-16 18:02:27
      handler_name    : Apple Alias Data Handler
    Stream #0:5(eng): Audio: pcm_s24le (in24 / 0x34326E69), 48000 Hz, 1 channels, s32 (24 bit), 1152 kb/s (default)
    Metadata:
      creation_time   : 2014-01-16 18:02:27
      handler_name    : Apple Alias Data Handler
    Stream #0:6(eng): Audio: pcm_s24le (in24 / 0x34326E69), 48000 Hz, 1 channels, s32 (24 bit), 1152 kb/s (default)
    Metadata:
      creation_time   : 2014-01-16 18:02:27
      handler_name    : Apple Alias Data Handler
    Stream #0:7(eng): Audio: pcm_s24le (in24 / 0x34326E69), 48000 Hz, 2 channels, s32 (24 bit), 2304 kb/s (default)
    Metadata:
      creation_time   : 2014-01-16 18:02:27
      handler_name    : Apple Alias Data Handler
    Stream #0:8(eng): Data: none (tmcd / 0x64636D74), 0 kb/s (default)
    Metadata:
      creation_time   : 2014-01-16 18:02:28
      handler_name    : Apple Alias Data Handler
      timecode        : 01:00:00;00
File '~/Downloads/out2.mov' already exists. Overwrite ? [y/N] y
Output #0, mov, to '~/Downloads/out2.mov':
  Metadata:
    major_brand     : qt  
    minor_version   : 537199360
    compatible_brands: qt  
    encoder         : Lavf56.25.101
    Stream #0:0(eng): Video: prores (apch / 0x68637061), yuv422p10le, 1920x1080 [SAR 1:1 DAR 16:9], q=2-31, 109843 kb/s, 29.97 fps, 29.97 tbr, 11988 tbn, 2997 tbc (default)
    Metadata:
      creation_time   : 2014-01-16 18:02:27
      handler_name    : Apple Alias Data Handler
      encoder         : Apple ProRes 422 (HQ)
      timecode        : 01:00:00;00
    Stream #0:1(eng): Audio: pcm_s24le (in24 / 0x34326E69), 48000 Hz, stereo, s32 (24 bit), 2304 kb/s (default)
    Metadata:
      creation_time   : 2014-01-16 18:02:27
      handler_name    : Apple Alias Data Handler
      encoder         : Lavc56.26.100 pcm_s24le
Stream mapping:
  Stream #0:0 -> #0:0 (copy)
  Stream #0:7 -> #0:1 (pcm_s24le (native) -> pcm_s24le (native))
Press [q] to stop, [?] for help
frame=  193 fps=109 q=-1.0 Lsize=   88166kB time=00:00:06.43 bitrate=112155.7kbits/s    
video:86349kB audio:1811kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.006946%

migrated from stackoverflow.com Apr 13 '15 at 18:10

This question came from our site for professional and enthusiast programmers.

  • 1
    You can mute audio sections like this stackoverflow.com/questions/29215197/…. You cannot use -acodec copy at the same time. – aergistal Apr 8 '15 at 20:33
  • Ah looks like putting quotes around the entire filter results in ffmpeg not throwing the error but I also get no other audio which is not intended. ffmpeg -i ~/Downloads/in.mov -vcodec copy -af "volume=volume='between(t,0,3)':volume=0" ~/Downloads/out2.mov – Tony Apr 9 '15 at 16:39
  • You should always include the complete console output along with your command when asking for help with ffmpeg. – llogan Apr 9 '15 at 16:50
  • You have 7 audio streams. Default stream selection will automatically select the stream with the most channels (0:7). Do you want to include the rest? They are just being ignored. The output is being encoded as AAC. Do you want that, or do you want it to be the same as the input? Also, your filtering command should probably look like: volume=enable='between(t,0,3)':volume=0. – llogan Apr 9 '15 at 18:12
  • @LordNeckbeard updated question a bit and posted most recent result. – Tony Apr 9 '15 at 20:29
2

Looks like ffmpeg needs to see the quotes around the parens, so you need to protect them from the shell with another layer of quotes.

ffmpeg -i ~/Downloads/in.mov -vcodec copy -af "volume=enable='between(t,0,3)':volume=0" ~/Downloads/out2.mov

Also, don't forget to specify something about the audio codec. ffmpeg's default AAC encoder is bad compared to libfdkaac. And you're not specifying an audio bitrate or quality.

  • Is there a better way of formating console code here, maybe with a linebreak to better distinguish it from the answer? – p2or Apr 11 '15 at 12:53
  • oops, I left out a trailing backquote so my ffmpeg command got mis-formatted. The only difference is that i added double quotes around the entire argument to -af. There are many other ways to protect the single quotes from the shell, or to quote the parens for ffmpeg's parser with backslashes. – Peter Cordes Apr 11 '15 at 13:23
1

If you want to mute the first 3 seconds of each audio stream then you have to filter each one:

ffmpeg -i input.mov -filter_complex \
"[0:a:0]volume=enable='between(t,0,3)':volume=0[a0]; \
 [0:a:0]volume=enable='between(t,0,3)':volume=0[a1]; \
 [0:a:0]volume=enable='between(t,0,3)':volume=0[a2]; \
 [0:a:0]volume=enable='between(t,0,3)':volume=0[a3]; \
 [0:a:0]volume=enable='between(t,0,3)':volume=0[a4]; \
 [0:a:0]volume=enable='between(t,0,3)':volume=0[a5]; \
 [0:a:0]volume=enable='between(t,0,3)':volume=0[a6]" \
-map 0:v -map "[a0]" -map "[a1]" -map "[a2]" -map "[a3]" \
-map "[a4]" -map "[a5]" -map "[a6]" -map 0:d -c copy -c:a pcm_s24le output.mov

If you prefer to merge all of the channels into a single, multichannel stream, then use amerge first:

ffmpeg -i input.mov -filter_complex \
"[0:a:0][0:a:1][0:a:2][0:a:3][0:a:4][0:a:5][0:a:6]amerge=inputs=6,volume=enable='between(t,0,3)':volume=0[a]; \
-map 0:v -map "[a]" -map 0:d -c copy -c:a pcm_s24le output.mov

I didn't test these examples since I do not have a similar input file and I was too lazy to make one.

  • filtering each audio stream doesn't seem to work or I'm missing the syntax somewhere as it just results in the prompt > – Tony Apr 10 '15 at 17:57
  • @Tony There were extra " in my example. Copy paste typo. I removed them. Try again. Or provide a short input sample and I can perform an actual test on it. – llogan Apr 10 '15 at 18:08
  • hmm ok revised version works but the audio is now slightly out of sync from where it was before. – Tony Apr 10 '15 at 18:14
  • @Tony You should update your question with your command and the console output. – llogan Apr 10 '15 at 18:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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