Sunday, 4 January 2015

How to rotate MOV video file


Free, cross-platform and easy to use tool is FFmpeg.

On Windows 


Go to Zeranoe FFmpeg builds and download the latest build which is a compressed file (e.g. ffmpeg-20150103-git-504267f-win64-static.7z). Unpack it and open FF Prompt window by clicking on file ff-prompt.bat.

In the prompt type the following command and hit the Enter:

>ffmpeg -i "C:\Users\Bojan\Downloads\IMG_3855.MOV" -vf "transpose=1" "C:\Users
\Bojan\Downloads\IMG_3855_rotated.MOV"
ffmpeg version N-68826-g504267f Copyright (c) 2000-2014 the FFmpeg developers
built on Jan 2 2015 22:12:34 with gcc 4.9.2 (GCC)
configuration: --enable-gpl --enable-version3 --disable-w32threads --enable-av
isynth --enable-bzlib --enable-fontconfig --enable-frei0r --enable-gnutls --enab
le-iconv --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --
enable-libfreetype --enable-libgme --enable-libgsm --enable-libilbc --enable-lib
modplug --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrw
b --enable-libopenjpeg --enable-libopus --enable-librtmp --enable-libschroedinge
r --enable-libsoxr --enable-libspeex --enable-libtheora --enable-libtwolame --en
able-libvidstab --enable-libvo-aacenc --enable-libvo-amrwbenc --enable-libvorbis
--enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx264 --enable-
libx265 --enable-libxavs --enable-libxvid --enable-lzma --enable-decklink --enab
le-zlib
libavutil 54. 16.100 / 54. 16.100
libavcodec 56. 19.100 / 56. 19.100
libavformat 56. 16.102 / 56. 16.102
libavdevice 56. 3.100 / 56. 3.100
libavfilter 5. 6.100 / 5. 6.100
libswscale 3. 1.101 / 3. 1.101
libswresample 1. 1.100 / 1. 1.100
libpostproc 53. 3.100 / 53. 3.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'C:\Users\Bojan\Downloads\IMG_3855.MOV
':
Metadata:
major_brand : qt
minor_version : 0
compatible_brands: qt
creation_time : 2015-01-04 15:32:44
Duration: 00:02:12.27, start: 0.000000, bitrate: 773 kb/s
Stream #0:0(und): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, mono, fltp,
62 kb/s (default)
Metadata:
rotate : 90
creation_time : 2015-01-04 15:32:45
handler_name : Core Media Data Handler
Stream #0:1(und): Video: h264 (Baseline) (avc1 / 0x31637661), yuv420p, 480x3
60, 707 kb/s, 30 fps, 30 tbr, 600 tbn, 1200 tbc (default)
Metadata:
rotate : 90
creation_time : 2015-01-04 15:32:45
handler_name : Core Media Data Handler
encoder : H.264
Side data:
displaymatrix: rotation of -90.00 degrees
[libx264 @ 0000000002c45fe0] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2
[libx264 @ 0000000002c45fe0] profile High, level 3.0
[libx264 @ 0000000002c45fe0] 264 - core 144 r2525 40bb568 - H.264/MPEG-4 AVC cod
ec - Copyleft 2003-2014 - http://www.videolan.org/x264.html - options: cabac=1 r
ef=3 deblock=1:0:0 analyse=0x3:0x113 me=hex subme=7 psy=1 psy_rd=1.00:0.00 mixed
_ref=1 me_range=16 chroma_me=1 trellis=1 8x8dct=1 cqm=0 deadzone=21,11 fast_pski
p=1 chroma_qp_offset=-2 threads=6 lookahead_threads=1 sliced_threads=0 nr=0 deci
mate=1 interlaced=0 bluray_compat=0 constrained_intra=0 bframes=3 b_pyramid=2 b_
adapt=1 b_bias=0 direct=1 weightb=1 open_gop=0 weightp=2 keyint=250 keyint_min=2
5 scenecut=40 intra_refresh=0 rc_lookahead=40 rc=crf mbtree=1 crf=23.0 qcomp=0.6
0 qpmin=0 qpmax=69 qpstep=4 ip_ratio=1.40 aq=1:1.00
Output #0, mov, to 'C:\Users\Bojan\Downloads\IMG_3855_rotated.MOV':
Metadata:
major_brand : qt
minor_version : 0
compatible_brands: qt
encoder : Lavf56.16.102
Stream #0:0(und): Video: h264 (libx264) (avc1 / 0x31637661), yuv420p, 360x48
0, q=-1--1, 30 fps, 15360 tbn, 30 tbc (default)
Metadata:
rotate : 90
creation_time : 2015-01-04 15:32:45
handler_name : Core Media Data Handler
encoder : Lavc56.19.100 libx264
Stream #0:1(und): Audio: aac (libvo_aacenc) (mp4a / 0x6134706D), 44100 Hz, m
ono, s16, 128 kb/s (default)
Metadata:
rotate : 90
creation_time : 2015-01-04 15:32:45
handler_name : Core Media Data Handler
encoder : Lavc56.19.100 libvo_aacenc
Stream mapping:
Stream #0:1 -> #0:0 (h264 (native) -> h264 (libx264))
Stream #0:0 -> #0:1 (aac (native) -> aac (libvo_aacenc))
Press [q] to stop, [?] for help
frame= 73 fps=0.0 q=29.0 size= 53kB time=00:00:03.53 bitrate= 122.3kbits/
frame= 114 fps=111 q=29.0 size= 162kB time=00:00:04.90 bitrate= 270.6kbits/
frame= 151 fps= 98 q=29.0 size= 282kB time=00:00:06.14 bitrate= 376.6kbits/

etc...

frame= 3966 fps= 62 q=29.0 size= 13253kB time=00:02:12.29 bitrate= 820.7kbits/
frame= 3968 fps= 61 q=-1.0 Lsize= 13544kB time=00:02:12.34 bitrate= 838.4kbits
/s
video:11342kB audio:2068kB subtitle:0kB other streams:0kB global headers:0kB mux
ing overhead: 0.998874%
[libx264 @ 0000000002c45fe0] frame I:23 Avg QP:22.99 size: 11966
[libx264 @ 0000000002c45fe0] frame P:2549 Avg QP:26.67 size: 3857
[libx264 @ 0000000002c45fe0] frame B:1396 Avg QP:29.93 size: 1079
[libx264 @ 0000000002c45fe0] consecutive B-frames: 32.7% 58.9% 7.0% 1.4%
[libx264 @ 0000000002c45fe0] mb I I16..4: 12.0% 63.2% 24.7%
[libx264 @ 0000000002c45fe0] mb P I16..4: 2.5% 6.0% 2.7% P16..4: 28.7% 20.4
% 9.9% 0.0% 0.0% skip:29.7%
[libx264 @ 0000000002c45fe0] mb B I16..4: 0.3% 0.2% 0.2% B16..8: 35.4% 11.9
% 2.0% direct: 1.9% skip:48.0% L0:51.5% L1:42.8% BI: 5.7%
[libx264 @ 0000000002c45fe0] 8x8 transform intra:53.3% inter:48.8%
[libx264 @ 0000000002c45fe0] coded y,uvDC,uvAC intra: 50.4% 35.4% 3.6% inter: 17
.5% 9.8% 0.3%
[libx264 @ 0000000002c45fe0] i16 v,h,dc,p: 55% 22% 9% 14%
[libx264 @ 0000000002c45fe0] i8 v,h,dc,ddl,ddr,vr,hd,vl,hu: 27% 19% 26% 3% 4%
5% 6% 4% 6%
[libx264 @ 0000000002c45fe0] i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 36% 16% 26% 3% 3%
4% 4% 4% 4%
[libx264 @ 0000000002c45fe0] i8c dc,h,v,p: 62% 11% 25% 2%
[libx264 @ 0000000002c45fe0] Weighted P-Frames: Y:9.1% UV:2.2%
[libx264 @ 0000000002c45fe0] ref P L0: 77.9% 13.8% 6.1% 2.0% 0.2%
[libx264 @ 0000000002c45fe0] ref B L0: 96.4% 3.5% 0.2%
[libx264 @ 0000000002c45fe0] ref B L1: 99.0% 1.0%
[libx264 @ 0000000002c45fe0] kb/s:702.40

>


Possible values for transpose operation are:

0 = 90 degrees counter-clockwise and vertical flip (default)
1 = 90 degrees clockwise
2 = 90 degrees counter-clockwise
3 = 90 degrees clockwise and vertical flip

Monday, 17 November 2014

How to check if OSX is 32 or 64-bit?

In order to determine whether bitness of the operating system, we can query it for the value of the POSIX constant LONG_BIT which tells the number of bits in a long int:
$ getconf LONG_BIT
64
Bitness of the kernel can be fetched from the machine hardware name. x86_64 in the output means that machine has the 64-bit CPU:
$ uname -m
x86_64

Thursday, 13 November 2014

Pulling content from the remote repository via SourceTree

Here is the list of commands used by SourceTree when you pull branch mybranch from origin for some repository myrepo:

git -c diff.mnemonicprefix=false -c core.quotepath=false -c credential.helper=sourcetree fetch origin
From ssh://my.git.host:8999/myproj/myrepo
e855518..9f48d16 master -> origin/master


git -c diff.mnemonicprefix=false -c core.quotepath=false -c credential.helper=sourcetree pull --no-commit origin mybranch
From ssh://my.git.host:8999/myproj/myrepo
* branch mybranch -> FETCH_HEAD
Already up-to-date.


git -c diff.mnemonicprefix=false -c core.quotepath=false -c credential.helper=sourcetree submodule update --init --recursive

Completed successfully

We can see that main commands used here are:


git fetch origin
git pull --no-commit origin mybranch
submodule update --init --recursive


Sunday, 9 March 2014

async - await idiom

async-await idiom has been introduced in C# 5.0 and it is basically a syntactic sugar for implementation of task's continuations.

Here are some interesting excerpts from the article "Easier Asynchronous Programming with the New Visual Studio Async CTP" by Eric Lippert, which was published in MSDN Magazine in October 2011:

The work that must come after a particular task is finished is called the continuation of the task.

An await expression (...) means “evaluate this expression to obtain an object representing work that will in the future produce a result. Sign up the remainder of the current method as the callback associated
with the continuation of that task. Once the task is produced and the callback is signed up, immediately return control to my caller.”

Every time an await is encountered, the currently executing method signs up the rest of the method as the thing to do when the current task is complete, and then immediately returns. Somehow each task will complete itself—either by being scheduled to run as an event on the current thread, or because it used an I/O completion thread or worker thread—and will then cause its continuation to “pick up where it left off ” in executing the rest of the method.

Note that the method is now marked with the new async keyword; this is simply an indicator to the compiler that lets it know that in the context of this method, the keyword await is to be treated as a point where the workflow returns control to its caller and picks up again when the associated task is finished.


Asynchronous Programming with Async and Await (MSDN)
async (C# Reference)(MSDN)
await (C# Reference)(MSDN)

Asynchrony in C# 5, Part One (Eric Lippert's blog)

Whenever a task is "awaited", the remainder of the current method is signed up as a continuation of the task, and then control immediately returns to the caller. When the task completes, the continuation is invoked and the method starts up where it was before.

Asynchronous Programming in C# 5.0 part two: Whence await? (Eric Lippert's blog)
Async articles from John Skeet's blog
Async/Await FAQ
What is thread doing after returning from async point? (SO)
What happens to an `awaiting` thread in C# Async CTP?

Thursday, 27 June 2013

Beginning Unit Testing with NUnit in Visual Studio

How to start with NUnit?

Download it from http://www.nunit.org/ and install it. It should be installed at C:\Program Files (x86)\NUnit 2.6.2. (2.6.2 is the current release version in the time of writing this article)

How to organise my projects? Where to put unit tests?

Put the business logic of your app in a class library project (e.g. MyBusinessLogic.dll). Your main app (MyApp.exe) project references this dll. Put unit tests in a separate project (e.g. MyBusinessLogicTester.dll) but within the same solution. MyBusinessLogicTester.dll will reference nunit.framework.dll (located at C:\Program Files (x86)\NUnit 2.6.2\bin) and MyBusinessLogic.dll.

How to run NUnit tests?

In MyBusinessLogicTester project: go to Properties -> Debug. Set Start external program to C:\Program Files (x86)\NUnit 2.6.2\bin\nunit.exe and put MyBusinessLogicTester.dll in Command line arguments field.

Set MyBusinessLogicTester as a StartUp project in your solution and run it. Nunit GUI app (nunit.exe) will open and display all test fixtures and tests in the left-hand side tree view. You can select tests you want to run and then execute them.

If you're running MyBusinessLogicTester tests with ReSharper, make sure MyBusinessLogicTester is marked to be built in the Configuration Manager.


Links and References:
http://www.nunit.org/
http://stackoverflow.com/questions/67299/is-unit-testing-worth-the-effort
http://stackoverflow.com/questions/1365943/how-to-start-unit-testing-or-tdd
http://stackoverflow.com/questions/347156/do-you-put-unit-tests-in-same-project-or-another-project
http://stackoverflow.com/questions/3979855/how-do-i-set-up-nunit-to-run-my-projects-unit-tests
http://stackoverflow.com/questions/759854/how-do-i-run-nunit-in-debug-mode-from-visual-studio
http://stackoverflow.com/questions/3476054/can-unit-testing-be-successfully-added-into-an-existing-production-project-if-s
http://stackoverflow.com/questions/6103807/unit-testing-philosophy


Thursday, 14 March 2013

Hello, world! in NSIS - the simplest NSIS script

NSIS requires two things to be present in a script:

1) call to OutFile function (in order to define installer's name and output directory)
2) at least one Section (NSIS script executes sections and each section can contain functions and instructions; functions contain instructions only)

So, the shortest script that compiles could be:

HelloWorld.nsi:




NSIS compiler creates HelloWorld-installer.exe in the same directory where HelloWorld.nsi resides. When run, installer looks like this:

NSIS-HelloWorld-1

If we click on Show details button, we can see the following:

NSIS-HelloWorld-2

We can use ShowInstDetails in order to make installer displaying details by default:



We can use DetailPrint in order to output our custom messages:



And so Installer displays our custom text and Details window by default:

NSIS-HelloWorld-3


If we want to perform some system checks when installer starts, we can place our code in predefined function .onInit. In the next example, we'll just put displaying message box:



When we run installer, message box is first displayed:

NSIS-HelloWorld-4

When we click on OK, main window shows:

NSIS-HelloWorld-5

I used instruction Name to customize title of Installer's windows.

We can do some more serious stuff in .onInit function, like Windows version check. Download GetWindowsVersion.nsh header, create directory headers in the same directory where HelloWorld.nsi is, place GetWindowsVersion.nsh in that new directory (as we want to keep downloaded scripts separately from our work), include that header in the script and call function it exposes - GetWindowsVersion:



Message box displays Windows version:

NSIS-HelloWorld-6

NOTE: Files with extension nsi are installer script files and files with extension nsh are installer headers.

NOTE: DetailPrint calls from .onInit are ignored.

Thursday, 10 January 2013

How to issue periodical execution of DOS command in a single line

Let's say we want to check the state of the socket connection on the port 4016 every second. We can use netstat command to display required information and ping invalid IP address with timeout of 1 second. These two commands can be grouped in the same line with & operator and that group can be put inside infinite FOR loop:

Command:
C:\Users\Scrillex>for /L %a in (0,0,0) do (netstat -an|find "4016" & ping 1.1.1.1 - n 1 -w 1000 >nul)

Output:
C:\Users\Bojan>(netstat -an | find "4016" & ping 1.1.1.1 -n 1 -w 1000 1>nul)
TCP 0.0.0.0:4016 0.0.0.0:0 LISTENING
TCP [::]:4016 [::]:0 LISTENING

C:\Users\Bojan>(netstat -an | find "4016" & ping 1.1.1.1 -n 1 -w 1000 1>nul)
TCP 0.0.0.0:4016 0.0.0.0:0 LISTENING
TCP [::]:4016 [::]:0 LISTENING

C:\Users\Bojan>(netstat -an | find "4016" & ping 1.1.1.1 -n 1 -w 1000 1>nul)
TCP 0.0.0.0:4016 0.0.0.0:0 LISTENING
TCP [::]:4016 [::]:0 LISTENING
^C

To stop the execution of this single line script use CTLR-C.