Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

This page was adapted from a page in the LLILAS Benson Digital Inititaives wiki space, and much of what follows was put together by Ryan Sullivant, Digital Content Curator at AILLA.

FFmpeg

...

The open-source FFmpeg engine can be used for several purposes. These include, converting between a/v containers and formats, re-encoding media with a different codec to produce smaller derivative access files, and rotating video. FFmpeg can be used as a command line tool or can be integrated into Python scripts using the ffmpeg-python package (github), which is useful for batch processes, especially if you are more comfortable using Python tools to identify which files need to be fed into FFmpeg (literal lists, reading from a file, regex filters with glob, etc.) than doing the same things with the command line, terminal, or powershell. As FFmpeg has no native MP3 encoder, another library, like LAME, may need to be installed to produce MP3 files.

Windows installation

FFmpeg is often distributed as a compressed folder. Depending on the format, Windows Explorer may not be able to open or extract this folder by default. You can use 7-Zip or WinRAR to open a wide variety of compressed file formats in Windows. Start by extracting the contents of the FFmpeg folder to a local directory, such as C:\FFmpeg.

In order to run FFmpeg directly using the command prompt in Windows, the location of the extracted bin folder containing ffmpeg.exe needs to be added to the Path environment variable. This process may require system administrator approval, but is relatively fast and easy. Instructions can be found here: http://web.archive.org/web/20210723181111/https://www.thewindowsclub.com/how-to-install-ffmpeg-on-windows-10

Once FFmpeg has been properly mapped to Path, it can be run in the Windows command prompt with 'ffmpeg' alone.

Convert audio formats

Sometimes we receive digitized or born-digital audio in formats that are not supported by our Islandora repository. Circa 2019 at AILLA, these have included files in WMA, AIFF and OPUS (a lossly format used by WhatsApp). Staff should convert these files into the supported WAV or MP3 formats, depending on the nature and quality of the unsupported digital files. Format conversion with FFmpeg can be as simple as specifying a different extension for the output file, but additional details, such as those discussed in Creating smaller audio files, may also be specified.

...

This syntax can also be used to extract MP3 audio from an MP4 file, by specifying the MP4 file as the input and the MP3 file as the output.

Batch converting audio formats

If you have a directory full of files that need to be converted from one format to another, you can perform this transformation on each of them in succession using a for loop in the command prompt:

...

In the above example, all WMA files found within the C:\directory\audio_files folder will have MP3 copies created. These extensions can be changed to any format supported by FFmpeg to achieve different results

Creating smaller audio files

Some digitization labs will produce uncompressed files (typically WAV format) with much greater resolution than is necessary or useful (for example, 24/96k), and are often 2 or 4 times are big as files produced in more smaller resolutions. In these cases, we can re-encode the files with one of these lower resolutions. (NB: these resolutions are ideal for recordings of speech meant for listening and acoustic speech analysis; audio files with different contents and purposes may require higher resolutions.)

...

Note that different commands may be used to alter the sizes of compressed files (like MP3).  

Rotating video files

Some video files specify their orientation in their technical metadata. Sometimes, a file is incorrectly presented as portrait when it should be in landscape orientation and vice-versa. It is possible to transpose all pixels of the video, but a simple solution is to edit the file's technical metadata (while copying all other metadata) to inform video players of the proper orientation. This is done with the -map_metadata-metadata:s:v and -codec copy flags as below. Note that rotate specified the degrees of rotation in a counterclockwise orientation; '90' rotates counterclockwise and '270' rotates counterclockwise. It is unclear how this command (in particular the -metadata:s:v flag) can be implemented with ffmpeg-python, so this function can only be done via the command line currently.

...

ffmpeg -i input_file_path -map_metadata 0 -metadata:s:v rotate="270" -codec copy output_file_path

Creating smaller video files

Some high-definition cameras will use codecs, like XAVC S, that produce very large files, in part because each frame contains many many pixels. Many of these files may be too large to ingest directly into a repository. One way to produce a smaller file that is still suitable for online viewing is to re-encode the file with a different codec, one very widely supported codec to try is H.264. 

...

Commands exist for altering the size of video frames in the output, but these have not yet been explored.

Converting MP3s to AAC MP4s

The UT Libraries Collections Portal will only stream an audio file if it has been ingested into the DAMS as an MP4 file with AAC audio. While it's normally used for video files, the MP4 extension is really just a "wrapper" to combine audio and video streams, and there' s no requirement that there even be a video stream. That means you can convert from MP3 audio directly to MP4, and as long as you specify that the output will use AAC audio, it will work with the Collections Portal. Using the command prompt:

...

According to Wikipedia, versions of FFmpeg released before February 2016 used an AAC encoder that produced generally low-quality output, so it is a good idea to use more up to date releases: https://en.wikipedia.org/wiki/Advanced_Audio_Coding#FFmpeg_and_Libav

Getting runtime (or other information) for a list of files

In addition to converting and manipulating objects, FFmpeg can also be used to extract technical information about A/V files. Specific technical metadata fields can be filtered in the Linux command line using the grep command. Using a Linux command line such as Ubuntu on the Windows Subsystem for Linux, the following script will produce a text list of filenames & runtimes:

...