Solved

FFMPEG Quality & Thumbnail

Posted on 2008-06-09
3
1,805 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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
This article discusses four methods for overlaying images in a container on a web page
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

744 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

12 Experts available now in Live!

Get 1:1 Help Now