[FFmpeg-user] Quick (I hope) CLI question

2017-07-24 Thread Eric Downing
Hi!

I have a folder of mixed format video files. I would like to:

• copy video format
• apply "ffmpeg-normalize" to the audio track(s), whilst preserving encoding
• batch process so I can run the same command on the root folder

For example:
video1.mp4 (aac 5.1)
video2.mkv (2 ch stereo)


The issue is that I have a bunch of video files in varying video and audio
formats that need loudness normalization. They number into the hundreds so
running a single command to accommodate each files particular encoding is
cumbersome. I want to preserve formatting for audio and video and apply
normalization to the audio - in batch. Surely there must be a way to script
this.

I have found and understand the CLI language to do these things one by one,
however I'm having a hard time concatenating these commands into a one
liner. It seems that each time the CLI wants me to define an output format
for the audio.

Thank you for any suggestions.

Eric


--
   *eric downing • 786.431.7918 <786.431.7918>*
___
ffmpeg-user mailing list
ffmpeg-user@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-user

To unsubscribe, visit link above, or email
ffmpeg-user-requ...@ffmpeg.org with subject "unsubscribe".

Re: [FFmpeg-user] Quick (I hope) CLI question

2017-07-24 Thread Eric Wilde

At 04:24 PM 7/24/2017 -0400, you wrote:

I want to preserve formatting for audio and video and apply
normalization to the audio - in batch. Surely there must be a way to script
this.




Here's the code that I use for both boosting and companding.  If $Compressor
is 1, it makes up parameters for mencoder.  If $Compressor is not 1, it
makes up parameters for ffmpeg.

#
# If the user wants the input volume boosted by a fixed amount, just set
# the boost volume to that amount.
#
if [ ${FixedBoost} -ne 0 ]; then
BoostVol=${FixedBoost}
#
# Otherwise, if the user wants the input volume boosted so that the peak is
# near 0dB, we need to figure out how much boost is necessary.
#
else
#
# Note that we must use ffmpeg to detect the volume of the input file
# because ffprobe doesn't offer this feature.  So, even if the
# compressor being used is mencoder, ffmpeg is still required to use
# this feature.  Also, we look at the first 300 seconds (five minutes)
# of the input file to get an accurate picture of the maximum volume.
# This takes about 20-30 seconds but gives a much better idea of what
# the maximum volume really is.
#
# Once we have a boost volume amount, we can apply it with the volume
# filter
#
if [[ ${AudioBoost} -ne 0 && -x ${CompressFFMpeg} ]]; then
BoostVol=`${CompressFFMpeg} -i $2 -af "volumedetect" -to 300 
-nostats -f null -y /dev/null 2>&1 | grep -e '^\\[Parsed.*max_volume' | sed 
's/^.*max_volume:\\s-\\([0-9\\.]*\\).*$/\\1/g'`


BoostTrue=`echo "${BoostVol} > 1" | bc`
if [ ${BoostTrue} -ne 0 ]; then
BoostVol=`echo "scale=1; ${BoostVol} - 1" | bc`
else
BoostVol=0
fi
else
BoostVol=0
fi
fi
 .
 .
 .
#
# If we are boosting the audio, set the audio filter to boost it by the
# amount that we pre-calculated.  Note that this has no effect on dynamic
# range, it just makes everything louder.
#
BoostTrue=`echo "${BoostVol} > 0" | bc`
if [ $BoostTrue -ne 0 ]; then
if [ $Compressor == 1 ]; then
AudioFilter="-af volume=+${BoostVol}dB"
else
AudioFilter="-af volume=${BoostVol}dB"
fi
fi
#
# If we are normalizing the audio, set the audio filter to lessen the
# dynamic range.
#
# For mencoder, the volume normalization filter seems to work well (having
# tried it on quite a bit of recorded TV, which has much too high dynamic
# range in many cases).
#
# For ffmpeg, the compand filter with the parameters shown seems to work
# well also.  Here's the note from tugshank at forum.videohelp.com:
#
#  -af "aformat=channel_layouts=stereo,
#compand=0 0:1 1:-90/-900 -70/-70 -30/-9 0/-3:6:0:0:0"
#
#  channel_layouts=stereo forces mono to stereo, just in case
#
#  compander (compressor/expander):
#
#   attack - 0
#   release - 1
#   -90 dB in, infinity out
#   -70 dB in, -70 dB out
#   -30 dB in, -9 dB out
#   0 dB in, -3 dB out,
#   soft knee 6
#   0 dB makeup gain
#   input level 0 dB
#   lookahead 0.
#
#  Specifically made for 'whisper+explosion' scenes.
#
# For publishing video, EBU R128 is currently the preferred standard.  To
# use EBU R128, one must build ffmpeg with libebur128.  Normally, this
# isn't the default so you must use "--enable-libebur128" when you run
# configure.  Then, the "loudnorm" audio filter can be used, as in
# "-af loudnorm".  To figure out if loudnorm is available, use the
# following:
#
#  ffmpeg -filters 2>/dev/null | grep loudnorm
#
if [ ${AudioNorm} -ne 0 ]; then
if [ $Compressor == 1 ]; then
AudioFilter="-af volnorm=2:0.75"
else
AudioFilter="-af \"aformat=channel_layouts=stereo,compand=0 0:1 
1:-90/-900 -70/-70 -30/-9 0/-3:6:0:0:0\""

fi
fi


___
ffmpeg-user mailing list
ffmpeg-user@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-user

To unsubscribe, visit link above, or email
ffmpeg-user-requ...@ffmpeg.org with subject "unsubscribe".

Re: [FFmpeg-user] Quick (I hope) CLI question

2017-07-24 Thread Cley Faye
2017-07-24 22:24 GMT+02:00 Eric Downing :

> Hi!
>
> I have a folder of mixed format video files. I would like to:
>
> • copy video format
> • apply "ffmpeg-normalize" to the audio track(s), whilst preserving
> encoding
> • batch process so I can run the same command on the root folder
>
> For example:
> video1.mp4 (aac 5.1)
> video2.mkv (2 ch stereo)
>
>
> The issue is that I have a bunch of video files in varying video and audio
> formats that need loudness normalization. They number into the hundreds so
> running a single command to accommodate each files particular encoding is
> cumbersome. I want to preserve formatting for audio and video and apply
> normalization to the audio - in batch. Surely there must be a way to script
> this.
>
> I have found and understand the CLI language to do these things one by one,
> however I'm having a hard time concatenating these commands into a one
> liner. It seems that each time the CLI wants me to define an output format
> for the audio.
>
> Thank you for any suggestions.
>

​I'm not sure what you mean exactly, but if I understand correctly, here
are some pieces that might help you:

- If you don't specify an output codec (for either video or audio), it will
use some default settings
- If you specify "-c:a copy" (for audio) or "-c:v copy" (for video), you
can't use filtering as it will copy the stream as-is
- You can get file informations using ffprobe, in a script-friendly format
(like json)

By combining that, you can make a script that take a file, pass it to
ffprobe, get the audio codec and settings, and replicate an ffmpeg command
line that will copy video "-c:v copy" and use the appropriate audio codec.
___
ffmpeg-user mailing list
ffmpeg-user@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-user

To unsubscribe, visit link above, or email
ffmpeg-user-requ...@ffmpeg.org with subject "unsubscribe".