Skip to content

Instantly share code, notes, and snippets.

@mshr-h
Created July 3, 2015 16:23
Show Gist options
  • Save mshr-h/f7029ba9130fc2f64308 to your computer and use it in GitHub Desktop.
Save mshr-h/f7029ba9130fc2f64308 to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char *argv[])
{
int h,w;
int width;
int height;
int total;
size_t frame_size;
long filesize;
FILE *fp_in;
FILE *fp_out;
unsigned char y,u,v;
unsigned char *frame_buf;
if(argc < 5)
{
printf("Usage\n");
printf(" %s movie.yuv movie_out.yuv 1920 1080\n", argv[0]);
exit(1);
}
width=atoi(argv[3]);
height=atoi(argv[4]);
total=width*height;
frame_size=total+total/4+total/4;
frame_buf=(unsigned char *)malloc(sizeof(unsigned char)*frame_size);
printf("video size: %d x %d\n", width, height);
if(NULL==(fp_in = fopen(argv[1], "rb")))
{
fprintf(stderr, "cant open %s\n", argv[1]);
exit(1);
}
if(NULL==(fp_out = fopen(argv[2], "wb")))
{
fprintf(stderr, "cant open %s\n", argv[2]);
exit(1);
}
fseek(fp_in, 0, 2);
filesize = ftell(fp_in);
fseek(fp_in, 0, 0);
while(frame_size==fread(frame_buf, 1, frame_size, fp_in))
{
for(w=0;w<width;w++)
{
for(h=0;h<height;h++)
{
y=frame_buf[h*width+w];
u=frame_buf[(h/2)*(width/2)+(w/2)+total];
v=frame_buf[(h/2)*(width/2)+(w/2)+total+(total/4)];
}
}
printf("%ld/%ld(%5.1f%%)\n", ftell(fp_in)/frame_size, filesize/frame_size, (double)ftell(fp_in)/filesize*100);
fwrite(frame_buf, 1, frame_size, fp_out);
}
free(frame_buf);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment