FFmpeg wrapper to encode upon some conditions.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Romain 5f963736c1 Snapshot 0a563dd372
Licence note Snapshot 0a563dd372
README.md Snapshot 0a563dd372
ffmpeg_ein.sh Snapshot 0a563dd372

README.md

FFmpeg Encode If Needed

FFmpeg wrapper to encode upon some conditions.

Installation

The script can be use "as is" with a command like ./ffmpeg_ein.sh but you could also "install" it with something like:

mv ffmpeg_ein.sh /usr/bin/ffmpeg_ein

Usage

ffmpeg_ein [OPTION] [INPUT]

Refer to the -h argument to get the full list of options.

Description

By default, FFmpeg encode a file regardless of the fact that the original and selected codec are the same. Although it may be be a desired outcome, it can lead to unnecessary operations losing time and quality.

This script allow the user to specified a desired codec for audio and video, only if either of those are not present an encoding will be triggered.

For example if the desired codecs are aac/h264 and the source file is wmav2/h264 then the file will be encoded with aac and the h264 stream copied.

Desired ( -a aac ) Source FFmpeg option
aac aac -c:a copy
aac X content of -b

Warning, by default no output is set, use the -d option or specify the output file with -o.

Batch friendly

This script is designed to be batch friendly allowing the sorting of processed and sources files within multiple directories. The following points also help in this endeavor:

  • INPUT can be multiple files and/or directories.
  • The output files will be automatically named with the -d option.
  • Errors generated by FFmepg are stored in a [FILE].error.txt file alongside the outputted file.
  • Friendly statistics available if the verbose option is set to default value.

Example

ffmpeg_ein \
-a aac -b "-c:a aac -b:a 48k" \
-v h264 -u "-c:v libx264 -crf 23" \
-d /tmp/ \
[FILE]

Will result in the encoding of the file(s) [FILE] if either their audio codec is not "aac" or their video codec is not "h264". The result encoded file(s) (if created) will have the same name as the original(s) and be placed in the "/tmp" folder.

Desired Source FFmpeg option
aac/h264 aac/h264 -c:a copy -c:v copy
aac/h264 X/h264 -c:a aac -b:a 48k -c:v copy
aac/h264 aac/X -c:a copy -c:v libx264 -crf 23
aac/h264 X/X -c:a aac -b:a 48k -c:v libx264 -crf 23

Limitations / Future roadmap

  • Only the first audio and video streams are accounted for during codec comparaison.
  • Only the codecs are checked so it's not possible to trigger encoding on other parameters like bitrate or length.
  • The comparaison doesn't allow for multiple value (example compare source against h264 and mpeg4)
  • No "-n, --dry-run" option exist to perform a trial run with no changes made.
  • Some assumptions are made regarding the fact that the user will provide valid input (valid FFmpeg arguments; read/write access to specified files and folders; ...)