upgrade libvpx+lv2, fix dbl tap play bug, add multi nest/unnest clips, add del top...
[goodguy/cinelerra.git] / cinelerra-5.1 / libzmpeg3 / mpeg31trkpony.C
1 #include <stdio.h>
2 #include "libzmpeg3.h"
3
4 /* reads a toc file which must refer to a transport stream
5  *  decodes the dvb data and attempts to identify the stream
6  *  nudge values to resync the related audio/video data
7  */
8
9 int main(int ac, char **av)
10 {
11   int ret, i, n, atrk, vtrk, w, h, channels, apid, vpid;
12   char name[256], enc[32];
13   const char *fmt;
14   double pts, apts, vpts, nudge;
15   zmpeg3_t *src = new zmpeg3_t(av[1],ret,ZIO_UNBUFFERED+ZIO_SINGLE_ACCESS);
16   if( !src || ret != 0 ) {
17     fprintf(stderr,"unable to open %s\n",av[1]);
18     exit(1);
19   }
20   if( !src->has_toc() ) {
21     fprintf(stderr,"not a toc file %s\n",av[1]);
22     exit(1);
23   }
24   char *path = src->title_path(0);
25   int total_atracks = src->total_astreams();
26   int total_vtracks = src->total_vstreams();
27   printf("toc file for %s, %d atracks, %d vtracks\n", path, total_atracks, total_vtracks);
28   if( !src->is_transport_stream() ) {
29     fprintf(stderr,"not a transport stream %s\n",path);
30     exit(1);
31   }
32   src->demuxer->create_title();
33
34   int total_channels = src->dvb.channel_count();
35   for( n=0; n<total_channels; ++n ) {
36     int major, minor, astreams, vstreams;
37     double frame_rate = 0.;
38     int sample_rate = 0;
39     src->dvb.get_channel(n, major, minor);
40     src->dvb.get_station_id(n, name);
41     src->dvb.total_astreams(n, astreams);
42     src->dvb.total_vstreams(n, vstreams);
43     printf("channel %d.%d,  %d video streams, %d audio streams\n",
44       major, minor, vstreams, astreams);
45     apts = vpts = -1.;
46     for( i=0; i<vstreams; ++i ) {
47       src->dvb.vstream_number(n, i, vtrk);
48       w = src->video_width(vtrk);
49       h = src->video_height(vtrk);
50       frame_rate = src->frame_rate(vtrk);
51       src->vtrack[vtrk]->video->rewind_video();
52       vpid = src->vtrack[vtrk]->pid;
53       pts = src->vtrack[vtrk]->demuxer->scan_pts();
54       printf(" vtrk %-2d/%03x stream %2d  %5dx%-5d %f   pts %f\n", 
55         i, vpid, vtrk, w, h, frame_rate, pts);
56       if( pts > vpts ) vpts = pts;
57     }
58     for( i=0; i<astreams; ++i ) {
59       src->dvb.astream_number(n, i, atrk, &enc[0]);
60       channels = src->audio_channels(atrk);
61       fmt = src->audio_format(atrk);
62       sample_rate = src->sample_rate(atrk);
63       src->atrack[atrk]->audio->rewind_audio();
64       apid = src->atrack[atrk]->pid;
65       pts = src->atrack[atrk]->demuxer->scan_pts();
66       printf(" atrk %-2d/%03x stream %2d %6s %2dch %-5d (%s)  pts %f\n", 
67         i, apid, atrk, fmt, channels, sample_rate, &enc[0], pts);
68       if( pts > apts ) apts = pts;
69     }
70     if( astreams > 0 ) {
71       if( apts >= 0. && vpts >= 0. ) {
72         nudge = vpts - apts;
73         printf("   nudge %f (%f frames, %d samples)",
74           -nudge, nudge*frame_rate, (int)(-nudge*sample_rate));
75       }
76       printf("\n");
77     }
78   }
79   delete src;
80   return 0;
81 }
82