annotate src/impl/hoofbaby/codec/decoder.d @ 7:9fdfe4a64a13

Added the beginnings of a decoder... Soon I'll have a crappier version of ffmpeg written in D!
author fraserofthenight
date Sun, 12 Jul 2009 03:04:27 -0700
parents
children 71ebad05f542
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
7
9fdfe4a64a13 Added the beginnings of a decoder... Soon I'll have a crappier version of ffmpeg written in D!
fraserofthenight
parents:
diff changeset
1 /**
9fdfe4a64a13 Added the beginnings of a decoder... Soon I'll have a crappier version of ffmpeg written in D!
fraserofthenight
parents:
diff changeset
2 * Hoofbaby -- http://www.dsource.org/projects/hoofbaby
9fdfe4a64a13 Added the beginnings of a decoder... Soon I'll have a crappier version of ffmpeg written in D!
fraserofthenight
parents:
diff changeset
3 * Copyright (C) 2009 Robert Fraser
9fdfe4a64a13 Added the beginnings of a decoder... Soon I'll have a crappier version of ffmpeg written in D!
fraserofthenight
parents:
diff changeset
4 *
9fdfe4a64a13 Added the beginnings of a decoder... Soon I'll have a crappier version of ffmpeg written in D!
fraserofthenight
parents:
diff changeset
5 * This program is free software; you can redistribute it andor
9fdfe4a64a13 Added the beginnings of a decoder... Soon I'll have a crappier version of ffmpeg written in D!
fraserofthenight
parents:
diff changeset
6 * modify it under the terms of the GNU General Public License
9fdfe4a64a13 Added the beginnings of a decoder... Soon I'll have a crappier version of ffmpeg written in D!
fraserofthenight
parents:
diff changeset
7 * as published by the Free Software Foundation; either version 2
9fdfe4a64a13 Added the beginnings of a decoder... Soon I'll have a crappier version of ffmpeg written in D!
fraserofthenight
parents:
diff changeset
8 * of the License, or (at your option) any later version.
9fdfe4a64a13 Added the beginnings of a decoder... Soon I'll have a crappier version of ffmpeg written in D!
fraserofthenight
parents:
diff changeset
9 *
9fdfe4a64a13 Added the beginnings of a decoder... Soon I'll have a crappier version of ffmpeg written in D!
fraserofthenight
parents:
diff changeset
10 * This program is distributed in the hope that it will be useful,
9fdfe4a64a13 Added the beginnings of a decoder... Soon I'll have a crappier version of ffmpeg written in D!
fraserofthenight
parents:
diff changeset
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9fdfe4a64a13 Added the beginnings of a decoder... Soon I'll have a crappier version of ffmpeg written in D!
fraserofthenight
parents:
diff changeset
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9fdfe4a64a13 Added the beginnings of a decoder... Soon I'll have a crappier version of ffmpeg written in D!
fraserofthenight
parents:
diff changeset
13 * GNU General Public License for more details.
9fdfe4a64a13 Added the beginnings of a decoder... Soon I'll have a crappier version of ffmpeg written in D!
fraserofthenight
parents:
diff changeset
14 */
9fdfe4a64a13 Added the beginnings of a decoder... Soon I'll have a crappier version of ffmpeg written in D!
fraserofthenight
parents:
diff changeset
15
9fdfe4a64a13 Added the beginnings of a decoder... Soon I'll have a crappier version of ffmpeg written in D!
fraserofthenight
parents:
diff changeset
16 module hoofbaby.codec.decoder;
9fdfe4a64a13 Added the beginnings of a decoder... Soon I'll have a crappier version of ffmpeg written in D!
fraserofthenight
parents:
diff changeset
17
9fdfe4a64a13 Added the beginnings of a decoder... Soon I'll have a crappier version of ffmpeg written in D!
fraserofthenight
parents:
diff changeset
18 import tango.stdc.stringz;
9fdfe4a64a13 Added the beginnings of a decoder... Soon I'll have a crappier version of ffmpeg written in D!
fraserofthenight
parents:
diff changeset
19
9fdfe4a64a13 Added the beginnings of a decoder... Soon I'll have a crappier version of ffmpeg written in D!
fraserofthenight
parents:
diff changeset
20 import hoofbaby.codec.libav.avutil;
9fdfe4a64a13 Added the beginnings of a decoder... Soon I'll have a crappier version of ffmpeg written in D!
fraserofthenight
parents:
diff changeset
21 import hoofbaby.codec.libav.avcodec;
9fdfe4a64a13 Added the beginnings of a decoder... Soon I'll have a crappier version of ffmpeg written in D!
fraserofthenight
parents:
diff changeset
22 import hoofbaby.codec.libav.avformat;
9fdfe4a64a13 Added the beginnings of a decoder... Soon I'll have a crappier version of ffmpeg written in D!
fraserofthenight
parents:
diff changeset
23
9fdfe4a64a13 Added the beginnings of a decoder... Soon I'll have a crappier version of ffmpeg written in D!
fraserofthenight
parents:
diff changeset
24 class Decoder
9fdfe4a64a13 Added the beginnings of a decoder... Soon I'll have a crappier version of ffmpeg written in D!
fraserofthenight
parents:
diff changeset
25 {
9fdfe4a64a13 Added the beginnings of a decoder... Soon I'll have a crappier version of ffmpeg written in D!
fraserofthenight
parents:
diff changeset
26 private AVFormatContext* formatContext;
9fdfe4a64a13 Added the beginnings of a decoder... Soon I'll have a crappier version of ffmpeg written in D!
fraserofthenight
parents:
diff changeset
27
9fdfe4a64a13 Added the beginnings of a decoder... Soon I'll have a crappier version of ffmpeg written in D!
fraserofthenight
parents:
diff changeset
28 public this(char[] inFilename)
9fdfe4a64a13 Added the beginnings of a decoder... Soon I'll have a crappier version of ffmpeg written in D!
fraserofthenight
parents:
diff changeset
29 {
9fdfe4a64a13 Added the beginnings of a decoder... Soon I'll have a crappier version of ffmpeg written in D!
fraserofthenight
parents:
diff changeset
30 int ret;
9fdfe4a64a13 Added the beginnings of a decoder... Soon I'll have a crappier version of ffmpeg written in D!
fraserofthenight
parents:
diff changeset
31
9fdfe4a64a13 Added the beginnings of a decoder... Soon I'll have a crappier version of ffmpeg written in D!
fraserofthenight
parents:
diff changeset
32 // Open file & find stream info
9fdfe4a64a13 Added the beginnings of a decoder... Soon I'll have a crappier version of ffmpeg written in D!
fraserofthenight
parents:
diff changeset
33 char* filename = toStringz(inFilename);
9fdfe4a64a13 Added the beginnings of a decoder... Soon I'll have a crappier version of ffmpeg written in D!
fraserofthenight
parents:
diff changeset
34 ret = av_open_input_file(&formatContext, filename, null, 0, null);
9fdfe4a64a13 Added the beginnings of a decoder... Soon I'll have a crappier version of ffmpeg written in D!
fraserofthenight
parents:
diff changeset
35 assert(ret == 0, "Could not open input file");
9fdfe4a64a13 Added the beginnings of a decoder... Soon I'll have a crappier version of ffmpeg written in D!
fraserofthenight
parents:
diff changeset
36 ret = av_find_stream_info(formatContext);
9fdfe4a64a13 Added the beginnings of a decoder... Soon I'll have a crappier version of ffmpeg written in D!
fraserofthenight
parents:
diff changeset
37 assert(ret >= 0, "Could not find stream info");
9fdfe4a64a13 Added the beginnings of a decoder... Soon I'll have a crappier version of ffmpeg written in D!
fraserofthenight
parents:
diff changeset
38 dump_format(formatContext, 0, filename, false);
9fdfe4a64a13 Added the beginnings of a decoder... Soon I'll have a crappier version of ffmpeg written in D!
fraserofthenight
parents:
diff changeset
39 }
9fdfe4a64a13 Added the beginnings of a decoder... Soon I'll have a crappier version of ffmpeg written in D!
fraserofthenight
parents:
diff changeset
40 }
9fdfe4a64a13 Added the beginnings of a decoder... Soon I'll have a crappier version of ffmpeg written in D!
fraserofthenight
parents:
diff changeset
41
9fdfe4a64a13 Added the beginnings of a decoder... Soon I'll have a crappier version of ffmpeg written in D!
fraserofthenight
parents:
diff changeset
42 /* int main(int argc, char *argv[])
9fdfe4a64a13 Added the beginnings of a decoder... Soon I'll have a crappier version of ffmpeg written in D!
fraserofthenight
parents:
diff changeset
43 {
9fdfe4a64a13 Added the beginnings of a decoder... Soon I'll have a crappier version of ffmpeg written in D!
fraserofthenight
parents:
diff changeset
44 AVFormatContext *pFormatCtx;
9fdfe4a64a13 Added the beginnings of a decoder... Soon I'll have a crappier version of ffmpeg written in D!
fraserofthenight
parents:
diff changeset
45 int i, videoStream;
9fdfe4a64a13 Added the beginnings of a decoder... Soon I'll have a crappier version of ffmpeg written in D!
fraserofthenight
parents:
diff changeset
46 AVCodecContext *pCodecCtx;
9fdfe4a64a13 Added the beginnings of a decoder... Soon I'll have a crappier version of ffmpeg written in D!
fraserofthenight
parents:
diff changeset
47 AVCodec *pCodec;
9fdfe4a64a13 Added the beginnings of a decoder... Soon I'll have a crappier version of ffmpeg written in D!
fraserofthenight
parents:
diff changeset
48 AVFrame *pFrame;
9fdfe4a64a13 Added the beginnings of a decoder... Soon I'll have a crappier version of ffmpeg written in D!
fraserofthenight
parents:
diff changeset
49 AVFrame *pFrameRGB;
9fdfe4a64a13 Added the beginnings of a decoder... Soon I'll have a crappier version of ffmpeg written in D!
fraserofthenight
parents:
diff changeset
50 AVPacket packet;
9fdfe4a64a13 Added the beginnings of a decoder... Soon I'll have a crappier version of ffmpeg written in D!
fraserofthenight
parents:
diff changeset
51 int frameFinished;
9fdfe4a64a13 Added the beginnings of a decoder... Soon I'll have a crappier version of ffmpeg written in D!
fraserofthenight
parents:
diff changeset
52 int numBytes;
9fdfe4a64a13 Added the beginnings of a decoder... Soon I'll have a crappier version of ffmpeg written in D!
fraserofthenight
parents:
diff changeset
53 uint8_t *buffer;
9fdfe4a64a13 Added the beginnings of a decoder... Soon I'll have a crappier version of ffmpeg written in D!
fraserofthenight
parents:
diff changeset
54
9fdfe4a64a13 Added the beginnings of a decoder... Soon I'll have a crappier version of ffmpeg written in D!
fraserofthenight
parents:
diff changeset
55 // Register all formats and codecs
9fdfe4a64a13 Added the beginnings of a decoder... Soon I'll have a crappier version of ffmpeg written in D!
fraserofthenight
parents:
diff changeset
56 av_register_all();
9fdfe4a64a13 Added the beginnings of a decoder... Soon I'll have a crappier version of ffmpeg written in D!
fraserofthenight
parents:
diff changeset
57
9fdfe4a64a13 Added the beginnings of a decoder... Soon I'll have a crappier version of ffmpeg written in D!
fraserofthenight
parents:
diff changeset
58 // Open video file
9fdfe4a64a13 Added the beginnings of a decoder... Soon I'll have a crappier version of ffmpeg written in D!
fraserofthenight
parents:
diff changeset
59 if(av_open_input_file(&pFormatCtx, argv[1], NULL, 0, NULL)!=0)
9fdfe4a64a13 Added the beginnings of a decoder... Soon I'll have a crappier version of ffmpeg written in D!
fraserofthenight
parents:
diff changeset
60 return -1; // Couldn't open file
9fdfe4a64a13 Added the beginnings of a decoder... Soon I'll have a crappier version of ffmpeg written in D!
fraserofthenight
parents:
diff changeset
61
9fdfe4a64a13 Added the beginnings of a decoder... Soon I'll have a crappier version of ffmpeg written in D!
fraserofthenight
parents:
diff changeset
62 // Retrieve stream information
9fdfe4a64a13 Added the beginnings of a decoder... Soon I'll have a crappier version of ffmpeg written in D!
fraserofthenight
parents:
diff changeset
63 if(av_find_stream_info(pFormatCtx)<0)
9fdfe4a64a13 Added the beginnings of a decoder... Soon I'll have a crappier version of ffmpeg written in D!
fraserofthenight
parents:
diff changeset
64 return -1; // Couldn't find stream information
9fdfe4a64a13 Added the beginnings of a decoder... Soon I'll have a crappier version of ffmpeg written in D!
fraserofthenight
parents:
diff changeset
65
9fdfe4a64a13 Added the beginnings of a decoder... Soon I'll have a crappier version of ffmpeg written in D!
fraserofthenight
parents:
diff changeset
66 // Dump information about file onto standard error
9fdfe4a64a13 Added the beginnings of a decoder... Soon I'll have a crappier version of ffmpeg written in D!
fraserofthenight
parents:
diff changeset
67 dump_format(pFormatCtx, 0, argv[1], false);
9fdfe4a64a13 Added the beginnings of a decoder... Soon I'll have a crappier version of ffmpeg written in D!
fraserofthenight
parents:
diff changeset
68
9fdfe4a64a13 Added the beginnings of a decoder... Soon I'll have a crappier version of ffmpeg written in D!
fraserofthenight
parents:
diff changeset
69 // Find the first video stream
9fdfe4a64a13 Added the beginnings of a decoder... Soon I'll have a crappier version of ffmpeg written in D!
fraserofthenight
parents:
diff changeset
70 videoStream=-1;
9fdfe4a64a13 Added the beginnings of a decoder... Soon I'll have a crappier version of ffmpeg written in D!
fraserofthenight
parents:
diff changeset
71 for(i=0; i<pFormatCtx.nb_streams; i++)
9fdfe4a64a13 Added the beginnings of a decoder... Soon I'll have a crappier version of ffmpeg written in D!
fraserofthenight
parents:
diff changeset
72 if(pFormatCtx.streams[i].codec.codec_type==CODEC_TYPE_VIDEO)
9fdfe4a64a13 Added the beginnings of a decoder... Soon I'll have a crappier version of ffmpeg written in D!
fraserofthenight
parents:
diff changeset
73 {
9fdfe4a64a13 Added the beginnings of a decoder... Soon I'll have a crappier version of ffmpeg written in D!
fraserofthenight
parents:
diff changeset
74 videoStream=i;
9fdfe4a64a13 Added the beginnings of a decoder... Soon I'll have a crappier version of ffmpeg written in D!
fraserofthenight
parents:
diff changeset
75 break;
9fdfe4a64a13 Added the beginnings of a decoder... Soon I'll have a crappier version of ffmpeg written in D!
fraserofthenight
parents:
diff changeset
76 }
9fdfe4a64a13 Added the beginnings of a decoder... Soon I'll have a crappier version of ffmpeg written in D!
fraserofthenight
parents:
diff changeset
77 if(videoStream==-1)
9fdfe4a64a13 Added the beginnings of a decoder... Soon I'll have a crappier version of ffmpeg written in D!
fraserofthenight
parents:
diff changeset
78 return -1; // Didn't find a video stream
9fdfe4a64a13 Added the beginnings of a decoder... Soon I'll have a crappier version of ffmpeg written in D!
fraserofthenight
parents:
diff changeset
79
9fdfe4a64a13 Added the beginnings of a decoder... Soon I'll have a crappier version of ffmpeg written in D!
fraserofthenight
parents:
diff changeset
80 // Get a pointer to the codec context for the video stream
9fdfe4a64a13 Added the beginnings of a decoder... Soon I'll have a crappier version of ffmpeg written in D!
fraserofthenight
parents:
diff changeset
81 pCodecCtx=&pFormatCtx.streams[videoStream].codec;
9fdfe4a64a13 Added the beginnings of a decoder... Soon I'll have a crappier version of ffmpeg written in D!
fraserofthenight
parents:
diff changeset
82
9fdfe4a64a13 Added the beginnings of a decoder... Soon I'll have a crappier version of ffmpeg written in D!
fraserofthenight
parents:
diff changeset
83 // Find the decoder for the video stream
9fdfe4a64a13 Added the beginnings of a decoder... Soon I'll have a crappier version of ffmpeg written in D!
fraserofthenight
parents:
diff changeset
84 pCodec=avcodec_find_decoder(pCodecCtx.codec_id);
9fdfe4a64a13 Added the beginnings of a decoder... Soon I'll have a crappier version of ffmpeg written in D!
fraserofthenight
parents:
diff changeset
85 if(pCodec==NULL)
9fdfe4a64a13 Added the beginnings of a decoder... Soon I'll have a crappier version of ffmpeg written in D!
fraserofthenight
parents:
diff changeset
86 return -1; // Codec not found
9fdfe4a64a13 Added the beginnings of a decoder... Soon I'll have a crappier version of ffmpeg written in D!
fraserofthenight
parents:
diff changeset
87
9fdfe4a64a13 Added the beginnings of a decoder... Soon I'll have a crappier version of ffmpeg written in D!
fraserofthenight
parents:
diff changeset
88 // Open codec
9fdfe4a64a13 Added the beginnings of a decoder... Soon I'll have a crappier version of ffmpeg written in D!
fraserofthenight
parents:
diff changeset
89 if(avcodec_open(pCodecCtx, pCodec)<0)
9fdfe4a64a13 Added the beginnings of a decoder... Soon I'll have a crappier version of ffmpeg written in D!
fraserofthenight
parents:
diff changeset
90 return -1; // Could not open codec
9fdfe4a64a13 Added the beginnings of a decoder... Soon I'll have a crappier version of ffmpeg written in D!
fraserofthenight
parents:
diff changeset
91
9fdfe4a64a13 Added the beginnings of a decoder... Soon I'll have a crappier version of ffmpeg written in D!
fraserofthenight
parents:
diff changeset
92 // Hack to correct wrong frame rates that seem to be generated by some
9fdfe4a64a13 Added the beginnings of a decoder... Soon I'll have a crappier version of ffmpeg written in D!
fraserofthenight
parents:
diff changeset
93 // codecs
9fdfe4a64a13 Added the beginnings of a decoder... Soon I'll have a crappier version of ffmpeg written in D!
fraserofthenight
parents:
diff changeset
94 if(pCodecCtx.frame_rate>1000 && pCodecCtx.frame_rate_base==1)
9fdfe4a64a13 Added the beginnings of a decoder... Soon I'll have a crappier version of ffmpeg written in D!
fraserofthenight
parents:
diff changeset
95 pCodecCtx.frame_rate_base=1000;
9fdfe4a64a13 Added the beginnings of a decoder... Soon I'll have a crappier version of ffmpeg written in D!
fraserofthenight
parents:
diff changeset
96
9fdfe4a64a13 Added the beginnings of a decoder... Soon I'll have a crappier version of ffmpeg written in D!
fraserofthenight
parents:
diff changeset
97 // Allocate video frame
9fdfe4a64a13 Added the beginnings of a decoder... Soon I'll have a crappier version of ffmpeg written in D!
fraserofthenight
parents:
diff changeset
98 pFrame=avcodec_alloc_frame();
9fdfe4a64a13 Added the beginnings of a decoder... Soon I'll have a crappier version of ffmpeg written in D!
fraserofthenight
parents:
diff changeset
99
9fdfe4a64a13 Added the beginnings of a decoder... Soon I'll have a crappier version of ffmpeg written in D!
fraserofthenight
parents:
diff changeset
100 // Allocate an AVFrame structure
9fdfe4a64a13 Added the beginnings of a decoder... Soon I'll have a crappier version of ffmpeg written in D!
fraserofthenight
parents:
diff changeset
101 pFrameRGB=avcodec_alloc_frame();
9fdfe4a64a13 Added the beginnings of a decoder... Soon I'll have a crappier version of ffmpeg written in D!
fraserofthenight
parents:
diff changeset
102 if(pFrameRGB==NULL)
9fdfe4a64a13 Added the beginnings of a decoder... Soon I'll have a crappier version of ffmpeg written in D!
fraserofthenight
parents:
diff changeset
103 return -1;
9fdfe4a64a13 Added the beginnings of a decoder... Soon I'll have a crappier version of ffmpeg written in D!
fraserofthenight
parents:
diff changeset
104
9fdfe4a64a13 Added the beginnings of a decoder... Soon I'll have a crappier version of ffmpeg written in D!
fraserofthenight
parents:
diff changeset
105 // Determine required buffer size and allocate buffer
9fdfe4a64a13 Added the beginnings of a decoder... Soon I'll have a crappier version of ffmpeg written in D!
fraserofthenight
parents:
diff changeset
106 numBytes=avpicture_get_size(PIX_FMT_RGB24, pCodecCtx.width,
9fdfe4a64a13 Added the beginnings of a decoder... Soon I'll have a crappier version of ffmpeg written in D!
fraserofthenight
parents:
diff changeset
107 pCodecCtx.height);
9fdfe4a64a13 Added the beginnings of a decoder... Soon I'll have a crappier version of ffmpeg written in D!
fraserofthenight
parents:
diff changeset
108 buffer=new uint8_t[numBytes];
9fdfe4a64a13 Added the beginnings of a decoder... Soon I'll have a crappier version of ffmpeg written in D!
fraserofthenight
parents:
diff changeset
109
9fdfe4a64a13 Added the beginnings of a decoder... Soon I'll have a crappier version of ffmpeg written in D!
fraserofthenight
parents:
diff changeset
110 // Assign appropriate parts of buffer to image planes in pFrameRGB
9fdfe4a64a13 Added the beginnings of a decoder... Soon I'll have a crappier version of ffmpeg written in D!
fraserofthenight
parents:
diff changeset
111 avpicture_fill(cast(AVPicture *)pFrameRGB, buffer, PIX_FMT_RGB24,
9fdfe4a64a13 Added the beginnings of a decoder... Soon I'll have a crappier version of ffmpeg written in D!
fraserofthenight
parents:
diff changeset
112 pCodecCtx.width, pCodecCtx.height);
9fdfe4a64a13 Added the beginnings of a decoder... Soon I'll have a crappier version of ffmpeg written in D!
fraserofthenight
parents:
diff changeset
113
9fdfe4a64a13 Added the beginnings of a decoder... Soon I'll have a crappier version of ffmpeg written in D!
fraserofthenight
parents:
diff changeset
114 // Read frames and save first five frames to disk
9fdfe4a64a13 Added the beginnings of a decoder... Soon I'll have a crappier version of ffmpeg written in D!
fraserofthenight
parents:
diff changeset
115 i=0;
9fdfe4a64a13 Added the beginnings of a decoder... Soon I'll have a crappier version of ffmpeg written in D!
fraserofthenight
parents:
diff changeset
116 while(av_read_frame(pFormatCtx, &packet)>=0)
9fdfe4a64a13 Added the beginnings of a decoder... Soon I'll have a crappier version of ffmpeg written in D!
fraserofthenight
parents:
diff changeset
117 {
9fdfe4a64a13 Added the beginnings of a decoder... Soon I'll have a crappier version of ffmpeg written in D!
fraserofthenight
parents:
diff changeset
118 // Is this a packet from the video stream?
9fdfe4a64a13 Added the beginnings of a decoder... Soon I'll have a crappier version of ffmpeg written in D!
fraserofthenight
parents:
diff changeset
119 if(packet.stream_index==videoStream)
9fdfe4a64a13 Added the beginnings of a decoder... Soon I'll have a crappier version of ffmpeg written in D!
fraserofthenight
parents:
diff changeset
120 {
9fdfe4a64a13 Added the beginnings of a decoder... Soon I'll have a crappier version of ffmpeg written in D!
fraserofthenight
parents:
diff changeset
121 // Decode video frame
9fdfe4a64a13 Added the beginnings of a decoder... Soon I'll have a crappier version of ffmpeg written in D!
fraserofthenight
parents:
diff changeset
122 avcodec_decode_video(pCodecCtx, pFrame, &frameFinished,
9fdfe4a64a13 Added the beginnings of a decoder... Soon I'll have a crappier version of ffmpeg written in D!
fraserofthenight
parents:
diff changeset
123 packet.data, packet.size);
9fdfe4a64a13 Added the beginnings of a decoder... Soon I'll have a crappier version of ffmpeg written in D!
fraserofthenight
parents:
diff changeset
124
9fdfe4a64a13 Added the beginnings of a decoder... Soon I'll have a crappier version of ffmpeg written in D!
fraserofthenight
parents:
diff changeset
125 // Did we get a video frame?
9fdfe4a64a13 Added the beginnings of a decoder... Soon I'll have a crappier version of ffmpeg written in D!
fraserofthenight
parents:
diff changeset
126 if(frameFinished)
9fdfe4a64a13 Added the beginnings of a decoder... Soon I'll have a crappier version of ffmpeg written in D!
fraserofthenight
parents:
diff changeset
127 {
9fdfe4a64a13 Added the beginnings of a decoder... Soon I'll have a crappier version of ffmpeg written in D!
fraserofthenight
parents:
diff changeset
128 // Convert the image from its native format to RGB
9fdfe4a64a13 Added the beginnings of a decoder... Soon I'll have a crappier version of ffmpeg written in D!
fraserofthenight
parents:
diff changeset
129 img_convert(cast(AVPicture *)pFrameRGB, PIX_FMT_RGB24,
9fdfe4a64a13 Added the beginnings of a decoder... Soon I'll have a crappier version of ffmpeg written in D!
fraserofthenight
parents:
diff changeset
130 cast(AVPicture*)pFrame, pCodecCtx.pix_fmt, pCodecCtx.width,
9fdfe4a64a13 Added the beginnings of a decoder... Soon I'll have a crappier version of ffmpeg written in D!
fraserofthenight
parents:
diff changeset
131 pCodecCtx.height);
9fdfe4a64a13 Added the beginnings of a decoder... Soon I'll have a crappier version of ffmpeg written in D!
fraserofthenight
parents:
diff changeset
132
9fdfe4a64a13 Added the beginnings of a decoder... Soon I'll have a crappier version of ffmpeg written in D!
fraserofthenight
parents:
diff changeset
133 // Save the frame to disk
9fdfe4a64a13 Added the beginnings of a decoder... Soon I'll have a crappier version of ffmpeg written in D!
fraserofthenight
parents:
diff changeset
134 if(++i<=5)
9fdfe4a64a13 Added the beginnings of a decoder... Soon I'll have a crappier version of ffmpeg written in D!
fraserofthenight
parents:
diff changeset
135 SaveFrame(pFrameRGB, pCodecCtx.width, pCodecCtx.height,
9fdfe4a64a13 Added the beginnings of a decoder... Soon I'll have a crappier version of ffmpeg written in D!
fraserofthenight
parents:
diff changeset
136 i);
9fdfe4a64a13 Added the beginnings of a decoder... Soon I'll have a crappier version of ffmpeg written in D!
fraserofthenight
parents:
diff changeset
137 }
9fdfe4a64a13 Added the beginnings of a decoder... Soon I'll have a crappier version of ffmpeg written in D!
fraserofthenight
parents:
diff changeset
138 }
9fdfe4a64a13 Added the beginnings of a decoder... Soon I'll have a crappier version of ffmpeg written in D!
fraserofthenight
parents:
diff changeset
139
9fdfe4a64a13 Added the beginnings of a decoder... Soon I'll have a crappier version of ffmpeg written in D!
fraserofthenight
parents:
diff changeset
140 // Free the packet that was allocated by av_read_frame
9fdfe4a64a13 Added the beginnings of a decoder... Soon I'll have a crappier version of ffmpeg written in D!
fraserofthenight
parents:
diff changeset
141 av_free_packet(&packet);
9fdfe4a64a13 Added the beginnings of a decoder... Soon I'll have a crappier version of ffmpeg written in D!
fraserofthenight
parents:
diff changeset
142 }
9fdfe4a64a13 Added the beginnings of a decoder... Soon I'll have a crappier version of ffmpeg written in D!
fraserofthenight
parents:
diff changeset
143
9fdfe4a64a13 Added the beginnings of a decoder... Soon I'll have a crappier version of ffmpeg written in D!
fraserofthenight
parents:
diff changeset
144 // Free the RGB image
9fdfe4a64a13 Added the beginnings of a decoder... Soon I'll have a crappier version of ffmpeg written in D!
fraserofthenight
parents:
diff changeset
145 delete buffer;
9fdfe4a64a13 Added the beginnings of a decoder... Soon I'll have a crappier version of ffmpeg written in D!
fraserofthenight
parents:
diff changeset
146 av_free(pFrameRGB);
9fdfe4a64a13 Added the beginnings of a decoder... Soon I'll have a crappier version of ffmpeg written in D!
fraserofthenight
parents:
diff changeset
147
9fdfe4a64a13 Added the beginnings of a decoder... Soon I'll have a crappier version of ffmpeg written in D!
fraserofthenight
parents:
diff changeset
148 // Free the YUV frame
9fdfe4a64a13 Added the beginnings of a decoder... Soon I'll have a crappier version of ffmpeg written in D!
fraserofthenight
parents:
diff changeset
149 av_free(pFrame);
9fdfe4a64a13 Added the beginnings of a decoder... Soon I'll have a crappier version of ffmpeg written in D!
fraserofthenight
parents:
diff changeset
150
9fdfe4a64a13 Added the beginnings of a decoder... Soon I'll have a crappier version of ffmpeg written in D!
fraserofthenight
parents:
diff changeset
151 // Close the codec
9fdfe4a64a13 Added the beginnings of a decoder... Soon I'll have a crappier version of ffmpeg written in D!
fraserofthenight
parents:
diff changeset
152 avcodec_close(pCodecCtx);
9fdfe4a64a13 Added the beginnings of a decoder... Soon I'll have a crappier version of ffmpeg written in D!
fraserofthenight
parents:
diff changeset
153
9fdfe4a64a13 Added the beginnings of a decoder... Soon I'll have a crappier version of ffmpeg written in D!
fraserofthenight
parents:
diff changeset
154 // Close the video file
9fdfe4a64a13 Added the beginnings of a decoder... Soon I'll have a crappier version of ffmpeg written in D!
fraserofthenight
parents:
diff changeset
155 av_close_input_file(pFormatCtx);
9fdfe4a64a13 Added the beginnings of a decoder... Soon I'll have a crappier version of ffmpeg written in D!
fraserofthenight
parents:
diff changeset
156
9fdfe4a64a13 Added the beginnings of a decoder... Soon I'll have a crappier version of ffmpeg written in D!
fraserofthenight
parents:
diff changeset
157 return 0;
9fdfe4a64a13 Added the beginnings of a decoder... Soon I'll have a crappier version of ffmpeg written in D!
fraserofthenight
parents:
diff changeset
158 } */