comparison src/test/hoofbaby/test/adhoc/transcode.d @ 8:71ebad05f542

It seems to be successfully opening input files... Now to transcode!
author fraserofthenight
date Sun, 12 Jul 2009 03:49:39 -0700
parents 9fdfe4a64a13
children
comparison
equal deleted inserted replaced
7:9fdfe4a64a13 8:71ebad05f542
18 import NONE_1 = tango.stdc.stdarg; // Must be linked in to prevent strange linker errors 18 import NONE_1 = tango.stdc.stdarg; // Must be linked in to prevent strange linker errors
19 debug import NONE_2 = tango.core.stacktrace.TraceExceptions; 19 debug import NONE_2 = tango.core.stacktrace.TraceExceptions;
20 import NONE_3 = hoofbaby.codec.libav.mingw; 20 import NONE_3 = hoofbaby.codec.libav.mingw;
21 import hoofbaby.app.libs; 21 import hoofbaby.app.libs;
22 22
23 import Math = tango.math.Math;
24 import hoofbaby.codec.decoder; 23 import hoofbaby.codec.decoder;
25 import hoofbaby.codec.encoder; 24 import hoofbaby.codec.encoder;
25
26
27 public int main(char[][] args)
28 {
29 initLibs();
30 scope Decoder dec = new Decoder("../../ref/testv-h264-vorbis-ass.mkv");
31 delete dec;
32 return 0;
33 }
34
35 /+
36
37 import Math = tango.math.Math;
26 import hoofbaby.codec.libav.avutil; 38 import hoofbaby.codec.libav.avutil;
27 import hoofbaby.codec.libav.avcodec; 39 import hoofbaby.codec.libav.avcodec;
28 import hoofbaby.codec.libav.avformat; 40 import hoofbaby.codec.libav.avformat;
29 41
30 private const int STREAM_FRAME_RATE = 25; 42 private const int STREAM_FRAME_RATE = 25;
37 49
38 private int frameCount = 0; 50 private int frameCount = 0;
39 private double audioCount = 0.0; 51 private double audioCount = 0.0;
40 private double audioIncr = 2 * Math.PI * 110.0 / SAMPLE_RATE; 52 private double audioIncr = 2 * Math.PI * 110.0 / SAMPLE_RATE;
41 private double audioIncr2 = 2 * Math.PI * 110.0 / SAMPLE_RATE / SAMPLE_RATE; 53 private double audioIncr2 = 2 * Math.PI * 110.0 / SAMPLE_RATE / SAMPLE_RATE;
42
43 private AVFrame* allocFrame(int pix_fmt, int width, int height)
44 {
45 AVFrame* picture;
46 char* buf;
47 int size;
48
49 picture = avcodec_alloc_frame();
50 if(!picture)
51 return null;
52 size = avpicture_get_size(pix_fmt, width, height);
53 buf = cast(char*) av_malloc(size);
54 if(!buf)
55 {
56 av_free(picture);
57 return null;
58 }
59 avpicture_fill(cast(AVPicture*) picture, buf, pix_fmt, width, height);
60 return picture;
61 }
62 54
63 private AVFrame* generatePicture(AVFrame* pict, int width, int height) 55 private AVFrame* generatePicture(AVFrame* pict, int width, int height)
64 { 56 {
65 int x, y, i; 57 int x, y, i;
66 i = frameCount; 58 i = frameCount;
106 } 98 }
107 99
108 public int main(char[][] args) 100 public int main(char[][] args)
109 { 101 {
110 initLibs(); 102 initLibs();
111 scope Decoder dec = new Decoder("../../ref/testv-h264-vorbis-ass.mkv");
112 return 0;
113
114 /+
115 initLibs();
116 scope Encoder enc = new Encoder("biff_happy.wmv"); 103 scope Encoder enc = new Encoder("biff_happy.wmv");
117 AUDIO_FRAME_SIZE = enc.audioContext.frame_size; 104 AUDIO_FRAME_SIZE = enc.audioContext.frame_size;
118 105
119 // Allocate a video frame and audio buffer to store stuff 106 // Allocate a video frame and audio buffer to store stuff
120 AVFrame* frame = allocFrame(PIX_FMT_YUV420P, WIDTH, HEIGHT); 107 AVFrame* frame = avpicture_alloc(PIX_FMT_YUV420P, WIDTH, HEIGHT);
121 assert(frame !is null, "Could not allocate frame"); 108 assert(frame !is null, "Could not allocate frame");
122 scope(exit) if(frame) av_free(frame); 109 scope(exit) if(frame) av_free(frame);
123 short* samples = cast(short*) av_malloc(AUDIO_FRAME_SIZE * 2 * 2); // AUDIO_FRAME_SIZE * 2 * number of channels 110 short* samples = cast(short*) av_malloc(AUDIO_FRAME_SIZE * 2 * 2); // AUDIO_FRAME_SIZE * 2 * number of channels
124 assert(frame !is null, "Could not allocate samples"); 111 assert(frame !is null, "Could not allocate samples");
125 scope(exit) if(samples) av_free(samples); 112 scope(exit) if(samples) av_free(samples);
126 113
127 // Write header 114 // Write header
128 enc.writeHeader(); 115 enc.writeHeader();
129 116
130 while(true) 117 while(true)
131 { 118 {
132 double audio_pts = cast(double) enc.audioStream.pts.val * enc.audioStream.time_base.num / enc.audioStream.time_base.den; 119 double audio_pts = cast(double) enc.audioStream.pts.val * enc.audioStream.time_base.num / enc.audioStream.time_base.den;
133 double video_pts = cast(double) enc.videoStream.pts.val * enc.videoStream.time_base.num / enc.videoStream.time_base.den; 120 double video_pts = cast(double) enc.videoStream.pts.val * enc.videoStream.time_base.num / enc.videoStream.time_base.den;
134 121
135 if(audio_pts >= STREAM_DURATION && video_pts >= STREAM_DURATION) 122 if(audio_pts >= STREAM_DURATION && video_pts >= STREAM_DURATION)
136 break; 123 break;
137 124
138 // Write interleaved audio & video 125 // Write interleaved audio & video
139 if(audio_pts < video_pts) 126 if(audio_pts < video_pts)
140 { 127 {
141 enc.writeAudioFrame(generateAudio(samples)); 128 enc.writeAudioFrame(generateAudio(samples));
142 } 129 }
155 142
156 enc.writeVideoFrame(frame); 143 enc.writeVideoFrame(frame);
157 frameCount++; 144 frameCount++;
158 } 145 }
159 } 146 }
160 147
161 // Write trailer 148 // Write trailer
162 enc.writeTrailer(); 149 enc.writeTrailer();
163 150
164 return 0; +/ 151 return 0;
165 } 152 }
153 +/