ffplay 命令
ffplay -video_size 640x480 -pix_fmt nv12 -i nv12.yuv
ffplay -video_size 640x480 -pix_fmt yuv420p -i i420.yuv
将yuv 数据写入文件
//Objective-c 写法
void writeNV12(void *src_y, int src_stride_y,
void *src_uv, int src_stride_uv,
int width, int height)
{
NSMutableData *dat = [[NSMutableData alloc] init];
[dat appendData:[NSData dataWithBytes:src_y length:src_stride_y*height]];
[dat appendData:[NSData dataWithBytes:src_uv length:src_stride_uv*height/2]];
NSString *path = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES).firstObject;
path = [path stringByAppendingPathComponent:@"nv12.yuv"];
NSLog(@"file path = %@ ============",path);
if (![[NSFileManager defaultManager] fileExistsAtPath:path]) {
[[NSFileManager defaultManager] createFileAtPath:path contents:nil attributes:nil];
}
NSFileHandle *fileHandle = [NSFileHandle fileHandleForWritingAtPath:path];
[fileHandle seekToEndOfFile];
[fileHandle writeData:dat];
[fileHandle closeFile];
}
//C 语言写法
void writeI420(void *src_y, int src_stride_y,
void *src_u, int src_stride_u,
void *src_v, int src_stride_v,
int width, int height)
{
static FILE* m_pOutFile = nullptr;
if (!m_pOutFile) {
std::string home{std::getenv("HOME")};
std::string path = home + "/i420.yuv";
m_pOutFile = fopen(path.c_str(), "a+");
printf("======== nv12_before_scale = %s\n",path.c_str());
}
//write y
fwrite(src_y, 1, height * src_stride_y, m_pOutFile);
//write u
fwrite(src_u, 1, height / 2 * src_stride_u, m_pOutFile);
//write v
fwrite(src_v, 1, height / 2 * src_stride_v, m_pOutFile);
}
网友评论