Search This Blog

Tuesday, May 26, 2015

Convert Video Frames To Milliseconds


convert frames to milliseconds

those familiar with video are also likely familiar with frame rates (number of frames per second) and timecode. sometimes, it is necessary to convert a certain number of frames value and/or a timecode value into standard seconds and milliseconds values for stream conditioning via NPT values, etc. 

let's take a look at the math required to do this sort of conversion. i like to use python, but you can use a calculator or maybe another repl for your favorite programming language to follow along.

in the following example, our video source file has a frame rate commonly referred to as "60 FPS", but more technically referred to as 59.94. we would like to calculate a more exact frame rate, determine how many milliseconds each frame occupies, and then see how many milliseconds are occupied by 3 frames as a simple usage example.

here we go!

Python 2.7.3 (default, Feb 13 2013, 16:44:35) 
[GCC 4.2.1 Compatible Apple LLVM 4.2 (clang-425.0.24)] on darwin.
Type "help", "copyright", "credits" or "%magic" for more information.

>>> 60/1.001 # calculate more exact frames per second more on this here:
59.940059940059946

>>> # there are 1000 milliseconds in 1 second

>>> # so how many milliseconds does each frame occupy?

>>> 1000 / (60 / 1.001) # milliseconds in 1 second divided by frames per second
16.68333333333333

>>> # so how many milliseconds are occupied by 3 frames?

>>> 3 * (1000/(60 / 1.001))
50.04999999999999

>>> # convert the above value back to seconds (underscore in python refers to last output)

>>> _ * .001
0.05004999999999999

>>> # now that we have the understanding, let's wrap this up into a simple function:

>>> def ftoms(f, r):
...    return (f * (1000 / (r / 1.001))) * .001

>>> # now let's run some tests with our new frames to milliseconds converter:

>>> ftoms(1, 60)
0.016683333333333331

>>> ftoms(3, 60)
0.05004999999999999

>>> ftoms(1, 30)
0.033366666666666663

>>> ftoms(1, 24)
0.041708333333333326

>>> ftoms(24, 24)
1.0009999999999999

>>> ftoms(30, 30)
1.0009999999999999

>>> ftoms(60, 60)
1.0009999999999999

>>> exit

and there you have it. granted, the function above is only applicable to 59.94, 29.97, and 23.98 frame rates, but it could easily be modified to account for 25, 24, and 30 frame rates. 
i hope this helps someone else in videoland!
cheers!
ryanlmcmurray

Tuesday, April 17, 2012

Build a CentOS Virtual Machine via Parallels

References used for this walkthrough:

1. Go here using Safari http://mirror.flhsi.com/centos/6.2/isos/x86_64/ and click CentOS-6.2-x86 64-netinstall.iso to download the netinstall file

2. After netinstall file has finished downloading, open Parallels

3. In the "Install from:" dropdown menu, choose the "CentOS-6.2-x86 64-netinstall.iso" file on your local machine (wherever you chose to save it in step 1)

4. Automatic detection fails so you have to select the operating system name from the drop down menu that automatically pops up. Choose "More Linux" and then "CentOS Linux" and click "OK"

5. Click "OK". Now you will see the CentOS logo on screen.

6. At bottom left of the Parallels window, click the dropdown and choose "Start". You'll now see some options on-screen. I choose the second option by using the arrow keys on the keyboard. You'll see a bunch of text scrolling on-screen once install begins.

7. After text stops scrolling, you'll see a Welcome screen. Click in the Parallels window, press the right arrow key on your keyboard to highlight the "Skip" option on-screen and press Enter on your keyboard.

8. Choose your language and press Enter. Choose the type of keyboard you have and press Enter.

9. On the "Installation Method" screen press the down arrow key on your keyboard to select the "URL" option and press Enter.

10. On the "Configure TCP/IP" menu screen, press the down arrow key on your keyboard to highlight the "OK" button and press Enter to choose default settings.

11. On the "URL Setup" screen, type: http://be.mirror.eurid.eu/centos/6.2/os/x86_64

*note - depending on your location in the world, you may want to choose a different mirror to download from to increase download speed. see the list of mirrors here: http://www.centos.org/modules/tinycontent/index.php?id=30

12. After the .img completes downloading, CentOS will ask for your input regarding various system options. Choose as you please.

Done.

Friday, May 21, 2010

Install FFMPEG on Mac OSX - The Easy Way


If you've ever felt the learning curve for installing and using FFMPEG was too steep, my documentation will help you get it set up and running with minimal effort even if you've never used Terminal (OSX command line interface) before.

Before wanting to use FFMPEG I had never really used Terminal before, and largely I still don't. This document will get you through FFMPEG set up as painlessly as possible.

I even included commands to do certain tasks that I have had to do.

Thank You to all of the other FFMPEG users who have documented their commands and tips online. Without you I would still be scratching my head.

Enjoy!

GETTING STARTED:

First, we'll need to install Xcode.

To download Xcode, you'll have to register as a developer with Apple. It's free. Register here:

While logged into your Apple Developer account, DOWNLOAD Xcode here:

INSTALL Xcode.

We will use MacPorts http://www.macports.org/index.php to install necessary command line tools ffmpeg and MPlayer along with all of the components that each of these tools requires.

DOWNLOAD MacPorts here: http://www.macports.org/install.php

INSTALL MacPorts.

Now, we'll use MacPorts to download the command line tools we need.

To use MacPorts, open Terminal. You'll find it in Applications > Utilities

To DOWNLOAD AND INSTALL FFMPEG, inside Terminal type: 
sudo port install ffmpeg

You will have to enter your computer password.
It will take a while for port to install ffmpeg and all of it's components.

To INSTALL MPlayer, type: 
sudo port install mplayer

You will have to enter your network password.
It will take a while for port to install MPlayer and all of it's components.
Welcome to the wonderful world of open source video encoding!



TERMINAL COMMANDS:

For FFMPEG and MPlayer to see a file, YOU MUST FIRST USE TERMINAL TO CHANGE TO THE DIRECTORY WHERE THE FILE IS LOCATED. The terminal command to change directories is: cd

Here's an example change directories command: cd /Users/rmcmur000/Desktop/FLVMP4

*Note: if there are spaces in the name of a folder, etc. that you need to change directories to, use the backslash before the space.

Example: cd /Volumes/Video\ Team\ 1

In the above example, my external FW drive is called: Video Team 1

*Note: Pressing the up arrow will load your last command into the command line prompt. you still have to press enter to run it however...

DOCUMENTATION: (there is no apple osx official terminal documentation online that i know of, but there are many good resources online for it. here is one: http://oreilly.com/pub/ct/51



FFMPEG COMMANDS:

In all of these example commands, I will use an actual video file name in the command. Sub in your own video file name to carry out your own FFMPEG commands.

TRANSCODE FLV TO MP4 Profile Main, Level 3.0:
ffmpeg -i jersey_108_bonus_e_53679.flv -b 800k -acodec libfaac -ab 96k -vcodec libx264 -vpre hq -vpre main -level 30 -crf 24 -threads 0 jersey_108_bonus_e_53679.mp4

GET INFO ABOUT VIDEO FILE:
ffmpeg -i abc_lost_burningclip.flv

GENERATE 1 THUMBNAIL FROM VIDEO FILE FROM 10 SECOND MARK:
ffmpeg -i abc_lost_burningclip.flv -vframes 1 -s 320x240 -ss 10 abc_lost_burningclip.jpg

GENERATE 1 THUMBNAIL EVERY 10 SECONDS FROM VIDEO FILE:
ffmpeg -i abc_lost_burningclip.flv -r 1/10 -s 320x240 abc_lost_burningclip.jpg

RIP AUDIO FROM VIDEO FILE:
ffmpeg -i abc_lost_burningclip.flv -ab 96k abc_lost_burningclip.mp3

CROP 16X9 LETTERBOXED FLV TO NATIVE 16X9 MP4 Profile Main, Level 3.0
ffmpeg -i jersey_108_bonus_e_53679.flv  -b 800k -acodec libfaac -ab 96k -vcodec libx264 -vpre hq -vpre main -level 30 -crf 24 -threads 0 -croptop 74 -cropbottom 74 -sameq -aspect 16:9 -s 640x360 -y jersey_108_bonus_e_53679.mp4

FULL DOCUMENTATION:




MPLAYER COMMANDS:

PLAY VIDEO FILE:
mplayer abc_lost_burningclip.flv

FULL DOCUMENTATION: