PHP Problem with UPLOAD_ERR_PARTIAL (File upload error code 3)

I have just spent the last 3 hours trying to figure out why only ever 3rd file would upload (and then files would only randomly upload) and i continued to get UPLOAD_ERR_PARTIAL. It turns out UPLOAD_ERR_PARTIAL can be caused by the header Connection: Keep-Alive.

If you are working on a web app that requires a lot of file uploading, make sure to use on your uploader script to set:
header("Connection: close");

This will force the connection to be closed, and for a new connection to be opened to upload the file, which allows the file to be properly uploaded.

jQuery UI Tabs without the ul and li elements

Now rather than using


<div class="tabs">
<ul>
<li><a href="#tab-1">Tab 1</a></li>
<li><a href="#tab-2">Tab 2</a></li>
<li><a href="#tab-3">Tab 3</a></li>
</ul>
<div id="tab-1">
</div>
<div id="tab-2">
</div>
<div id="tab-3">
</div>
</div>

You can use


<div class="tabs">
<div id="tab-1" title="Tab 1">
</div>
<div id="tab-2" title="Tab 2">
</div>
<div id="tab-3" title="Tab 3">
</div>
</div>

Using the simple code below with jquery+jqueryui, you can remove the need entirely for the ul and li elements.


$('.tabs').each(function() {
var m_ul = $('<ul/>');
$(this).children('div[title]').each(function() {
var m_id = ($(this).attr('id') != undefined ? $(this).attr('id') : $(this).attr('title').replace(/\s/g, '_'));
$(this).attr('id', m_id);
$(m_ul).append($('<li/>').append($('<a/>').attr('href', '#' + m_id).text($(this).attr('title'))));
});
$(this).prepend(m_ul);
}).tabs();

Watermark Video in FFMPEG without vhook

It has always been that with ffmpeg, if you want to watermark a video, you needed vhook. vhook as we all know is old and not very useful to windows users and in the newer ffmpeg builds has been replaced with video filters, or –vf.

One of the filters in the new –vf format is a watermark filter, allowing you to watermark your videos during the transcoding procedure.

An example would be: –vf “overlay:10:10” which would tell the overlay to position 10 pixels from the top of the main video, and 10 pixels from the left.

But what if we want to position from the right? Or from the bottom? Or centre the overlay? This is where main_w (main video width), main_h (main video height), overlay_w (overlay video width) and overlay_h  (overlay video height) comes in. You can use these variables to represent the certain set sizes of the video and the overlay.

So what if we wanted to position 10 pixels from the right and 10 pixels from the bottom? We would the use: –vf “overlay:main_w-overlay_w-10:main_h-overlay_h-10”.

So how do we specify the overlay? What we do is use the “movie” video filter which would take our png or jpg and convert that into a movie which is then overlaid on top of our existing movie.

See example below:

ffmpeg –i inputvideo.avi -vf "movie=watermarklogo.png [watermark]; [in][watermark] overlay=main_w-overlay_w-10:10 [out]" outputvideo.flv

Or if you are planing to use your video with a newer version of flash that supports h264 encoded videos, you could use:

ffmpeg.exe -i input.avi -sameq -vcodec libx264 -acodec libfaac -vf "movie=logo.png [watermark]; [in][watermark] overlay=(main_w-overlay_w)/2:main_h-overlay_h-10 [out]" -threads 0 "output-slow.mp4"

qt-faststart.exe output-slow.mp4 output-fast.mp4

Thus giving you a watermarked MPEG4 h264 + AAC file capable of streaming with a flash player.

Search and Replace in Linux Command Line

I wanted to search and replace every file in a directory tree and find a URL that linked to /web-design and remove that part of the URL, and i also wanted to find the phrase “Web Design” in a link and replace it with “Affordable Web Design”.

Usually i would have to go through each individual file via SSH or FTP and then open the file, make the edits, save the file and re-upload the file. The problem with that is, i needed to do this for over 15,000 files on over 3000 web sites, and that isn’t something i wanted to do.

Firstly, i needed to find all the html files that could possibly have these two defects, so i went with “find”, its simple, and easy, and crawls sub directories as default.

Find all files with the extension “.html” in the current directory and all sub directories:
find . -iname '*.html'

The problem i had then was, web sites that are still being worked on are in a private directory that i do not want to alter, so i needed to exclude these directories:
find . -iname '*.html' -not -path '*private*'

This now gives me a list of everything that i need to do a search and replace on.

For this next part, you can use either “sed” or “perl”. I chose to go with perl as i know perl better than sed.

This cold should replace “/web-design” with “” in a file called “index.html” in the current folder. (Follows the format “s/what to find/what to replace with/g”):
perl -pi -w -e 's/\/web-design//g;' index.html

So what we need to do now is use xargs to combine the two parts and make the search and replace in all files:
find . -iname '*.html' -not -path '*private*' | xargs perl -pi -w -e 's/\/web-design//g;' -sl

This code should now look in the current directory, and all sub-directories contained within for any html file not in a private folder, and remove the text “/web-design” and replace it with nothing.

The next bit was a simple modification to replace the phrase “Web Design” with “Affordable Web Design”, though we needed to take into account that we only wanted to replace content within a A HREF tag, so we need to search for “>Web Design<”
find . -iname '*.html' -not -path '*private*' | xargs perl -pi -w -e 's/\>Web Design\</\>Affordable Web Design\</g;' -sl

Make sure that when you are creating your regular expressions, you escape any special characters such as \ / < > and friends.

AnyFontCss – Use CSS to load any font (TTF/Freetype) in modern browsers

With Chrome, Firefox and now IE9 becoming more and more wide spread, and the impending death of IE6. I began to look into googles font loading library and it turned out to be some new CSS features (new to me anyway) that loaded up and allowed any font to be used within a website natively, without the need for Flash or Canvas.

You simply select a font and font style, and the app simply generates all the CSS and even the link code for the HTML to allow the loading of any installed font.

Download AnyFontCss (Requires .NET Framework 2.0)

FFmpeg Win32 Builds down indefinitely

I am sorry to say that my hosting provider did not like me using the dedicated host i paid for, so that i could run build processes on the server, running build processes on the server.

They killed my entire build environment, and all the builds.

Until i am able to find a new host that is willing to let me create these builds, the ffmpeg builds will remain down.

Anyone looking to get ffmpeg builds for windows for now should look at http://ffmpeg.zeranoe.com/

Sorry, and thank you to everyone who used my builds.

FFmpeg Win32 Builds Back Up

Hi,

sorry for the delay in getting this back up but we have had some server issues over the past few weeks and i have only just got round to getting this sorted.

FFmpeg win32 builds are now being generated nightly again from the ffmpeg git repository.

FFmpeg Windows Builds (Repeating Builds)

Some of you may have noticed that some builds have been repeating over the past 2 weeks, this is down to git not being able to recognise that i have manually applied some patches that now made it into the main ffmpeg branch. i have had to undo these packages and i have now created a seperate experimental clone to test experimental patches.

this should now stop any future messups.

ffmpeg windows builds

How to build libvpx for windows and ffmpeg win32

I initially ran into quite a lot of difficulty building libvpx (webm) for windows (win32) under msys or linux using mingw32, but I eventually cracked it.

git clone git://review.webmproject.org/libvpx.git
cd libvpx
CROSS=i686-pc-mingw32- ./configure --prefix=/usr/i686-pc-mingw32/mingw --target=x86-win32-gcc
make
make install

The only thing you would generally need to change is the “i686-pc-mingw32″ generally needs to be changed to reflect the mingw in your build system and the prefix needs to point to your mingw toolset root. Not only will this create a working library to use within windows projects (the libvpx.a can be added to visual studio projects), it creates and installs a library that builds perfectly into ffmpeg win32 builds.

Simple, no patches required.

Fast convert x264 mkv to Xbox360 mp4 (Play mkv on Xbox 360)

Most HD is distributed in either WMV-HD or mkv x264. WMV-HD plays by default on the Xbox360 but mkv’s do not and transcoding 1080p can take a long time.

The thing is, you dont need to transcode the entire file, usually just the audio (360 cant play AC3 from within a mp4 container). The x264 that exists within the mkv works perfectly on an Xbox 360 and it takes nothing more than copying the video from one container to another, and re-code the audio.

You simply need:

ffmpeg -i input.mkv -vcodec copy -acodec aac -ab 192k -ac 2 -threads 0 -strict experimental output.mp4

Depending on your version of ffmpeg, you need to replace aac with libfaac.

You can also create a batch script that converts an entire directory of mkv’s to mp4′s for you.

FOR /R “in” %%D in (*.mkv) DO ffmpeg -i “%%D” -vcodec copy -acodec libfaac -ab 192k -ac 2 -threads 0 -strict experimental “out\%%~nD.mp4″

Create a text file called convert-mkv-mp4.bat and paste this line inside, when you run it the script will look inside a directory “in” and outputs the mp4′s in a directory called “out”. You will need to create the two directories yourself before running the script or errors will ensue :)

If you need recent win32 ffmpeg builds, you need to check my ffmpeg win32 autobuilds page.

Older posts >>