The Mobile Galaxy The New Mobile Era Has Come | Mobile – A Time To Remember

30Aug/114

中国地图偏移校正算法

该校正适用于 Google map China, Microsoft map china ,MapABC 等,因为这些地图构成方法是一样的。

需要offset.dat文件,该文件为0.01精度校正数据, 有需要者请联系作者, 报价: 5,000.00 RMB。

php算法

<?php
/*
   代码功能:利用0.01精度校正库文件修正中国地图经纬度偏移。
*/
header("Content-Type:text/html; charset=utf-8");
define('__dat_db__' , 'offset.dat' );// DAT数据文件
define('datmax' , 9813675 );// 数据条数-结束记录

// # offset.php?lat=39.914914&lon=116.460633
$lon=$_GET['lon'];
$lat=$_GET['lat'];
$tmplon=intval($lon * 100);
$tmplat=intval($lat * 100);
//经度到像素X值
function lngToPixel($lng,$zoom) {
return ($lng+180)*(256<<$zoom)/360;
}
//像素X到经度
function pixelToLng($pixelX,$zoom){
return $pixelX*360/(256<<$zoom)-180;
}
//纬度到像素Y
function latToPixel($lat, $zoom) {
$siny = sin($lat * pi() / 180);
$y=log((1+$siny)/(1-$siny));
return (128<<$zoom)*(1-$y/(2*pi()));
}
//像素Y到纬度
function pixelToLat($pixelY, $zoom) {
$y = 2*pi()*(1-$pixelY /(128 << $zoom));
$z = pow(M_E, $y);
$siny = ($z -1)/($z +1);
return asin($siny) * 180/pi();
}

function xy_fk( $number ){
        $fp = fopen(__dat_db__,"rb"); //■1■.将 r 改为 rb
        $myxy=$number;//#"112262582";
        $left = 0;//开始记录
        $right = datmax;//结束记录

        //采用用二分法来查找查数据
        while($left <= $right){
            $recordCount =(floor(($left+$right)/2))*8; //取半
            //echo "运算:left=".$left." right=".$right." midde=".$recordCount."<br />";
            @fseek ( $fp, $recordCount , SEEK_SET ); //设置游标
            $c = fread($fp,8); //读8字节
            $lon = unpack('s',substr($c,0,2));
            $lat = unpack('s',substr($c,2,2));
            $x = unpack('s',substr($c,4,2));
            $y = unpack('s',substr($c,6,2));
            $jwd=$lon[1].$lat[1];
            //echo "找到的经纬度:".$jwd;
            if ($jwd==$myxy){
               fclose($fp);
               return $x[1]."|".$y[1];
               break;
            }else if($jwd<$myxy){
               //echo " > ".$myxy."<br />";
               $left=($recordCount/8) +1;
            }else if($jwd>$myxy){
               //echo " < ".$myxy."<br />";
               $right=($recordCount/8) -1;
            }

        }
        fclose($fp);
}

$offset =xy_fk($tmplon.$tmplat);
$off=explode('|',$offset);
$lngPixel=lngToPixel($lon,18)+$off[0];
$latPixel=latToPixel($lat,18)+$off[1];

echo pixelToLat($latPixel,18).",".pixelToLng($lngPixel,18);

?>

c#算法

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;   

namespace MapDigit.GIS
{
    public class GeoLatLng
    {   

        public GeoLatLng(double latitude, double longitude)
        {
            this.latitude = latitude;
            this.longitude = longitude;
        }
        public double latitude;
        public double longitude;
    }   

    public class GeoPoint
    {
        public GeoPoint(int x, int y)
        {
            this.x = x;
            this.y = y;
        }
        public int x;
        public int y;
    }   

    public class OffsetInChina
    {
        //用于从GPS坐标转换为偏移后坐标
        public static GeoLatLng fromEarthToMars(GeoLatLng earth)
        {
            GeoPoint ptOffset = getOffset(earth.latitude, earth.longitude);
            if (ptOffset.x != 0 || ptOffset.y != 0)
            {
                int pixelX, pixelY;
                TileSystem.LatLongToPixelXY(earth.latitude, earth.longitude, 18, out pixelX, out pixelY);
                GeoPoint pt = new GeoPoint(pixelX, pixelY);
                pt.x += ptOffset.x;
                pt.y += ptOffset.y;
                double latitude, longitude;
                TileSystem.PixelXYToLatLong(pt.x, pt.y, 18, out latitude, out longitude);
                return new GeoLatLng(latitude, longitude);   

            }
            else
            {
                return new GeoLatLng(earth.latitude, earth.longitude);
            }   

        }   

        //用于将偏移后坐标转成真实的坐标
        public static GeoLatLng fromMarToEarth(GeoLatLng mars)
        {
            GeoPoint ptOffset = getOffset(mars.latitude, mars.longitude);
            if (ptOffset.x != 0 || ptOffset.y != 0)
            {
                int pixelX, pixelY;
                TileSystem.LatLongToPixelXY(mars.latitude, mars.longitude, 18, out pixelX, out pixelY);
                GeoPoint pt = new GeoPoint(pixelX, pixelY);
                pt.x -= ptOffset.x;
                pt.y -= ptOffset.y;
                double latitude, longitude;
                TileSystem.PixelXYToLatLong(pt.x, pt.y, 18, out latitude, out longitude);
                return new GeoLatLng(latitude, longitude);   

            }
            else
            {
                return new GeoLatLng(mars.latitude, mars.longitude);
            }
        }   

        //这个函数用于将需要查询的经纬度转成最近的0.01分度值,无插值
        //也可以自行实现插值
        private static GeoPoint getQueryLocation(double latitude, double longitude)
        {
            int lat = (int)(latitude * 100);
            int lng = (int)(longitude * 100);
            double lat1 = ((int)(latitude * 1000 + 0.499999)) / 10.0;
            double lng1 = ((int)(longitude * 1000 + 0.499999)) / 10.0;
            for (double x = longitude; x < longitude + 1; x += 0.5)
            {
                for (double y = latitude; x < latitude + 1; y += 0.5)
                {
                    if (x <= lng1 && lng1 < (x + 0.5) && lat1 >= y && lat1 < (y + 0.5))
                    {
                        return new GeoPoint((int)(x + 0.5), (int)(y + 0.5));
                    }
                }
            }
            return new GeoPoint(lng, lat);
        }   

        private static GeoPoint getOffset(double longitude, double latitude)
        {
            //这个函数用于返回查询结果,就是从校正数据中返回18级时x,y方偏移
            //可以自行实现
            return null;
        }   

    }
}
Share
Tagged as: , 4 Comments
28Aug/110

UITableVIew实现类似于电话本的首字母索引

实际上UITableView默认就支持象电话本那样的按首字母索引。 实现sectionIndexTitlesForTableView 和 sectionForSectionIndexTitle 这两个接口即可。 细节请参考UITableViewDataSource帮助文档。

- (NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView
{

NSMutableArray *toBeReturned = [[NSMutableArray alloc]init];

for(char c = ‘A’;c<=‘Z’;c++)

[toBeReturned addObject:[NSString stringWithFormat:@"%c",c]];

return toBeReturned;

}

- (NSInteger)tableView:(UITableView *)tableView sectionForSectionIndexTitle:(NSString *)title atIndex:(NSInteger)index
{

NSInteger count = 0;

for(NSString *character in arrayOfCharacters)

{

if([character isEqualToString:title])

{

return count;

}

count ++;

}

return 0;

}

- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{

if([arrayOfCharacters count]==0)

{

return @”";

}

return [arrayOfCharacters objectAtIndex:section];

}
Share
27Aug/110

用摄像头画面做 view 背景

This action starts camera as a backgroud of the view:-

-(IBAction)btnStartCamera_TouchUpInside{

picker = [[UIImagePickerController alloc] init];
#if TARGET_IPHONE_SIMULATOR
picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
picker.view = viewCategoryCamera;
#elif TARGET_OS_IPHONE
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
picker.showsCameraControls = NO;
[picker.view addSubview:viewCategoryCamera];
//picker.cameraOverlayView = viewCamera;
#endif
[self presentModalViewController:picker animated:YES];
}
This action stops camera:-
-(IBAction)btnStopCamera_TouchUpInside:(id)sender{

[self dismissModalViewControllerAnimated:YES];
[self.navigationController popToRootViewControllerAnimated:YES];
}
Share
27Aug/110

Check Valid Email

BOOL NSStringIsValidEmail(NSString *checkString)
{
NString *stricterFilterString = @"[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,4}";
NSString *laxString = @".+@.+\.[A-Za-z]{2}[A-Za-z]*";
NSString *emailRegex = stricterFilter ? stricterFilterString : laxString;
NSPredicate *emailTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", emailRegex];
return [emailTest evaluateWithObject:checkString];
}
Share
27Aug/110

Map distance and annotation

From: http://www.cocoachina.com/bbs/read.php?tid-17969.html

1,看到很多人问如何计算两点之间的距离,其实很简单哎。
准备两个CLLocation的对象,比如要计算某个位置与使用者当前位置的距离,则其 中一个CLLocation是userLocation = [locationManager location],locationManager是CLLocationManager的实例,并已执行[locationManager startUpdatingLocation];
然后计算这两个CLLocation的距离(已格式化成12.34 km):

  1. [NSString stringWithFormat:@"%0.2f km",[userLocation getDistanceFrom:location]/1000]

PS: another method

Giving credit as the function was derived from contents of: http://www.jaimerios.com/?p=39
- (double) CalculateKilometerDistanceFrom: (CLLocationCoordinate2D) point1 To: (CLLocationCoordinate2D) point2 {
    double nRadius = 6371; // Earth's radius in Kilometers
    // Get the difference between our two points
    // then convert the difference into radians
    double nLat1 = point1.latitude;
    double nLon1 = point1.longitude;
    double nLat2 = point2.latitude;
    double nLon2 = point2.longitude;
    double nDLat = (nLat2 - nLat1) * (M_PI/180);
    double nDLon = (nLon2 - nLon1) * (M_PI/180);
    // Here is the new line
    nLat1 =  (nLat1) * (M_PI/180);
    nLat2 =  (nLat2) * (M_PI/180);
    double nA = pow ( sin(nDLat/2), 2 ) + cos(nLat1) * cos(nLat2) * pow ( sin(nDLon/2), 2 );
    double nC = 2 * atan2( sqrt(nA), sqrt( 1 - nA ));
    double nD = nRadius * nC;
    return nD; // Return our calculated distance
}

2, 在处理MKAnnotationView时,都要判断对应annotation是不是MKUserLocation这个显示用户当前位置的蓝点,以避免误 操作。

  1. [annotation isKindOfClass:[MKUserLocation class]]

3,- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation
这个delegate函数一般会在给MKMapView对象添加 annotations后马上执行,但执行不会马上结束。如果在它完成之前就调用
[mapView viewForAnnotation:someAnnotation];的话,会返回nil的结果,这时对这个返回的nil做任何操作都不会在屏幕上显 示……

4,MKMapView放大缩小时,需要注意的是放大,至少放大2倍以上才会被执行。

  1. - (IBAction)doZoomIn:(id)sender{//放大
  2.     MKCoordinateRegion region = mMapView.region;
  3.     region.span.latitudeDelta=region.span.latitudeDelta * 0.4;
  4.     region.span.longitudeDelta=region.span.longitudeDelta * 0.4;
  5.     [mapView setRegion:region animated:YES];
  6. }
  7. - (IBAction)doZoomOut:(id)sender{//缩小
  8.     MKCoordinateRegion region = mMapView.region;
  9.     region.span.latitudeDelta=region.span.latitudeDelta * 1.3;
  10.     region.span.longitudeDelta=region.span.longitudeDelta * 1.3;
  11.     [mapView setRegion:region animated:YES];
  12. }

5, 下面随便列一些其他没提到的代码,供搜索引擎搜索

  1. CLLocationCoordinate2D coordinate;
  2. //Location Paris
  3. coordinate.latitude = 48.856660;
  4. coordinate.longitude = 2.350996;
  5. MKCoordinateRegion viewRegion = MKCoordinateRegionMakeWithDistance(coordinate, distance, distance);
  6. MKCoordinateRegion adjustedRegion = [mapView regionThatFits:viewRegion];
  7. [mapView setRegion:adjustedRegion animated:animated];

6,问 题:
发现MKAnnotationView的Callout View有bug。
我在后台更新subtitle后,若不手动点一下其他 MKAnnotationView再点回之前已经显示Calloutview的MKAnnotationView的话,那这个 MKAnnotationView的Calloutview里的subtitle就不会被更新……
说清楚点就是:点了某个大头针显示信息后,若这 时后台更新了它的subtitle,然后你再点这个大头针会发现它的subtitle显示成了一个空白。这时得点一下其他大头针,再点回来,原来那个大头 针的信息才是完整的。
虽然有个notification是 MKAnnotationCalloutInfoDidChangeNotification,但SDK手册里说这个已经不能用了。我尝试用了一下也没有 任何效果……
不知道还有其他方法没

Share
25Aug/110

短信与iPhone

很多年前,短信应用因然而生,很多人没有引起足够的重视,突然之间,短信成了当时最抢手的应用。2007年苹果推出基于iPhone的App store, 同样是看似不怎么起眼的应用,也是突然之间爆发成最火爆的应用。中国有句古话:不以恶小而为之,在当今的互联网时代,恰恰是不以利小而不为之,往往越是很多不被人们看中的小应用,恰恰会成为这个时代的黑马。下一个应用会是什么呢?或许就在你身边。

Share
Filed under: Other No Comments
11Aug/110

Objective-C中对Url的参数进行编码

1、对于中文和一些非url的字符串,可以使用stringByAddingPercentEscapesUsingEncoding:

NSString* escapedUrlString =
   [unescapedString stringByAddingPercentEscapesUsingEncoding:
                        NSASCIIStringEncoding];

2、对于url格式的参数,上面方法不行,可以使用下面的方法解决这个问题:

  NSString * encodedString = (NSString *)CFURLCreateStringByAddingPercentEscapes
(    NULL,    (CFStringRef)unencodedString,    NULL,
    (CFStringRef)@"!*'();:@&=+$,/?%#[]",    kCFStringEncodingUTF8 );
Share
11Aug/110

Apple内部去除地图偏移的方法

MKLocationManager (a Private API) in iOS

Beware: Apps that use non-public APIs will be rejected;

Apple内部对MKUserLocation去除偏移的方法。

[MKLocationManager _applyChinaLocationShift:(CLLocation*)arg]

这个方法返回去除偏移后的CLLocation*。

Code:

@interface MKLocationManager
- (CLLocation*)_applyChinaLocationShift:(CLLocation*)arg;
- (BOOL)chinaShiftEnabled;
+ (id)sharedLocationManager;
@end

CLLocationManager's Delegate:

- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
{
if ([[MKLocationManager sharedLocationManager] chinaShiftEnabled]) {
newLocation = [[MKLocationManager sharedLocationManager] _applyChinaLocationShift:newLocation];
if (newLocation == nil) return;
}
}

reference: http://stackoverflow.com/questions/6401593/how-to-use-mklocationmanager-a-private-api-in-ios

// in some header file, you may want to give the method a prefix too CLLocation *ApplyLocationManagerChinaLocationShift(CLLocation *newLocation);
 
CLLocation *ApplyLocationManagerChinaLocationShift(CLLocation *newLocation) {   
id sharedLocationManager = [NSClassFromString(@"MKLocationManager") performSelector:@selector(sharedLocationManager)];
SEL theSelector = @selector(_applyChinaLocationShift:);   
// this will ensure sharedLocationManager is non-nil and responds appropriately   
if (![sharedLocationManager respondsToSelector:theSelector]) { 
    return nil; // fail silently - check this in the caller   } 
  return [sharedLocationManager performSelector:theSelector withObject:newLocation]; }
 
Share
Filed under: iPhone No Comments
11Aug/110

Google Maps API 相关算法

  1. 通过明文经度和纬度获得静态地图,地图大小可以指定,地图比例尺可以指定,地图上可以添加标注,标注的颜色和字母可以自定义
  2. 通过街道名称获得明文经纬度,这个功能正在进行尝试

下面的代码是Google的经纬度转块号算法:

package com.datuu.googlemap;/**
* Created by IntelliJ IDEA.
* User: ShiChaoYun
* Date: 2008-11-17
* Time: 17:43:10
*/

/**
* <p>Title: </p>
* <p>Description: </p>
* <p/>
* <p>Copyright: Copyright (c) 2006</p>
* <p/>
* <p>Company: </p>
*
* @author not attributable
* @version 1.0
*/

public class MapProjectionUtil {

    public MapProjectionUtil() {
}

    private final static int pixelsPerTile = 256;                                                //每块象素
    public final static double minLatitude = -85.0511287798;                                    //最小纬度
    public final static double maxLatitude = 85.0511287798;                                     //最大纬度
    public final static double minLongitude = -180;                                             //最小经度
    public final static double maxLongitude = 180;                                              //最大经度
    //采用WGS84-长半径6378137,短半径6356752.3142
    private final static double earthRadiusInMeters = 6378137;                                 //地球半径
   private final static double earthCircumferenceInMeters = 2 * Math.PI * earthRadiusInMeters; //地球周长

/**
* 功能:返回一个范围在minValue和maxValue之间的数
*
* @param n
* @param minValue
* @param maxValue
* @return 返回n,如果n小于minValue则返回minValue,如果n大于maxValue则返回maxValue;
*/

private static double clip(double n, double minValue, double maxValue) {
return Math.min(Math.max(n, minValue), maxValue);
}

    /**
* 功能:将经地理坐标转换为象素坐标
*
* @param latitude      double
* @param longitude     double
* @param levelOfDetail int
* @return long[]
*/

public static long[] translateLongLatToPixels(
double longitude, double latitude,
int levelOfDetail) {
long xPixel = 0;
long yPixel = 0;
latitude = clip(latitude, minLatitude, maxLatitude) * Math.PI / 180;
longitude = clip(longitude, minLongitude, maxLongitude) * Math.PI / 180;
double sinLatitude = Math.sin(latitude);
double xMeters = earthRadiusInMeters * longitude;
double yMeters = earthRadiusInMeters / 2 *
Math.log((1 + sinLatitude) / (1 - sinLatitude));

        long numPixels = (long) 256 << levelOfDetail;
double metersPerPixel = earthCircumferenceInMeters / numPixels;
xPixel = (long) clip((earthCircumferenceInMeters / 2 + xMeters) /
metersPerPixel + 0.5, 0, numPixels - 1);

        yPixel = (long) clip((earthCircumferenceInMeters / 2 - yMeters) /
metersPerPixel + 0.5, 0, numPixels - 1);
long[] ret = new long[2];
ret[0] = xPixel;
ret[1] = yPixel;
return ret;
}

    /**
* 将象素坐标转换为块号和块内像素位置
*
* @param xPixel long
* @param yPixel long
* @return long[]
*/

public static long[] translatePixelsToTile(long xPixel, long yPixel) {
long xTile = 0, yTile = 0, xTilePixel = 0, yTilePixel = 0;
xTile = xPixel / pixelsPerTile;
yTile = yPixel / pixelsPerTile;
xTilePixel = xPixel % pixelsPerTile;
yTilePixel = yPixel % pixelsPerTile;
long[] ret = new long[4];
ret[0] = xTile;
ret[1] = yTile;
ret[2] = xTilePixel;
ret[3] = yTilePixel;
return ret;
}

    /**
* 将象素坐标转换为地理坐标
*
* @param xPixel        long
* @param yPixel        long
* @param levelOfDetail int
* @return double[]
*/

public static double[] pixelsToLongLat(long xPixel, long yPixel,
int levelOfDetail) {
double[] ret = new double[2];
double fd = 40075016.685578488D /
(double) ((1 << levelOfDetail) * 256);
double ia = (double) xPixel * fd - 20037508.342789244D;
double hT = 20037508.342789244D - (double) yPixel * fd;
ret[0] = ia / 6378137D;
ret[0] *= 57.295779513082323D;
ret[1] = 1.5707963267948966D - 2D * Math.atan(Math.exp(-hT / 6378137D));
ret[1] *= 57.295779513082323D;
return ret;
}

    /**
* 将地理坐标转换为块号和块内像素位置
*
* @param latitude      double
* @param longitude     double
* @param levelOfDetail int
* @return long[]
*/

public static long[] translateLongLatToTile(double longitude,
double latitude,
int levelOfDetail) {
long[] tuple = null;
tuple = translateLongLatToPixels(latitude, longitude, levelOfDetail);
return translatePixelsToTile(tuple[0], tuple[1]);
}

    /**
* @param args
*/

public static void main(String[] args) {
double x = 116.397, y = 39.917;
int zoom = 14;
//经纬度转像素坐标
        long[] result = MapProjectionUtil.translateLongLatToPixels(x, y, zoom);
System.out.println("像素:" + result[0] + "," + result[1]);
//27624630,12711262
        long xPixel = result[0];
long yPixel = result[1];
//像素坐标转块号
        result = MapProjectionUtil.translatePixelsToTile(xPixel, yPixel);
System.out.println("块号:" + result[0] + "," + result[1] + " 块内像素:" + result[2] + ","+ result[3]);
//431634,198613
        //215817,99306

//像素转经纬度
        double[] longLat = MapProjectionUtil.pixelsToLongLat(xPixel, yPixel, zoom);
System.out.println("经纬度:" + longLat[0] + "," + longLat[1]);

//        像素:3453079,1588908
//        块号:53954,24826 块内像素:23,44
//        经纬度:116.38014793395995,39.93211714223259
    }

}

 

Share
Filed under: iPhone No Comments
10Aug/110

FFMPEG Video/Audio Encoding Cheat Sheet

From: http://rodrigopolo.com/ffmpeg/cheats.html

Video Size and Aspect Ratios

iPhone:

Name Size Aspect
Wide 16:9 480x270 4:3
Old TV 4:3 427x320 16:9
Wide 16:9 /16 480x272 480:272
Old TV 4:3 /16 432x320 432:320

DV NTSC Video

Name Size Aspect
Wide 16:9 720x480 16:9
Old TV 4:3 720x480 4:3

Youtube and Vimeo Upload

Name Size Aspect
SD 4:3 640:480 4:3
HD 16:9 1280x720 16:9

HD, Blu-Ray, AVCHD

Name Size Aspect
720p 1280x720 16:9
1080p/i Anamorphic 1440x1080 16:9
1080p/i 1920x1080 16:9

Frame Rates

Name Standard Fps FFmpeg
Movies NTSC 23.976 24000/1001
Movies QuickTime N/A 29.976 10000000/417083
TV Video NTSC 29.97 30000/1001
Movies PAL 25 25
TV Video PAL 30 30

FFmpeg Encoding

X264 Presets

default fastfirstpass lossless_ultrafast lossless_slower
baseline slowfirstpass lossless_fast lossless_max
normal hq lossless_medium ipod320
main max lossless_slow ipod640

High quality 2 Pass

ffmpeg -y -i INPUT -r 30000/1001 -b 2M -bt 4M -vcodec libx264 -pass 1 -vpre fastfirstpass -an output.mp4
ffmpeg -y -i INPUT -r 30000/1001 -b 2M -bt 4M -vcodec libx264 -pass 2 -vpre hq -acodec libfaac -ac 2 -ar 48000 -ab 192k output.mp4

iPod-iPhone 320 width

ffmpeg -i INPUT -s 320x240 -r 30000/1001 -b 200k -bt 240k -vcodec libx264 -vpre ipod320 -acodec libfaac -ac 2 -ar 48000 -ab 192k output.mp4

iPod-iPhone 640 width

ffmpeg -i INPUT -s 640x480 -r 30000/1001 -b 200k -bt 240k -vcodec libx264 -vpre ipod640 -acodec libfaac -ac 2 -ar 48000 -ab 192k output.mp4

Hight quality, 2 pass without presset

ffmpeg -y -i input -r 24000/1001 -b 6144k -bt 8192k -vcodec libx264 -pass 1 -flags +loop -me_method dia -g 250 -qcomp 0.6 -qmin 10 -qmax 51 -qdiff 4 -bf 16 -b_strategy 1 -i_qfactor 0.71 -cmp +chroma -subq 1 -me_range 16 -coder 1 -sc_threshold 40 -flags2 -bpyramid-wpred-mixed_refs-dct8x8+fastpskip -keyint_min 25 -refs 1 -trellis 0 -directpred 1 -partitions -parti8x8-parti4x4-partp8x8-partp4x4-partb8x8-an output.mp4

ffmpeg -y -i input -r 24000/1001 -b 6144k -bt 8192k -vcodec libx264 -pass 2 -flags +loop -me_method umh -g 250 -qcomp 0.6 -qmin 10 -qmax 51 -qdiff 4 -bf 16 -b_strategy 1 -i_qfactor 0.71 -cmp +chroma -subq 8 -me_range 16 -coder 1 -sc_threshold 40 -flags2 +bpyramid+wpred+mixed_refs+dct8x8+fastpskip -keyint_min 25 -refs 4 -trellis 1 -directpred 3 -partitions +parti8x8+parti4x4+partp8x8+partb8x8-acodec libfaac -ac 2 -ar 44100 -ab 128k output.mp4

iPod-iPhone 320 width, without presset

ffmpeg -i INPUT -s 320x240 -r 30000/1001 -b 200k -bt 240k -vcodec libx264 -coder 0 -bf 0 -flags2 -wpred-dct8x8 -level 13 -maxrate 768k -bufsize 3M-acodec libfaac -ac 2 -ar 48000 -ab 192k output.mp4

iPod-iPhone 640 width, without presset

ffmpeg -i INPUT -s 320x240 -r 30000/1001 -b 200k -bt 240k -vcodec libx264 coder 0 -bf 0 -refs 1 -flags2 -wpred-dct8x8 -level 30 -maxrate 10M -bufsize 10M-acodec libfaac -ac 2 -ar 48000 -ab 192k output.mp4

iPod-iPhone, 2 pass custom

ffmpeg -y -i input -r 30000/1001 -s 480x272 -aspect 480:272 -vcodec libx264 -b 512k -bt 1024k -maxrate 4M -flags +loop -cmp +chroma -me_range 16 -g 300 -keyint_min 25 -sc_threshold 40 -i_qfactor 0.71 -rc_eq "blurCplx^(1-qComp)" -qcomp 0.6 -qmin 10 -qmax 51 -qdiff 4 -coder 0 -refs 1 -bufsize 4M -level 21 -partitions parti4x4+partp8x8+partb8x8 -subq 5 -f mp4 -pass 1 -an -title "Title" output.mp4

ffmpeg -y -i input -r 30000/1001 -s 480x272 -aspect 480:272 -vcodec libx264 -b 512k -bt 1024k -maxrate 4M -flags +loop -cmp +chroma -me_range 16 -g 300 keyint_min 25 -sc_threshold 40 -i_qfactor 0.71 -rc_eq "blurCplx^(1-qComp)" -qcomp 0.6 -qmin 10 -qmax 51 -qdiff 4 -coder 0 -refs 1 -bufsize 4M -level 21 -partitions parti4x4+partp8x8+partb8x8 -subq 5 -f mp4 -pass 2 -acodec libfaac -ac 2 -ar 44100 -ab 128k -title "Title" output.mp4

DV Video

To DV

ffmpeg -i input -target ntsc-dv -aspect 4:3 -y output.dv

From DV To Microsoft AVI DV

ffmpeg -i input.dv -vcodec copy -vtag dvsd -acodec pcm_s16le -f avi -aspect 4:3 -y output.avi

Audio

AAC Stereo HQ

-acodec libfaac -ac 2 -ar 48000 -ab 192k

AAC Stereo SQ

-acodec libfaac -ac 2 -ar 44100 -ab 128k

AAC 5.1 HQ

-acodec libfaac -ac 6 -ar 48000 -ab 448k

AAC 5.1 LQ

-acodec libfaac -ac 6 -ar 44100 -ab 224k

AAC to AC3 (Recomended use AviSynth for channel mapping)

ffmpeg -i intput.aac -vn -acodec ac3 -ac 6 -ar 48000 -ab 448k

AC3 to M4V (Mux to be opened and edited in other appz)

ffmpeg -i input.ac3 -vn -acodec copy output.m4v

AC3 to AAC (not working as expected)

ffmpeg -i input.ac3 -vn -r 30000/1001 -acodec libfaac -ac 6 -ar 48000 -ab 448k output.aac

Eac3To

AC3 5.1 Channel Mapping Fix

eac3to true_hd.ac3 fixed_true_hd.ac3 -blu-ray -448

AAC to AC3

  1. Open AAC on Audacity or SoundBooth
  2. Export to Wav
  3. Remux from Wav to Wav with FFmpeg:ffmpeg -i audio.wav â€"vn -acodec copy audio-out.wav
  4. Convert to AC3 with EAC3toeac3to.exe audio.wav Main.ac3 -448

Other FFmpeg Options

-threads thread count
-y overwrite output files
-ss time_off set the start time offset
-t duration record or transcode "duration" seconds of audio/video
-ildct Interlaced
Share