1 /*
2 * NUT (de)muxing via libnut
3 * copyright (c) 2006 Oded Shimon <ods15@ods15.dyndns.org>
4 *
5 * This file is part of FFmpeg.
6 *
7 * FFmpeg is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
12 * FFmpeg is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with FFmpeg; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 */
21
22 /**
23 * @file
24 * NUT demuxing and muxing via libnut.
25 * @author Oded Shimon <ods15@ods15.dyndns.org>
26 */
27
31 #include <libnut.h>
32
33 #define ID_STRING "nut/multimedia container"
34 #define ID_LENGTH (strlen(ID_STRING) + 1)
35
38 nut_stream_header_tt *
s;
40
45 { 0, 0 },
46 };
47
48 #if CONFIG_LIBNUT_MUXER
52 //avio_flush(bc);
54 }
55
59 nut_muxer_opts_tt mopts = {
60 .output = {
61 .priv = bc,
62 .write = av_write,
63 },
65 .write_index = 1,
66 .realtime_stream = 0,
67 .max_distance = 32768,
69 };
70 nut_stream_header_tt *
s;
71 int i;
72
74 if(!s)
76
79 int j;
81 int num, denom, ssize;
82
84
87
88 if (!fourcc) {
91 }
92
93 s[i].fourcc_len = 4;
95 for (j = 0; j < s[i].fourcc_len; j++) s[i].fourcc[j] = (fourcc >> (j*8)) & 0xFF;
96
99
100 s[i].time_base.num = denom;
101 s[i].time_base.den = num;
102
103 s[i].fixed_fps = 0;
107
109 s[i].width = par->
width;
110 s[i].height = par->
height;
111 s[i].sample_width = 0;
112 s[i].sample_height = 0;
113 s[i].colorspace_type = 0;
114 } else {
116 s[i].samplerate_denom = 1;
118 }
119 }
120
122 priv->
nut = nut_muxer_init(&mopts, s,
NULL);
123
124 return 0;
125 }
126
129 nut_packet_tt p;
130
135 p.next_pts = 0;
136
137 nut_write_frame_reorder(priv->
nut, &p, pkt->
data);
138
139 return 0;
140 }
141
145 int i;
146
147 nut_muxer_uninit_reorder(priv->
nut);
149
150 for(i = 0; priv->
s[i].type != -1; i++ )
av_freep(&priv->
s[i].fourcc);
152
153 return 0;
154 }
155
158 .long_name = "nut format",
159 .mime_type = "video/x-nut",
160 .extensions = "nut",
168 };
169 #endif /* CONFIG_LIBNUT_MUXER */
170
173
174 return 0;
175 }
176
180 }
181
182 static off_t
av_seek(
void *
h, int64_t pos,
int whence) {
184 if (whence == SEEK_END) {
186 whence = SEEK_SET;
187 }
189 }
190
194 nut_demuxer_opts_tt dopts = {
195 .input = {
196 .priv = bc,
200 .file_pos = 0,
201 },
203 .read_index = 1,
204 .cache_syncpoints = 1,
205 };
206 nut_context_tt * nut = priv->
nut = nut_demuxer_init(&dopts);
207 nut_stream_header_tt *
s;
208 int ret, i;
209
210 if(!nut)
211 return -1;
212
213 if ((ret = nut_read_headers(nut, &s,
NULL))) {
215 nut_demuxer_uninit(nut);
217 return -1;
218 }
219
221
222 for (i = 0; s[i].type != -1 && i < 2; i++) {
224 int j;
225
226 if (!st)
228
229 for (j = 0; j < s[i].fourcc_len && j < 8; j++) st->
codecpar->
codec_tag |= s[i].fourcc[j]<<(j*8);
230
232
236 nut_demuxer_uninit(nut);
239 }
241 }
242
246
248
250 case NUT_AUDIO_CLASS:
253
256 break;
257 case NUT_VIDEO_CLASS:
260
265 break;
266 }
268 }
269
270 return 0;
271 }
272
275 nut_packet_tt pd;
276 int ret;
277
278 ret = nut_read_next_packet(priv->
nut, &pd);
279
281 if (ret != NUT_ERR_EOF)
283 return -1;
284 }
285
290
291 ret = nut_read_frame(priv->
nut, &pd.len, pkt->
data);
292
293 return ret;
294 }
295
298 int active_streams[] = { stream_index, -1 };
299 double time_pos = target_ts * priv->
s[stream_index].time_base.num / (double)priv->
s[stream_index].time_base.den;
300
302
303 return 0;
304 }
305
308
309 nut_demuxer_uninit(priv->
nut);
310
311 return 0;
312 }
313
323 .extensions = "nut",
324 };
static void write_packet(OutputFile *of, AVPacket *pkt, OutputStream *ost, int unqueue)
int64_t avio_size(AVIOContext *s)
Get the filesize.
void * av_realloc(void *ptr, size_t size)
Allocate, reallocate, or free a block of memory.
int64_t pos
byte position in stream, -1 if unknown
static int read_seek(AVFormatContext *ctx, int stream_index, int64_t timestamp, int flags)
enum AVCodecID codec_id
Specific type of the encoded data (the codec used).
AVRational sample_aspect_ratio
sample aspect ratio (0 if unknown)
int64_t avio_seek(AVIOContext *s, int64_t offset, int whence)
fseek() equivalent for AVIOContext.
int64_t(* seek)(void *opaque, int64_t offset, int whence)
This struct describes the properties of an encoded stream.
static int nut_read_header(AVFormatContext *avf)
AVStream * avformat_new_stream(AVFormatContext *s, const AVCodec *c)
Add a new stream to a media file.
AVStream ** streams
A list of all streams in the file.
static int nut_write_packet(AVFormatContext *s, AVPacket *pkt)
static av_cold int read_close(AVFormatContext *ctx)
static av_always_inline int64_t avio_tell(AVIOContext *s)
ftell() equivalent for AVIOContext.
void avio_write(AVIOContext *s, const unsigned char *buf, int size)
int avio_read(AVIOContext *s, unsigned char *buf, int size)
Read size bytes from AVIOContext into buf.
#define AV_PKT_FLAG_KEY
The packet contains a keyframe.
static int nut_read_seek(AVFormatContext *avf, int stream_index, int64_t target_ts, int flags)
int av_new_packet(AVPacket *pkt, int size)
Allocate the payload of a packet and initialize its fields with default values.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
void ff_parse_specific_params(AVStream *st, int *au_rate, int *au_ssize, int *au_scale)
static int nut_write_header(AVFormatContext *s)
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
int video_delay
Video only.
preferred ID for decoding MPEG audio layer 1, 2 or 3
enum AVMediaType codec_type
General type of the encoded data.
const AVCodecTag ff_codec_wav_tags[]
static void * av_mallocz_array(size_t nmemb, size_t size)
int flags
A combination of AV_PKT_FLAG values.
static const AVCodecTag nut_tags[]
int extradata_size
Size of the extradata content in bytes.
unsigned char * buf
Buffer must have AVPROBE_PADDING_SIZE of extra allocated bytes filled with zero.
unsigned int nb_streams
Number of elements in AVFormatContext.streams.
int void avio_flush(AVIOContext *s)
Force flushing of buffered data.
const AVCodecTag ff_codec_bmp_tags[]
static int write_trailer(AVFormatContext *s1)
internal header for RIFF based (de)muxers do NOT include this in end user applications ...
static int read_header(FFV1Context *f)
static int read_packet(void *opaque, uint8_t *buf, int buf_size)
AVIOContext * pb
I/O context.
static off_t av_seek(void *h, int64_t pos, int whence)
static size_t av_read(void *h, size_t len, uint8_t *buf)
static int nut_write_trailer(AVFormatContext *s)
This structure contains the data a format has to probe a file.
static int nut_probe(AVProbeData *p)
static int nut_read_close(AVFormatContext *s)
int64_t duration
Decoding: duration of the stream, in stream time base.
int sample_rate
Audio only.
int64_t start_time
Decoding: pts of the first frame of the stream in presentation order, in stream time base...
AVInputFormat ff_libnut_demuxer
void * priv_data
Format private data.
static void write_header(FFV1Context *f)
uint8_t * extradata
Extra binary data needed for initializing the decoder, codec-dependent.
AVCodecParameters * codecpar
uint32_t codec_tag
Additional information about the codec (corresponds to the AVI FOURCC).
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented...
#define MKTAG(a, b, c, d)
This structure stores compressed data.
static int nut_read_packet(AVFormatContext *avf, AVPacket *pkt)
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...