Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7773053
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T17:01:56+00:00 2026-06-01T17:01:56+00:00

I am writing a php script (I have to use php) to cycle through

  • 0

I am writing a php script (I have to use php) to cycle through a dir of media files and displaying media information in a chart.

Right now, I’m trying to do it on 1 file.

I can successfully do so. I currently can parse the output (using regular expressions) to obtain information such as file name, duration, resolution, etc

I was told that I can combine the regular expressions to make it more efficient.

When I do however, I am unable to parse the ffmpeg output correctly.

Consequently, I’ve tried copying the output to a string and parsing that using multiple expressions and it works just fine.

Any help is appreciated.

Thanks.


Working code

$media_info = "'test.mkv': Metadata: creation_time : 2011-03-12 09:04:18 Duration: 00:21:44.10, start: 0.000000, bitrate: 500 kb/s Chapter #0.0: start 0.097000, end 1304.107000 Metadata: title : 00:00:00.097 Stream #0:0: Video: h264 (High), yuv420p, 720x400 [SAR 80:81 DAR 16:9], 23.98 fps, 23.98 tbr, 1k tbn, 47.95 tbc (default) Stream #0:1: Audio: aac, 48000 Hz, stereo, s16 (default) At least one output file must be specified";


$file = array();
$file_test = preg_match_all("/'([a-zA-Z0-9\._]*\.[a-zA-Z0-9]*)'.* Duration: ([0-9]{2,}:[0-9]{2}:[0-9]{2}\.[0-9]*)/", $media_info, $file);;
var_dump($file)

Not Working Code

ob_start();
passthru("C:\\wamp\\www\\ffmpeg\\bin\\ffmpeg.exe -i \"{$videofile}\" 2>&1");
$raw_data = ob_get_contents();
ob_end_clean();


$ffmpeg_info =  explode("from", $raw_data);


$media_info = $ffmpeg_info[1];

$file = array();
$file_test = preg_match_all("/'([a-zA-Z0-9\._]*\.[a-zA-Z0-9]*)'.* Duration: ([0-9]{2,}:[0-9]{2}:[0-9]{2}\.[0-9]*)/", $media_info, $file);;
var_dump($file)

New Code

I tried using the ffmpeg-php extension and the following works (except for printing the bit rate)

$movie = new ffmpeg_movie($video_file);

echo $movie->getFilename();
echo "<br/>" ; 
echo $movie->getDuration();
echo "<br/>" ;
echo $movie->getFrameWidth();
echo "x";
echo $movie->getFrameHeight();
echo "<br/>" ; 
echo $movie->getBitRate();
echo "<br/>" ; 
echo $movie->getVideoBitRate();
echo "<br/>" ; 
echo $movie->getAudioBitRate();
echo "<br/>" ;
echo $movie->getVideoCodec();
echo "<br/>" ;
echo $movie->getAudioCodec();
?>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T17:01:57+00:00Added an answer on June 1, 2026 at 5:01 pm

    Are you able to use a library to extract the information instead of a regex on the output of a command line tool? For example, ffmpeg-php?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm writing a photo gallery script in PHP and have a single directory where
I'm writing a PHP script that downloads a series of generated files (using wget
I have a list of proxies, need to use them in a php script
I want to use PHP writing git hooks but have some problem. I use
The standard way of writing PHP extensions is to use autoconf/automake alongside a script
I am writing a php script to grab information from more than 30 different
I am writing a PHP script that needs to interpret Diff files as created
Im writing a php script to compare the similarity of 2 strings. This works
I'm writing a PHP script and the script outputs a simple text file log
I'm writing a PHP script that does a lot of repetitive work, and when

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.