Introduction

Presenting audio and video stimuli can be challenge. Different task software may require different formats or it might be necessary to adjust the resolution of the videos. Below, a few options and examples are given on how to transcode audio and video. 

Audacity

Audacity is an audio editor and recorder that is free and open-source. Audacity is available at Leiden University and can be downloaded from the Software Center.

Examples of using Audacity:

  • Audio can be cut out by selecting a part of the Audio signal and going to Edit ⇒ Cut / Delete
  • The format of the audio can be changed by exporting the Audio. Go to File ⇒ Export ⇒ choose the desired format. Then, some Format Options might become available.
  • To change the Project Rate (Hz), go to the lower-left corner. Here, the project rate can be adjusted. After adjusting, export the audio in the desired format. For some task software, it is necessary that all sound files have the same rate. 

VLC

VLC media player is a free media player that offers some basic video conversion options. VLC is available at Leiden University and can be downloaded from the Software Center.

Video transcoding instructions:

  • Go to Media ⇒ Convert / Save
  • Click Add, navigate to the video(s) you want to convert and open them
  • Click Convert / Save
  • In the Profile drop-down menu a profile can be chosen. To edit the profile, click on the wrench icon. Here, the format, video and audio codec and resolution (under Video codec) can be adjusted. 
  • Click Save and click Start to convert.

VLC-convert.gif

FFmpeg

FFmpeg is an easy-to-use command line tool for converting video files. There is a lot that ffmpeg can do, below some instructions are given on how to download it and use it for simple video conversions. For more commands and information, visit the ffmpeg documentation page.

Download ffmpeg

Ffmpeg can be downloaded here. To get the ffmpeg executable, go to Get packages & executable files. For Windows, select the Windows image. Go to for example the Windows builds from gyan.dev. Here, downloading an essentials built should be enough. Download ffmpeg-git-essentials.7z. Extract this folder (needs 7zip). In the folder in bin, the ffmpeg executable can be found.

Convert videos with ffmpeg

  • Place your video(s) in the same folder as the ffmpeg.exe file. 
  • Start the Windows Command Prompt app (type Command Prompt in your Windows search bar).
  • In the Command Prompt, navigate to the folder where you placed ffmpeg.exe and the video(s). This needs to be a local path (not on a network drive such as the J- or P- drive). Use the cd command to do this, for example: cd C:\ExperimentData\ffmpeg.
  • Execute the desired ffmpeg command. Find below some examples.

ffmpeg.gif

Change format and video and audio codecs

Below a sample code that uses the input (-i) video testIn.mpeg and outputs testOut.wmv with audio codec (-acodec) wmav2 and video codec (-vcodec) wmv3.

ffmpeg -i testIn.mpeg -acodec wmav2 -vcodec wmv3 testOut.wmv

Use ffmpeg -codecs to get a list of all codecs

Remove audio from the video

Below sample code that uses input video (-i) testIn.wmv, copies the video stream (-c:v copy), removes the audio (-an) and saves it in testOut.wmv.

ffmpeg -i testIn.wmv -c:v copy -an testOut.wmv

Change resolution of the video

Below sample code that uses input video (-i) testIn.wmv, changes the resolution of the video to 1920 x 1080 (-vf scale=1920x1080) and saves it in testOut.wmv.

ffmpeg -i testIn.wmv -vf scale=1920:1080 testOut.wmv

The sample below uses input video (-i) testIn.wmv, changes the resolution width to 320 (-vf scale=320:-1) and keeps the aspect ratio and saves it in testOut.wmv.

ffmpeg -i testIn.wmv -vf scale=320:-1 testOut.wmv

Cut video

The sample below uses input video (-i) testIn.wmv, cuts the video from 15 seconds (-ss 00:00:15, format is hh:mm:ss) to 25 seconds (-to 00:00:25), while keeping the same codecs (-c copy) and saves it in testOut.wmv.

ffmpeg -i testIn.wmv -ss 00:00:15 -to 00:00:25 -c copy testOut.wmv

Change the quality of the video

When converting a video from one format to the other, video and/or audio quality is sometimes reduced. This might be fixed by specifying the quality of the video and audio. The sample below uses input video (-i) testIn.mpeg and converts it to in testOut.wmv with wma (-acodec wmav2) and wmv (-vcodec wmv3) codecs. The audio quality (-q:a 1) and video quality (-q:v 1) are kept high (1 = high quality, 10 = low quality). 

ffmpeg -i testIn.mpeg -q:a 1 -q:v 1 -acodec wmav2 -vcodec wmv3 testOut.wmv

Add a background

It might be necessary to have a screen filling video, but rather than making the video larger by stretching, a background can be added to the video that is larger than the video. For this, the video can be overlayed on an image, which can be just a colored background (e.g. a grey image made in paint). The sample below uses input image grey.png (-i) and input video (-i) testIn.wmv, it loops the image for the duration of the video (-loop 1), overlays the image and video (-filter_complex "overlay=(W-w)/2:shortest=1") and saves it in testOut.wmv.

ffmpeg -loop 1 -i grey.png -i testIn.wmv -filter_complex "overlay=(W-w)/2:shortest=1" testOut.wmv
Tags:
Created by Iris Spruit on 2022/10/07 14:23
   

Topics