<p>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.</p>

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

<pre><code>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
</code></pre>

<p>The individual settings:</p>

<ul>
<li>Video codec: <code>libx265</code> (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. <a href="https://www.videolan.org/vlc/index.html" rel="nofollow">VLC</a> supports this codec for viewing the video.</li>
<li>Encoding speed vs. compression density: <code>-preset veryslow</code>. Converting videos with this preset takes <em>very</em> long time, but may reduce file size with around 20 % compared to the fastest setting. If you want quicker encoding, use <code>ultrafast</code>, <code>fast</code>, <code>medium</code> or <code>slow</code>.</li>
<li>Video quality: <code>-crf 23</code>. 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. <code>18</code> is visually lossless but takes up much space.</li>
<li>Volume gain: <code>volume=25dB</code></li>
<li>High pass filter >200 Hz: <code>highpass=f=200</code></li>
<li>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: <code>equalizer=f=50:width_type=h:width=100:g=-15</code></li>
<li>Audio codec: <code>aac</code></li>
<li>Audio quality: <code>-b:a 192k</code></li>
</ul>

<p><strong>Optional</strong>:</p>

<ul>
<li>Lighten video curves: <code>-vf "curves=preset=lighter"</code></li>
</ul>

<p><strong>Ideas for improvement:</strong></p>

<ul>
<li>A good way to gate audio to filter out background noise and keep only the talky bits.</li>
</ul>

CC BY-SA 3.0
2015-11-21T12:13:50.163Z
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
CC BY-SA 3.0
2015-11-21T12:40:08.787Z
@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
CC BY-SA 3.0
2015-11-21T12:48:56.593Z
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"  @ http://ffmpeg.org/ffmpeg-all.html#toc-dynaudnorm. May be able to bypass 'volume'
Gyan
CC BY-SA 3.0
2015-11-21T13:55:17.593Z
@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
CC BY-SA 3.0
2015-11-21T14:08:35.857Z
Try using an audio gate before the dynaudnorm: http://ffmpeg.org/ffmpeg-all.html#toc-agate
Gyan
CC BY-SA 3.0
2015-11-23T17:33:08.440Z
If you're the teacher, borrow a lavalier from your school's library/ media dept.  If you're the student, search google for a dslr shotgun mic and sit in the front row.
Jason Conrad
CC BY-SA 3.0
2015-12-08T21:32:52.867Z
@Mulvya Do you have any suggestions on a good video codec for this purpose? I use `x265` to keep the file sizes to a minimum and still have the text on the blackboard legible. But encoding 1 hr of footage @ 1080p takes almost 24 hours. I'm looking at either getting swaths of more CPU power to run multiple jobs in parallel, or if there's a closer-to real-time codec out there which maintains an adequate quality/filesize.
P A N
CC BY-SA 3.0
2015-12-09T03:46:39.113Z
You're looking to square the circle: you want a file with small size but good quality that gets encoded quickly :) Experiment with x264 to aim for a target bitrate of about 1.5-1.7x of your x265 encodes. It should encode quicker and maybe, the result is acceptable. Another thing to look at is if you can crop the input and encode at the cropped size - viable if your composition is wider than the area of interest.
Gyan
CC BY-SA 3.0
2015-12-09T17:34:51.903Z
Can `-threads` be used to any effect? I've seen it mentioned, but not much, so I'm assuming the default value (not even including it in the command line) is already optimal. I have a quad-core processor.
P A N
CC BY-SA 3.0
2015-11-21T11:48:15.830Z
2015-12-04T13:27:41.997Z
2015-12-04T13:27:41.997Z
P A N
<p>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.</p>

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

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

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

<p>How should I go about to meet these objectives?</p>

<p>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.</p>

CC BY-SA 3.0
2015-11-17T16:09:59.393Z
Does it have to be a single command per file? And does the process have to be automatic?
Gyan
CC BY-SA 3.0
2015-11-21T11:33:05.310Z
@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
CC BY-SA 3.0
2015-11-21T11:33:53.623Z
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
<ffmpeg>
FFmpeg script to clean up and compress iPhone video recordings from university lectures
P A N
# FFmpeg script to clean up and compress iPhone video recordings from university lectures

(Asked by: username_0 on 2015-11-11)

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.

**Tags:** ffmpeg

> **Comments:**
> **username_1**: Does it have to be a single command per file? And does the process have to be automatic?  
> **username_0**: @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.  
> **username_0**: 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.  

---

## 1 answers

### Answer by username_0 on 2015-11-21. Score: 2 | Accepted answer

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.

> **Comments:**
> **username_1**: 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?  
> **username_0**: @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(?).  
> **username_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"  @ http://ffmpeg.org/ffmpeg-all.html#toc-dynaudnorm. May be able to bypass 'volume'  
> **username_0**: @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.  
> **username_1**: Try using an audio gate before the dynaudnorm: http://ffmpeg.org/ffmpeg-all.html#toc-agate  
> **username_2**: If you're the teacher, borrow a lavalier from your school's library/ media dept.  If you're the student, search google for a dslr shotgun mic and sit in the front row.  
> **username_0**: @Mulvya Do you have any suggestions on a good video codec for this purpose? I use `x265` to keep the file sizes to a minimum and still have the text on the blackboard legible. But encoding 1 hr of footage @ 1080p takes almost 24 hours. I'm looking at either getting swaths of more CPU power to run multiple jobs in parallel, or if there's a closer-to real-time codec out there which maintains an adequate quality/filesize.  
> **username_1**: You're looking to square the circle: you want a file with small size but good quality that gets encoded quickly :) Experiment with x264 to aim for a target bitrate of about 1.5-1.7x of your x265 encodes. It should encode quicker and maybe, the result is acceptable. Another thing to look at is if you can crop the input and encode at the cropped size - viable if your composition is wider than the area of interest.  
> **username_0**: Can `-threads` be used to any effect? I've seen it mentioned, but not much, so I'm assuming the default value (not even including it in the command line) is already optimal. I have a quad-core processor.  

---

