Get the dimensions of a H.264 MP4 - php

Does anybody know a ready-made, reliable way to tell the dimensions (width x height) of a MP4 encoded using the H.264 codec without ffmpeg or similar extensions, in pure PHP?
Thanks for all the answers folks. The bounty is running out and I will not have time to check the offered solutions before it does. I will accept the solution that I feel has the greatest likelihood to work.

getID3 is pure php and extracts an amazing amount of information from media files of all sorts. It will depend on what encoded your file in the first place as to what metadata is available and how reliable it is. getID3 has a nice demo page with lots of different file types. I tried to post more links but as a newbie I only get one.

It sounds like http://code.google.com/p/php-mp4info/ might be your answer. It reads MP4's but it doesn't mention anything about H.264.
also, what OS are you using?

What comes to mind:
mediainfo a huge project with GUI, but also has a CLI
mp4info (part of the seemingly defunct mp4mpeg project) is almost perfect for this
ffmpeg although this is overkill for the task. then again, you very well may need it for other tasks

ffmpeg and php: http://www.lampdeveloper.co.uk/linux/detecting-a-videos-dimensions-using-php-and-ffmpeg.html

php-reader is a full implementation of the ISO 14496 done in pure PHP. You can use this library to read all of the boxes which the mp4 consist of, like the moov atom containing metadata about the file.

Native PHP does not support anything like this, ffmpeg is only one library that come on my mind.

Related

Converting PPTX to PDF with PHP

I am developing an API, in PHP, hosted on a linux server, that requires me to make jpeg previews for a .pptx powerpoint presentation.
I first convert the file to pdf and then convert the pdf to jpegs.
The second step is easy, with ghostscript, it's the first part that's proving difficult.
I have tried using the libreoffice executable, but pptx isn't completely compatible. Certain backgrounds become invisible.
I have the same problem with many 3rd party APIs (which I suspect also use libreoffice); the ones that do work, are ridiculously expensive.
Installing office on a Linux server and using COM functions seems impossible, or very tedious at best.
I have looked at Aspose.Slides, which also seems rather expensive, and their documentation is filled with errors.
I could use suggestions on how to tackle this problem.
I have tried to find the underlying problem of why LibreOffice and online conversion tools have a problem with the backgrounds of the presentations I need to convert.
The background is a .emf file, which has bad support.
My solution
I've unzipped the presentation, converted the .emf files to png (using ghostscript), changed all mentions of .emf to .png in the XML, and rezipped the altered presentation.
When I now use the LibreOffice headless to convert to pdf, the background shows up.
It might be a bit hacky, but it works for the intent of my program.
ps. I see that my question has gathered a few downvotes. In my opinion it was a valid question, and listed the various solutions that had worked for others, but not for me. If anyone has insights or ways to improve it, feel free to comment.

RAW images and PHP

I would like to extract a thumbnail from a RAW image file, like Canon's .CR2 or Nikon's .NEF. I've understood that this can somehow be done with ImageMagick, but haven't grasped if it's possible through the PHP wrapper.
Are there any good solutions? Preferably using the built in thumbnail for speed.
Yep, iMagick (the php version of ImageMagick) can handle these extensions: http://www.imagemagick.org/script/formats.php
Here's a great set of tuts that got me going with Imagick. The owner responded to a few of my questions quickly, and despite a bit of a language barrier was able to easily get me through my hurdles
As an aside, I've begun using Gallery to do image admin. No need to worry about thumbnailing, uploading, etc....it's all automatic. Then on the front end I can do jquery magic (getting photos via php query from the gallery database tables) to make it look really good.
Likely, if PHP's imagemagick libraries are to support this, they would be drawing from some functionality exposed through imagemagick's 'identify' command line tool (as the tool would be itself exposing functionality in the imagemagick libraries). Looking at the documentation for this tool, it doesn't look good. If you tried running identify -verbose, theoretically, the thumbnail information would appear in there somewhere, perhaps as an encoded value. Try it yourself: if it does, maybe you could possibly further extract the information returned from identify, either through the imagemagick functions in PHP (though I don't see any past the Exif libraries which only work on JPEG), or by scraping the return of a PHP system call to the identify tool.
Either way, doesn't look likely.
Benjamin Horn has submitted a complete example about reading the requested data and even saving it locally for later use.
Check this out:
https://benjaminhorn.io/code/extracting-thumbnails-from-camera-raw-files-cr2-and-nef-with-php/

PHP rotate video

I have my own video sharing app,
My question is... is there any library,script or something else, to help me in rotating videos whatever their file extension is?
Many peoples are uploading videos but sometimes i found video (guessing shared with iphones or mobile phones) and i see them horizontally instead of vertically...
Does anyone have any ideas how to rotate them dynamically?
Im not familiar with any "libraries" that will do that. I think your better bet would be to find a command-prompt-enabled video software package (like Any Video Converter [See Q7]) that PHP can execute via command prompt on the fly.
PHP doesn't do that, and there are no extensions that I know off, made for that purpose.
You can use ffmpeg to manipulate videos, by calling it from your scripts (see shell_execute() and such functions). Reading the ffmpeg documentation will help you figure what can (and can't) be done with that powerful tool.

combining .mov movies with php

I have quicktime movies uploaded to my server that I need to combine together (there are sound tracks too). I cannot install ffmpeg (or anything else for that matter away from standard PEAR stuff).
I suppose an option open to me would be to open up the files with php. Can anyone provide any pointers on how to do this. Am I entering a world of pain?
Thanks in advance
Tudor
Am I entering a world of pain?
Probably yes. :)
I'm not familiar with the internal workings of the mov format, but if the format is not like MP3 (in which you can actually simply just glue two files together and they'll work in most players!), what you want to do is most likely not possible in pure PHP.

PHP Extract audio from video

I need a way to extract the audio from some video (in PHP). I have the video streaming in from YouTube, so I would really like it if it were on the fly streaming, not I have to save it to a temp directory and process it there (though that is acceptable.) Thanks, Isaac Waller
Edit: to be more specific, I have a MP4 and I want it to be a MP3.
You're going to want to use something like ffmpeg and call it using php's exec command. If you look around in the docs, I'm sure you can figure out what flag to use to only get the audio.
I've used this app before on a project for live transcoding of video, works like a charm. Just make sure your server has it correctly installed.
Mplayer should do this for you, and there are libraries and codecs that you can call (PHP supports C libraries) which will strip the video from the AV stream on the fly.
Given that you're targeting youttube your job is a bit easier because they use a very small subset of file encodings.
If you take the time to learn the format, you can very easily remove the video stream on the fly and return only the audio stream.
If you give a little more information, such as what you're encoding it to, or where it's going to end up we may be able to help more specifically.
-Adam

Categories