1 /*
2  *  probe_mov.c
3  *
4  *  Copyright (C) Thomas Oestreich - Januray 2002
5  *
6  *  This file is part of transcode, a video stream processing tool
7  *
8  *  transcode is free software; you can redistribute it and/or modify
9  *  it under the terms of the GNU General Public License as published by
10  *  the Free Software Foundation; either version 2, or (at your option)
11  *  any later version.
12  *
13  *  transcode is distributed in the hope that it will be useful,
14  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  *  GNU General Public License for more details.
17  *
18  *  You should have received a copy of the GNU General Public License
19  *  along with GNU Make; see the file COPYING.  If not, write to
20  *  the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
21  *
22  */
23 
24 #include "transcode.h"
25 #include "tcinfo.h"
26 #include "ioaux.h"
27 #include "tc.h"
28 #include "libtc/libtc.h"
29 #include "libtc/ratiocodes.h"
30 
31 #ifdef HAVE_LIBQUICKTIME
32 
33 extern int binary_dump;
34 
35 #include <quicktime.h>
36 
probe_mov(info_t * ipipe)37 void probe_mov(info_t *ipipe)
38 {
39 
40   quicktime_t *qt_file=NULL;
41   char *codec=NULL;
42 
43   int j, tracks;
44 
45   /* open movie for video probe */
46   if(qt_file==NULL)
47     if(NULL == (qt_file = quicktime_open((char *)ipipe->name,1,0))){
48       tc_log_error(__FILE__,"can't open quicktime!");
49       ipipe->error=1;
50       return;
51     }
52 
53   // extract audio parameters
54   tracks=quicktime_audio_tracks(qt_file);
55 
56   if(tracks>TC_MAX_AUD_TRACKS) {
57     tc_log_warn(__FILE__, "only %d of %d audio tracks scanned",
58                 TC_MAX_AUD_TRACKS, tracks);
59     tracks=TC_MAX_AUD_TRACKS;
60   }
61 
62   for(j=0; j<tracks; ++j) {
63 
64     ipipe->probe_info->track[j].samplerate = quicktime_sample_rate(qt_file, j);
65     ipipe->probe_info->track[j].chan = quicktime_track_channels(qt_file, j);
66     ipipe->probe_info->track[j].bits = quicktime_audio_bits(qt_file, j);
67 
68     codec  = quicktime_audio_compressor(qt_file, j);
69 
70     if(strcasecmp(codec,QUICKTIME_RAW)==0 || strcasecmp(codec,QUICKTIME_TWOS)==0)
71       ipipe->probe_info->track[j].format = CODEC_PCM;
72     else if(strcasecmp(codec,QUICKTIME_IMA4)==0)
73       ipipe->probe_info->track[j].format = CODEC_IMA4;
74     else
75       /* XXX not right but works */
76       ipipe->probe_info->track[j].format = CODEC_PCM;
77 
78     if (! binary_dump)
79     	tc_log_info(__FILE__, "audio codec=%s", codec);
80 
81     if(ipipe->probe_info->track[j].chan>0) ++ipipe->probe_info->num_tracks;
82   }
83 
84 
85   // read all video parameter from input file
86   ipipe->probe_info->width  =  quicktime_video_width(qt_file, 0);
87   ipipe->probe_info->height =  quicktime_video_height(qt_file, 0);
88   ipipe->probe_info->fps = quicktime_frame_rate(qt_file, 0);
89 
90   ipipe->probe_info->frames = quicktime_video_length(qt_file, 0);
91 
92   codec  =  quicktime_video_compressor(qt_file, 0);
93 
94   //check for supported codecs
95 
96   if(codec!=NULL) {
97 
98     if(strlen(codec)==0) {
99       ipipe->probe_info->codec=TC_CODEC_RGB;
100     } else {
101 
102       if(strcasecmp(codec,QUICKTIME_DV)==0)
103 	ipipe->probe_info->codec=TC_CODEC_DV;
104 
105       if(strcasecmp(codec,"dvsd")==0)
106 	ipipe->probe_info->codec=TC_CODEC_DV;
107 
108       if(strcasecmp(codec,"DIV3")==0)
109 	ipipe->probe_info->codec=TC_CODEC_DIVX3;
110 
111       if(strcasecmp(codec,"DIVX")==0)
112 	ipipe->probe_info->codec=TC_CODEC_DIVX4;
113 
114       if(strcasecmp(codec,"DX50")==0)
115 	ipipe->probe_info->codec=TC_CODEC_DIVX5;
116 
117       if(strcasecmp(codec,"MJPG")==0 || strcasecmp(codec,"JPEG")==0)
118 	ipipe->probe_info->codec=TC_CODEC_MJPEG;
119 
120       if(strcasecmp(codec,"YUV2")==0)
121 	ipipe->probe_info->codec=TC_CODEC_YUV2;
122 
123       if(strcasecmp(codec,"SVQ1")==0)
124 	ipipe->probe_info->codec=TC_CODEC_SVQ1;
125 
126       if(strcasecmp(codec,"SVQ3")==0)
127 	ipipe->probe_info->codec=TC_CODEC_SVQ3;
128     }
129   } else
130     ipipe->probe_info->codec=TC_CODEC_UNKNOWN;
131 
132   if (! binary_dump)
133   	tc_log_info(__FILE__, "video codec=%s", codec);
134   ipipe->probe_info->magic=TC_MAGIC_MOV;
135   tc_frc_code_from_value(&(ipipe->probe_info->frc),
136                          ipipe->probe_info->fps);
137 
138   return;
139 }
140 
141 #else   // HAVE_LIBQUICKTIME
142 
probe_mov(info_t * ipipe)143 void probe_mov(info_t *ipipe)
144 {
145 	tc_log_error(__FILE__, "no support for Quicktime compiled - exit.");
146 	ipipe->error=1;
147 	return;
148 }
149 
150 #endif
151 
152