00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include <stdlib.h>
00022 #include <stdio.h>
00023
00024 #include "avformat.h"
00025
00026 #undef exit
00027
00028 int main(int argc, char **argv)
00029 {
00030 const char *filename;
00031 AVFormatContext *ic;
00032 int i, ret, stream_id;
00033 int64_t timestamp;
00034 AVFormatParameters params, *ap= ¶ms;
00035 memset(ap, 0, sizeof(params));
00036 ap->channels=1;
00037 ap->sample_rate= 22050;
00038
00039
00040 av_register_all();
00041
00042 if (argc != 2) {
00043 printf("usage: %s input_file\n"
00044 "\n", argv[0]);
00045 exit(1);
00046 }
00047
00048 filename = argv[1];
00049
00050
00051 ic = av_alloc_format_context();
00052 if (!ic) {
00053 fprintf(stderr, "Memory error\n");
00054 exit(1);
00055 }
00056
00057 ret = av_open_input_file(&ic, filename, NULL, 0, ap);
00058 if (ret < 0) {
00059 fprintf(stderr, "cannot open %s\n", filename);
00060 exit(1);
00061 }
00062
00063 ret = av_find_stream_info(ic);
00064 if (ret < 0) {
00065 fprintf(stderr, "%s: could not find codec parameters\n", filename);
00066 exit(1);
00067 }
00068
00069 for(i=0; ; i++){
00070 AVPacket pkt;
00071 AVStream *st;
00072
00073 memset(&pkt, 0, sizeof(pkt));
00074 if(ret>=0){
00075 ret= av_read_frame(ic, &pkt);
00076 printf("ret:%2d", ret);
00077 if(ret>=0){
00078 st= ic->streams[pkt.stream_index];
00079 printf(" st:%2d dts:%f pts:%f pos:%" PRId64 " size:%d flags:%d", pkt.stream_index, pkt.dts*av_q2d(st->time_base), pkt.pts*av_q2d(st->time_base), pkt.pos, pkt.size, pkt.flags);
00080 }
00081 printf("\n");
00082 }
00083
00084 if(i>25) break;
00085
00086 stream_id= (i>>1)%(ic->nb_streams+1) - 1;
00087 timestamp= (i*19362894167LL) % (4*AV_TIME_BASE) - AV_TIME_BASE;
00088 if(stream_id>=0){
00089 st= ic->streams[stream_id];
00090 timestamp= av_rescale_q(timestamp, AV_TIME_BASE_Q, st->time_base);
00091 }
00092 ret = av_seek_frame(ic, stream_id, timestamp, (i&1)*AVSEEK_FLAG_BACKWARD);
00093 printf("ret:%2d st:%2d ts:%f flags:%d\n", ret, stream_id, timestamp*(stream_id<0 ? 1.0/AV_TIME_BASE : av_q2d(st->time_base)), i&1);
00094 }
00095
00096 return 0;
00097 }