Retrieve ID3 info from m4a file in PHP - 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

Related

Streaming a video using PHP and manipulating it using FFMPEG

I use the class in this tutorial to open a mp4 file in PHP and stream it to HTML5 video player and everything works fine. Now I would like to do some manipulations to the stream on the fly. e.g: adding a watermark to the stream. I am not sure if it can be done using ffmpeg command or PHP-FFMpeg.
The class in the mentioned tutorial opens the file (or the range of the file that is needed by the player), into the $data variable:
$data = fread($this->stream, $bytesToRead);
echo $data;
flush();
I guess I need to pass the $data to ffmpeg somehow, add the watermark and then echo() the manipulated $data instead of the original one. But I am not sure if it's possible or not, and if it is, how it can be done? I don't know how to open a variable in ffmpeg instead of a file and how to get the output as a variable, and not a file.
Any help would be appreciated.

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

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);

Downloading youtubevideos to server with php

So i want to download youtubevideos as mp3 to my server, so i can listen them easily as mp3.
I have some ecperience in PHP, and second to none in youtube API, but if i have understood correctly youtubevideos are loaded in chunks, and 1 of them is the mp3 soundtrack of the video.
If that is incorrect, could you advice other way to do the downloading?
To this point i have managed to do small php script to get the nessessary information to save the audio.
$id = $_POST["A"];
$xmlData = simplexml_load_string(file_get_contents("http://gdata.youtube.com/feeds/api/videos/{$id}?fields=title"));
$title = (string)$xmlData->title;
$bad = array_merge(
array_map('chr', range(0,31)),
array("<", ">", ":", '"', "/", "\\", "|", "?", "*"));
$result = str_replace($bad, "-", $title);
$file = "$result.mp3";
fopen("$file", 'w+') or die('Cannot open file: '."$file");
//echo "http://youtubeinmp3.com/fetch/?video=http://www.youtube.com/watch?v=$id";
$current = file_get_contents("$file");
//$current .= "http://youtubeinmp3.com/fetch/?video=http://www.youtube.com/watch?v=$id";
file_put_contents("$file", $current);
(post A is coming from my html part of code and it includes youtube video ID)
So, in that code i dont exactly use youtube to download the mp3 track...
so it would be great if any of you would know how to download it directly from youtube, and how to save it, because by my logick that code should perfectly work, and it does, untill the saving the audio, it saves about 50 bits and then stops, i dont get any errors or anything so its realy hard to debug.
Also if you notice any errors os better ways to do things in my code pleace notify me.
Also sorry for my bad english i m from finland, and yes sorry for crappy code, this is actualy first practical program i would be going to use :)
Youtube API doesn't provide direct links to audio or video content, only thumbnails. The only way is to parse regular page using regular expression to extract link to media. Thats how all "getfromyoutube" sites doing.
After you get content you can process it with ffmpeg or other tool. I don't think there is separate mp3 track. Normally audio track is embedded to mp4 container.
Yet it is illegal and you shouldn't doing this. e.t.c. e.t.c.
I warned you ;)

Recording live stream from IP camera (MJPEG Compression)

I have a live stream from a Tenvis IP camera through http live streaming and its in mjpeg compression.
I am trying to save it to a file, and I have tried using php to do this. my code looks like this:
<?php
$input = fopen("http://xxx.xxx.xxx.xxx:81/videostream.cgi?user=user&pwd=admin&resolution=8");
$output = fopen("video.mpg", "c+");
$end = time() + 60;
do {
fwrite($output, (fread($input, 30000)), 30000);
} while (time() <= $end);
fclose($output);
fclose($input);
echo "<h1>Recording</h1>";
?>
The code I have creates the file but doesn't write anything to it. Any suggestions will be appreciated
According to the Wikipedia page about MJPEG (http://en.wikipedia.org/wiki/Motion_JPEG#M-JPEG_over_HTTP), the MJPEG stream over HTTP is basically a sequence of JPEG frames, accompanied by a special mime-type. In order to capture these and save them to a video file, I am not sure you can simply write the incoming data to an .mpg file and have a working video.
To be honest, I am not quite sure why your script does not write anything at all, but I came across the following page, which, although it is written for specific software, provides examples on how to capture an MJPEG stream and pass it on to a browser:
http://www.lavrsen.dk/foswiki/bin/view/Motion/MjpegFrameGrabPHP
You could try one of their examples, and instead of passing it to the browser, save it to a file. You can see they read one image at a time:
while (substr_count($r,"Content-Length") != 2) $r.=fread($input,512);
$start = strpos($r,'ΓΏ');
$end = strpos($r,$boundary,$start)-1;
$frame = substr("$r",$start,$end - $start);
If this does fix the stream capturing part but not saving it as a video, another option would be to save all frames individually as a JPEG file, then later stitch them together using a tool such as ffmpeg to create a video: Image sequence to video quality
Update
If you decide to take the ffmpeg road, it is also possible to capture the stream using ffmpeg only. See this question for an example.
Hope this helps.
Most of the time, when a camera supports mjpeg, it also supports rtsp and as such you might want to pursue that as a solution for what you are trying to accomplish. With that, its fairly simple to record using an app like VLC.

Generating docx files with php using PHPDOCX

I guess no one was lucky to found the best solution of handling reports in php, specialy when it's a .doc/x report or file .... i searched for sometime and then i found phpdocx.com .. amazing php script, but it just doesn't work, and i don't know exactly where to find the output file ... and unfortunately the documentation doesn't help at any level ...
Now i need to know the way this script work .. i mean how results come out and become usable ... and what needs it take the script to work .. because it simply doesn't work on my local host .. i am using appache 2, php 5.2.6 ..
I don't actually need more than writing html with in ( a real doc format file, not rename a html file to .doc !! ), so if there is any solution ( without the COM Lib ... i am not on a windows server ) to generate real doc file with HTML .. please but it here
Thanks very much in advance :)
I guess no one was lucky to found the best solution of handling
reports in php, specialy when it's a .doc/x report or file
This is not the question corresponding to the title, but you should try OpenTBS.
It's an open source PHP library which builds DOCX with the technique of templates.
No temp directory, no extra exe needed. First create your DOCX, XLSX, PPTX with Ms Office, (ODT, ODS, ODP are also supported, that's OpenOffice files). Then you use OpenTBS to load the template and change the content using the Template Engine (easy, see the demo). At the end, you save the result where you need. It can be a new file, a download flow, a PHP binary string.
OpenTBS can also change pictures and charts in a document.
Demo page
Documentation
The documentation of PHPDocX has been greatly improved.
Have you tried to look at the PHPDocX tutorial?
You may also have a look at the Forum.
require_once "Path of phpdocx library/CreateDocx.inc";
$docx = new CreateDocx();
$html = 'your data will store in this variable';
$docx->embedHTML(
$html,
array(
'parseDivsAsPs' => true,
'downloadImages' => true,
'WordStyles' => array(
'<table>' => 'MediumGrid3-accent5PHPDOCX'
),
'tableStyle' => 'NormalTablePHPDOCX'
)
);
$docx->createDocx($varPublicPath.'/word_export_file/example1_'.time());
// this is location where your docx file will generate(inside word_export_file docx file will store)

Categories