author | Stepan777 <stepik-777@mail.ru> |
Mon, 09 Jul 2012 21:45:30 +0400 | |
changeset 7379 | aa29a2f16cc7 |
parent 7376 | 48b79b3ca592 |
child 7542 | 37ef1891efe2 |
permissions | -rw-r--r-- |
7180 | 1 |
|
2 |
#include <stdlib.h> |
|
3 |
#include <stdio.h> |
|
7280
fd707afbc3a2
pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents:
7235
diff
changeset
|
4 |
#include <stdint.h> |
7180 | 5 |
#include <string.h> |
6 |
#include <stdarg.h> |
|
7 |
#include "libavformat/avformat.h" |
|
8 |
||
7356
1ae5cf294216
fix for older ffmpeg (0.7.13)
Stepan777 <stepik-777@mail.ru>
parents:
7306
diff
changeset
|
9 |
#ifndef AVIO_FLAG_WRITE |
1ae5cf294216
fix for older ffmpeg (0.7.13)
Stepan777 <stepik-777@mail.ru>
parents:
7306
diff
changeset
|
10 |
#define AVIO_FLAG_WRITE AVIO_WRONLY |
1ae5cf294216
fix for older ffmpeg (0.7.13)
Stepan777 <stepik-777@mail.ru>
parents:
7306
diff
changeset
|
11 |
#endif |
1ae5cf294216
fix for older ffmpeg (0.7.13)
Stepan777 <stepik-777@mail.ru>
parents:
7306
diff
changeset
|
12 |
|
7180 | 13 |
static AVFormatContext* g_pContainer; |
14 |
static AVOutputFormat* g_pFormat; |
|
15 |
static AVStream* g_pAStream; |
|
16 |
static AVStream* g_pVStream; |
|
17 |
static AVFrame* g_pAFrame; |
|
18 |
static AVFrame* g_pVFrame; |
|
19 |
static AVCodec* g_pACodec; |
|
20 |
static AVCodec* g_pVCodec; |
|
21 |
static AVCodecContext* g_pAudio; |
|
22 |
static AVCodecContext* g_pVideo; |
|
23 |
||
7198
5debd5fe526e
1. Add IFDEFs for video recording
Stepan777 <stepik-777@mail.ru>
parents:
7180
diff
changeset
|
24 |
static int g_Width, g_Height; |
7280
fd707afbc3a2
pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents:
7235
diff
changeset
|
25 |
static uint32_t g_Frequency, g_Channels; |
7376
48b79b3ca592
rework saving of camera positions so there is no need to know framerate during prerecording.
Stepan777 <stepik-777@mail.ru>
parents:
7359
diff
changeset
|
26 |
static int g_VQuality; |
7198
5debd5fe526e
1. Add IFDEFs for video recording
Stepan777 <stepik-777@mail.ru>
parents:
7180
diff
changeset
|
27 |
static AVRational g_Framerate; |
7180 | 28 |
|
29 |
static FILE* g_pSoundFile; |
|
30 |
static int16_t* g_pSamples; |
|
31 |
static int g_NumSamples; |
|
32 |
||
33 |
/* |
|
34 |
Initially I wrote code for latest ffmpeg, but on Linux (Ubuntu) |
|
35 |
only older version is available from repository. That's why you see here |
|
36 |
all of this #if LIBAVCODEC_VERSION_MAJOR < 54. |
|
37 |
Actually, it may be possible to remove code for newer version |
|
38 |
and use only code for older version. |
|
39 |
*/ |
|
40 |
||
41 |
#if LIBAVCODEC_VERSION_MAJOR < 54 |
|
42 |
#define OUTBUFFER_SIZE 200000 |
|
43 |
static uint8_t g_OutBuffer[OUTBUFFER_SIZE]; |
|
44 |
#endif |
|
45 |
||
46 |
// pointer to function from hwengine (uUtils.pas) |
|
47 |
static void (*AddFileLogRaw)(const char* pString); |
|
48 |
||
49 |
static void FatalError(const char* pFmt, ...) |
|
50 |
{ |
|
51 |
const char Buffer[1024]; |
|
52 |
va_list VaArgs; |
|
53 |
||
54 |
va_start(VaArgs, pFmt); |
|
55 |
vsnprintf(Buffer, 1024, pFmt, VaArgs); |
|
56 |
va_end(VaArgs); |
|
57 |
||
58 |
AddFileLogRaw("Error in av-wrapper: "); |
|
59 |
AddFileLogRaw(Buffer); |
|
60 |
AddFileLogRaw("\n"); |
|
61 |
exit(1); |
|
62 |
} |
|
63 |
||
64 |
// Function to be called from libav for logging. |
|
65 |
// Note: libav can call LogCallback from different threads |
|
66 |
// (there is mutex in AddFileLogRaw). |
|
67 |
static void LogCallback(void* p, int Level, const char* pFmt, va_list VaArgs) |
|
68 |
{ |
|
69 |
const char Buffer[1024]; |
|
70 |
||
71 |
vsnprintf(Buffer, 1024, pFmt, VaArgs); |
|
72 |
AddFileLogRaw(Buffer); |
|
73 |
} |
|
74 |
||
75 |
static void Log(const char* pFmt, ...) |
|
76 |
{ |
|
77 |
const char Buffer[1024]; |
|
78 |
va_list VaArgs; |
|
79 |
||
80 |
va_start(VaArgs, pFmt); |
|
81 |
vsnprintf(Buffer, 1024, pFmt, VaArgs); |
|
82 |
va_end(VaArgs); |
|
83 |
||
84 |
AddFileLogRaw(Buffer); |
|
85 |
} |
|
86 |
||
7198
5debd5fe526e
1. Add IFDEFs for video recording
Stepan777 <stepik-777@mail.ru>
parents:
7180
diff
changeset
|
87 |
static void AddAudioStream() |
7180 | 88 |
{ |
7235
baa69bd025d9
1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
7198
diff
changeset
|
89 |
#if LIBAVFORMAT_VERSION_MAJOR >= 54 |
7180 | 90 |
g_pAStream = avformat_new_stream(g_pContainer, g_pACodec); |
91 |
#else |
|
92 |
g_pAStream = av_new_stream(g_pContainer, 1); |
|
93 |
#endif |
|
94 |
if(!g_pAStream) |
|
7280
fd707afbc3a2
pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents:
7235
diff
changeset
|
95 |
{ |
7306
3cff5c769509
Here they come - thumbnails.
Stepan777 <stepik-777@mail.ru>
parents:
7282
diff
changeset
|
96 |
Log("Could not allocate audio stream\n"); |
7280
fd707afbc3a2
pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents:
7235
diff
changeset
|
97 |
return; |
fd707afbc3a2
pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents:
7235
diff
changeset
|
98 |
} |
7180 | 99 |
g_pAStream->id = 1; |
100 |
||
101 |
g_pAudio = g_pAStream->codec; |
|
7198
5debd5fe526e
1. Add IFDEFs for video recording
Stepan777 <stepik-777@mail.ru>
parents:
7180
diff
changeset
|
102 |
|
7180 | 103 |
avcodec_get_context_defaults3(g_pAudio, g_pACodec); |
7198
5debd5fe526e
1. Add IFDEFs for video recording
Stepan777 <stepik-777@mail.ru>
parents:
7180
diff
changeset
|
104 |
g_pAudio->codec_id = g_pACodec->id; |
7180 | 105 |
|
106 |
// put parameters |
|
107 |
g_pAudio->sample_fmt = AV_SAMPLE_FMT_S16; |
|
108 |
g_pAudio->sample_rate = g_Frequency; |
|
109 |
g_pAudio->channels = g_Channels; |
|
110 |
||
7198
5debd5fe526e
1. Add IFDEFs for video recording
Stepan777 <stepik-777@mail.ru>
parents:
7180
diff
changeset
|
111 |
// set quality |
7376
48b79b3ca592
rework saving of camera positions so there is no need to know framerate during prerecording.
Stepan777 <stepik-777@mail.ru>
parents:
7359
diff
changeset
|
112 |
g_pAudio->bit_rate = 160000; |
48b79b3ca592
rework saving of camera positions so there is no need to know framerate during prerecording.
Stepan777 <stepik-777@mail.ru>
parents:
7359
diff
changeset
|
113 |
|
48b79b3ca592
rework saving of camera positions so there is no need to know framerate during prerecording.
Stepan777 <stepik-777@mail.ru>
parents:
7359
diff
changeset
|
114 |
// for codecs that support variable bitrate use it, it should be better |
48b79b3ca592
rework saving of camera positions so there is no need to know framerate during prerecording.
Stepan777 <stepik-777@mail.ru>
parents:
7359
diff
changeset
|
115 |
g_pAudio->flags |= CODEC_FLAG_QSCALE; |
48b79b3ca592
rework saving of camera positions so there is no need to know framerate during prerecording.
Stepan777 <stepik-777@mail.ru>
parents:
7359
diff
changeset
|
116 |
g_pAudio->global_quality = 1*FF_QP2LAMBDA; |
7198
5debd5fe526e
1. Add IFDEFs for video recording
Stepan777 <stepik-777@mail.ru>
parents:
7180
diff
changeset
|
117 |
|
7180 | 118 |
// some formats want stream headers to be separate |
119 |
if (g_pFormat->flags & AVFMT_GLOBALHEADER) |
|
120 |
g_pAudio->flags |= CODEC_FLAG_GLOBAL_HEADER; |
|
121 |
||
122 |
// open it |
|
7359
8bb4da06b065
Fix compilation of hwengine on ffmpeg 0.7.13.
Stepan777 <stepik-777@mail.ru>
parents:
7356
diff
changeset
|
123 |
#if LIBAVCODEC_VERSION_MAJOR >= 53 |
7180 | 124 |
if (avcodec_open2(g_pAudio, g_pACodec, NULL) < 0) |
7359
8bb4da06b065
Fix compilation of hwengine on ffmpeg 0.7.13.
Stepan777 <stepik-777@mail.ru>
parents:
7356
diff
changeset
|
125 |
#else |
8bb4da06b065
Fix compilation of hwengine on ffmpeg 0.7.13.
Stepan777 <stepik-777@mail.ru>
parents:
7356
diff
changeset
|
126 |
if (avcodec_open(g_pAudio, g_pACodec) < 0) |
8bb4da06b065
Fix compilation of hwengine on ffmpeg 0.7.13.
Stepan777 <stepik-777@mail.ru>
parents:
7356
diff
changeset
|
127 |
#endif |
7280
fd707afbc3a2
pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents:
7235
diff
changeset
|
128 |
{ |
7306
3cff5c769509
Here they come - thumbnails.
Stepan777 <stepik-777@mail.ru>
parents:
7282
diff
changeset
|
129 |
Log("Could not open audio codec %s\n", g_pACodec->long_name); |
7280
fd707afbc3a2
pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents:
7235
diff
changeset
|
130 |
return; |
fd707afbc3a2
pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents:
7235
diff
changeset
|
131 |
} |
7180 | 132 |
|
133 |
#if LIBAVCODEC_VERSION_MAJOR >= 54 |
|
134 |
if (g_pACodec->capabilities & CODEC_CAP_VARIABLE_FRAME_SIZE) |
|
135 |
#else |
|
136 |
if (g_pAudio->frame_size == 0) |
|
137 |
#endif |
|
138 |
g_NumSamples = 4096; |
|
139 |
else |
|
140 |
g_NumSamples = g_pAudio->frame_size; |
|
141 |
g_pSamples = (int16_t*)av_malloc(g_NumSamples*g_Channels*sizeof(int16_t)); |
|
142 |
g_pAFrame = avcodec_alloc_frame(); |
|
143 |
if (!g_pAFrame) |
|
7280
fd707afbc3a2
pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents:
7235
diff
changeset
|
144 |
{ |
7306
3cff5c769509
Here they come - thumbnails.
Stepan777 <stepik-777@mail.ru>
parents:
7282
diff
changeset
|
145 |
Log("Could not allocate frame\n"); |
7280
fd707afbc3a2
pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents:
7235
diff
changeset
|
146 |
return; |
fd707afbc3a2
pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents:
7235
diff
changeset
|
147 |
} |
7180 | 148 |
} |
149 |
||
150 |
// returns non-zero if there is more sound |
|
151 |
static int WriteAudioFrame() |
|
152 |
{ |
|
7198
5debd5fe526e
1. Add IFDEFs for video recording
Stepan777 <stepik-777@mail.ru>
parents:
7180
diff
changeset
|
153 |
if (!g_pAStream) |
5debd5fe526e
1. Add IFDEFs for video recording
Stepan777 <stepik-777@mail.ru>
parents:
7180
diff
changeset
|
154 |
return 0; |
5debd5fe526e
1. Add IFDEFs for video recording
Stepan777 <stepik-777@mail.ru>
parents:
7180
diff
changeset
|
155 |
|
7180 | 156 |
AVPacket Packet = { 0 }; |
157 |
av_init_packet(&Packet); |
|
158 |
||
159 |
int NumSamples = fread(g_pSamples, 2*g_Channels, g_NumSamples, g_pSoundFile); |
|
160 |
||
161 |
#if LIBAVCODEC_VERSION_MAJOR >= 54 |
|
162 |
AVFrame* pFrame = NULL; |
|
163 |
if (NumSamples > 0) |
|
164 |
{ |
|
165 |
g_pAFrame->nb_samples = NumSamples; |
|
166 |
avcodec_fill_audio_frame(g_pAFrame, g_Channels, AV_SAMPLE_FMT_S16, |
|
167 |
(uint8_t*)g_pSamples, NumSamples*2*g_Channels, 1); |
|
168 |
pFrame = g_pAFrame; |
|
169 |
} |
|
170 |
// when NumSamples == 0 we still need to call encode_audio2 to flush |
|
171 |
int got_packet; |
|
172 |
if (avcodec_encode_audio2(g_pAudio, &Packet, pFrame, &got_packet) != 0) |
|
173 |
FatalError("avcodec_encode_audio2 failed"); |
|
174 |
if (!got_packet) |
|
175 |
return 0; |
|
176 |
#else |
|
177 |
if (NumSamples == 0) |
|
178 |
return 0; |
|
179 |
int BufferSize = OUTBUFFER_SIZE; |
|
180 |
if (g_pAudio->frame_size == 0) |
|
181 |
BufferSize = NumSamples*g_Channels*2; |
|
182 |
Packet.size = avcodec_encode_audio(g_pAudio, g_OutBuffer, BufferSize, g_pSamples); |
|
183 |
if (Packet.size == 0) |
|
184 |
return 1; |
|
185 |
if (g_pAudio->coded_frame && g_pAudio->coded_frame->pts != AV_NOPTS_VALUE) |
|
186 |
Packet.pts = av_rescale_q(g_pAudio->coded_frame->pts, g_pAudio->time_base, g_pAStream->time_base); |
|
187 |
Packet.flags |= AV_PKT_FLAG_KEY; |
|
188 |
Packet.data = g_OutBuffer; |
|
189 |
#endif |
|
190 |
||
191 |
// Write the compressed frame to the media file. |
|
192 |
Packet.stream_index = g_pAStream->index; |
|
193 |
if (av_interleaved_write_frame(g_pContainer, &Packet) != 0) |
|
194 |
FatalError("Error while writing audio frame"); |
|
195 |
return 1; |
|
196 |
} |
|
197 |
||
198 |
// add a video output stream |
|
7198
5debd5fe526e
1. Add IFDEFs for video recording
Stepan777 <stepik-777@mail.ru>
parents:
7180
diff
changeset
|
199 |
static void AddVideoStream() |
7180 | 200 |
{ |
7235
baa69bd025d9
1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
7198
diff
changeset
|
201 |
#if LIBAVFORMAT_VERSION_MAJOR >= 54 |
7180 | 202 |
g_pVStream = avformat_new_stream(g_pContainer, g_pVCodec); |
203 |
#else |
|
204 |
g_pVStream = av_new_stream(g_pContainer, 0); |
|
205 |
#endif |
|
206 |
if (!g_pVStream) |
|
207 |
FatalError("Could not allocate video stream"); |
|
208 |
||
209 |
g_pVideo = g_pVStream->codec; |
|
7235
baa69bd025d9
1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
7198
diff
changeset
|
210 |
|
7198
5debd5fe526e
1. Add IFDEFs for video recording
Stepan777 <stepik-777@mail.ru>
parents:
7180
diff
changeset
|
211 |
avcodec_get_context_defaults3(g_pVideo, g_pVCodec); |
5debd5fe526e
1. Add IFDEFs for video recording
Stepan777 <stepik-777@mail.ru>
parents:
7180
diff
changeset
|
212 |
g_pVideo->codec_id = g_pVCodec->id; |
7180 | 213 |
|
214 |
// put parameters |
|
215 |
// resolution must be a multiple of two |
|
7282
c65992e2d794
correctly fix odd dimensions (it was incorrectly fixed in previous commit)
Stepan777 <stepik-777@mail.ru>
parents:
7280
diff
changeset
|
216 |
g_pVideo->width = g_Width & ~1; // make even (dimensions should be even) |
c65992e2d794
correctly fix odd dimensions (it was incorrectly fixed in previous commit)
Stepan777 <stepik-777@mail.ru>
parents:
7280
diff
changeset
|
217 |
g_pVideo->height = g_Height & ~1; // make even |
7180 | 218 |
/* time base: this is the fundamental unit of time (in seconds) in terms |
219 |
of which frame timestamps are represented. for fixed-fps content, |
|
220 |
timebase should be 1/framerate and timestamp increments should be |
|
221 |
identically 1. */ |
|
7198
5debd5fe526e
1. Add IFDEFs for video recording
Stepan777 <stepik-777@mail.ru>
parents:
7180
diff
changeset
|
222 |
g_pVideo->time_base.den = g_Framerate.num; |
5debd5fe526e
1. Add IFDEFs for video recording
Stepan777 <stepik-777@mail.ru>
parents:
7180
diff
changeset
|
223 |
g_pVideo->time_base.num = g_Framerate.den; |
7180 | 224 |
//g_pVideo->gop_size = 12; /* emit one intra frame every twelve frames at most */ |
225 |
g_pVideo->pix_fmt = PIX_FMT_YUV420P; |
|
226 |
||
7198
5debd5fe526e
1. Add IFDEFs for video recording
Stepan777 <stepik-777@mail.ru>
parents:
7180
diff
changeset
|
227 |
// set quality |
5debd5fe526e
1. Add IFDEFs for video recording
Stepan777 <stepik-777@mail.ru>
parents:
7180
diff
changeset
|
228 |
if (g_VQuality > 100) |
5debd5fe526e
1. Add IFDEFs for video recording
Stepan777 <stepik-777@mail.ru>
parents:
7180
diff
changeset
|
229 |
g_pVideo->bit_rate = g_VQuality; |
5debd5fe526e
1. Add IFDEFs for video recording
Stepan777 <stepik-777@mail.ru>
parents:
7180
diff
changeset
|
230 |
else |
5debd5fe526e
1. Add IFDEFs for video recording
Stepan777 <stepik-777@mail.ru>
parents:
7180
diff
changeset
|
231 |
{ |
5debd5fe526e
1. Add IFDEFs for video recording
Stepan777 <stepik-777@mail.ru>
parents:
7180
diff
changeset
|
232 |
g_pVideo->flags |= CODEC_FLAG_QSCALE; |
5debd5fe526e
1. Add IFDEFs for video recording
Stepan777 <stepik-777@mail.ru>
parents:
7180
diff
changeset
|
233 |
g_pVideo->global_quality = g_VQuality*FF_QP2LAMBDA; |
5debd5fe526e
1. Add IFDEFs for video recording
Stepan777 <stepik-777@mail.ru>
parents:
7180
diff
changeset
|
234 |
} |
5debd5fe526e
1. Add IFDEFs for video recording
Stepan777 <stepik-777@mail.ru>
parents:
7180
diff
changeset
|
235 |
|
7180 | 236 |
// some formats want stream headers to be separate |
237 |
if (g_pFormat->flags & AVFMT_GLOBALHEADER) |
|
238 |
g_pVideo->flags |= CODEC_FLAG_GLOBAL_HEADER; |
|
239 |
||
7376
48b79b3ca592
rework saving of camera positions so there is no need to know framerate during prerecording.
Stepan777 <stepik-777@mail.ru>
parents:
7359
diff
changeset
|
240 |
#if LIBAVCODEC_VERSION_MAJOR < 54 |
48b79b3ca592
rework saving of camera positions so there is no need to know framerate during prerecording.
Stepan777 <stepik-777@mail.ru>
parents:
7359
diff
changeset
|
241 |
// for some versions of ffmpeg x264 options must be set explicitly |
48b79b3ca592
rework saving of camera positions so there is no need to know framerate during prerecording.
Stepan777 <stepik-777@mail.ru>
parents:
7359
diff
changeset
|
242 |
if (strcmp(g_pVCodec->name, "libx264") == 0) |
48b79b3ca592
rework saving of camera positions so there is no need to know framerate during prerecording.
Stepan777 <stepik-777@mail.ru>
parents:
7359
diff
changeset
|
243 |
{ |
48b79b3ca592
rework saving of camera positions so there is no need to know framerate during prerecording.
Stepan777 <stepik-777@mail.ru>
parents:
7359
diff
changeset
|
244 |
g_pVideo->coder_type = FF_CODER_TYPE_AC; |
48b79b3ca592
rework saving of camera positions so there is no need to know framerate during prerecording.
Stepan777 <stepik-777@mail.ru>
parents:
7359
diff
changeset
|
245 |
g_pVideo->flags |= CODEC_FLAG_LOOP_FILTER; |
48b79b3ca592
rework saving of camera positions so there is no need to know framerate during prerecording.
Stepan777 <stepik-777@mail.ru>
parents:
7359
diff
changeset
|
246 |
g_pVideo->crf = 23; |
48b79b3ca592
rework saving of camera positions so there is no need to know framerate during prerecording.
Stepan777 <stepik-777@mail.ru>
parents:
7359
diff
changeset
|
247 |
g_pVideo->thread_count = 3; |
48b79b3ca592
rework saving of camera positions so there is no need to know framerate during prerecording.
Stepan777 <stepik-777@mail.ru>
parents:
7359
diff
changeset
|
248 |
g_pVideo->me_cmp = FF_CMP_CHROMA; |
48b79b3ca592
rework saving of camera positions so there is no need to know framerate during prerecording.
Stepan777 <stepik-777@mail.ru>
parents:
7359
diff
changeset
|
249 |
g_pVideo->partitions = X264_PART_I8X8 | X264_PART_I4X4 | X264_PART_P8X8 | X264_PART_B8X8; |
48b79b3ca592
rework saving of camera positions so there is no need to know framerate during prerecording.
Stepan777 <stepik-777@mail.ru>
parents:
7359
diff
changeset
|
250 |
g_pVideo->me_method = ME_HEX; |
48b79b3ca592
rework saving of camera positions so there is no need to know framerate during prerecording.
Stepan777 <stepik-777@mail.ru>
parents:
7359
diff
changeset
|
251 |
g_pVideo->me_subpel_quality = 7; |
48b79b3ca592
rework saving of camera positions so there is no need to know framerate during prerecording.
Stepan777 <stepik-777@mail.ru>
parents:
7359
diff
changeset
|
252 |
g_pVideo->me_range = 16; |
48b79b3ca592
rework saving of camera positions so there is no need to know framerate during prerecording.
Stepan777 <stepik-777@mail.ru>
parents:
7359
diff
changeset
|
253 |
g_pVideo->gop_size = 250; |
48b79b3ca592
rework saving of camera positions so there is no need to know framerate during prerecording.
Stepan777 <stepik-777@mail.ru>
parents:
7359
diff
changeset
|
254 |
g_pVideo->keyint_min = 25; |
48b79b3ca592
rework saving of camera positions so there is no need to know framerate during prerecording.
Stepan777 <stepik-777@mail.ru>
parents:
7359
diff
changeset
|
255 |
g_pVideo->scenechange_threshold = 40; |
48b79b3ca592
rework saving of camera positions so there is no need to know framerate during prerecording.
Stepan777 <stepik-777@mail.ru>
parents:
7359
diff
changeset
|
256 |
g_pVideo->i_quant_factor = 0.71; |
48b79b3ca592
rework saving of camera positions so there is no need to know framerate during prerecording.
Stepan777 <stepik-777@mail.ru>
parents:
7359
diff
changeset
|
257 |
g_pVideo->b_frame_strategy = 1; |
48b79b3ca592
rework saving of camera positions so there is no need to know framerate during prerecording.
Stepan777 <stepik-777@mail.ru>
parents:
7359
diff
changeset
|
258 |
g_pVideo->qcompress = 0.6; |
48b79b3ca592
rework saving of camera positions so there is no need to know framerate during prerecording.
Stepan777 <stepik-777@mail.ru>
parents:
7359
diff
changeset
|
259 |
g_pVideo->qmin = 10; |
48b79b3ca592
rework saving of camera positions so there is no need to know framerate during prerecording.
Stepan777 <stepik-777@mail.ru>
parents:
7359
diff
changeset
|
260 |
g_pVideo->qmax = 51; |
48b79b3ca592
rework saving of camera positions so there is no need to know framerate during prerecording.
Stepan777 <stepik-777@mail.ru>
parents:
7359
diff
changeset
|
261 |
g_pVideo->max_qdiff = 4; |
48b79b3ca592
rework saving of camera positions so there is no need to know framerate during prerecording.
Stepan777 <stepik-777@mail.ru>
parents:
7359
diff
changeset
|
262 |
g_pVideo->max_b_frames = 3; |
48b79b3ca592
rework saving of camera positions so there is no need to know framerate during prerecording.
Stepan777 <stepik-777@mail.ru>
parents:
7359
diff
changeset
|
263 |
g_pVideo->refs = 3; |
48b79b3ca592
rework saving of camera positions so there is no need to know framerate during prerecording.
Stepan777 <stepik-777@mail.ru>
parents:
7359
diff
changeset
|
264 |
g_pVideo->directpred = 1; |
48b79b3ca592
rework saving of camera positions so there is no need to know framerate during prerecording.
Stepan777 <stepik-777@mail.ru>
parents:
7359
diff
changeset
|
265 |
g_pVideo->trellis = 1; |
48b79b3ca592
rework saving of camera positions so there is no need to know framerate during prerecording.
Stepan777 <stepik-777@mail.ru>
parents:
7359
diff
changeset
|
266 |
g_pVideo->flags2 = CODEC_FLAG2_BPYRAMID | CODEC_FLAG2_MIXED_REFS | CODEC_FLAG2_WPRED | CODEC_FLAG2_8X8DCT | CODEC_FLAG2_FASTPSKIP; |
48b79b3ca592
rework saving of camera positions so there is no need to know framerate during prerecording.
Stepan777 <stepik-777@mail.ru>
parents:
7359
diff
changeset
|
267 |
g_pVideo->weighted_p_pred = 2; |
48b79b3ca592
rework saving of camera positions so there is no need to know framerate during prerecording.
Stepan777 <stepik-777@mail.ru>
parents:
7359
diff
changeset
|
268 |
} |
48b79b3ca592
rework saving of camera positions so there is no need to know framerate during prerecording.
Stepan777 <stepik-777@mail.ru>
parents:
7359
diff
changeset
|
269 |
#endif |
48b79b3ca592
rework saving of camera positions so there is no need to know framerate during prerecording.
Stepan777 <stepik-777@mail.ru>
parents:
7359
diff
changeset
|
270 |
|
7180 | 271 |
// open the codec |
7359
8bb4da06b065
Fix compilation of hwengine on ffmpeg 0.7.13.
Stepan777 <stepik-777@mail.ru>
parents:
7356
diff
changeset
|
272 |
#if LIBAVCODEC_VERSION_MAJOR >= 53 |
8bb4da06b065
Fix compilation of hwengine on ffmpeg 0.7.13.
Stepan777 <stepik-777@mail.ru>
parents:
7356
diff
changeset
|
273 |
AVDictionary* pDict = NULL; |
8bb4da06b065
Fix compilation of hwengine on ffmpeg 0.7.13.
Stepan777 <stepik-777@mail.ru>
parents:
7356
diff
changeset
|
274 |
if (strcmp(g_pVCodec->name, "libx264") == 0) |
7376
48b79b3ca592
rework saving of camera positions so there is no need to know framerate during prerecording.
Stepan777 <stepik-777@mail.ru>
parents:
7359
diff
changeset
|
275 |
av_dict_set(&pDict, "preset", "medium", 0); |
7359
8bb4da06b065
Fix compilation of hwengine on ffmpeg 0.7.13.
Stepan777 <stepik-777@mail.ru>
parents:
7356
diff
changeset
|
276 |
|
7180 | 277 |
if (avcodec_open2(g_pVideo, g_pVCodec, &pDict) < 0) |
7359
8bb4da06b065
Fix compilation of hwengine on ffmpeg 0.7.13.
Stepan777 <stepik-777@mail.ru>
parents:
7356
diff
changeset
|
278 |
#else |
8bb4da06b065
Fix compilation of hwengine on ffmpeg 0.7.13.
Stepan777 <stepik-777@mail.ru>
parents:
7356
diff
changeset
|
279 |
if (avcodec_open(g_pVideo, g_pVCodec) < 0) |
8bb4da06b065
Fix compilation of hwengine on ffmpeg 0.7.13.
Stepan777 <stepik-777@mail.ru>
parents:
7356
diff
changeset
|
280 |
#endif |
7180 | 281 |
FatalError("Could not open video codec %s", g_pVCodec->long_name); |
282 |
||
283 |
g_pVFrame = avcodec_alloc_frame(); |
|
284 |
if (!g_pVFrame) |
|
285 |
FatalError("Could not allocate frame"); |
|
286 |
||
287 |
g_pVFrame->linesize[0] = g_Width; |
|
288 |
g_pVFrame->linesize[1] = g_Width/2; |
|
289 |
g_pVFrame->linesize[2] = g_Width/2; |
|
290 |
g_pVFrame->linesize[3] = 0; |
|
291 |
} |
|
292 |
||
7280
fd707afbc3a2
pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents:
7235
diff
changeset
|
293 |
static int WriteFrame(AVFrame* pFrame) |
7180 | 294 |
{ |
295 |
double AudioTime, VideoTime; |
|
296 |
||
297 |
// write interleaved audio frame |
|
298 |
if (g_pAStream) |
|
299 |
{ |
|
300 |
VideoTime = (double)g_pVStream->pts.val*g_pVStream->time_base.num/g_pVStream->time_base.den; |
|
301 |
do |
|
302 |
AudioTime = (double)g_pAStream->pts.val*g_pAStream->time_base.num/g_pAStream->time_base.den; |
|
303 |
while (AudioTime < VideoTime && WriteAudioFrame()); |
|
304 |
} |
|
7198
5debd5fe526e
1. Add IFDEFs for video recording
Stepan777 <stepik-777@mail.ru>
parents:
7180
diff
changeset
|
305 |
|
5debd5fe526e
1. Add IFDEFs for video recording
Stepan777 <stepik-777@mail.ru>
parents:
7180
diff
changeset
|
306 |
if (!g_pVStream) |
5debd5fe526e
1. Add IFDEFs for video recording
Stepan777 <stepik-777@mail.ru>
parents:
7180
diff
changeset
|
307 |
return 0; |
7180 | 308 |
|
309 |
AVPacket Packet; |
|
310 |
av_init_packet(&Packet); |
|
311 |
Packet.data = NULL; |
|
312 |
Packet.size = 0; |
|
313 |
||
314 |
g_pVFrame->pts++; |
|
315 |
if (g_pFormat->flags & AVFMT_RAWPICTURE) |
|
316 |
{ |
|
317 |
/* raw video case. The API will change slightly in the near |
|
318 |
future for that. */ |
|
319 |
Packet.flags |= AV_PKT_FLAG_KEY; |
|
320 |
Packet.stream_index = g_pVStream->index; |
|
321 |
Packet.data = (uint8_t*)pFrame; |
|
322 |
Packet.size = sizeof(AVPicture); |
|
323 |
||
324 |
if (av_interleaved_write_frame(g_pContainer, &Packet) != 0) |
|
325 |
FatalError("Error while writing video frame"); |
|
326 |
return 0; |
|
327 |
} |
|
328 |
else |
|
329 |
{ |
|
330 |
#if LIBAVCODEC_VERSION_MAJOR >= 54 |
|
331 |
int got_packet; |
|
332 |
if (avcodec_encode_video2(g_pVideo, &Packet, pFrame, &got_packet) < 0) |
|
333 |
FatalError("avcodec_encode_video2 failed"); |
|
334 |
if (!got_packet) |
|
335 |
return 0; |
|
336 |
||
337 |
if (Packet.pts != AV_NOPTS_VALUE) |
|
338 |
Packet.pts = av_rescale_q(Packet.pts, g_pVideo->time_base, g_pVStream->time_base); |
|
339 |
if (Packet.dts != AV_NOPTS_VALUE) |
|
340 |
Packet.dts = av_rescale_q(Packet.dts, g_pVideo->time_base, g_pVStream->time_base); |
|
341 |
#else |
|
342 |
Packet.size = avcodec_encode_video(g_pVideo, g_OutBuffer, OUTBUFFER_SIZE, pFrame); |
|
343 |
if (Packet.size < 0) |
|
344 |
FatalError("avcodec_encode_video failed"); |
|
345 |
if (Packet.size == 0) |
|
346 |
return 0; |
|
347 |
||
348 |
if( g_pVideo->coded_frame->pts != AV_NOPTS_VALUE) |
|
349 |
Packet.pts = av_rescale_q(g_pVideo->coded_frame->pts, g_pVideo->time_base, g_pVStream->time_base); |
|
350 |
if( g_pVideo->coded_frame->key_frame ) |
|
351 |
Packet.flags |= AV_PKT_FLAG_KEY; |
|
352 |
Packet.data = g_OutBuffer; |
|
353 |
#endif |
|
354 |
// write the compressed frame in the media file |
|
355 |
Packet.stream_index = g_pVStream->index; |
|
356 |
if (av_interleaved_write_frame(g_pContainer, &Packet) != 0) |
|
357 |
FatalError("Error while writing video frame"); |
|
358 |
||
359 |
return 1; |
|
360 |
} |
|
361 |
} |
|
362 |
||
363 |
void AVWrapper_WriteFrame(uint8_t* pY, uint8_t* pCb, uint8_t* pCr) |
|
364 |
{ |
|
365 |
g_pVFrame->data[0] = pY; |
|
366 |
g_pVFrame->data[1] = pCb; |
|
367 |
g_pVFrame->data[2] = pCr; |
|
368 |
WriteFrame(g_pVFrame); |
|
369 |
} |
|
370 |
||
7198
5debd5fe526e
1. Add IFDEFs for video recording
Stepan777 <stepik-777@mail.ru>
parents:
7180
diff
changeset
|
371 |
void AVWrapper_Init( |
5debd5fe526e
1. Add IFDEFs for video recording
Stepan777 <stepik-777@mail.ru>
parents:
7180
diff
changeset
|
372 |
void (*pAddFileLogRaw)(const char*), |
5debd5fe526e
1. Add IFDEFs for video recording
Stepan777 <stepik-777@mail.ru>
parents:
7180
diff
changeset
|
373 |
const char* pFilename, |
7280
fd707afbc3a2
pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents:
7235
diff
changeset
|
374 |
const char* pDesc, |
7198
5debd5fe526e
1. Add IFDEFs for video recording
Stepan777 <stepik-777@mail.ru>
parents:
7180
diff
changeset
|
375 |
const char* pSoundFile, |
5debd5fe526e
1. Add IFDEFs for video recording
Stepan777 <stepik-777@mail.ru>
parents:
7180
diff
changeset
|
376 |
const char* pFormatName, |
5debd5fe526e
1. Add IFDEFs for video recording
Stepan777 <stepik-777@mail.ru>
parents:
7180
diff
changeset
|
377 |
const char* pVCodecName, |
5debd5fe526e
1. Add IFDEFs for video recording
Stepan777 <stepik-777@mail.ru>
parents:
7180
diff
changeset
|
378 |
const char* pACodecName, |
5debd5fe526e
1. Add IFDEFs for video recording
Stepan777 <stepik-777@mail.ru>
parents:
7180
diff
changeset
|
379 |
int Width, int Height, |
5debd5fe526e
1. Add IFDEFs for video recording
Stepan777 <stepik-777@mail.ru>
parents:
7180
diff
changeset
|
380 |
int FramerateNum, int FramerateDen, |
7376
48b79b3ca592
rework saving of camera positions so there is no need to know framerate during prerecording.
Stepan777 <stepik-777@mail.ru>
parents:
7359
diff
changeset
|
381 |
int VQuality) |
7180 | 382 |
{ |
383 |
AddFileLogRaw = pAddFileLogRaw; |
|
384 |
av_log_set_callback( &LogCallback ); |
|
385 |
||
7282
c65992e2d794
correctly fix odd dimensions (it was incorrectly fixed in previous commit)
Stepan777 <stepik-777@mail.ru>
parents:
7280
diff
changeset
|
386 |
g_Width = Width; |
c65992e2d794
correctly fix odd dimensions (it was incorrectly fixed in previous commit)
Stepan777 <stepik-777@mail.ru>
parents:
7280
diff
changeset
|
387 |
g_Height = Height; |
7198
5debd5fe526e
1. Add IFDEFs for video recording
Stepan777 <stepik-777@mail.ru>
parents:
7180
diff
changeset
|
388 |
g_Framerate.num = FramerateNum; |
5debd5fe526e
1. Add IFDEFs for video recording
Stepan777 <stepik-777@mail.ru>
parents:
7180
diff
changeset
|
389 |
g_Framerate.den = FramerateDen; |
5debd5fe526e
1. Add IFDEFs for video recording
Stepan777 <stepik-777@mail.ru>
parents:
7180
diff
changeset
|
390 |
g_VQuality = VQuality; |
7180 | 391 |
|
392 |
// initialize libav and register all codecs and formats |
|
393 |
av_register_all(); |
|
394 |
||
7198
5debd5fe526e
1. Add IFDEFs for video recording
Stepan777 <stepik-777@mail.ru>
parents:
7180
diff
changeset
|
395 |
// find format |
5debd5fe526e
1. Add IFDEFs for video recording
Stepan777 <stepik-777@mail.ru>
parents:
7180
diff
changeset
|
396 |
g_pFormat = av_guess_format(pFormatName, NULL, NULL); |
7180 | 397 |
if (!g_pFormat) |
7198
5debd5fe526e
1. Add IFDEFs for video recording
Stepan777 <stepik-777@mail.ru>
parents:
7180
diff
changeset
|
398 |
FatalError("Format \"%s\" was not found", pFormatName); |
7180 | 399 |
|
400 |
// allocate the output media context |
|
401 |
g_pContainer = avformat_alloc_context(); |
|
402 |
if (!g_pContainer) |
|
403 |
FatalError("Could not allocate output context"); |
|
404 |
||
7198
5debd5fe526e
1. Add IFDEFs for video recording
Stepan777 <stepik-777@mail.ru>
parents:
7180
diff
changeset
|
405 |
g_pContainer->oformat = g_pFormat; |
7180 | 406 |
|
7280
fd707afbc3a2
pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents:
7235
diff
changeset
|
407 |
// store description of file |
fd707afbc3a2
pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents:
7235
diff
changeset
|
408 |
av_dict_set(&g_pContainer->metadata, "comment", pDesc, 0); |
fd707afbc3a2
pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents:
7235
diff
changeset
|
409 |
|
7198
5debd5fe526e
1. Add IFDEFs for video recording
Stepan777 <stepik-777@mail.ru>
parents:
7180
diff
changeset
|
410 |
// append extesnion to filename |
7235
baa69bd025d9
1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
7198
diff
changeset
|
411 |
char ext[16]; |
baa69bd025d9
1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
7198
diff
changeset
|
412 |
strncpy(ext, g_pFormat->extensions, 16); |
baa69bd025d9
1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
7198
diff
changeset
|
413 |
ext[15] = 0; |
baa69bd025d9
1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
7198
diff
changeset
|
414 |
ext[strcspn(ext,",")] = 0; |
baa69bd025d9
1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
7198
diff
changeset
|
415 |
snprintf(g_pContainer->filename, sizeof(g_pContainer->filename), "%s.%s", pFilename, ext); |
7180 | 416 |
|
7198
5debd5fe526e
1. Add IFDEFs for video recording
Stepan777 <stepik-777@mail.ru>
parents:
7180
diff
changeset
|
417 |
// find codecs |
5debd5fe526e
1. Add IFDEFs for video recording
Stepan777 <stepik-777@mail.ru>
parents:
7180
diff
changeset
|
418 |
g_pVCodec = avcodec_find_encoder_by_name(pVCodecName); |
5debd5fe526e
1. Add IFDEFs for video recording
Stepan777 <stepik-777@mail.ru>
parents:
7180
diff
changeset
|
419 |
g_pACodec = avcodec_find_encoder_by_name(pACodecName); |
5debd5fe526e
1. Add IFDEFs for video recording
Stepan777 <stepik-777@mail.ru>
parents:
7180
diff
changeset
|
420 |
|
5debd5fe526e
1. Add IFDEFs for video recording
Stepan777 <stepik-777@mail.ru>
parents:
7180
diff
changeset
|
421 |
// add audio and video stream to container |
7180 | 422 |
g_pVStream = NULL; |
423 |
g_pAStream = NULL; |
|
7198
5debd5fe526e
1. Add IFDEFs for video recording
Stepan777 <stepik-777@mail.ru>
parents:
7180
diff
changeset
|
424 |
|
5debd5fe526e
1. Add IFDEFs for video recording
Stepan777 <stepik-777@mail.ru>
parents:
7180
diff
changeset
|
425 |
if (g_pVCodec) |
5debd5fe526e
1. Add IFDEFs for video recording
Stepan777 <stepik-777@mail.ru>
parents:
7180
diff
changeset
|
426 |
AddVideoStream(); |
5debd5fe526e
1. Add IFDEFs for video recording
Stepan777 <stepik-777@mail.ru>
parents:
7180
diff
changeset
|
427 |
else |
5debd5fe526e
1. Add IFDEFs for video recording
Stepan777 <stepik-777@mail.ru>
parents:
7180
diff
changeset
|
428 |
Log("Video codec \"%s\" was not found; video will be ignored.\n", pVCodecName); |
7180 | 429 |
|
7198
5debd5fe526e
1. Add IFDEFs for video recording
Stepan777 <stepik-777@mail.ru>
parents:
7180
diff
changeset
|
430 |
if (g_pACodec) |
7280
fd707afbc3a2
pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents:
7235
diff
changeset
|
431 |
{ |
fd707afbc3a2
pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents:
7235
diff
changeset
|
432 |
g_pSoundFile = fopen(pSoundFile, "rb"); |
fd707afbc3a2
pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents:
7235
diff
changeset
|
433 |
if (g_pSoundFile) |
fd707afbc3a2
pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents:
7235
diff
changeset
|
434 |
{ |
fd707afbc3a2
pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents:
7235
diff
changeset
|
435 |
fread(&g_Frequency, 4, 1, g_pSoundFile); |
fd707afbc3a2
pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents:
7235
diff
changeset
|
436 |
fread(&g_Channels, 4, 1, g_pSoundFile); |
fd707afbc3a2
pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents:
7235
diff
changeset
|
437 |
AddAudioStream(); |
fd707afbc3a2
pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents:
7235
diff
changeset
|
438 |
} |
fd707afbc3a2
pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents:
7235
diff
changeset
|
439 |
else |
7306
3cff5c769509
Here they come - thumbnails.
Stepan777 <stepik-777@mail.ru>
parents:
7282
diff
changeset
|
440 |
Log("Could not open %s\n", pSoundFile); |
7280
fd707afbc3a2
pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents:
7235
diff
changeset
|
441 |
} |
7198
5debd5fe526e
1. Add IFDEFs for video recording
Stepan777 <stepik-777@mail.ru>
parents:
7180
diff
changeset
|
442 |
else |
5debd5fe526e
1. Add IFDEFs for video recording
Stepan777 <stepik-777@mail.ru>
parents:
7180
diff
changeset
|
443 |
Log("Audio codec \"%s\" was not found; audio will be ignored.\n", pACodecName); |
5debd5fe526e
1. Add IFDEFs for video recording
Stepan777 <stepik-777@mail.ru>
parents:
7180
diff
changeset
|
444 |
|
5debd5fe526e
1. Add IFDEFs for video recording
Stepan777 <stepik-777@mail.ru>
parents:
7180
diff
changeset
|
445 |
if (!g_pAStream && !g_pVStream) |
5debd5fe526e
1. Add IFDEFs for video recording
Stepan777 <stepik-777@mail.ru>
parents:
7180
diff
changeset
|
446 |
FatalError("No video, no audio, aborting..."); |
7180 | 447 |
|
448 |
// write format info to log |
|
7198
5debd5fe526e
1. Add IFDEFs for video recording
Stepan777 <stepik-777@mail.ru>
parents:
7180
diff
changeset
|
449 |
av_dump_format(g_pContainer, 0, g_pContainer->filename, 1); |
7180 | 450 |
|
451 |
// open the output file, if needed |
|
452 |
if (!(g_pFormat->flags & AVFMT_NOFILE)) |
|
453 |
{ |
|
7198
5debd5fe526e
1. Add IFDEFs for video recording
Stepan777 <stepik-777@mail.ru>
parents:
7180
diff
changeset
|
454 |
if (avio_open(&g_pContainer->pb, g_pContainer->filename, AVIO_FLAG_WRITE) < 0) |
7306
3cff5c769509
Here they come - thumbnails.
Stepan777 <stepik-777@mail.ru>
parents:
7282
diff
changeset
|
455 |
FatalError("Could not open output file (%s)", g_pContainer->filename); |
7180 | 456 |
} |
457 |
||
458 |
// write the stream header, if any |
|
459 |
avformat_write_header(g_pContainer, NULL); |
|
7198
5debd5fe526e
1. Add IFDEFs for video recording
Stepan777 <stepik-777@mail.ru>
parents:
7180
diff
changeset
|
460 |
|
7180 | 461 |
g_pVFrame->pts = -1; |
462 |
} |
|
463 |
||
464 |
void AVWrapper_Close() |
|
465 |
{ |
|
466 |
// output buffered frames |
|
467 |
if (g_pVCodec->capabilities & CODEC_CAP_DELAY) |
|
468 |
while( WriteFrame(NULL) ); |
|
469 |
// output any remaining audio |
|
470 |
while( WriteAudioFrame() ); |
|
471 |
||
472 |
// write the trailer, if any. |
|
473 |
av_write_trailer(g_pContainer); |
|
474 |
||
7198
5debd5fe526e
1. Add IFDEFs for video recording
Stepan777 <stepik-777@mail.ru>
parents:
7180
diff
changeset
|
475 |
// close the output file |
5debd5fe526e
1. Add IFDEFs for video recording
Stepan777 <stepik-777@mail.ru>
parents:
7180
diff
changeset
|
476 |
if (!(g_pFormat->flags & AVFMT_NOFILE)) |
5debd5fe526e
1. Add IFDEFs for video recording
Stepan777 <stepik-777@mail.ru>
parents:
7180
diff
changeset
|
477 |
avio_close(g_pContainer->pb); |
5debd5fe526e
1. Add IFDEFs for video recording
Stepan777 <stepik-777@mail.ru>
parents:
7180
diff
changeset
|
478 |
|
5debd5fe526e
1. Add IFDEFs for video recording
Stepan777 <stepik-777@mail.ru>
parents:
7180
diff
changeset
|
479 |
// free everything |
5debd5fe526e
1. Add IFDEFs for video recording
Stepan777 <stepik-777@mail.ru>
parents:
7180
diff
changeset
|
480 |
if (g_pVStream) |
7180 | 481 |
{ |
7198
5debd5fe526e
1. Add IFDEFs for video recording
Stepan777 <stepik-777@mail.ru>
parents:
7180
diff
changeset
|
482 |
avcodec_close(g_pVideo); |
5debd5fe526e
1. Add IFDEFs for video recording
Stepan777 <stepik-777@mail.ru>
parents:
7180
diff
changeset
|
483 |
av_free(g_pVideo); |
5debd5fe526e
1. Add IFDEFs for video recording
Stepan777 <stepik-777@mail.ru>
parents:
7180
diff
changeset
|
484 |
av_free(g_pVStream); |
7180 | 485 |
av_free(g_pVFrame); |
486 |
} |
|
7198
5debd5fe526e
1. Add IFDEFs for video recording
Stepan777 <stepik-777@mail.ru>
parents:
7180
diff
changeset
|
487 |
if (g_pAStream) |
7180 | 488 |
{ |
7198
5debd5fe526e
1. Add IFDEFs for video recording
Stepan777 <stepik-777@mail.ru>
parents:
7180
diff
changeset
|
489 |
avcodec_close(g_pAudio); |
5debd5fe526e
1. Add IFDEFs for video recording
Stepan777 <stepik-777@mail.ru>
parents:
7180
diff
changeset
|
490 |
av_free(g_pAudio); |
5debd5fe526e
1. Add IFDEFs for video recording
Stepan777 <stepik-777@mail.ru>
parents:
7180
diff
changeset
|
491 |
av_free(g_pAStream); |
7180 | 492 |
av_free(g_pAFrame); |
493 |
av_free(g_pSamples); |
|
494 |
fclose(g_pSoundFile); |
|
495 |
} |
|
496 |
||
497 |
av_free(g_pContainer); |
|
498 |
} |