We are still actively working on the spam issue.

Difference between revisions of "WebM"

From InstallGentoo Wiki
Jump to: navigation, search
(Added 8chan limitations section.)
Line 134: Line 134:
 
     j=$((j+1))
 
     j=$((j+1))
 
  done
 
  done
 +
 +
 +
'''Poster Image with Audio'''
 +
ffmpeg -loop 1 -i 1.png -i 1.wav -c:v libvpx -c:a libvorbis -b:a 64k -shortest out.webm
  
 
== GUI Options ==
 
== GUI Options ==

Revision as of 11:08, 11 November 2015

WebM support is the newest addition to 4chan (as of April 6th, 2014). WebM is an open, royalty-free, media file format designed for the web.

WebM defines the file container structure, video and audio formats. WebM files consist of video streams compressed with the VP8 video codec and audio streams compressed with the Vorbis audio codec. The WebM file structure is based on the Matroska container.

This wiki page is meant to serve as an instructional tool to help you get started converting your content to WebM for posting.

General Info

List of Stickies / Test Threads

Limitations

Current limits for WebM files on 4chan are:

  • Maximum file size is 4096KB.
  • Maximum duration is 300 seconds (5 minutes).
  • Maximum resolution is 2048x2048 pixels.
  • No audio streams except on /gif/ and /wsg/. (use -an)

Current limits for WebM files on 8chan are:

  • Maximum file size is 8192KB.
  • Maximum resolution is 10000x10000 pixels.
  • Audio streams permitted globally.

Converting with ffmpeg

Note: avconv and ffmpeg are not entirely drop-in replacements. Make sure you know which one you are using.

OS X Users: The homebrew version of ffmpeg doesn't include webm support by default, try brew install ffmpeg --with-libvpx.

Command Line Options

Below is an ffmpeg command:

ffmpeg -i input.mp4 -c:v libvpx -b:v 1M -c:a libvorbis output.webm 

This may look intimidating but it is not all that bad. Let's look at the different parameters:

  • -i: Specifies the input file, which you're converting to another format.
  • -c:v Specifies the video codec to use. webm isn't actually an encoding type unto itself, but an audio/video container, like mkv. Nevertheless, you will almost always use libvpx for the video.
  • -b: Sets the target bitrate. -b:v sets video bitrate and -b:a sets audio. Only use this option if you desire a constant bitrate, which will produce a higher quality file. If you are looking for a smaller file size, consider leaving this out.
  • -c:a: Specifies the audio codec to use. Some options include libvorbis, libmp3lame, etc. If you are unsure stick with libvorbis.


Other popular options:

  • -threads: Tells ffmpeg to use multithreading. Enter the number of cores your processor has as a parameter or put 0 to use them all.
  • -ac: Sets number of audio channels, normally 2 or 1. Sometimes setting to 1 will give you a smaller filesize. You should probably not touch this unless you know what you're doing.
  • -an: Disable audio. Use when converting .gif files to .webm.
  • -crf: Sets CRF value. Must be from 4-63. Lower is higher quality. 10 is a nice starting point.
  • -ss: Seeks to a position in the file. Useful for cutting out small scenes. Takes time in seconds as a parameter or HH:MM:SS syntax. use -t in tandem to set the file duration. For example, -t 00:00:10 cuts out the first ten seconds of the video for conversion, and -ss 00:00:10 -t 00:00:10 would skip the first ten seconds and cut out the next ten for conversion.


To simply print metadata about a video file: ffmpeg -i input_file -f ffmetadata metadata.txt

Operations with -vf

The -vf flag allows you to define 'filters' which can help you further manipulate the file. The syntax for this looks something like -vf \<filter\<=\<param\>. Use ffmpeg -filters to get a list of filters and how to use them. Some of the more common ones will be explored below.

  • scale: Scale takes two arguments separated by a colon, which are width and height respectively. If you enter -1 for either variable, ffmpeg will scale the video based off of the aspect ratio of the source file. An example of this would be -vf scale=640:-1

Premade Scripts

If you're that lazy, here's a couple premade scripts for video and gif conversion.

Windows

Save these programs as a .bat file and place them in the folder of the video you want to convert.

Video to WebM

@echo off
rem about 3megabyte in bit 3*1024*1024*8*0.95
set /A MAXSIZE=23907532
set WIDTH=720
ffmpeg -i %1 2> webm.tmp
for /F "tokens=1,2,3,4,5,6 delims=:., " %%i in (webm.tmp) do (
    if "%%i"=="Duration" call :calcLength %%j %%k %%l %%m
)
del webm.tmp
SET /a BITRATE=%MAXSIZE%/%VSECONDS%
ffmpeg -y -i %1 -threads 0 -sn -an -c:v libvpx -b:v %BITRATE% -vf scale=-1:%WIDTH% -quality best -cpu-used 0 -slices 8 -auto-alt-ref 1 -f webm -pass 1 NUL
ffmpeg -y -i %1 -threads 0 -sn -an -c:v libvpx -b:v %BITRATE% -vf scale=-1:%WIDTH% -quality best -cpu-used 0 -slices 8 -auto-alt-ref 1 -f webm -pass 2 "%~n1.webm"
del ffmpeg2pass-0.log > NUL
goto :EOF
:calcLength
FOR /F "tokens=* delims=0" %%A IN ("%3") DO SET /A s=%%A
FOR /F "tokens=* delims=0" %%A IN ("%2") DO SET /A s=s+%%A*60
FOR /F "tokens=* delims=0" %%A IN ("%1") DO SET /A s=s+%%A*60*60
set /A VSECONDS=s

gif to webm

@ECHO OFF
ffmpeg -y -i "%~1" -b:v 3M -quality best -cpu-used 0 -slices 8 "%~1.webm"

Linux / OS X

If you're using OS X or Linux, you probably know how to save and execute these scripts already, but here's a quick overview:

  1. Create a file, such as ~/bin/my_script.sh
  2. Copy and paste the code into this file with your favorite editor.
  3. Open a shell. Run the command chmod +x ~/bin/my_script.sh
  4. The script can now be called as ~/bin/my_script.sh some_file.type or if you have your PATH set correctly, my_script.sh some_file.type

webm.bash

It does interactive cropping with mplayer, interactive selection of start and end times with mplayer, hardsubs, and has many more options.

https://gist.github.com/interjection/4b83c0790ce82982caec

.gif Convert

#!/bin/bash
ffmpeg -i $1 -threads 0 -cpu-used 0 -c:v libvpx -f webm -b:v 700k -quality good -qmin 10 -qmax 42 -an /dev/null
ffmpeg -i $1 -threads 0 -cpu-used 0 -c:v libvpx -f webm -b:v 700k -quality good -qmin 10 -qmax 42 -an "$F"

High-End Video Convert

#!/bin/bash
# Warning: this script will probably take up a lot of CPU usage. Don't crash your machine.
ffmpeg -i $1 -threads 0 -cpu-used 0 -c:v libvpx -c:a libvorbis -ac 2 -qmin 0 -qmax 10 -bufsize 1000k -quality good -crf 4 -b:v 2M -pass 1 /dev/null
ffmpeg -i $1 -threads 0 -cpu-used 0 -c:v libvpx -c:a libvorbis -ac 2 -qmin 0 -qmax 10 -bufsize 1000k -quality good -crf 4 -b:v 2M -pass 1 "$1".webm

̈́Split Video

#!/bin/bash
# Takes a large video file and splits it into multiple 3MB webm files
crf=18
bitrate=500K
threads=8
# Duration of original video in seconds
duration=$(expr `mediainfo --Inform="General;%Duration%" "$1"` / 1000)
sec=0
j=1
until (($sec >= $duration))
do
    ffmpeg -ss $sec -i "$1" -an -sn -threads $threads -c:v libvpx -crf $crf -b:v $bitrate -fs 3M $j.webm  
    # Duration of previous video is added to the sum of every previous video
    sec=$(expr $(expr `mediainfo --Inform="General;%Duration%" $j.webm` / 1000) + $sec)
    j=$((j+1))
done


Poster Image with Audio

ffmpeg -loop 1 -i 1.png -i 1.wav -c:v libvpx -c:a libvorbis -b:a 64k -shortest out.webm

GUI Options

Recorders

- WebMCam

Webm cam screenshot.png

Records the selected area and saves the output as WebM, just like GifCam does it with GIFs.

https://github.com/TheTarkus/WebMCam/

Converters

You can also refer to Recommended_software for video editing and converting programs.

Sources and Resources

  1. https://trac.ffmpeg.org/wiki/vpxEncodingGuide
  2. WebM of a WebM tutorial: https://rbt.asia/boards/g/img/0411/75/1396646705233.webm
  3. http://www.webmproject.org/docs/encoder-parameters/
  4. http://wiki.webmproject.org/ffmpeg
  5. N0Lif3's Windows tutorial: https://www.youtube.com/watch?v=WeM3SUp-HRg