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