Daala Quickstart Windows: Difference between revisions
m (→Using batch files to encode/decode a video at different compression levels: readability update) |
(→Using batch files to encode/decode a video at different compression levels: more code legibility) |
||
Line 90: | Line 90: | ||
:: Drag-and-drop .y4m files onto this .bat file to auto-process them! | :: Drag-and-drop .y4m files onto this .bat file to auto-process them! | ||
:: turn off auto command outputting | :: turn off auto command-outputting | ||
@echo off | @echo off | ||
:: if we have no input files, go to the :end pointer | :: if we have no input files, go to the :end pointer | ||
if [%1]==[] ( | if [%~1]==[] ( | ||
echo No input files given! | echo No input files given! | ||
goto end | goto end | ||
Line 105: | Line 105: | ||
set batchLocation=%~dp0 | set batchLocation=%~dp0 | ||
:loop | :: this marks the start of our input-file loop | ||
:inputFileLoop | |||
:: | :: loop the commands after the "do" using a compression factor %%i | ||
:: starting at 0 (daala lossless quality), in increments of 20, up to 511 (max daala lossy compression) | |||
for /l %%i in (0,20,511) do ( | |||
:: write the current compression factor into a log file (>> appends to file, > truncates data in file then writes to it) | |||
echo Encoding %~n1 using -v %%i... >> out\Log.txt | echo Encoding %~n1 using -v %%i... >> out\Log.txt | ||
:: call = call another bit of code, but return to this file when done! | |||
:: timecmd = time how long the following command takes | |||
:: encoder_example.exe = encode using daala! | |||
:: -v %%i = using this amount of compression | |||
:: "%~1" = the input file's name and extension (double quotes guard against spaces in name) | |||
:: -o "%~n1%%i.ogv" = output the daala-encoded video to this file | |||
:: dp (within %~dp1) = grab input file drive and path only | |||
:: n (within %~n1) = grab input file name only | |||
call "%batchLocation%timecmd" "%batchLocation%encoder_example.exe" -v %%i "%~1" -o "%~dp1out\%~n1_%%i.ogv" >> out\Log.txt | call "%batchLocation%timecmd" "%batchLocation%encoder_example.exe" -v %%i "%~1" -o "%~dp1out\%~n1_%%i.ogv" >> out\Log.txt | ||
echo Decoding %~n1 using -v %%i... >> out\Log.txt | |||
echo Decoding %~n1, which was encoded using -v %%i... >> out\Log.txt | |||
:: x (within %~x1) = grab input file extension only | |||
call "%batchLocation%timecmd" "%batchLocation%decoder_example.exe" "%~dp1out\%~n1_%%i.ogv" -o "%~dp1out\%~n1_%%i%~x1" >> out\Log.txt | call "%batchLocation%timecmd" "%batchLocation%decoder_example.exe" "%~dp1out\%~n1_%%i.ogv" -o "%~dp1out\%~n1_%%i%~x1" >> out\Log.txt | ||
) | ) | ||
Line 129: | Line 132: | ||
shift | shift | ||
::if we have another file, go to the : | ::if we have another file, go to the :inputFileLoop label to encode it! | ||
if not [%1]==[] goto | if not [%~1]==[] goto inputFileLoop | ||
:end | :end |
Revision as of 14:55, 27 January 2015
This is a simple guide to getting the code and encoding a simple video within Windows.
There is also a Daala Quickstart page for Linux/MacOS.
Pre-requisites
- Source Code - Solution files and source code patches
- Git
- libogg (v1.3.0 or later) - the VS solution files were tested with libogg-1.3.2
- Visual Studio (2008 or 2010)
The VS solution files were created using Visual Studio 2008 Team System and Visual Studio 2010 Ultimate.
Even though the provided solutions might work with the express versions of VS, this has not been tested.
Installation Procedure
- Clone the Daala.git repository (this can take several minutes)
git clone https://git.xiph.org/daala.git
- Unpack libogg into a folder named ogg.
If you cloned the Daala repository onto your C-drive root, your folder structure should now look like this:
C:\daala C:\ogg
Make sure you run the git clone operation on the same machine where you intend to use the code.
Checking out a copy on Windows and then trying to use it on Linux will not work, as executable permissions and line-endings will not be set properly.
Building the executables
- Open the file Daala_static.sln located at daala\win32\Visual Studio\VS20xx folder.
- Build the solution.
This will generate 2 executables and 3 static libraries:
- encoder_example.exe
- decoder_example.exe
- LibDaalaBase.lib
- libdaaladec.lib
- libdaalaenc.lib
Encoding a Video
Get a sample video or two in .y4m format from media.xiph.org.
These videos are relatively large and will take a long time to encode.
There are also subsets of 1-second-long videos for faster encoding: video-1-short
Xiph also maintains a set of still-image collections in .y4m format:
- Subset 1 (50 images, small training set)
- Subset 2 (50 images, small testing set)
- Subset 3 (1000 images, large training set)
- Subset 4 (1000 images, large testing set)
Encode the video:
./examples/encoder_example -v 30 video.y4m -o video.ogv
where
- -v ??? specifies the amount of compression (currently from 0 to 511, where 0 is lossless, 511 is very lossy)
- video.y4m is the input video you want to encode
- -o video.ogv is the name of the encoded video file to output.
Use encoder_example.exe -h for the in-built help.
Decoding a Video
You can decode the video back to .y4m with
./examples/decoder_example video.ogv -o decoded_video.y4m
Many other players can play back these .y4m files and other tools can convert them to various other formats.
Using batch files to encode/decode a video at different compression levels
Save the following 2 batch files to your daala\win32\Visual Studio\VS20xx\Debug directory.
This is where the encode_example.exe and decode_example.exe files should be after you successfully build the Daala_static.sln solution (see notes above).
- EncodeDecode.bat
:: Drag-and-drop .y4m files onto this .bat file to auto-process them! :: turn off auto command-outputting @echo off :: if we have no input files, go to the :end pointer if [%~1]==[] ( echo No input files given! goto end ) :: make an out folder to keep our files in if not exist out mkdir out ::store the path to this batch file set batchLocation=%~dp0 :: this marks the start of our input-file loop :inputFileLoop :: loop the commands after the "do" using a compression factor %%i :: starting at 0 (daala lossless quality), in increments of 20, up to 511 (max daala lossy compression) for /l %%i in (0,20,511) do ( :: write the current compression factor into a log file (>> appends to file, > truncates data in file then writes to it) echo Encoding %~n1 using -v %%i... >> out\Log.txt :: call = call another bit of code, but return to this file when done! :: timecmd = time how long the following command takes :: encoder_example.exe = encode using daala! :: -v %%i = using this amount of compression :: "%~1" = the input file's name and extension (double quotes guard against spaces in name) :: -o "%~n1%%i.ogv" = output the daala-encoded video to this file :: dp (within %~dp1) = grab input file drive and path only :: n (within %~n1) = grab input file name only call "%batchLocation%timecmd" "%batchLocation%encoder_example.exe" -v %%i "%~1" -o "%~dp1out\%~n1_%%i.ogv" >> out\Log.txt echo Decoding %~n1, which was encoded using -v %%i... >> out\Log.txt :: x (within %~x1) = grab input file extension only call "%batchLocation%timecmd" "%batchLocation%decoder_example.exe" "%~dp1out\%~n1_%%i.ogv" -o "%~dp1out\%~n1_%%i%~x1" >> out\Log.txt ) :: shift the files in our input file list, file %~2 becomes %~1 shift ::if we have another file, go to the :inputFileLoop label to encode it! if not [%~1]==[] goto inputFileLoop :end :: when all the above encodes/decodes are done, don't close the command window! pause
- timecmd.bat
:: this code was obtained from https://stackoverflow.com/questions/673523/how-to-measure-execution-time-of-command-in-windows-command-line @echo off @setlocal :: start timing! set start=%time% :: runs your command cmd /c "%*" :: stop timing! set end=%time% :: spawn variables to hold start- and end-date parts set options="tokens=1-4 delims=:." for /f %options% %%a in ("%start%") do set start_h=%%a & set /a start_m=100%%b %% 100 & set /a start_s=100%%c %% 100 & set /a start_cs=100%%d %% 100 for /f %options% %%a in ("%end%") do set end_h=%%a & set /a end_m=100%%b %% 100 & set /a end_s=100%%c %% 100 & set /a end_cs=100%%d %% 100 :: calculate duration in different units set /a hours=%end_h%-%start_h% set /a mins=%end_m%-%start_m% set /a secs=%end_s%-%start_s% set /a cs=%end_cs%-%start_cs% if %hours% lss 0 set /a hours = 24%hours% if %mins% lss 0 set /a hours = %hours% - 1 & set /a mins = 60%mins% if %secs% lss 0 set /a mins = %mins% - 1 & set /a secs = 60%secs% if %cs% lss 0 set /a secs = %secs% - 1 & set /a cs = 100%cs% if %hours% lss 10 set hours=0%hours% if %mins% lss 10 set mins=0%mins% if %secs% lss 10 set secs=0%secs% if %cs% lss 10 set cs=0%cs% :: mission accomplished set /a totalsecs = %hours%*3600 + %mins%*60 + %secs% echo Command took %hours%:%mins%:%secs%.%cs% (%totalsecs%.%cs%s total) echo.
Drag-and-drop a y4m video onto EncodeDecode.bat and go grab a coffee, 'cause video encoding/decoding takes a while!
Creating y4m from other formats
You can use the ffmpeg tool to generate y4m from any of its supported video formats:
ffmpeg -i video.webm -pix_fmt yuv420p video.y4m
Note that ffmpeg is optimized for speed. You may not get repeatable results across machines.