advanced ffmpeg recipes

Output a single frame from the video into an image file:

ffmpeg -i input.flv -ss 00:00:14.435 -vframes 1 out.png

Output one image every second, named out1.png, out2.png, out3.png, etc.

ffmpeg -i input.flv -vf fps=1 out%d.png

Output one image every minute, named img001.jpg, img002.jpg, img003.jpg, etc. The %03d dictates that the ordinal number of each output image will be formatted using 3 digits.

ffmpeg -i myvideo.avi -vf fps=1/60 img%03d.jpg

Extracting X images from a video of variable length

ffmpeg -i <input_file> -vsync 0 -vf "select='not(mod(n,100))'" <output_file>

(where 100 is the frame-frequency you’d like to use, for example, every 100th frame)

The filter thumbnail tries to find the most representative frames in the video:

ffmpeg -i input.mp4 -vf  "thumbnail,scale=640:360" -frames:v 1 thumb.png

and the following command selects only frames that have more than 40% of changes compared to previous (and so probably are scene changes) and generates a sequence of 5 PNGs.

ffmpeg -i input.mp4 -vf  "select=gt(scene\,0.4),scale=640:360" -frames:v 5 thumb%03d.png

Looks for the first >40%-change frame within each of 5 time spans, where the time spans are the 1st, 2nd, 3rd, 4th, and 5th 20% of the video.

ffmpeg -ss 3 -i input.mp4 -vf "select=gt(scene\,0.4)" -frames:v 5 -vsync vfr fps=fps=1/600 out%02d.jpg

Missing cygwin1.dll Simple Fix: Put Cygwin in PATH

f you try running Cygwin from another program, or are running an installer (say for yasm) and you get a “missing cygwin1.dll” error, you should check that you have put Cygwin into your Windows PATH environment variable. The file is part of cygwin , so most likely it’s located in C:\cygwin\bin. To fix the problem all you have to do is add C:\cygwin\bin (or the location where cygwin1.dll can be found) to your system path. Alternatively you can copy cygwin1.dll into your Windows directory.

To add to your user profile path you can do the following from the command line using the setx command which is built into Windows Vista and above. In earlier versions of Windows you can use the Windows Resource Kit to get it.

Say Cygwin in installed in c:\cygwin, do:

SETX path c:\cygwin;c:\cygwin\bin;%path%

Or for you, as user only:

SETX -m path c:\cygwin;c:\cygwin\bin;%path%

Or via the GUI

Position element at the bottom of parent

Assign position:relative to the parent element, and then position:absolute; bottom:0; to the element.

So for:

<div id="container">
ehtoif
  <footer id="copyright">
    Copyright James Fishwick
  </footer>
</div>

Assign position:relative to #container, and then position:absolute; bottom:0; to #copyright.

Bonus flexbox method:

#container {
    display: flex;
}
#footer{
    align-self: flex-end;
}

Javascript: Return an array of objects according to key, value, or key and value matching

function getObjects(obj, key, val) {
    var objects = [];
    for (var i in obj) {
        if (!obj.hasOwnProperty(i)) continue;
        if (typeof obj[i] == 'object') {
            objects = objects.concat(getObjects(obj[i], key, val));    
        } else 
        //if key matches and value matches or if key matches and value is not passed (eliminating the case where key matches but passed value does not)
        if (i == key && obj[i] == val || i == key && val == '') { //
            objects.push(obj);
        } else if (obj[i] == val && key == ''){
            //only add if the object is not already in the array
            if (objects.lastIndexOf(obj) == -1){
                objects.push(obj);
            }
        }
    }
    return objects;
}

Reverse line order in Notepad++

Input:

Line 1
Line 2
Line 3

Required Output:

Line 3
Line 2
Line 1

  1. Edit > Select All
  2. TextFX > TextFX Tools > Insert Line Numbers
  3. If TextFX > TextFX Tools > +Sort ascending is checked, uncheck it
  4. TextFX > TextFX Tools > Sort lines case sensitive (at column)
  5. TextFX > TextFX Tools > Delete Line Numbers or First Word

If TextFX is not found then go to: Plugins » Plugin Manager » Show Plugin Manager » Check “TextFX Characters”, Click Install.

Simple video info extraction with ffmpeg

To get a lot of information about a media file one can do

ffmpeg -i <filename>

It’s a little like drinking from a firehose though. How can we just quickly determine, say, if the video is h264 encoded? Or simply the duration length?

One catch is that ffmpeg is writing that information to stderr, not stdout. So to pipe this info stream to another program, we need to redirect standard error to standard output. Try this:

ffmpeg -i file.mp4 2>&1 | grep Duration |  awk '{print $2}' | tr -d ,

This should give you a string like: 00:04:13.67

You can also use

ffprobe -show_streams -i Video5ThanksInternal.mp4 2>&1 | grep codec_name

ffprobe gathers information from multimedia streams and prints it in human- and machine-readable fashion.

-show_streams
Show information about each media stream contained in the input multimedia stream.

405 error when POSTing to ASMX using jQuery?

The method has to be decorated with [WebInvoke] to enable POST method.

[WebInvoke(Method = "POST", ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.WrappedRequest)]

If it is asmx, include the below protocols in web.config

<webServices>
    <protocols>
        <add name="HttpGet"/>
        <add name="HttpPost"/>
    </protocols>
</webServices>

in system.web

Also, decorate the web method with [scriptmethod] to be accessed from script