3

I video record my university lectures using an iPhone 6 and then export them to OS X. The files can often become up to 4 GB/hour in size.

I'm looking to create or use a pre-existing solution that can do the following for my video files:

  • Amplify the audio
  • Normalize or level the audio
  • Audio click removal (optional)
  • Compress video to save disk space
  • Do the above by running a script or shell command (for batches of files if possible)

I'm assuming that FFmpeg can be helpful for running existing scripts, or creating a new one.

How should I go about to meet these objectives?

I have also looked at other alternatives like Handbrake but didn't find that it can do the audio adjustments adequately – let me know if I'm wrong.

  • Does it have to be a single command per file? And does the process have to be automatic? – Gyan Nov 17 '15 at 16:09
  • @Mulvya Thanks for your comment. It would be good to "streamline" the process as much as possible. I'm trying to find ways for instance, if it is possible to rig a "drop box" where a script is automatically run if a file is placed inside that folder. – P A N Nov 21 '15 at 11:33
  • For now, I have posted what I currently have in an answer below. Feel free to improve it liberally or come with other suggestions and post an answer. – P A N Nov 21 '15 at 11:33
2

This is what I have come up with so far. Feel free to improve this answer liberally, with the objective of cleaning up and encoding lecture notes, within a streamlined process.

The command is run in the working directory, e.g. cd /Users/me/Downloads, and will encode all .MOV files present.

for i in *.MOV; do ffmpeg -i "$i" -c:v libx265 -preset veryslow -crf 23 -af "volume=25dB, highpass=f=200, equalizer=f=50:width_type=h:width=100:g=-15" -c:a aac -strict experimental -b:a 192k "${i%.MOV}-ENCODED.MOV"; done

The individual settings:

  • Video codec: libx265 (HEVC). This codec is unorthodox because it's still in development, but it's many times better than its predecessor in keeping file sizes low. VLC supports this codec for viewing the video.
  • Encoding speed vs. compression density: -preset veryslow. Converting videos with this preset takes very long time, but may reduce file size with around 20 % compared to the fastest setting. If you want quicker encoding, use ultrafast, fast, medium or slow.
  • Video quality: -crf 23. Quite good quality. Decreasing this number will increase quality but also logarithmically increase file size. This setting strikes an okay balance between file size and quality. 18 is visually lossless but takes up much space.
  • Volume gain: volume=25dB
  • High pass filter >200 Hz: highpass=f=200
  • EQ notch filter @ 50Hz±100Hz (this should be mitigated by the high pass filter already, but for some reason this seems to remove background noise: equalizer=f=50:width_type=h:width=100:g=-15
  • Audio codec: aac
  • Audio quality: -b:a 192k

Optional:

  • Lighten video curves: -vf "curves=preset=lighter"

Ideas for improvement:

  • A good way to gate audio to filter out background noise and keep only the talky bits.
  • 1) You've opted for HEVC, so I guess this is for limited distribution. H264 is the standard codec for online streaming or wide playback compatibility. 2) You're applying a fixed gain of 25dB, so are all your source videos at similar levels coming in? 3) normalization not required? – Gyan Nov 21 '15 at 12:13
  • @Mulvya 1) That's right, I opted for HEVC because it saves disk space. But you're correct that H264 is more compatible for wider distribution. If one wants to change, I assume the only thing that needs to change is c:v? 2) The gain is not always the same, but I'm not sure how to analyze and then adapt appropriate gain automatically. 25dB is conservative but helps most cases for these videos. 3) Not sure if normalization really is required because AFAIK it just shifts the waveform to peak at 0dB. But a leveller could be useful(?). – P A N Nov 21 '15 at 12:40
  • 1
    1) Yes, you would use libx264 in place of libx265. 2)Try out the dynamic audio normalizer - "This filter applies a certain amount of gain to the input audio in order to bring its peak magnitude to a target level (e.g. 0 dBFS). However, in contrast to more "simple" normalization algorithms, the Dynamic Audio Normalizer dynamically re-adjusts the gain factor to the input audio. This allows for applying extra gain to the "quiet" sections of the audio while avoiding distortions or clipping the "loud" sections" @ ffmpeg.org/ffmpeg-all.html#toc-dynaudnorm. May be able to bypass 'volume' – Gyan Nov 21 '15 at 12:48
  • @Mulvya Thanks for the good suggestion on dynaudnorm. I tried it out but because there is a lot of background noise ("whiteish" mid-range noise from the room) it didn't pick up and amplify the speech parts compared to so called "silence" (which isn't really silent). Maybe it would work better if a noise reduction tool was used first, but I think that would require sampling silence first, which can be hard when running a standardized script for different videos. – P A N Nov 21 '15 at 13:55
  • 1
    Try using an audio gate before the dynaudnorm: ffmpeg.org/ffmpeg-all.html#toc-agate – Gyan Nov 21 '15 at 14:08

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.