Solved

FFMPEG Quality & Thumbnail

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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
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…
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…
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 …

705 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