Jump to content

Daala Quickstart Windows: Difference between revisions

From XiphWiki
Using batch files to encode/decode a video at different compression levels: added limited multi-file drag and drop, out folder
No edit summary
 
(18 intermediate revisions by 2 users not shown)
Line 3: Line 3:
There is also a '''[[Daala Quickstart]]''' page for Linux/MacOS.
There is also a '''[[Daala Quickstart]]''' page for Linux/MacOS.


=== Pre-requisites ===
If you wish to use Cygwin to compile Daala within Windows, there is a guide at '''[[Daala and Cygwin]]'''.
* '''[https://review.xiph.org/559/ Source Code]''' - Solution files and source code patches
 
You can also use mingw64 to compile Daala on Windows. To do so, follow the ''[[Daala Quickstart]]'' guide for Unix operating systems.
 
Note that using MSVC to build Daala will result in a slower binary, due to the lack of MSVC compatible CPU detection [https://github.com/xiph/daala/issues/106]. Patches welcome!
 
=== Prerequisites ===
* '''[http://git-scm.com/downloads Git]'''
* '''[http://git-scm.com/downloads Git]'''
* '''[http://downloads.xiph.org/releases/ogg/?C=M;O=D libogg]''' (v1.3.0 or later) - the VS solution files were tested with '''[http://downloads.xiph.org/releases/ogg/libogg-1.3.2.zip libogg-1.3.2]'''
* '''[http://www.visualstudio.com/en-us/downloads/download-visual-studio-vs.aspx Visual Studio]''' (2008 or 2010)
* '''[http://www.visualstudio.com/en-us/downloads/download-visual-studio-vs.aspx Visual Studio]''' (2008 or 2010)
* '''[http://downloads.xiph.org/releases/ogg/?C=M;O=D libogg]''' v1.3.0 or later (VS solutions tested with '''[http://downloads.xiph.org/releases/ogg/libogg-1.3.2.zip libogg-1.3.2]''')
* '''[https://www.wxwidgets.org/downloads/ wxWidgets]''' is only required if you want to run the Daala bitstream analyser (VS solutions tested with version '''[http://sourceforge.net/projects/wxwindows/files/3.0.2/ 3.0.2]''')


The VS solution files were created using '''Visual Studio 2008 Team System''' and '''Visual Studio 2010 Ultimate'''.<br />
The VS solution files were created using '''Visual Studio 2008 Team System''' and '''Visual Studio 2010 Ultimate'''.<br />
Line 13: Line 19:


=== Installation Procedure ===
=== Installation Procedure ===
* Clone the Daala.git repository (this can take several minutes)
* Clone the Daala.git repository (this can take several minutes)


     git clone https://git.xiph.org/daala.git
     git clone https://git.xiph.org/daala.git
Make sure you run git clone operations on the same machine you intend to use the code on.<br />
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.


* Unpack libogg into a folder named '''ogg'''.
* 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:
* Unpack wxWidgets into a folder named '''wxWidgets'''.


    C:\daala
Your folder structure should now look like this:
    C:\ogg


Make sure you run the git clone operation on the same machine where you intend to use the code.<br />
    <your folder>\daala
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.
    <your folder>\ogg
    <your folder>\wxWidgets


== Building the executables ==
== Building the executables ==
Line 33: Line 41:
* Build the solution.
* Build the solution.


This will generate 2 executables and 3 static libraries:  
This will generate 3 executables and 3 static libraries:  


* encoder_example.exe  
* analyser.exe
* encoder_example.exe
* decoder_example.exe
* decoder_example.exe
* LibDaalaBase.lib
* LibDaalaBase.lib
Line 41: Line 50:
* libdaalaenc.lib
* libdaalaenc.lib


== Encoding a Video ==
{{Encoding with Daala}}
 
Get a sample video or two in .y4m format from [https://media.xiph.org/video/derf/ media.xiph.org].<br />
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: [https://people.xiph.org/~tdaede/video-1-short/ video-1-short]
 
Xiph also maintains a set of still-image collections in .y4m format:
 
* [https://people.xiph.org/~tterribe/daala/subset1-y4m.tar.gz Subset 1] (50 images, small training set)
* [https://people.xiph.org/~tterribe/daala/subset2-y4m.tar.gz Subset 2] (50 images, small testing set)
* [https://people.xiph.org/~tterribe/daala/subset3-y4m.tar.gz Subset 3] (1000 images, large training set)
* [https://people.xiph.org/~tterribe/daala/subset4-y4m.tar.gz 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.
{{Decoding with Daala}}


== Using batch files to encode/decode a video at different compression levels ==
== 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.
Save the following 2 batch files to your '''daala\win32\Visual Studio\VS20xx\Release''' directory.(you can also use '''Debug''', but the Release executables will be MUCH faster)


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).
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
To use the below batch files, drag-and-drop a couple of y4m video or image files onto '''EncodeDecode.bat''' and go grab a coffee, 'cause video encoding/decoding takes a while!
 
=== EncodeDecode.bat ===


<pre style="white-space: pre-wrap;
<syntaxhighlight lang="dos">
white-space: -moz-pre-wrap;
::Drag-and-drop .y4m files onto this .bat file to auto-process them!
white-space: -pre-wrap;
white-space: -o-pre-wrap;
word-wrap: break-word;">
:: 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]==[] goto end
if [%~1]==[] (
echo No input files given!
goto end
)


:: make an out folder to keep our files in
::make an out folder to keep our files in
if not exist out mkdir out
if not exist out mkdir out


Line 102: Line 82:
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)
::write the current compression factor into a log file (>> appends to file, > truncates data in file then writes to it)
 
::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


:: for /l %%i in (0,20,511) do = loop the commands after the "do" using a variable %%i starting at 0(daala lossless quality), in increments of 20, up to 511 (max daala lossy compression)
::x (within %~x1) = grab input file extension only
:: echo Encoding -v %%i... >> Log.txt = write the current compression factor into a log file (>> appends to file, > truncates data in file then writes to it)
for /l %%i in (0,20,511) do (
:: & = allow multiple commands within the for loop
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
:: x (within %~x1) = grab input file extension only
:: the rest of the code follows along in similar lines...
for /l %%i in (0,1,9) do echo Encoding %~n1 using -v %%i... >> 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 & 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
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
 
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
shift


::if we have another file, go to the :loop label to encode it!
::if we have another file, go to the :inputFileLoop label to encode it!
if not [%1]==[] goto loop
if not [%~1]==[] goto inputFileLoop


:end
:end


:: when all the above encodes/decodes are done, don't close the command window!
::when all the above encodes/decodes are done, don't close the command window!
pause
pause
</pre>
</syntaxhighlight>


* timecmd.bat
=== timecmd.bat ===


<pre style="white-space: pre-wrap;
<syntaxhighlight lang="dos">
white-space: -moz-pre-wrap;
white-space: -pre-wrap;
white-space: -o-pre-wrap;
word-wrap: break-word;">
:: this code was obtained from https://stackoverflow.com/questions/673523/how-to-measure-execution-time-of-command-in-windows-command-line
:: this code was obtained from https://stackoverflow.com/questions/673523/how-to-measure-execution-time-of-command-in-windows-command-line
@echo off
@echo off
@setlocal
@setlocal
Line 154: Line 140:
set options="tokens=1-4 delims=:."
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_ms=100%%d %% 100
for /f %options% %%a in ("%start%") do (
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_ms=100%%d %% 100
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
:: calculate duration in different units
Line 161: Line 158:
set /a mins=%end_m%-%start_m%
set /a mins=%end_m%-%start_m%
set /a secs=%end_s%-%start_s%
set /a secs=%end_s%-%start_s%
set /a ms=%end_ms%-%start_ms%
set /a cs=%end_cs%-%start_cs%


if %hours% lss 0 set /a hours = 24%hours%
if %hours% lss 0 set /a hours = 24%hours%
if %mins% lss 0 set /a hours = %hours% - 1 & set /a mins = 60%mins%
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 %secs% lss 0 set /a mins = %mins% - 1 & set /a secs = 60%secs%
if %ms% lss 0 set /a secs = %secs% - 1 & set /a ms = 100%ms%
if %cs% lss 0 set /a secs = %secs% - 1 & set /a cs = 100%cs%
if 1%ms% lss 100 set ms=0%ms%
 
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
:: mission accomplished
set /a totalsecs = %hours%*3600 + %mins%*60 + %secs%
set /a totalsecs = %hours%*3600 + %mins%*60 + %secs%
echo Command took %hours%:%mins%:%secs%.%ms% (%totalsecs%.%ms%s total)
echo Command took %hours%:%mins%:%secs%.%cs% (%totalsecs%.%cs%s total)
echo.
echo.
</pre>
</syntaxhighlight>
 
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
{{Converting to y4m}}


Note that ffmpeg is optimized for speed. You may not get repeatable results across machines.
{{Merging two y4m videos side-by-side}}


[[Category:Daala]]
[[Category:Daala]]

Latest revision as of 21:52, 18 September 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.

If you wish to use Cygwin to compile Daala within Windows, there is a guide at Daala and Cygwin.

You can also use mingw64 to compile Daala on Windows. To do so, follow the Daala Quickstart guide for Unix operating systems.

Note that using MSVC to build Daala will result in a slower binary, due to the lack of MSVC compatible CPU detection [1]. Patches welcome!

Prerequisites

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

Make sure you run git clone operations on the same machine you intend to use the code on.
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.

  • Unpack libogg into a folder named ogg.
  • Unpack wxWidgets into a folder named wxWidgets.

Your folder structure should now look like this:

   <your folder>\daala
   <your folder>\ogg
   <your folder>\wxWidgets

Building the executables

  • Open the file Daala_static.sln located at daala\win32\Visual Studio\VS20xx folder.
  • Build the solution.

This will generate 3 executables and 3 static libraries:

  • analyser.exe
  • encoder_example.exe
  • decoder_example.exe
  • LibDaalaBase.lib
  • libdaaladec.lib
  • libdaalaenc.lib

Encoding a Video

Test Media

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 subsets of 1-second-long videos for faster encoding:

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)

Using the encoder

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/Playing a Video

Play the video in a window:

   ./examples/player_example video.ogv

For information on the controls available while playing, run

   ./examples/player_example --help

If you want to use a different player, you can decode the video back to .y4m with

   ./examples/dump_video video.ogv -o decoded_video.y4m

Or you can pipe the raw video stream directly to the player of your choice:

   ./examples/dump_video video.ogv | mpv -

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\Release directory.(you can also use Debug, but the Release executables will be MUCH faster)

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).

To use the below batch files, drag-and-drop a couple of y4m video or image files onto EncodeDecode.bat and go grab a coffee, 'cause video encoding/decoding takes a while!

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)
	::write the current compression factor into a log file (>> appends to file, > truncates data in file then writes to it)

	::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

	::x (within %~x1) = grab input file extension only
for /l %%i in (0,20,511) do (
	echo Encoding %~n1 using -v %%i... >> out\Log.txt

	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

	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.

Converting to 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

Or just encode directly without an intermediate file:

   ffmpeg -i video.webm -pix_fmt yuv420p -f yuv4mpegpipe - | ./encoder_example - -o video.ogv

Note that ffmpeg is optimized for speed. You may not get comparable results across machines.

Merging two y4m videos side-by-side

To combine two y4m videos into a single video (with the input videos displayed side-by-side), do:

ffmpeg -i left.y4m -i right.y4m -filter_complex "[0:v]setpts=PTS-STARTPTS, pad=iw*2:ih[bg]; \
           [1:v]setpts=PTS-STARTPTS[fg]; [bg][fg]overlay=w" a_b_compare.y4m

Substitute ffmpeg with avconv if needed.