en en en en de en en en en en en en en en en en en en en en en en ja en en en en en en en en en ja en en en en en en az en en en en en en en en en en en en en en en sv et de en en en en fr en en en en en en en en en az en en en en en en en en en en en en en en en sv et de en en en en fr en en en en en en en en en az en en en en en en en en en en pt en en en en en en en
If you pass a video to avconv, it returns meta-data about the video, including its duration, e.g.
A search on the Ubuntu forums returned an easy way to parse the above output using Linux scripting1.
Once, I had the above data (e.g.  “00:00:03.76”) in a string, I needed to convert it to an integer value. Further research returned the following snippet of PHP code
list($hours,$mins,$secs) = explode(':',$duration); $seconds = mktime($hours,$mins,$secs) - mktime(0,0,0);
The first mktime returned a timestamp relative to the current time, so we need to subtract the number of seconds from the current timestamp at midnight. This gives us the number of seconds in our video as an integer value.
Raguet Roman, 2012, accessed  21 April 2014,  .
2012, Stack Overflow, accessed  21 April 2014, .
Posted in PHP, Video Encoding, Web DevelopmentTagged Linux, Mint, PHP, Ubuntu, VideoLeave a comment
Splitting a file path in PHP
Posted on Apr 13, 2014 by Denis G Noonan
During the week, I was faced with the problem of dividing a given string containing a file path into the file name, extension and the path to the file’s directory. For example, “/home/myuser/myfile.ext”, has to be split into “/home/myuser/”, “myfile” and “ext”.
My first instinct was to use PHP’s explode() function to split the string on the forward slash. This would give me my file name and extension in the last element of the returned array and each of the directories of my path in the preceding elements. Of course, I would then have to build my directory path from these elements before returning the result, re-inserting the forward slash along the way.
This did not strike me as an elegant way to proceed. So on further reflection, I started my solution using basename(). This returns the file name and extension for a given file path. From here, I used explode to split the base file name into it’s file name and extension. Note that I did not store the “.” between the file name and extension as the specification did not require this.
Now, I needed the directory path to the file. Of course, my input string already had this information. I just had to remove the file name and extension from the end. So, I used substr() to get the sub string from the start of the source path less the length of the base file name (with it’s extension).
This struck me as being a more succinct resolution which is more intuitive to understand. I have included some sample code below.
class PathSplitter { function __construct() { $source = "/home/myuser/myfile.ext"; echo "Source path: {$source}\n\n"; $splitPath = $this->splitPath($source); echo "Split Path:\n"; var_dump($splitPath); } private function splitPath($source) { // Get the file name and extension, i.e. the basename $baseName = basename($source); // Break down the basename into file name and extension $parts = explode(".", $baseName); $name = $parts[0]; $extension = $parts[1]; // The path is the full path name less the basename $path = substr($source, 0, -strlen($baseName)); $splitPath = array( "path" => $path, "name" => $name, "extension" => $extension ); return $splitPath; } }
Posted in PHPTagged file path, PHP, string handlingLeave a comment
Follow Denis' Technology Blog on WordPress.com
How to Set up a Minikube Lab with VMware Workstation
How to install Elasticsearch on Fedora 28
Versioning in Git using Tags
Getting the Duration of a Video with PHP
Splitting a file path in PHP
Denis G Noonan on How to install Elasticsearch o…
Max on How to install Elasticsearch o…
SutoCom on Installing Laravel on Linux Mi…
Denis G Noonan on Including Autoloader and …
thenewphalls on Including Autoloader and …
How to Set up a Minikube Lab with VMware Workstation
How to install Elasticsearch on Fedora 28
Versioning in Git using Tags
Getting the Duration of a Video with PHP
Splitting a file path in PHP
Denis G Noonan on How to install Elasticsearch o…
Max on How to install Elasticsearch o…
SutoCom on Installing Laravel on Linux Mi…
Denis G Noonan on Including Autoloader and …
thenewphalls on Including Autoloader and …
Follow Denis' Technology Blog on WordPress.com
How to Set up a Minikube Lab with VMware Workstation
How to install Elasticsearch on Fedora 28
Versioning in Git using Tags
Getting the Duration of a Video with PHP
Splitting a file path in PHP
Website Powered by WordPress.com.
Privacy & Cookies: This site uses cookies. By continuing to use this website, you agree to their use.