[xiph-cvs] cvs commit: theora/examples dump_video.c
Timothy Terriberry
tterribe at xiph.org
Sat Nov 15 09:27:13 PST 2003
tterribe 03/11/15 12:27:13
Modified: examples dump_video.c
Log:
Added a -o command-line option.
Changed the output format to not interleave the U and V planes, so that it can be decoded with mplayer using the yv12 pixel format.
Fixed video_write() so that it is only called when a frame has been decoded, not every time a page is processed.
Revision Changes Path
1.7 +39 -14 theora/examples/dump_video.c
Index: dump_video.c
===================================================================
RCS file: /usr/local/cvsroot/theora/examples/dump_video.c,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- dump_video.c 26 Oct 2003 21:49:59 -0000 1.6
+++ dump_video.c 15 Nov 2003 17:27:12 -0000 1.7
@@ -11,7 +11,7 @@
********************************************************************
function: example dumpvid application; dumps Theora streams
- last mod: $Id: dump_video.c,v 1.6 2003/10/26 21:49:59 giles Exp $
+ last mod: $Id: dump_video.c,v 1.7 2003/11/15 17:27:12 tterribe Exp $
********************************************************************/
@@ -30,13 +30,21 @@
/*#include <sys/time.h>*/
#include <sys/types.h>
#include <sys/stat.h>
+#include <io.h>
#include <fcntl.h>
#include <math.h>
#include <signal.h>
+#include "getopt.h"
#include "theora/theora.h"
+const char *optstring = "o:";
+struct option options [] = {
+ {"output",required_argument,NULL,'o'},
+ {NULL,0,NULL,0}
+};
+
/* Helper; just grab some more compressed bitstream and sync it for
page extraction */
int buffer_data(FILE *in,ogg_sync_state *oy){
@@ -83,10 +91,10 @@
for(i=0;i<yuv.y_height;i++)
fwrite(yuv.y+yuv.y_stride*i, 1, yuv.y_width, outfile);
- for(i=0;i<yuv.uv_height;i++){
+ for(i=0;i<yuv.uv_height;i++)
fwrite(yuv.v+yuv.uv_stride*i, 1, yuv.uv_width, outfile);
- fwrite(yuv.u+yuv.uv_stride*i, 1, yuv.uv_width, outfile);
- }
+ for(i=0;i<yuv.uv_height;i++)
+ fwrite(yuv.u+yuv.uv_stride*i, 1, yuv.uv_width, outfile);
}
/* dump the theora (or vorbis) comment header */
@@ -130,12 +138,15 @@
int main(int argc,char *argv[]){
- int i,j;
ogg_packet op;
+ int long_option_index;
+ int c;
+
FILE *infile = stdin;
outfile = stdout;
+
#ifdef _WIN32 /* We need to set stdin/stdout to binary mode. Damn windows. */
/* Beware the evil ifdef. We avoid these where we can, but this one we
cannot. Don't add any more, you'll probably go to hell if you do. */
@@ -143,17 +154,31 @@
_setmode( _fileno( stdout ), _O_BINARY );
#endif
- /* open the input file if any */
- if(argc==2){
- infile=fopen(argv[1],"rb");
+ /* Process option arguments. */
+ while((c=getopt_long(argc,argv,optstring,options,&long_option_index))!=EOF){
+ switch(c){
+ case 'o':
+ outfile=fopen(optarg,"wb");
+ if(outfile==NULL){
+ fprintf(stderr,"Unable to open output file '%s'\n", optarg);
+ exit(1);
+ }
+ break;
+
+ default:
+ usage();
+ }
+ }
+ if(optind<argc){
+ infile=fopen(argv[optind],"rb");
if(infile==NULL){
- fprintf(stderr,"Unable to open '%s' for extraction.\n", argv[1]);
+ fprintf(stderr,"Unable to open '%s' for extraction.\n", argv[optind]);
exit(1);
}
- }
- if(argc>2){
+ if(++optind<argc){
usage();
exit(1);
+ }
}
/* start up Ogg stream synchronization layer */
@@ -278,10 +303,10 @@
queue_page(&og);
}
}
-
/* dumpvideo frame, and get new one */
- video_write();
- videobuf_ready=0;
+ else video_write();
+
+ videobuf_ready=0;
}
/* close everything */
<p><p>--- >8 ----
List archives: http://www.xiph.org/archives/
Ogg project homepage: http://www.xiph.org/ogg/
To unsubscribe from this list, send a message to 'cvs-request at xiph.org'
containing only the word 'unsubscribe' in the body. No subject is needed.
Unsubscribe messages sent to the list will be ignored/filtered.
More information about the commits
mailing list