• Main Page
  • Related Pages
  • Modules
  • Data Structures
  • Files
  • File List
  • Globals

tests/seek_test.c

Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2003 Fabrice Bellard
00003  * Copyright (c) 2007 Michael Niedermayer
00004  *
00005  * This file is part of FFmpeg.
00006  *
00007  * FFmpeg is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU Lesser General Public
00009  * License as published by the Free Software Foundation; either
00010  * version 2.1 of the License, or (at your option) any later version.
00011  *
00012  * FFmpeg is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015  * Lesser General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU Lesser General Public
00018  * License along with FFmpeg; if not, write to the Free Software
00019  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
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= &params;
00037     memset(ap, 0, sizeof(params));
00038     ap->channels=1;
00039     ap->sample_rate= 22050;
00040 
00041     /* initialize libavcodec, and register all codecs and formats */
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     /* allocate the media context */
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 }

Generated on Sat Feb 16 2013 09:23:15 for ffmpeg by  doxygen 1.7.1