Posts Tagged ‘video’

Extract full resolution (original) gif image (or other media) from a power point file

Sunday, March 29th, 2015

I’d lost the original to an animated gif that I’d embedded in a previous talk’s powerpoint slide. I tried clicking “Save image as…” but this gave me a lower resolution, scaled version without the animation. Seems there is a well known trick to finding original media in modern Microsoft office files. The .*x files are actually zipped directories. So unzip them to a folder using something like:

unzip myfile.pptx -d myfile/

Then you should find your media files somewhere in this directory. I found mine in: myfile/ppt/media/.


Download video as mp4 from

Thursday, February 5th, 2015

Given a url to a video like: Here’s how you can rearrange the url to download the video as an mp4:

wget $(echo "" | sed -e "s/com\/\(.*\)/com\/transcodes\/\1?format=1\&chunk=0/") -O output.mp4

Probably if it’s a long video you’ll need to increment the chunk=0 to chunk=1 and so on and then stitch the video together.

VHS filter matlab script

Wednesday, April 23rd, 2014

A while ago I found this killer tutorial for apply a VHS look to an image. I was able to whip up a little matlab filter to do it procedurally. Here’s the vhs function:

function V = vhs(im,varargin)
  % VHS Apply a VHS filter to an image
  % V = vhs(im)
  % V = vhs(im,'ParameterName',ParameterValue,...)
  % Inputs:
  %   im  h by w by c image
  %   Optional:
  %     'VerticalLoop' followed by whether to loop the bent strip vertically
  %     over time and output a sequence of images.
  % Output:
  %   V  h by w by c by f image of (f long sequence of images)

  looping = false;
  % Map of parameter names to variable names
  params_to_variables = containers.Map( {'VerticalLoop'},{'looping'});
  v = 1;
  iter = 1;
  while v <= numel(varargin)
    param_name = varargin{v};
    if isKey(params_to_variables,param_name)
      v = v+1;
      % Trick: use feval on anonymous function to use assignin to this workspace
      error('Unsupported parameter: %s',varargin{v});

  if looping 
    strip_top = 1;
    strip_top = ceil(0.4*size(im,1));

  first = 1;
  while true

    A = im;
    B = im;
    C = im;
    D = im;
    % exclusion blend like photoshop
    ex = @(T,B) 0.5 - 2.*(T-0.5).*(B-0.5);
    % kill color channels
    A(:,:,1) = 0;
    B(:,:,2) = 0;
    C(:,:,3) = 0;
    % Shift color layers
    nudge = @(f) ceil(f*rand(1)*size(im,2));
    A = A(:,mod(nudge(0.02)+(1:end)-1,end)+1,:);
    B = B(:,mod(nudge(0.02)+(1:end)-1,end)+1,:);
    C = C(:,mod(nudge(0.02)+(1:end)-1,end)+1,:);
    A = A(mod(nudge(0.005)+(1:end)-1,end)+1,:,:);
    B = B(mod(nudge(0.005)+(1:end)-1,end)+1,:,:);
    C = C(mod(nudge(0.005)+(1:end)-1,end)+1,:,:);
    % exclusion blend colored layers and alpha blend with original

    F = D+0.3*(ex(ex(C,B),A)-D);
    N = rand(size(im));

    % inverse mapping function
    bend_w = (2*rand(1)-1)*5;
    bend = @(x,u) [mod(x(:,1)+(1-x(:,2)/max(x(:,2))).^2*bend_w,max(x(:,1))) x(:,2)];
    % maketform arguments
    ndims_in = 2;
    ndims_out = 2;
    tdata = [];
    tform = maketform('custom', 2,2, [], bend, tdata);

    % Bend strip
    strip_h = ceil(1/4*size(im,1));
    strip = mod(strip_top+(1:strip_h)-1,size(im,1))+1;
    F(strip,:,:) = imtransform(F(strip,:,:), tform);

    % overlay gray line
    ol= @(T,B) (T>0.5).*(1-(1-2.*(T-0.5)).*(1-B))+(T<=0.5).*((2.*T).*B);
    G = repmat(0.75,[numel(-1:1) size(F,2) size(F,3)]);
    F(mod(strip_top+(-1:1)-1,size(F,1))+1,:,:) = ...
      ol( F(mod(strip_top+(-1:1)-1,size(F,1))+1,:,:),G);

    % overlay horizontal lines
    L = zeros(size(F));
    L(1:4:end,:,:) = 1;
    L(2:4:end,:,:) = 1;
    L = imfilter(L,fspecial('gaussian',[5 5],1.5),'replicate');
    F = ol(F,L);

    % Fade in random color gradient
    m = rand(1,2)*2-1;
    R = bsxfun(@plus,m(1)*(1:size(F,2)),m(2)*(1:size(F,1))');
    R = (R-min(R(:)))./(max(R(:))-min(R(:)));
    R = gray2rgb(R,colormap(jet(255)));
    F = F+0.05*(ol(F,R)-F);

    % soft light
    sl = @(T,B) (B>0.5).*(1-(1-T).*(1-(B-0.5))) + (B<=0.5).*(T.*(B+0.5));
    F = F + 0.15*(sl(F,N)-F);

    % sharpen
    V(:,:,:,iter) = imsharpen(F);


    strip_top = strip_top+round(0.057*size(im,1));
    iter = iter+1;
    if ~looping || strip_top > size(im,1)


Doing it procedurally is cool because you can generate a whole animation of them. Like this:

kavinsky vhs animation

or this

rioux vhs animation

or this

dylan vhs animation

Append a progress bar to a video or image sequence and show frame reordering

Thursday, December 19th, 2013

For a project we’re reordering the frames of a video. Here’s how to append a progress bar that visualizes where the frames are coming from in the original video.

Load in a video, here I use a video object:

video = VideoReader('rhinos.avi');

Let’s define a vector of indices I to be a remapping of the video frames so that frame f of the new video will be frame I(f) of the original video. We’ll use the original ordering

I = 1:video.NumberOfFrames;

or a random ordering:

I = randperm(video.NumberOfFrames);

Then append a progress bar and store the composite as an Height-by-Width-by-3-by-NumberOfFrames image sequence matrix S:

bar_w = video.Width;
bar_h = 20;
S = zeros(video.Height+bar_h,video.Width,3,video.NumberOfFrames);
for f = 1:video.NumberOfFrames
  S(1:video.Height,:,:,f) = read(video,f);
  col_If = round((I(f)-1)/(video.NumberOfFrames-1) * (bar_w-1)) + 1;
  col_f = round((f-1)/(video.NumberOfFrames-1) * (bar_w-1)) + 1;
  S(video.Height+(1:bar_h),1:col_f,:,f) = 0.2;
  S(video.Height+(1:bar_h),col_If,1,f) = 1;

Here’s what the result looks like for the original ordering:

original rhino ordering with progress bar

And with the random ordering:

remapped rhino ordering with progress bar

Note: This assumes that the remapped video and the original video are the same length.

Average all frames of a video in MATLAB

Monday, December 16th, 2013

Here’s a snippet to import a video in MATLAB and average all frames.

avg = zeros([video.Height video.Width 3]);
for f = 1:nf
  avg = avg + (1/nf).*im2double(read(video,f));

I get a bit of a boost (200%) by using a parfor parallel for loop:

avg = zeros([video.Height video.Width 3]);
parfor f = 1:nf
  avg = avg + (1/nf).*im2double(read(video,f));

Convert mkv into high quality mp4 for iPad

Friday, November 1st, 2013

Here’s what I’m using to convert 1080p BluRay rips from .mkv to .mp4s for playing back on the iPad.

ffmpeg -i input.mkv -acodec aac -ac 2 -strict experimental -ab 160k -s 1920x1080 -vcodec copy -f mp4 -threads 0 output.mp4

Update: This only works if the input .mkv file is already using h264 as the video codec (see, it’s copying the video rather than transcoding it). Otherwise, you’ll need this (takes much longer):

ffmpeg -i input.mkv -acodec aac -ac 2 -strict experimental -ab 160k -vcodec libx264 -preset slow -profile:v baseline -level 30 -maxrate 10000000 -bufsize 10000000 -b 1200k -f mp4 -threads 0 output.mp4

Colours I AM A MAN MAN MAN MAN REMIX ft. Grouplove

Monday, December 24th, 2012

Download high resolution video
Download mp3

Convert a bunch of images into a video, batch job

Friday, October 26th, 2012

I was sure I posted this some time before, but just in case, here it is again. My programs can easily dump jpgs, pngs, or tga image files at every frame. Sometimes it suffices to convert these to an animated GIF using imagemagick. But if there are many images and they’re all hi-res then really you need a proper video codec to get a reasonably small file. I use this ffmpeg command:

ffmpeg -f image2 -r 30 -i myimages-%04d.tga -r 30 -vcodec libx264 -pix_fmt yuv420p -q:vscale 0 output.mp4

or using GLOB for a lexicographical, alphabetical file list:

ffmpeg -f image2 -r 30 -pattern_type glob -i 'my-images-*.png' -r 30 -vcodec libx264 -pix_fmt yuv420p -q:vscale 0 output.mp4

Update : The -pix_fmt yuv420p` is important for getting the output video to play in quicktime.

Ffmpeg to wmv bitrate parameter order gotcha

Tuesday, July 3rd, 2012

I had been using:

ffmpeg -pass 1 -passlogfile ffmpeg2pass -g 1 -b 16000k -i output.wmv
ffmpeg -pass 2 -passlogfile ffmpeg2pass -g 1 -b 16000k -i output.wmv

which at one point gave me an error on the second pass:

[msmpeg4 @ 0x7fde41844e00] requested bitrate is too low

I tried increasing 16000k to 32000k, but this did not make the error go away. Turns out I just needed to switch the order of the parameters:

ffmpeg -pass 1 -passlogfile ffmpeg2pass -g 1 -i  -b 16000k output.wmv
ffmpeg -pass 2 -passlogfile ffmpeg2pass -g 1 -i  -b 16000k output.wmv

After Effects preserve correct colors on export

Tuesday, July 3rd, 2012

The preview in after effects was showing me the correct colors I wanted to see, but then when I exported (even using Quicktime Animation) the colors became a bit faded and washed out. To fix this I went to File > Project Settings … and set Depth to 32 bits per channel and Working Space to Apple RGB.


After effects with default color settings


After effects with good color settings