Trim and fade in/out video and audio with avconv (or different tool)

avconvffmpegtrimvideovideo editing

I'm using avconv for trimming and converting videos. Let's say I want to drop the first 7 and last 2.5 seconds of the video stream and one audio stream of an one-hour mts file:

avconv -i input.mts -map 0:0 -map 0:3 -ss 0:0:07 -t 0:59:50.5 out.mov

This works so far, but now I want to add two seconds of fading in and out at the beginning and the end by adding:

-vf fade=type=in:start_frame=350:nb_frames=100 -vf fade=type=out:start_frame=178750:nb_frames=100

Those frames are calculated with the 50 fps that avconv reports for the video source. But there is neither fading in nor out.

1) What goes wrong with the video fading and how to do it right?
2) How to add audio fading. There seems to be an -afade option. but I don't find it documented.

Alternatively, you can propose a different tool for this goal (trim and fade video and audio), preferrably available as package for Debian 8.

Best Answer

I finally found the time to try the answer suggested by @Mario G., but it seemed extremely cumbersome. I need to do this many dozens of times. I read the documentation of ffmpeg and found it much more powerful than avconv, including fading for audio and video, so the solution is

ffmpeg -i input.mts -map 0:0 -map 0:3 -ss 0:0:07 -to 0:59:57.5 -vf 'fade=t=in:st=7:d=2,fade=t=out:st=3595.5:d=2,crop=out_h=692' -af 'afade=t=in:st=7:d=2,afade=t=out:st=3595.5:d=2' out.mov

So the st= and d= parameters for the fade take times in seconds, no need for converting to frames.

I also discovered the -to option to take the end time directly instead of calculating the length.

This command does all steps

  • channel selection with -map,
  • trimming with -ss and -to,
  • video fading with -vf option fade=t=in and fade=t=out,
  • audio fading with -af option afade=t=in and afade=t=out and
  • cropping with -vf option crop=

in a single step.

Related Question