PHP: How to read the metadata of m4v, avi, mkv, mp4 - php

I am trying to read meta data for some different video formats (m4v, avi, mkv, mp4) using PHP.
I was hoping I could get some small example of how to do this.
I was looking around and I saw a some suggestions for PHP-Reader. I don't want to use Zend Framwork unless it is the only way to do it, and the versions without Zend don't have any examples of how to use it, and I wasn't able to figure it out myself.
I tried a built in PHP function, but I think it doesn't with the formats I want it in.
$path = 'I:\\Movies\\21 Jump Street {mp4}.mp4'
$meta_data = get_meta_tags($path, true);
echo '<pre>';
echo 'meta_data: ';print_r($meta_data);

Related

PHP - changing metadata of a JPEG

Or other image file. Can this be done in a (fairly) simple way using PHP?
I'm coding a website that will allow users to upload photos, but I know JPEGs are notorious for their metadata and ideally I'd like to strip all images uploaded of metadata, either by removal or replacement with junk text.
If you're just looking to strip most of the exif data quickly and easily without using a library to specifically write it, you can 'resave' the image using gd:
$file = 'myjpg.jpg';
$im = imagecreatefromjpeg($file);
imagejpeg($im, 'myjpg2.jpg');
Maybe not the best/prettiest solution, but it accomplishes what you want without adding additional libraries.
Take a look at this extension for PHP: http://lsolesen.github.io/pel/
i use getID3 library for this. it makes it quite easy
http://getid3.sourceforge.net/
it works with al lot of file extentions
for a demo click here:
demo

Retrieve ID3 info from m4a file in PHP

I've written some PHP code to pull out ID3 tags from mp3 files. The next step is to do the same with .m4a files. From the research I've done it looks like most m4a files do not use ID3 but instead a format using 'atoms'.
Are there any PHP libraries out there that can parse out these 'atoms'? I've seen some C#/C++ ones but haven't been able to find any PHP ones. Any other guides or documentation would be great as well.
This project handles many audio files formats including AAC (M4A is AAC) :
http://getid3.sourceforge.net/
hope this can help
I came across a similar issue not too long ago and had a look around. The simplest and most effective method (in my opinion) is to use the exec command in order to extra media information.
I based my code on a forum post over at longtailvideo http://www.longtailvideo.com/support/forums/jw-player/setup-issues-and-embedding/9448/how-to-get-video-duration-with-ffmpeg-and-php
<?php
$videofile="/var/video/user_videos/partofvideo.avi";
ob_start();
passthru("/usr/bin/ffmpeg -i \"{$videofile}\" 2>&1");
$duration = ob_get_contents();
ob_end_clean();
$search='/Duration: (.*?),/';
$duration=preg_match($search, $duration, $matches, PREG_OFFSET_CAPTURE, 3);
echo $matches[1][0]; <-- Duration
?>
This script can handle anything ffmpeg is prepared to handle (which is a lot!) I know the above example illustrates a video file but, it will work fine with audio also

Upload jpg/png, convert to pdf and save with PHP?

Been doing a fair bit of digging this morning, and not seeing an obvious answer - is it possible to save an image to pdf format using PHP (or one of it's many libraries)?
I am fairly familiar with GD, although it doesn't seem to have a built in PDF format exporter/save function from my reading so far.
If anyone has any suggestions, it would be much appreciated!!
I tried to add this to the accepted answer. Here is an example of how to convert an image to a different format (including pdf) with the Imagick module:
$img = new Imagick('path/to/image.jpg');
$img->setImageFormat('pdf');
$success = $img->writeImage('path/to/image.pdf');
OR
$img = new Imagick();
$img->readImageBlob($imageBytes);
$img->setImageFormat('pdf');
$success = $img->writeImage('path/to/image.pdf');
I see 2 other options :
the pdflib extension, but the opensource edition is quite limited (I don't know if you can use image functions without a paid license)
Zend_Pdf, which is a plain-PHP lib, part of the Zend Framework.

How to read Lightroom keywords from image file using PHP?

I have a photo community (www.jungledragon.com) that allows users to upload photos. My platform is PHP/CodeIgniter.
As part of the upload process I'm already reading EXIF info using PHP's exif_read_data function, which works fine. I read camera details and show these on an info tab.
On top of that, user's are expected to manually set the photo title, description and tags on the website after uploading the photo. However, some users manage these fields in their image management program, for example Lightroom. It would be great if I could read those as well, uploading would become a total joy.
I already improved my EXIF reading to read the "caption", this way users don't have to set the image title after uploading anymore. Now I'm looking to read keywords, which is where I am stuck. Here's a partial screenshot of an image in Lightroom:
I can read the Metadata, but how do I read the keywords? The fact that it is not inside metadata makes me wonder if it's at all possible? I've tried reading every value I can get (ANY_TAG, IFD0, EXIF, APP12) using exif_read_data, but the keywords are not to be found.
Any thoughts?
As suggested you may have to use another method of reading metadata.
http://www.foto-biz.com/Lightroom/Exif-vs-iptc-vs-xmp
Image keywords may be stored in IPTC and not in EXIF. I don't know if there is a standard platform method for reading iptc but a quick google shows this
http://php.net/manual/en/function.iptcparse.php
Try using PEL, a much more comprehensive library than exif_read_data() for exif data.
After a long research, i found the solution to get keywords exported by lightroom in a jpg file :
$image = getimagesize($imagepath, $info);
if(isset($info['APP13']))
{
$iptc = iptcparse($info['APP13']);
$keywordcount = count($iptc["2#025"]);
for ($i=0; $i<$keywordcount; $i++)
{
echo "keyword : " . $iptc["2#025"][$i] . "<br/>";
}
}

PHP Photo Effects

I am working on a new site and would like it to be able to add effects to photos uploaded. (Blur, Pan, Swirl, Sparkle, Border, Frames, etc ) I would like the photo manipulation to be in PHP if possible. I need the user to be able to upload the photo, make the edits, then save the edited photo to their computer.
This may be better as a separate question, but if at all possible I would also like the user to be able to save the edited image as their Facebook profile image.
Try PHP extensions for ImageMagick It's a standard, tried and true image manipulation library.
From the homepage:
Use ImageMagick to translate, flip,
mirror, rotate, scale, shear and
transform images, adjust image colors,
apply various special effects, or draw
text, lines, polygons, ellipses and
Bézier curves.
If you consider using the MagickWand PHP extension:
The MagicWand docs start off with a nice PHP code sample shown here:
<?php
$magick_wand=NewMagickWand();
MagickReadImage($magick_wand,'rose.jpg');
$drawing_wand=NewDrawingWand();
DrawSetFont($drawing_wand,"/usr/share/fonts/bitstream-vera/Vera.ttf");
DrawSetFontSize($drawing_wand,20);
DrawSetGravity($drawing_wand,MW_CenterGravity);
$pixel_wand=NewPixelWand();
PixelSetColor($pixel_wand,"white");
DrawSetFillColor($drawing_wand,$pixel_wand);
if (MagickAnnotateImage($magick_wand,$drawing_wand,0,0,0,"Rose") != 0)
{
MagickEchoImageBlob( $magick_wand );
}
else
{
echo MagickGetExceptionString($magick_wand);
}
?>
Similarily, documentation for things you seek:
blur
swirl
frame
magnify
and a plethora of others.... On that the main documentation page see all methods listed by searching for the heading: "MagickWand For PHP Methods".

Categories