Solved

FFMPEG Quality & Thumbnail

Posted on 2008-06-09
3
1,811 Views
Last Modified: 2009-12-10
Hi Guys,

I have a 2 part question.

#1. I have a script that works fine to convert uploaded video to an flv file using ffmpeg but the quality isn't great. I have tried increasing the bitrate from the default of 200kb/s to 700kb/s which seems to make the converted video much worse. What options should i use to get a better quality video output?

Here is the line of code im using:
$output = exec ("ffmpeg -i source.ext -s qvga -ab 128 -y output.flv);

#2. I have another line of code that then creates a thumbnail from the converted video but what i would like is the code to take a thumbnail from the central location of the video rather than just the start. How would i do that without knowing the length of the video to divide it?

Here is the current thumbnail code:
$output2 = exec ("ffmpeg -y -i output.flv -r 3.0 -sameq -f image2 -an output.jpg");

Thanks.
0
Comment
Question by:jwatsonPICTS
3 Comments
 
LVL 24

Expert Comment

by:glcummins
ID: 21745898
To improve quality, try increasing the frame rate via the -r option:

 $output = exec ("ffmpeg -i source.ext -s qvga -r 24 -ab 128 -y output.flv");

or

 $output = exec ("ffmpeg -i source.ext -s qvga -r 30 -ab 128 -y output.flv");

Below is a solution to finding the total number of frames in a file, which you could use to determine the middle frame:

http://lists.mplayerhq.hu/pipermail/ffmpeg-user/2006-August/003884.html (Note that the language is not PHP, but you should be able to get the general idea).
0
 
LVL 5

Accepted Solution

by:
nacker2000 earned 250 total points
ID: 21749732
Hi,

The code below should seek to the middle of the file an output a JPEG. I have tested this and it does work. Somethings to be aware of are that the function for getting the FLV duration I got from this forum: http://flixforums.com/archive/index.php/t-149.html and on it its says that depending on the file size the function could take a while, so the thumbnail should only be produced once, after the file has been uploaded.

Also the -ss command for ffmpeg moves the position in the file to the second that is passed. Some builds of ffmpeg seem to have an issue with -ss, but it wokred fine on mine so you will just have to try it and see.
<?php

	function GetFLVDuration($file){

		// get contents of a file into a string

		if(file_exists($file)){

			$handle = fopen($file, "r");

			$contents = fread($handle, filesize($file));

			fclose($handle);

		

			if(strlen($contents) > 3){

				if(substr($contents,0 , 3) == "FLV"){

					$taglen = hexdec(bin2hex(substr($contents, strlen($contents)-3)));

					if(strlen($contents) > $taglen){

						$duration = hexdec(bin2hex(substr($contents, strlen($contents) - $taglen, 3)));

						return $duration;

					}

				}

			}

		}

		return 0;

	}

	

	// get duration and divide by 2 to get middle

	$duration = number_format((GetFLVDuration('output.flv') / 1000) / 2);

	

	// check for error

	if($duration<0){

		$duration = 0;

	}

	

	//save out thumbnail

	$output2 = exec('ffmpeg -y -i output.flv -r 1 -vframes 1 -sameq -f image2 -ss ' . $duration . ' -an output.jpg');

?>

Open in new window

0
 
LVL 23

Expert Comment

by:Rajkumar Gs
ID: 26025736
nacker2000, Can you suggest any useful tips to my question related to ffmpeg ?
http://www.experts-exchange.com/Programming/Multimedia_Programming/Video_Editing/Q_24967652.html

Thanks
--Raj
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Both Easy and Powerful How easy is PHP? http://lmgtfy.com?q=how+easy+is+php (http://lmgtfy.com?q=how+easy+is+php)  Very easy.  It has been described as "a programming language even my grandmother can use." How powerful is PHP?  http://en.wikiped…
Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now