Solved

FFMPEG Quality & Thumbnail

Posted on 2008-06-09
3
1,836 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

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

Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
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.

733 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