1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
|
/*
* probe_ffmpeg.c -- libavcodec/libavformat based probing code
* (C) 2006-2010 Francesco Romani <fromani -at- gmail -dot- com>
*
* This file is part of transcode, a video stream processing tool.
*
* transcode is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* transcode is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "transcode.h"
#include "tcinfo.h"
#include "ioaux.h"
#include "tc.h"
#include "libtc/libtc.h"
#include "libtc/ratiocodes.h"
#ifdef HAVE_FFMPEG
#include "libtc/tcavcodec.h"
static void translate_info(const AVFormatContext *ctx, ProbeInfo *info)
{
AVStream *st = NULL;
int i = 0, j = 0;
if (ctx == NULL || info == NULL) {
return;
}
/* first of all, video */
for (i = 0; i < ctx->nb_streams; i++) {
st = ctx->streams[i];
if (st->codec->codec_type == AVMEDIA_TYPE_VIDEO) {
info->bitrate = st->codec->bit_rate / 1000;
info->width = st->codec->width;
info->height = st->codec->height;
if (st->r_frame_rate.num > 0 && st->r_frame_rate.den > 0) {
info->fps = av_q2d(st->r_frame_rate);
} else {
/* watch out here */
info->fps = 1.0/av_q2d(st->codec->time_base);
}
tc_frc_code_from_value(&info->frc, info->fps);
break;
}
}
/* then audio track(s) */
for (i = 0; i < ctx->nb_streams; i++) {
st = ctx->streams[i];
if (st->codec->codec_type == AVMEDIA_TYPE_AUDIO
&& j < TC_MAX_AUD_TRACKS) {
info->track[j].format = 0x1; /* known wrong */
info->track[j].chan = st->codec->channels;
info->track[j].samplerate = st->codec->sample_rate;
info->track[j].bitrate = st->codec->bit_rate / 1000;
/* XXX: known wrong for PCM */
info->track[j].bits = BITS;
/*
* XXX where libavcodec/libaformat provide this?
* Should be inferred by CODEC_ID used?
* */
info->track[j].pts_start = 0; /* XXX: ?!? */
j++;
}
}
info->num_tracks = j;
}
void probe_ffmpeg(info_t *ipipe)
{
/* to be completed */
AVFormatContext *lavf_dmx_context = NULL;
int ret = 0;
close(ipipe->fd_in);
TC_INIT_LIBAVCODEC;
ret = av_open_input_file(&lavf_dmx_context, ipipe->name,
NULL, 0, NULL);
if (ret != 0) {
tc_log_error(__FILE__, "unable to open '%s'"
" (libavformat failure)",
ipipe->name);
ipipe->error = 1;
return;
}
ret = av_find_stream_info(lavf_dmx_context);
if (ret < 0) {
tc_log_error(__FILE__, "unable to fetch informations from '%s'"
" (libavformat failure)",
ipipe->name);
ipipe->error = 1;
return;
}
translate_info(lavf_dmx_context, ipipe->probe_info);
av_close_input_file(lavf_dmx_context);
return;
}
#else // HAVE_FFMPEG
void probe_ffmpeg(info_t *ipipe)
{
tc_log_error(__FILE__, "no support for FFmpeg compiled - exit.");
ipipe->error = 1;
return;
}
#endif // HAVE_FFMPEG
/*************************************************************************/
/*
* Local variables:
* c-file-style: "stroustrup"
* c-file-offsets: ((case-label . *) (statement-case-intro . *))
* indent-tabs-mode: nil
* End:
*
* vim: expandtab shiftwidth=4:
*/
|