Is there a simple way to get the dimensions of a video that's been uploaded. I've looked around and either find suggestions the use something else on the web that either doesn't work or doesn't exist.
I'm uploading a video and writing it to the server. I then want to find out its dimensions.
Something like this:
getsise($filename)
Can anyone help?
Ok, I didn't read the entire thread, but I read enough. The ffmpeg option will work, and you shouldn't even need ffmpeg-php, regular shell-based ffmpeg will work (that is, if you have a Linux server...not sure about Windows).
I recently needed to find the length of multiple video files (over 100) and I wasn't about to do it manually, so I found an alternative: - function getDuration($videofile) {
-
ob_start();
-
passthru("/usr/bin/ffmpeg -i \"". $videofile . "\" 2>&1");
-
$results = ob_get_contents();
-
ob_end_clean();
-
-
preg_match("#Duration: ([\d]{2}):([\d]{2}):([\d]{2}).([\d]{1,2}), start#si", $results, $match);
-
$seconds = makeSeconds($match[1], $match[2], $match[3], $match[4]);
-
return $seconds;
-
}
Running the command (ffmpeg -i "videofile.mov" 2>&1) returns something like this: - FFmpeg version SVN-rUNKNOWN, Copyright (c) 2000-2007 Fabrice Bellard, et al.
-
configuration: --prefix=/usr --libdir=${prefix}/lib --shlibdir=${prefix}/lib --incdir=${prefix}/include/ffmpeg --enable-shared --enable-libmp3lame --enable-gpl --enable-libfaad --mandir=${prefix}/share/man --enable-libvorbis --enable-pthreads --enable-libfaac --enable-xvid --enable-libdts --enable-amr_nb --enable-amr_wb --enable-pp --enable-libogg --enable-libgsm --enable-x264 --enable-liba52 --enable-libtheora --extra-cflags=-Wall -g -fPIC -DPIC --cc=ccache cc --enable-swscaler
-
libavutil version: 49.4.0
-
libavcodec version: 51.40.2
-
libavformat version: 51.11.0
-
built on Feb 4 2008 14:49:27, gcc: 4.1.2 20061115 (prerelease) (Debian 4.1.1-21)
-
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'videofile.mov':
-
Duration: 00:00:08.7, start: 0.000000, bitrate: 1483 kb/s
-
Stream #0.0(eng): Video: svq3, yuv420p, 640x360, 29.97 fps(r)
-
Stream #0.1(eng): Audio: mp3, 44100 Hz, stereo
-
Must supply at least one output file
You can see in my function that I used regular expressions to find the duration, you can do this with the dimensions as well. I don't want to figure out the regular expression right now, but you'd want to go after the Video: text, since it only occurs once in the output, then just iterate through until you find the dimensions, which in this case are 640x360.
I hope this helps you out, it sure saved me a ton of time.
28 16961
I don't think PHP can do this. Search for a program that does this, perhaps through a CLI. and just have PHP call it.
something like: -
-
exec("someprogram -f videofile.mpg",$output);
-
-
Dan
Can you suggest a program or how to do it through the command line? I have searched for other types of code that do it and couldn't find any which I why I came here.
The ffmpeg-php extension may be of use to you. Are you able to add extensions to your server?
I found a lot of references to ffmpeg-php. What is it? I couldn't seem to find out where to download it.
Well, ffmpeg is a widely used video-editing library. Someone wrote the PHP extension for it (which just wraps the C library, and exposes it to PHP-land). However, the project was last updated 10 months ago. Not sure whether it's dead, or not.
I seem to have downloaded a rar file. Do you know what I'm supposed to do with it?
You're going to need to compile the extension. What OS are you on?
I'm using Microsoft Windows XP Professional Version 2002.
Do you have a C compiler at hand?
Not on Windows but I have one on another OS available that uses Unix.
Unfortunately it has to be compiled on the same OS it's going to be used, not sure if you could do cross-compilation from Unix to Windows. Visual Studio C++ Express is free.
I wouldn't have thought the OS was an issue if I'm going to be using in a php application which has to be run on the web.
However, the extension itself is written in C, and has the problem of being compiled on the OS it is intended to be used on.
I guess I'll need to download Visual Studio C++ Express then or do I need to get it from somewhere?
I've downloaded an installed a C complier for Windows. What do I need to do next?
Which compiler do you have?
Microsoft Visual C++ 2008 Express Edition. Thank you for all the time you're spending on this. I really do appreciate it.
Anything for a fellow brit. ;)
Right. I think you may also need the re-distributable - don't worry, this one's a small download.
Now, to compile an extension, we need the PHP headers and the php5 library file. However, I'm assuming you downloaded the binary files from php.net, i.e., you didn't compile PHP yourself. If that is the case, we'll have to download the PHP source.
<break>
This can be quite hairy for a newcomer. You could, instead, find an ffmpeg binary that has already been compiled for windows, and then use one of the system functions in PHP to call the binary, as dlite922 suggested.
Now, we can either do the whole compile-from-source thing, or just use a pre-built binary. With the former, it's a tedious process and may also involve a PHP-upgrade or downgrade, depending on your current PHP version and what tags there are in the PHP SVN repository. Also, this would mean producing a new php.exe with either the php-ffmpeg extension statically compiled into the binary or compiled to a shared library (.dll). However, the benefits of this give you a well-defined PHP API to work with, as opposed to running the ffmpeg binary with command-line switches to get the desired output.
The second option is as simple as installing a compiled ffmpeg binary on your system, pointing your PATH environment variable to it, and then running system('ffmpeg -some -switches -etc); to get your desired functionality. Pros: simple to setup. Cons: no well-defined PHP API to use, involves using command line switches, etc.
Let me have a think of how this could be made easier.
I've downloaded a Windows binary for ffmpeg to give my self a choice of what to do. The file extension is 7z. Does that sound right? I might have to use your second option but I'm a bit worried how it will affect the other websites on my server.
I have had a think about this after being on holiday. I'm not too sure about ffmpef-php since the project is not up to date and there could be some problems with IMAP.
Would it help if you new my web server configuration details, or is there any other way to do this?
Is it possible to extract the funactionality of ffmpeg-php and put it into a php file?
Would the CLI method suggested by Dan work and if so would someone be able to help me through with that?
The file extension is 7z. Does that sound right?
that’s a zipped archive.
Is it possible to extract the funactionality of ffmpeg-php and put it into a php file?
it’s a shared extension, I guess there is a reason why …
Is they a way to do this with JavaScript? I'm total willing to use JavaScript if that will work. I just think the ffmpeg-php is getting to complicated more me (and from what I can make out, far to risky).
Ok, I didn't read the entire thread, but I read enough. The ffmpeg option will work, and you shouldn't even need ffmpeg-php, regular shell-based ffmpeg will work (that is, if you have a Linux server...not sure about Windows).
I recently needed to find the length of multiple video files (over 100) and I wasn't about to do it manually, so I found an alternative: - function getDuration($videofile) {
-
ob_start();
-
passthru("/usr/bin/ffmpeg -i \"". $videofile . "\" 2>&1");
-
$results = ob_get_contents();
-
ob_end_clean();
-
-
preg_match("#Duration: ([\d]{2}):([\d]{2}):([\d]{2}).([\d]{1,2}), start#si", $results, $match);
-
$seconds = makeSeconds($match[1], $match[2], $match[3], $match[4]);
-
return $seconds;
-
}
Running the command (ffmpeg -i "videofile.mov" 2>&1) returns something like this: - FFmpeg version SVN-rUNKNOWN, Copyright (c) 2000-2007 Fabrice Bellard, et al.
-
configuration: --prefix=/usr --libdir=${prefix}/lib --shlibdir=${prefix}/lib --incdir=${prefix}/include/ffmpeg --enable-shared --enable-libmp3lame --enable-gpl --enable-libfaad --mandir=${prefix}/share/man --enable-libvorbis --enable-pthreads --enable-libfaac --enable-xvid --enable-libdts --enable-amr_nb --enable-amr_wb --enable-pp --enable-libogg --enable-libgsm --enable-x264 --enable-liba52 --enable-libtheora --extra-cflags=-Wall -g -fPIC -DPIC --cc=ccache cc --enable-swscaler
-
libavutil version: 49.4.0
-
libavcodec version: 51.40.2
-
libavformat version: 51.11.0
-
built on Feb 4 2008 14:49:27, gcc: 4.1.2 20061115 (prerelease) (Debian 4.1.1-21)
-
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'videofile.mov':
-
Duration: 00:00:08.7, start: 0.000000, bitrate: 1483 kb/s
-
Stream #0.0(eng): Video: svq3, yuv420p, 640x360, 29.97 fps(r)
-
Stream #0.1(eng): Audio: mp3, 44100 Hz, stereo
-
Must supply at least one output file
You can see in my function that I used regular expressions to find the duration, you can do this with the dimensions as well. I don't want to figure out the regular expression right now, but you'd want to go after the Video: text, since it only occurs once in the output, then just iterate through until you find the dimensions, which in this case are 640x360.
I hope this helps you out, it sure saved me a ton of time.
This looks like it could be the answer I'll have a play on Monday (after a weekend's rest) and let you know how I get on.
Many thanks.
Thanks for your help HaLo2FrEeEk. Is there anyone who knows if there is a shell based ffmpeg for Windows or how I can run one from Windows or am I going back to sqaure 1?
I did a quick search and found this page: http://ffmpeg.arrozcru.org/autobuilds/
You'll want to download the most recent build of ffmpeg. Is your Windows server your own computer, or are you at a hosting company? Are you on dedicated hosting or shared? You'll need to know these things, but ultimately you should be able to run the binary.
Basically, download the executable to a root folder, outside of the scope of the actual website, then use command prompt to use it. The code in PHP should be the same, exec().
I'm not absolutely 100% sure on this because I'm on a Linux server which has ffmpeg installed natively.
Thanks for your help. I'll give this a go and see what happens.
I think I've found another solutuion.
I found this code - for filename in $(ls *mpg *avi)
-
do mplayer -nosound -vo null -ss 03:00:00 -really-quiet -identify $filename
-
echo -e "\n**************\n"
-
done >>info.txt
I don't know if this will get the information I want. Will this help me and if so, how do I get the Internet to talk to the command promt?
Sign in to post your reply or Sign up for a free account.
Similar topics
by: S |
last post by:
Whew!
Thanks for your help on that last post. I actually understand what you
wrote. I'm trying not to use these groups as a way to get my code...
|
by: Dave |
last post by:
Dear Sirs,
Is there a way to get the width and height of an image without
downloading the image, or with just downloading a minimal portion of...
|
by: Dundappa |
last post by:
hi all,
Can any one help me in setting the page width & height in asp.net
(language used is vb)
Thanks in anticipation.
|
by: ayoubahmed |
last post by:
Hi,,
Im trying to print invoices in VB.net, and the invoice is 8.5 x 8.5 inches.
Now i have to specify the new height, but when i do specify it...
|
by: Farce Milverk |
last post by:
Hi,
I'm looking for an algorithm to resize an image of arbitrary size to a
"fixed" / required width and height.
For example, my application...
|
by: emma.sax |
last post by:
My script is as follows:
function setImageSizes() {
var staticHeight = 70;
if(!document.getElementsByTagName || !document.images) return...
|
by: cooldudevamsee |
last post by:
HI fellows, How can I get visible viewport dimensions of any browser ?
|
by: gopim |
last post by:
i uploaded image into database.but i want to restrict if images having more size(width & height) before uploading into database. could any please...
|
by: chelvan |
last post by:
hi
all
i want to know is it possible to define a browsers width & height through php?
if so how is it?
thanks
chel-1
|
by: Kemmylinns12 |
last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and...
|
by: jalbright99669 |
last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made...
|
by: antdb |
last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine
In the overall architecture, a new "hyper-convergence" concept was...
|
by: Matthew3360 |
last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function.
Here is my code.
...
|
by: Matthew3360 |
last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it...
|
by: AndyPSV |
last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable...
|
by: WisdomUfot |
last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific...
|
by: Oralloy |
last post by:
Hello Folks,
I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA.
My problem (spelled failure) is with the...
|
by: Carina712 |
last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand....
| |