Help:Converting video

From Wikimedia Commons, the free media repository
Jump to navigation Jump to search

Shortcut: Help:CV

Video conversion help in other languages:

català | Deutsch | English | español | français | galego | italiano | 日本語 | polski | português | 中文 | українська | Bahasa Indonesia | +/−

Wikimedia Commons seeks video files which are within the project scope, such as educational videos, and which are in a free file format, which currently only means WebM and Ogg Theora (and WebM is preferred).

However, most videos available online or produced by recording devices are in other formats, which is why conversion is needed. Wikimedia community wishes to encourage the use of free and open source software. Some of the programs that can be used for video conversion (and also editing) are Miro Video Converter, aTube Catcher and Avidemux. Each has limitations and drawbacks and may not work on all video files. Converting video is a subject that still needs research and testing.

It should be noted that the process can get technically complicated, especially when it comes to advanced settings and command line interfaces, yet it's possible to convert with user-friendly applications with default configuration.

Easiest way for most users[edit]

Start at step 3 and upload the file to Video2commons.

Or another easy way to get video into Wikimedia Commons is as follows:

  1. Identify the video file which you wish to share
    1. Confirm that either you own the copyright to the video and are willing to apply a free license to it, or otherwise that the video already has a free copyright license
    2. Confirm that the video is within the scope of what Commons will accept
  2. Use Video2commons to convert the file to a free format and import it to Commons. You can provide the url of a video or upload it there.
    1. The conversion happens in the cloud on the Wikimedia server side
    2. No software configuration is required
  3. The file is now in Commons; process it here
    1. Categorize it, fix metadata
    2. Integrate the video with other Wikimedia projects, if you like

Another way to convert video format is as follows: If you are working in UBUNTU platform, click APPLICATIONS -> SOUND&VIDEOS-> TRANSMAGEDDON VIDEO TRANSCODER to convert a video format to another.

General conversion tips[edit]

  • When uploading a video (for use on Wikipedia), TimedMediaHandler will convert it into different versions, so you don’t need to provide separate versions for people on slow Internet connections. It is strongly recommended to upload your video with the best quality (bit rate and frame size) possible. If your resulting video file is larger than 100MB (104,857,600 Bytes) you should use UploadWizard (or another tool supporting chunked upload) allowing 4 GB; or use server-side upload (request help from a privileged user).
  • WebM is the preferred format, but please do not convert from Ogg Theora unnecessarily, as it is also supported.
  • Some of the tools listed here for converting to Theora output the converted file with a .ogg filename extension. Rename the file to a .ogv extension, as this is now the preferred extension. For details see RFC 5334 and xiph.org. Pay attention to repeat the .ogv file type during upload; otherwise it (wrongly) defaults to .ogg again...
  • RFC 5334 .ogx for MIME type application/ogg is not yet widely supported; you can use .ogg for Theora video with FLAC instead of Vorbis audio.

Online conversion tools[edit]

VideoCutTool[edit]

VideoCutTool is a tool to upload videos from a device, edit and then upload back to Wikimedia Commons. The tool automatically converts the uploaded video to a Commons compatible format. It includes function such as removing audio, cropping video, trimming, and rotating. The tool uses OAuth to login. You can find a description of this tool at Commons:VideoCutTool.

Video2commons[edit]

Video2commons is a tool to upload videos from a url to Wikimedia Commons, it automatically converts the video to a commons compatible format. It includes function such as removing audio, subtitles, video. The tool uses OAuth to login. You can find a description of this tool at Commons:video2commons.

Internet Archive[edit]

Internet Archive offers a video upload tool which automatically converts it to a number of formats, including ogg.

Convert-video-online.com[edit]

Convert-video-online.com allows you to upload the video file (max. 2Gb). Uploading speed depends on the internet connection speed. A free web app that converts video files, allowing you to change the video format, resolution or size right in a browser. All the app features are accessible free of charge and has no limit on the number of files you can convert. Moreover, users don’t even need to sign up or sign in.

Online-convert.com[edit]

Video.online-convert.com allows you to upload the video file (max. 100MB without registration). The website will convert the video for you and present you with a link to download the converted file. The process may take several minutes depending on the size and quality of the video.

Multi-platform command-line conversion tools[edit]

ffmpeg[edit]

FFmpeg is the Swiss army knife of video conversion. It's a highly flexible software suite that brings together a large amount of tools for handling video, audio, and other multimedia. It provides a command-line program "ffmpeg", with which you can convert also to WebM. See FFmpeg wiki's VP9 Encoding Guide for more information on its usage with VP9 specifically. For even more information on available command-line arguments specific to VP9 encoding, see FFmpeg's built-in help with the command ffmpeg -h encoder=libvpx-vp9

.webm[edit]

The recommended way to use VP9 is to utilise two-pass constant quality encoding. This is a combination of two modes (2-pass and constant quality) that have traditionally been separate approaches, and is recommended due to some quality-enhancing features in the libvpx encoder only being available in two-pass mode. Two-pass mode goes through the video twice, first to analyze it and second to use the collected data to encode the video efficiently at a certain set average bitrate. Constant quality mode aims to achieve a certain perceptual quality level for all parts of the video. Two-pass constant quality mode does an analysis pass and then encodes the video with a quality level set by the user. The quality level is set with the -crf switch and also requires that -b:v is set to 0 (zero).

There are other useful options available (not all of them specific to VP9), some of which are used in the example commands below and explained further in the bullet points below.

Two-pass encoding is done by running two commands, one for each pass, and specifying which pass you're running with the -pass switch. The first pass creates an analysis log file named ffmpeg2pass-0.log, which can be deleted after the second pass is done.

Since the command lines of different platforms use slightly different syntax (Windows uses NUL instead of /dev/null), the commands for each platform are listed separately.

Linux and OS X command line[edit]
First pass:
ffmpeg -i input.mp4 -c:v libvpx-vp9 -b:v 0 -crf 30 -pass 1 -row-mt 1 -an -f webm -y /dev/null
Second pass:
ffmpeg -i input.mp4 -c:v libvpx-vp9 -b:v 0 -crf 30 -pass 2 -row-mt 1 -c:a libopus output.webm

The two commands can be run back-to-back by combining them with two & signs, like so:

ffmpeg -i input.mp4 -c:v libvpx-vp9 -b:v 0 -crf 30 -pass 1 -row-mt 1 -an -f webm -y /dev/null && ffmpeg -i input.mp4 -c:v libvpx-vp9 -b:v 0 -crf 30 -pass 2 -row-mt 1 -c:a libopus output.webm

Create a script: When you frequently convert videos it can be handy to create a script video2webm:

#!/bin/bash
# Convert video file to webm
# Author: Geert Van Pamel
# Parameters:
#  P1: input file name

if [[ -z "$1" ]] ;then
 echo "Input file missing"
 exit 1
fi

input="$1"
output=$(basename "$1").webm

ffmpeg -i "$input" -c:v libvpx-vp9 -b:v 0 -crf 30 -pass 1 -row-mt 1 -an -f webm -y /dev/null &&
ffmpeg -i "$input" -c:v libvpx-vp9 -b:v 0 -crf 30 -pass 2 -row-mt 1 -c:a libopus "$output"

Then simply execute:

video2webm file.mp4

A file file.mp4.webm is created in the current directory.

Linux using VAAPI on Intel devices[edit]

Those running Linux on a modern Intel-based machine (Kaby/Coffee Lake, 9th generation or later) may see significant speedup by using the Video Acceration API (VAAPI) with ffmpeg. This takes advantage of the Intel QuickSync hardware in the integrated GPU (iGPU) of the Intel UHD Graphics 630 or the Iris Plus. Speeds of up to 8x can be seen using hardware VP9 encoding, versus pure CPU-only encoding speeds of 1-2x.

The following command can be invoked to tap into the VP9 VAAPI driver:

ffmpeg -vaapi_device /dev/dri/renderD128 -i input.mp4 -vf 'format=nv12,hwupload' -c:v vp9_vaapi -c:a libopus -b:a 96K -bsf:v vp9_raw_reorder,vp9_superframe output.webm
Windows command line[edit]
First pass:
ffmpeg -i input.mp4 -c:v libvpx-vp9 -b:v 0 -crf 30 -pass 1 -row-mt 1 -an -f webm -y NUL
Second pass:
ffmpeg -i input.mp4 -c:v libvpx-vp9 -b:v 0 -crf 30 -pass 2 -row-mt 1 -c:a libopus output.webm
Combined:
ffmpeg -i input.mp4 -c:v libvpx-vp9 -b:v 0 -crf 30 -pass 1 -row-mt 1 -an -f webm -y NUL && ffmpeg -i input.mp4 -c:v libvpx-vp9 -b:v 0 -crf 30 -pass 2 -row-mt 1 -c:a libopus output.webm
  • The target quality of -crf is specified on a scale from 0 to 63, with smaller values indicating higher quality. The default value is 30, which is sufficient for HD video. In general, the higher the video resolution the higher the value can be set since VP9 is more efficient at higher resolutions. This is useful to keep in mind when encoding resolutions higher than 1080p.
  • The audio quality, when not manually determined by the -b:a switch, is set to 96k by default. This is more than sufficient for most use cases as Opus is a very efficient audio codec. However, if your use case requires it you may wish to set it to a different value.
  • If you wish your video to not have audio, you can remove it by using the -an flag during the second pass. This is always done with the first pass since re-encoding audio would slow it down for no benefit. Furthermore, if you wish to specify the number audio channels yourself (for example, for converting 5.1 surround audio to stereo, or even mono), you can use the -ac flag followed by the number of audio channels desired (ie. -ac 2 for stereo).
  • The log file created during the first pass can be re-used and isn't actually specific to the quality level specified during the first pass. So if you encoded a video with a certain quality level but aren't happy with the result, as long as you didn't delete the log file, you can just re-run the second pass with a different quality setting and save time by not re-running the first pass.
  • The -row-mt 1 switch tells the encoder to use row-based multithreading. This can speed up encoding significantly on computers with more than 4 CPU cores/threads, resulting in a speed-up of 2x or more depending on the video resolution and the amount of CPU cores available. This option is set to 0 by default (as of January 2019) and thus needs to be set manually.
  • If you're using a pre-2018 version of FFmpeg, you may find VP9 encoding performance lacking. This is due to the aforementioned -row-mt multithreading feature being introduced in version 1.7.0 of libvpx (the VP8/VP9 encoding library used by FFmpeg), released on January 25th, 2018. FFmpeg added support for -row-mt in FFmpeg 3.4.
Furthermore, libvpx versions prior to 1.7.0 also require setting other multithreading features manually. These are the amount of threads, set with the -threads switch, and the amount of tile columns to use, set with the -tile-columns switch. The amount of threads should be set to the amount of processor threads made available by your CPU. The number of tile columns possible is determined by the resolution of the video and also affects the maximum amount of encoding threads the encoder can use. Below is a table of the recommended tile-columns values for various resolutions and the maximum amount of threads made possible by them, taken from Google's VP9 encoding guide.
Video resolution -tile-columns value Number of threads
320x240 1 2
640x360 2 4
640x480 2 4
1280x720 4 8
1920x1080 4 8
2560x1440 8 16
3840x2160 16 24

.ogv[edit]

NOTE! Theora is older and significantly less efficient than VP9, leading to higher file sizes (and thus longer upload times and higher storage space use) at the same quality compared to newer formats. In general the use of Theora for new uploads should be avoided and VP9 used instead. Nevertheless, examples for converting to Theora are provided below.

Theora video with Vorbis audio:

ffmpeg -i demo.mp4 -c:v libtheora -q:v 7 -c:a libvorbis -q:a 6 demo.ogv

Theora video with FLAC audio:

ffmpeg -i demo.mp4 -c:v libtheora -q:v 7 -c:a flac -sample_fmt s16 demo.ogv

Theora video with audio removed:

ffmpeg -i demo.mp4 -c:v libtheora -q:v 7 -an demo.ogv

The quality of the video and audio is specified with -q:v and -q:a respectively (0–10, higher is better). See TheoraVorbisEncodingGuide for more information.

Note on pixel formats[edit]

Note that by default, FFmpeg will attempt to convert video losslessly from one pixel format to another. Since pixel formats other than yuv420p aren't supported by all browsers, this can become problematic when encoding HDR content or when making a video from a series of images. Motion JPEG files, for example, will be converted by ffmpeg to yuv422p, and PNG files can end up converted to RGB. Not only can these videos cause problems with browser playback, but usually they also end up much larger when encoding them using the regular quality values.

In cases like this, adding -pix_fmt yuv420p to the FFmpeg command will ensure wide playback compatibility by converting the video to the yuv420p format.

Rotating videos[edit]

Videos can be rotated by using the parameter -vf "transpose=<direction>" where "direction" is one of cclock_flip, clock, cclock or clock_flip (respectively, 90 degrees counter-clockwise and vertical flip, 90 degrees clockwise, 90 degrees counter-clockwise, and 90 degrees clockwise and vertical flip). To rotate 180 degrees, try -vf "vflip,hflip". The video stream must be transcoded during this process, but the audio stream can be copied with -c:a copy if it is already in a suitable codec. It's recommended to specify video transcoding options as in the sections above since the FFmpeg defaults will likely result in a severe drop in quality.

For example, to rotate an existing WebM video 90 degrees clockwise while keeping a decent quality, run:

ffmpeg -i input.webm -c:a copy -c:v libvpx-vp9 -b:v 0 -crf 30 -vf "transpose=clock" output.webm

avconv[edit]

Libav is a fork of FFmpeg providing the similar command-line program "avconv". It appears that the quality is not as good as oggconvert. Also the first and last seconds of an mp3 file can be lost (which is certainly not OK).

apt-get install libav-tools
  • To extract 325 seconds of audio starting at second 475 with a bitrate of 64 Mbit/s:
avconv -i input-file.mp3 -b 64k -ss 475 -t 325 output-file.mp3

The input file bit rate should be higher or equal to the output file bit rate... otherwise bad audio quality will be the result.

  • To convert multiple mp3 files at once to ogg format:
for i in *.mp3 ;do avconv -i ${i} ${i:%mp3}ogg ;done
  • To remove the (bad) sound from a video:
avconv -i infile -c copy -an outfile

ffmpeg2theora[edit]

ffmpeg2theora command-line tool converting a video file

ffmpeg2theora was a popular converter recommended at the Theora project page. It is a cross-platform command-line tool. The latest version is 0.30, released in January 2016.

In most cases you will only need a simple command indicating the name of the file to convert. (Video and audio quality is set to max.)

Command line examples
ffmpeg2theora file.avi -v 10 -a 10
ffmpeg2theora file.avi --noaudio -v 10


MPlayer[edit]

MPlayer is an open source multimedia player also being capable to transcode files but having the advantage of supporting both a GUI as well as the command line; available for most operating systems including Windows, Linux, and macOS. The MPlayer included by some SMPlayer distributions for Windows does not contain mencoder.exe.

OggConvert[edit]

OggConvert allows you to produce ogg/ogv output files. To install:

apt-get install oggconvert

VLC media player[edit]

VLC is a GUI version media player with conversion capabilities. A helpful tutorial can be found at TheoraCookbook. Encoding using the GUI requires a targeted bitrate which yields inferior quality than encoding for a specified video quality.

XiphQT[edit]

Xiph's QuickTime Components can be used to add OGG support to QuickTime Pro, under both macOS (versions 10.3.9 to 10.11) and Windows.

Download and install the component, and it will add a "Movie to OGG" option to the File->Export dialog. On macOS, you can only do this using QuickTime 7, and you can download QuickTime 7 by visiting Apple.

youtube-dl[edit]

youtube-dl is an open-source command line program that can download videos from YouTube and a selection of other video sites, such as archive.org or Vimeo (full list here). If installed alongside FFmpeg or Libav, it can transcode downloaded videos to a free format. The following examples will show how this can be done, using the YouTube video What is Creative Commons? by the Wikimedia Foundation as an example.

Many videos on YouTube already have a WebM version available, using the VP9 and Opus codecs. To check:

youtube-dl -F dPZTh2NKTm4 (note: you can specify the full URL or just the video ID)

The output of the above command shows the available formats, arranged by file extension and resolution:

Output of youtube-dl -F
$ youtube-dl -F dPZTh2NKTm4

[youtube] dPZTh2NKTm4: Downloading webpage
[youtube] dPZTh2NKTm4: Downloading video info webpage
[info] Available formats for dPZTh2NKTm4:
format code  extension  resolution note
249          webm       audio only tiny   56k , opus @ 50k (48000Hz), 530.03KiB
250          webm       audio only tiny   76k , opus @ 70k (48000Hz), 722.58KiB
140          m4a        audio only tiny  127k , m4a_dash container, mp4a.40.2@128k (44100Hz), 1.27MiB
251          webm       audio only tiny  144k , opus @160k (48000Hz), 1.35MiB
160          mp4        256x144    144p  112k , avc1.4d400c, 30fps, video only, 646.32KiB
278          webm       256x144    144p  119k , webm container, vp9, 30fps, video only, 746.38KiB
133          mp4        426x240    240p  246k , avc1.4d4015, 30fps, video only, 1.31MiB
242          webm       426x240    240p  291k , vp9, 30fps, video only, 1.50MiB
243          webm       640x360    360p  562k , vp9, 30fps, video only, 2.85MiB
134          mp4        640x360    360p  635k , avc1.4d401e, 30fps, video only, 3.27MiB
244          webm       854x480    480p 1048k , vp9, 30fps, video only, 5.05MiB
135          mp4        854x480    480p 1181k , avc1.4d401f, 30fps, video only, 5.99MiB
247          webm       1280x720   720p 2066k , vp9, 30fps, video only, 10.12MiB
136          mp4        1280x720   720p 2387k , avc1.4d401f, 30fps, video only, 11.70MiB
302          webm       1280x720   720p60 3243k , vp9, 60fps, video only, 16.05MiB
298          mp4        1280x720   720p60 3483k , avc1.4d4020, 60fps, video only, 17.49MiB
248          webm       1920x1080  1080p 3604k , vp9, 30fps, video only, 17.90MiB
137          mp4        1920x1080  1080p 4368k , avc1.640028, 30fps, video only, 20.92MiB
303          webm       1920x1080  1080p60 5429k , vp9, 60fps, video only, 27.01MiB
299          mp4        1920x1080  1080p60 5800k , avc1.64002a, 60fps, video only, 29.41MiB
271          webm       2560x1440  1440p 11997k , vp9, 30fps, video only, 52.51MiB
308          webm       2560x1440  1440p60 15209k , vp9, 60fps, video only, 74.46MiB
313          webm       3840x2160  2160p 24605k , vp9, 30fps, video only, 112.91MiB
315          webm       3840x2160  2160p60 32659k , vp9, 60fps, video only, 155.65MiB
18           mp4        640x360    360p  536k , avc1.42001E, mp4a.40.2@ 96k (44100Hz), 5.34MiB
22           mp4        1280x720   720p 1301k , avc1.64001F, mp4a.40.2@192k (44100Hz) (best)

Individual formats can be downloaded by specifying the format code in the first column:

youtube-dl -f 22 dPZTh2NKTm4

Video and audio can be downloaded together and combined into a single file with FFmpeg or Libav, if installed:

youtube-dl -f 315+251 dPZTh2NKTm4

To download the best available free format for both audio and video without needing to know the format codes:

youtube-dl --prefer-free-formats dPZTh2NKTm4

Note that youtube-dl considers MP4 a free format, but MP4 video is not supported on Commons; to download WebM instead:

youtube-dl -f 'bestvideo[ext=webm]+bestaudio[ext=webm]' dPZTh2NKTm4

WebM may not always be available, but FFmpeg or Libav can be used to transcode the video once downloaded. For example:

youtube-dl -f best --recode-video webm dPZTh2NKTm4 (-f best is used here to force a single file MP4 download; it won't always be necessary)

If either FFmpeg or Libav is on your PATH, youtube-dl will automatically find and use it. Otherwise, you can tell it where to find the conversion program with the --ffmpeg-location option.

See the README for more on what youtube-dl can do (like batch downloading or audio extraction), as well as example commands and frequently asked questions.

Tools for Windows[edit]

XMedia Recode - Conversion to OGV
See above for multi-platform solutions. Frequent FFmpeg builds and a user forum are offered by zeranoe.
FFCoder

FFCoder (v2.2 BETA, 2013-02) is a .NET 2.0 frontend for FFmpeg and MEncoder.

Video to Theora

Video to Theora (version 2.0, 2013) is an AutoIt GUI for ffmpeg2theora.

XMedia Recode

XMedia Recode was recommended by the WebM project. Download an installer from xmedia-recode.de; a portable version is also available.

Windows PowerPoint

Windows PowerPoint allows recording a demo session, with sound, and export to mpeg4. Then afterwards you can do further video processing (cut video frames, overlay sound and audio, add subtitling).

Tools for Linux[edit]

See above for multi-platform solutions.

Multi-platform editing tools[edit]

Using mkvmerge to cut a video
See above for the command line tools avconv, ffmpeg, and ffmpeg2theora.

Handbrake[edit]

HandBrake is an opensource video converter. It will quickly and simply take an MP4 file and output it as webm. It is available for Linux, MacOS and Windows.

Ogg Video Tools[edit]

The Xiph oggz tool is able to 'chop' or split a theora file between given start and end times and 'merge' or join two Theora-encoded videos.
Ogg Video Tools is a collection of command-line tools that help with OGG video editing, including resizing, splitting and joining, creating slideshows from png files, and joining or separating audio and video streams from a .ogv file.

Shotcut[edit]

Shotcut is a free and open source software for Windows, Linux, macOS. It is based on FFmpeg, Media Lovin' Toolkit, Frei0r, Qt, and ICU, among others. Versions 14.11 (2014-11) and later support OPUS.

WebM with mkvtoolnix[edit]

WebM files are just MKV (Matroska) files which use a subset of the features for this format. With mkvtoolnix (GPLv2 for all platforms) it's very easy to manipulate them. VP9 video and OPUS audio in a WebM container are supported since 2013.

OpenShot[edit]

OpenShot Video Editor is an Open source graphical video editing tool available for all current platforms. It is an ideal platform to edit and export videos to ogv format. Choose the "All Formats OGG High" format with the highest possible resolution.

Kdenlive[edit]

Kdenlive is an open-source video editor for GNU/Linux, BSD, macOS and (recently) Windows.

See also[edit]

External links[edit]