author | koda |
Mon, 16 Nov 2015 13:59:04 +0100 | |
branch | 0.9.22 |
changeset 11601 | 1b58732e0dd7 |
parent 11599 | 49c82c3e3836 |
child 11602 | 1a57b0d4cc4e |
permissions | -rw-r--r-- |
7542
37ef1891efe2
Insert license in avwrapper.c
Stepan777 <stepik-777@mail.ru>
parents:
7376
diff
changeset
|
1 |
/* |
37ef1891efe2
Insert license in avwrapper.c
Stepan777 <stepik-777@mail.ru>
parents:
7376
diff
changeset
|
2 |
* Hedgewars, a free turn based strategy game |
11046 | 3 |
* Copyright (c) 2004-2015 Andrey Korotaev <unC0Rr@gmail.com> |
7542
37ef1891efe2
Insert license in avwrapper.c
Stepan777 <stepik-777@mail.ru>
parents:
7376
diff
changeset
|
4 |
* |
37ef1891efe2
Insert license in avwrapper.c
Stepan777 <stepik-777@mail.ru>
parents:
7376
diff
changeset
|
5 |
* This program is free software; you can redistribute it and/or modify |
37ef1891efe2
Insert license in avwrapper.c
Stepan777 <stepik-777@mail.ru>
parents:
7376
diff
changeset
|
6 |
* it under the terms of the GNU General Public License as published by |
37ef1891efe2
Insert license in avwrapper.c
Stepan777 <stepik-777@mail.ru>
parents:
7376
diff
changeset
|
7 |
* the Free Software Foundation; version 2 of the License |
37ef1891efe2
Insert license in avwrapper.c
Stepan777 <stepik-777@mail.ru>
parents:
7376
diff
changeset
|
8 |
* |
37ef1891efe2
Insert license in avwrapper.c
Stepan777 <stepik-777@mail.ru>
parents:
7376
diff
changeset
|
9 |
* This program is distributed in the hope that it will be useful, |
37ef1891efe2
Insert license in avwrapper.c
Stepan777 <stepik-777@mail.ru>
parents:
7376
diff
changeset
|
10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
37ef1891efe2
Insert license in avwrapper.c
Stepan777 <stepik-777@mail.ru>
parents:
7376
diff
changeset
|
11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
37ef1891efe2
Insert license in avwrapper.c
Stepan777 <stepik-777@mail.ru>
parents:
7376
diff
changeset
|
12 |
* GNU General Public License for more details. |
37ef1891efe2
Insert license in avwrapper.c
Stepan777 <stepik-777@mail.ru>
parents:
7376
diff
changeset
|
13 |
* |
37ef1891efe2
Insert license in avwrapper.c
Stepan777 <stepik-777@mail.ru>
parents:
7376
diff
changeset
|
14 |
* You should have received a copy of the GNU General Public License |
37ef1891efe2
Insert license in avwrapper.c
Stepan777 <stepik-777@mail.ru>
parents:
7376
diff
changeset
|
15 |
* along with this program; if not, write to the Free Software |
10108
c68cf030eded
update FSF address. note: two sdl include files (by Sam Lantinga) still have the old FSF address in their copyright - but I ain't gonna touch their copyright headers
sheepluva
parents:
9998
diff
changeset
|
16 |
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
7542
37ef1891efe2
Insert license in avwrapper.c
Stepan777 <stepik-777@mail.ru>
parents:
7376
diff
changeset
|
17 |
*/ |
7180 | 18 |
|
19 |
#include <stdlib.h> |
|
20 |
#include <stdio.h> |
|
7280
fd707afbc3a2
pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents:
7235
diff
changeset
|
21 |
#include <stdint.h> |
7180 | 22 |
#include <string.h> |
23 |
#include <stdarg.h> |
|
11295
210650fc7182
Update libav API, keeping forward and backward compatibility
Vittorio Giovara <vittorio.giovara@gmail.com>
parents:
11046
diff
changeset
|
24 |
|
210650fc7182
Update libav API, keeping forward and backward compatibility
Vittorio Giovara <vittorio.giovara@gmail.com>
parents:
11046
diff
changeset
|
25 |
#include "libavcodec/avcodec.h" |
7180 | 26 |
#include "libavformat/avformat.h" |
11295
210650fc7182
Update libav API, keeping forward and backward compatibility
Vittorio Giovara <vittorio.giovara@gmail.com>
parents:
11046
diff
changeset
|
27 |
#include "libavutil/avutil.h" |
8065 | 28 |
#include "libavutil/mathematics.h" |
7180 | 29 |
|
9203
bcc25cb9b122
and now also avwrapper can be shared/static, add visibility to its exported functions, drop (needed only when static)
koda
parents:
9080
diff
changeset
|
30 |
#if (defined _MSC_VER) |
bcc25cb9b122
and now also avwrapper can be shared/static, add visibility to its exported functions, drop (needed only when static)
koda
parents:
9080
diff
changeset
|
31 |
#define AVWRAP_DECL __declspec(dllexport) |
bcc25cb9b122
and now also avwrapper can be shared/static, add visibility to its exported functions, drop (needed only when static)
koda
parents:
9080
diff
changeset
|
32 |
#elif ((__GNUC__ >= 3) && (!__EMX__) && (!sun)) |
bcc25cb9b122
and now also avwrapper can be shared/static, add visibility to its exported functions, drop (needed only when static)
koda
parents:
9080
diff
changeset
|
33 |
#define AVWRAP_DECL __attribute__((visibility("default"))) |
bcc25cb9b122
and now also avwrapper can be shared/static, add visibility to its exported functions, drop (needed only when static)
koda
parents:
9080
diff
changeset
|
34 |
#else |
bcc25cb9b122
and now also avwrapper can be shared/static, add visibility to its exported functions, drop (needed only when static)
koda
parents:
9080
diff
changeset
|
35 |
#define AVWRAP_DECL |
bcc25cb9b122
and now also avwrapper can be shared/static, add visibility to its exported functions, drop (needed only when static)
koda
parents:
9080
diff
changeset
|
36 |
#endif |
bcc25cb9b122
and now also avwrapper can be shared/static, add visibility to its exported functions, drop (needed only when static)
koda
parents:
9080
diff
changeset
|
37 |
|
7180 | 38 |
static AVFormatContext* g_pContainer; |
39 |
static AVOutputFormat* g_pFormat; |
|
40 |
static AVStream* g_pAStream; |
|
41 |
static AVStream* g_pVStream; |
|
42 |
static AVFrame* g_pAFrame; |
|
43 |
static AVFrame* g_pVFrame; |
|
44 |
static AVCodec* g_pACodec; |
|
45 |
static AVCodec* g_pVCodec; |
|
46 |
static AVCodecContext* g_pAudio; |
|
47 |
static AVCodecContext* g_pVideo; |
|
48 |
||
7198
5debd5fe526e
1. Add IFDEFs for video recording
Stepan777 <stepik-777@mail.ru>
parents:
7180
diff
changeset
|
49 |
static int g_Width, g_Height; |
7280
fd707afbc3a2
pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents:
7235
diff
changeset
|
50 |
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
|
51 |
static int g_VQuality; |
7198
5debd5fe526e
1. Add IFDEFs for video recording
Stepan777 <stepik-777@mail.ru>
parents:
7180
diff
changeset
|
52 |
static AVRational g_Framerate; |
7180 | 53 |
|
54 |
static FILE* g_pSoundFile; |
|
55 |
static int16_t* g_pSamples; |
|
56 |
static int g_NumSamples; |
|
57 |
||
58 |
||
11295
210650fc7182
Update libav API, keeping forward and backward compatibility
Vittorio Giovara <vittorio.giovara@gmail.com>
parents:
11046
diff
changeset
|
59 |
// compatibility section |
7180 | 60 |
#if LIBAVCODEC_VERSION_MAJOR < 54 |
61 |
#define OUTBUFFER_SIZE 200000 |
|
62 |
static uint8_t g_OutBuffer[OUTBUFFER_SIZE]; |
|
11295
210650fc7182
Update libav API, keeping forward and backward compatibility
Vittorio Giovara <vittorio.giovara@gmail.com>
parents:
11046
diff
changeset
|
63 |
#define avcodec_open2(x, y, z) avcodec_open(x, y) |
7180 | 64 |
#endif |
65 |
||
11295
210650fc7182
Update libav API, keeping forward and backward compatibility
Vittorio Giovara <vittorio.giovara@gmail.com>
parents:
11046
diff
changeset
|
66 |
#if LIBAVCODEC_VERSION_MAJOR < 56 |
210650fc7182
Update libav API, keeping forward and backward compatibility
Vittorio Giovara <vittorio.giovara@gmail.com>
parents:
11046
diff
changeset
|
67 |
#define av_frame_alloc avcodec_alloc_frame |
210650fc7182
Update libav API, keeping forward and backward compatibility
Vittorio Giovara <vittorio.giovara@gmail.com>
parents:
11046
diff
changeset
|
68 |
#define av_frame_free av_freep |
11597
4575b6990348
videorec: Appropriately rescale timestamps and duration
Vittorio Giovara <vittorio.giovara@gmail.com>
parents:
11596
diff
changeset
|
69 |
#define av_packet_rescale_ts rescale_ts |
4575b6990348
videorec: Appropriately rescale timestamps and duration
Vittorio Giovara <vittorio.giovara@gmail.com>
parents:
11596
diff
changeset
|
70 |
|
4575b6990348
videorec: Appropriately rescale timestamps and duration
Vittorio Giovara <vittorio.giovara@gmail.com>
parents:
11596
diff
changeset
|
71 |
static void rescale_ts(AVPacket *pkt, AVRational ctb, AVRational stb) |
4575b6990348
videorec: Appropriately rescale timestamps and duration
Vittorio Giovara <vittorio.giovara@gmail.com>
parents:
11596
diff
changeset
|
72 |
{ |
4575b6990348
videorec: Appropriately rescale timestamps and duration
Vittorio Giovara <vittorio.giovara@gmail.com>
parents:
11596
diff
changeset
|
73 |
if (pkt->pts != AV_NOPTS_VALUE) |
4575b6990348
videorec: Appropriately rescale timestamps and duration
Vittorio Giovara <vittorio.giovara@gmail.com>
parents:
11596
diff
changeset
|
74 |
pkt->pts = av_rescale_q(pkt->pts, ctb, stb); |
4575b6990348
videorec: Appropriately rescale timestamps and duration
Vittorio Giovara <vittorio.giovara@gmail.com>
parents:
11596
diff
changeset
|
75 |
if (pkt->dts != AV_NOPTS_VALUE) |
4575b6990348
videorec: Appropriately rescale timestamps and duration
Vittorio Giovara <vittorio.giovara@gmail.com>
parents:
11596
diff
changeset
|
76 |
pkt->dts = av_rescale_q(pkt->dts, ctb, stb); |
4575b6990348
videorec: Appropriately rescale timestamps and duration
Vittorio Giovara <vittorio.giovara@gmail.com>
parents:
11596
diff
changeset
|
77 |
if (pkt->duration > 0) |
4575b6990348
videorec: Appropriately rescale timestamps and duration
Vittorio Giovara <vittorio.giovara@gmail.com>
parents:
11596
diff
changeset
|
78 |
pkt->duration = av_rescale_q(pkt->duration, ctb, stb); |
4575b6990348
videorec: Appropriately rescale timestamps and duration
Vittorio Giovara <vittorio.giovara@gmail.com>
parents:
11596
diff
changeset
|
79 |
} |
11295
210650fc7182
Update libav API, keeping forward and backward compatibility
Vittorio Giovara <vittorio.giovara@gmail.com>
parents:
11046
diff
changeset
|
80 |
#endif |
210650fc7182
Update libav API, keeping forward and backward compatibility
Vittorio Giovara <vittorio.giovara@gmail.com>
parents:
11046
diff
changeset
|
81 |
|
11601 | 82 |
#if LIBAVCODEC_VERSION_MAJOR < 56 |
11295
210650fc7182
Update libav API, keeping forward and backward compatibility
Vittorio Giovara <vittorio.giovara@gmail.com>
parents:
11046
diff
changeset
|
83 |
#define AV_CODEC_CAP_DELAY CODEC_CAP_DELAY |
210650fc7182
Update libav API, keeping forward and backward compatibility
Vittorio Giovara <vittorio.giovara@gmail.com>
parents:
11046
diff
changeset
|
84 |
#define AV_CODEC_CAP_VARIABLE_FRAME_SIZE CODEC_CAP_VARIABLE_FRAME_SIZE |
210650fc7182
Update libav API, keeping forward and backward compatibility
Vittorio Giovara <vittorio.giovara@gmail.com>
parents:
11046
diff
changeset
|
85 |
#define AV_CODEC_FLAG_GLOBAL_HEADER CODEC_FLAG_GLOBAL_HEADER |
210650fc7182
Update libav API, keeping forward and backward compatibility
Vittorio Giovara <vittorio.giovara@gmail.com>
parents:
11046
diff
changeset
|
86 |
#define AV_CODEC_FLAG_QSCALE CODEC_FLAG_QSCALE |
210650fc7182
Update libav API, keeping forward and backward compatibility
Vittorio Giovara <vittorio.giovara@gmail.com>
parents:
11046
diff
changeset
|
87 |
#endif |
210650fc7182
Update libav API, keeping forward and backward compatibility
Vittorio Giovara <vittorio.giovara@gmail.com>
parents:
11046
diff
changeset
|
88 |
|
210650fc7182
Update libav API, keeping forward and backward compatibility
Vittorio Giovara <vittorio.giovara@gmail.com>
parents:
11046
diff
changeset
|
89 |
#if LIBAVFORMAT_VERSION_MAJOR < 53 |
210650fc7182
Update libav API, keeping forward and backward compatibility
Vittorio Giovara <vittorio.giovara@gmail.com>
parents:
11046
diff
changeset
|
90 |
#define AVIO_FLAG_WRITE AVIO_WRONLY |
210650fc7182
Update libav API, keeping forward and backward compatibility
Vittorio Giovara <vittorio.giovara@gmail.com>
parents:
11046
diff
changeset
|
91 |
#endif |
210650fc7182
Update libav API, keeping forward and backward compatibility
Vittorio Giovara <vittorio.giovara@gmail.com>
parents:
11046
diff
changeset
|
92 |
|
210650fc7182
Update libav API, keeping forward and backward compatibility
Vittorio Giovara <vittorio.giovara@gmail.com>
parents:
11046
diff
changeset
|
93 |
#if LIBAVFORMAT_VERSION_MAJOR < 54 |
210650fc7182
Update libav API, keeping forward and backward compatibility
Vittorio Giovara <vittorio.giovara@gmail.com>
parents:
11046
diff
changeset
|
94 |
#define avformat_new_stream(x, y) av_new_stream(x, y->type == AVMEDIA_TYPE_AUDIO) |
210650fc7182
Update libav API, keeping forward and backward compatibility
Vittorio Giovara <vittorio.giovara@gmail.com>
parents:
11046
diff
changeset
|
95 |
#endif |
210650fc7182
Update libav API, keeping forward and backward compatibility
Vittorio Giovara <vittorio.giovara@gmail.com>
parents:
11046
diff
changeset
|
96 |
|
210650fc7182
Update libav API, keeping forward and backward compatibility
Vittorio Giovara <vittorio.giovara@gmail.com>
parents:
11046
diff
changeset
|
97 |
#if LIBAVUTIL_VERSION_MAJOR < 54 |
210650fc7182
Update libav API, keeping forward and backward compatibility
Vittorio Giovara <vittorio.giovara@gmail.com>
parents:
11046
diff
changeset
|
98 |
#define AV_PIX_FMT_YUV420P PIX_FMT_YUV420P |
210650fc7182
Update libav API, keeping forward and backward compatibility
Vittorio Giovara <vittorio.giovara@gmail.com>
parents:
11046
diff
changeset
|
99 |
#endif |
210650fc7182
Update libav API, keeping forward and backward compatibility
Vittorio Giovara <vittorio.giovara@gmail.com>
parents:
11046
diff
changeset
|
100 |
|
210650fc7182
Update libav API, keeping forward and backward compatibility
Vittorio Giovara <vittorio.giovara@gmail.com>
parents:
11046
diff
changeset
|
101 |
|
7180 | 102 |
// pointer to function from hwengine (uUtils.pas) |
103 |
static void (*AddFileLogRaw)(const char* pString); |
|
104 |
||
9925
113e61a8cadc
Fixed avwrapper exit calls, fixing issue 752
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents:
9224
diff
changeset
|
105 |
static int FatalError(const char* pFmt, ...) |
7180 | 106 |
{ |
8065 | 107 |
char Buffer[1024]; |
7180 | 108 |
va_list VaArgs; |
109 |
||
110 |
va_start(VaArgs, pFmt); |
|
111 |
vsnprintf(Buffer, 1024, pFmt, VaArgs); |
|
112 |
va_end(VaArgs); |
|
113 |
||
114 |
AddFileLogRaw("Error in av-wrapper: "); |
|
115 |
AddFileLogRaw(Buffer); |
|
116 |
AddFileLogRaw("\n"); |
|
9925
113e61a8cadc
Fixed avwrapper exit calls, fixing issue 752
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents:
9224
diff
changeset
|
117 |
return(-1); |
7180 | 118 |
} |
119 |
||
120 |
// Function to be called from libav for logging. |
|
121 |
// Note: libav can call LogCallback from different threads |
|
122 |
// (there is mutex in AddFileLogRaw). |
|
123 |
static void LogCallback(void* p, int Level, const char* pFmt, va_list VaArgs) |
|
124 |
{ |
|
8065 | 125 |
char Buffer[1024]; |
7180 | 126 |
|
127 |
vsnprintf(Buffer, 1024, pFmt, VaArgs); |
|
128 |
AddFileLogRaw(Buffer); |
|
129 |
} |
|
130 |
||
131 |
static void Log(const char* pFmt, ...) |
|
132 |
{ |
|
8065 | 133 |
char Buffer[1024]; |
7180 | 134 |
va_list VaArgs; |
135 |
||
136 |
va_start(VaArgs, pFmt); |
|
137 |
vsnprintf(Buffer, 1024, pFmt, VaArgs); |
|
138 |
va_end(VaArgs); |
|
139 |
||
140 |
AddFileLogRaw(Buffer); |
|
141 |
} |
|
142 |
||
7198
5debd5fe526e
1. Add IFDEFs for video recording
Stepan777 <stepik-777@mail.ru>
parents:
7180
diff
changeset
|
143 |
static void AddAudioStream() |
7180 | 144 |
{ |
145 |
g_pAStream = avformat_new_stream(g_pContainer, g_pACodec); |
|
146 |
if(!g_pAStream) |
|
7280
fd707afbc3a2
pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents:
7235
diff
changeset
|
147 |
{ |
7306
3cff5c769509
Here they come - thumbnails.
Stepan777 <stepik-777@mail.ru>
parents:
7282
diff
changeset
|
148 |
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
|
149 |
return; |
fd707afbc3a2
pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents:
7235
diff
changeset
|
150 |
} |
7180 | 151 |
g_pAStream->id = 1; |
152 |
||
153 |
g_pAudio = g_pAStream->codec; |
|
7198
5debd5fe526e
1. Add IFDEFs for video recording
Stepan777 <stepik-777@mail.ru>
parents:
7180
diff
changeset
|
154 |
|
7180 | 155 |
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
|
156 |
g_pAudio->codec_id = g_pACodec->id; |
7180 | 157 |
|
158 |
// put parameters |
|
159 |
g_pAudio->sample_fmt = AV_SAMPLE_FMT_S16; |
|
160 |
g_pAudio->sample_rate = g_Frequency; |
|
161 |
g_pAudio->channels = g_Channels; |
|
162 |
||
11596
ba7e67586fcd
videorec: Always initialize audio and video time bases
Vittorio Giovara <vittorio.giovara@gmail.com>
parents:
11595
diff
changeset
|
163 |
// set time base as invers of sample rate |
ba7e67586fcd
videorec: Always initialize audio and video time bases
Vittorio Giovara <vittorio.giovara@gmail.com>
parents:
11595
diff
changeset
|
164 |
g_pAudio->time_base.den = g_pAStream->time_base.den = g_Frequency; |
ba7e67586fcd
videorec: Always initialize audio and video time bases
Vittorio Giovara <vittorio.giovara@gmail.com>
parents:
11595
diff
changeset
|
165 |
g_pAudio->time_base.num = g_pAStream->time_base.num = 1; |
ba7e67586fcd
videorec: Always initialize audio and video time bases
Vittorio Giovara <vittorio.giovara@gmail.com>
parents:
11595
diff
changeset
|
166 |
|
7198
5debd5fe526e
1. Add IFDEFs for video recording
Stepan777 <stepik-777@mail.ru>
parents:
7180
diff
changeset
|
167 |
// 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
|
168 |
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
|
169 |
|
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
|
170 |
// for codecs that support variable bitrate use it, it should be better |
11295
210650fc7182
Update libav API, keeping forward and backward compatibility
Vittorio Giovara <vittorio.giovara@gmail.com>
parents:
11046
diff
changeset
|
171 |
g_pAudio->flags |= AV_CODEC_FLAG_QSCALE; |
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
|
172 |
g_pAudio->global_quality = 1*FF_QP2LAMBDA; |
7198
5debd5fe526e
1. Add IFDEFs for video recording
Stepan777 <stepik-777@mail.ru>
parents:
7180
diff
changeset
|
173 |
|
7180 | 174 |
// some formats want stream headers to be separate |
175 |
if (g_pFormat->flags & AVFMT_GLOBALHEADER) |
|
11295
210650fc7182
Update libav API, keeping forward and backward compatibility
Vittorio Giovara <vittorio.giovara@gmail.com>
parents:
11046
diff
changeset
|
176 |
g_pAudio->flags |= AV_CODEC_FLAG_GLOBAL_HEADER; |
7180 | 177 |
|
178 |
// open it |
|
179 |
if (avcodec_open2(g_pAudio, g_pACodec, NULL) < 0) |
|
7280
fd707afbc3a2
pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents:
7235
diff
changeset
|
180 |
{ |
7306
3cff5c769509
Here they come - thumbnails.
Stepan777 <stepik-777@mail.ru>
parents:
7282
diff
changeset
|
181 |
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
|
182 |
return; |
fd707afbc3a2
pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents:
7235
diff
changeset
|
183 |
} |
7180 | 184 |
|
185 |
#if LIBAVCODEC_VERSION_MAJOR >= 54 |
|
11295
210650fc7182
Update libav API, keeping forward and backward compatibility
Vittorio Giovara <vittorio.giovara@gmail.com>
parents:
11046
diff
changeset
|
186 |
if (g_pACodec->capabilities & AV_CODEC_CAP_VARIABLE_FRAME_SIZE) |
7180 | 187 |
#else |
188 |
if (g_pAudio->frame_size == 0) |
|
189 |
#endif |
|
190 |
g_NumSamples = 4096; |
|
191 |
else |
|
192 |
g_NumSamples = g_pAudio->frame_size; |
|
193 |
g_pSamples = (int16_t*)av_malloc(g_NumSamples*g_Channels*sizeof(int16_t)); |
|
11295
210650fc7182
Update libav API, keeping forward and backward compatibility
Vittorio Giovara <vittorio.giovara@gmail.com>
parents:
11046
diff
changeset
|
194 |
g_pAFrame = av_frame_alloc(); |
7180 | 195 |
if (!g_pAFrame) |
7280
fd707afbc3a2
pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents:
7235
diff
changeset
|
196 |
{ |
7306
3cff5c769509
Here they come - thumbnails.
Stepan777 <stepik-777@mail.ru>
parents:
7282
diff
changeset
|
197 |
Log("Could not allocate frame\n"); |
7280
fd707afbc3a2
pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents:
7235
diff
changeset
|
198 |
return; |
fd707afbc3a2
pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents:
7235
diff
changeset
|
199 |
} |
7180 | 200 |
} |
201 |
||
9925
113e61a8cadc
Fixed avwrapper exit calls, fixing issue 752
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents:
9224
diff
changeset
|
202 |
// returns non-zero if there is more sound, -1 in case of error |
7180 | 203 |
static int WriteAudioFrame() |
204 |
{ |
|
7198
5debd5fe526e
1. Add IFDEFs for video recording
Stepan777 <stepik-777@mail.ru>
parents:
7180
diff
changeset
|
205 |
if (!g_pAStream) |
5debd5fe526e
1. Add IFDEFs for video recording
Stepan777 <stepik-777@mail.ru>
parents:
7180
diff
changeset
|
206 |
return 0; |
5debd5fe526e
1. Add IFDEFs for video recording
Stepan777 <stepik-777@mail.ru>
parents:
7180
diff
changeset
|
207 |
|
11297
bf5cfd830f7d
Let initialization happen in the appropriate function
Vittorio Giovara <vittorio.giovara@gmail.com>
parents:
11295
diff
changeset
|
208 |
AVPacket Packet; |
7180 | 209 |
av_init_packet(&Packet); |
11593
72be390795db
videorec: Make sure the audio packet is considered empty
Vittorio Giovara <vittorio.giovara@gmail.com>
parents:
11297
diff
changeset
|
210 |
Packet.data = NULL; |
72be390795db
videorec: Make sure the audio packet is considered empty
Vittorio Giovara <vittorio.giovara@gmail.com>
parents:
11297
diff
changeset
|
211 |
Packet.size = 0; |
7180 | 212 |
|
213 |
int NumSamples = fread(g_pSamples, 2*g_Channels, g_NumSamples, g_pSoundFile); |
|
214 |
||
8065 | 215 |
#if LIBAVCODEC_VERSION_MAJOR >= 53 |
7180 | 216 |
AVFrame* pFrame = NULL; |
217 |
if (NumSamples > 0) |
|
218 |
{ |
|
219 |
g_pAFrame->nb_samples = NumSamples; |
|
220 |
avcodec_fill_audio_frame(g_pAFrame, g_Channels, AV_SAMPLE_FMT_S16, |
|
221 |
(uint8_t*)g_pSamples, NumSamples*2*g_Channels, 1); |
|
222 |
pFrame = g_pAFrame; |
|
223 |
} |
|
224 |
// when NumSamples == 0 we still need to call encode_audio2 to flush |
|
225 |
int got_packet; |
|
226 |
if (avcodec_encode_audio2(g_pAudio, &Packet, pFrame, &got_packet) != 0) |
|
9925
113e61a8cadc
Fixed avwrapper exit calls, fixing issue 752
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents:
9224
diff
changeset
|
227 |
return FatalError("avcodec_encode_audio2 failed"); |
7180 | 228 |
if (!got_packet) |
229 |
return 0; |
|
11597
4575b6990348
videorec: Appropriately rescale timestamps and duration
Vittorio Giovara <vittorio.giovara@gmail.com>
parents:
11596
diff
changeset
|
230 |
|
4575b6990348
videorec: Appropriately rescale timestamps and duration
Vittorio Giovara <vittorio.giovara@gmail.com>
parents:
11596
diff
changeset
|
231 |
av_packet_rescale_ts(&Packet, g_pAudio->time_base, g_pAStream->time_base); |
7180 | 232 |
#else |
233 |
if (NumSamples == 0) |
|
234 |
return 0; |
|
235 |
int BufferSize = OUTBUFFER_SIZE; |
|
236 |
if (g_pAudio->frame_size == 0) |
|
237 |
BufferSize = NumSamples*g_Channels*2; |
|
238 |
Packet.size = avcodec_encode_audio(g_pAudio, g_OutBuffer, BufferSize, g_pSamples); |
|
239 |
if (Packet.size == 0) |
|
240 |
return 1; |
|
241 |
if (g_pAudio->coded_frame && g_pAudio->coded_frame->pts != AV_NOPTS_VALUE) |
|
242 |
Packet.pts = av_rescale_q(g_pAudio->coded_frame->pts, g_pAudio->time_base, g_pAStream->time_base); |
|
243 |
Packet.flags |= AV_PKT_FLAG_KEY; |
|
244 |
Packet.data = g_OutBuffer; |
|
245 |
#endif |
|
246 |
||
247 |
// Write the compressed frame to the media file. |
|
248 |
Packet.stream_index = g_pAStream->index; |
|
8811 | 249 |
if (av_interleaved_write_frame(g_pContainer, &Packet) != 0) |
9925
113e61a8cadc
Fixed avwrapper exit calls, fixing issue 752
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents:
9224
diff
changeset
|
250 |
return FatalError("Error while writing audio frame"); |
7180 | 251 |
return 1; |
252 |
} |
|
253 |
||
254 |
// add a video output stream |
|
9925
113e61a8cadc
Fixed avwrapper exit calls, fixing issue 752
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents:
9224
diff
changeset
|
255 |
static int AddVideoStream() |
7180 | 256 |
{ |
257 |
g_pVStream = avformat_new_stream(g_pContainer, g_pVCodec); |
|
258 |
if (!g_pVStream) |
|
9925
113e61a8cadc
Fixed avwrapper exit calls, fixing issue 752
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents:
9224
diff
changeset
|
259 |
return FatalError("Could not allocate video stream"); |
7180 | 260 |
|
261 |
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
|
262 |
|
7198
5debd5fe526e
1. Add IFDEFs for video recording
Stepan777 <stepik-777@mail.ru>
parents:
7180
diff
changeset
|
263 |
avcodec_get_context_defaults3(g_pVideo, g_pVCodec); |
5debd5fe526e
1. Add IFDEFs for video recording
Stepan777 <stepik-777@mail.ru>
parents:
7180
diff
changeset
|
264 |
g_pVideo->codec_id = g_pVCodec->id; |
7180 | 265 |
|
266 |
// put parameters |
|
267 |
// 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
|
268 |
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
|
269 |
g_pVideo->height = g_Height & ~1; // make even |
7180 | 270 |
/* time base: this is the fundamental unit of time (in seconds) in terms |
271 |
of which frame timestamps are represented. for fixed-fps content, |
|
272 |
timebase should be 1/framerate and timestamp increments should be |
|
273 |
identically 1. */ |
|
11596
ba7e67586fcd
videorec: Always initialize audio and video time bases
Vittorio Giovara <vittorio.giovara@gmail.com>
parents:
11595
diff
changeset
|
274 |
g_pVideo->time_base.den = g_pVStream->time_base.den = g_Framerate.num; |
ba7e67586fcd
videorec: Always initialize audio and video time bases
Vittorio Giovara <vittorio.giovara@gmail.com>
parents:
11595
diff
changeset
|
275 |
g_pVideo->time_base.num = g_pVStream->time_base.num = g_Framerate.den; |
11599
49c82c3e3836
videorec: Drop a commented out option
Vittorio Giovara <vittorio.giovara@gmail.com>
parents:
11598
diff
changeset
|
276 |
|
11295
210650fc7182
Update libav API, keeping forward and backward compatibility
Vittorio Giovara <vittorio.giovara@gmail.com>
parents:
11046
diff
changeset
|
277 |
g_pVideo->pix_fmt = AV_PIX_FMT_YUV420P; |
7180 | 278 |
|
7198
5debd5fe526e
1. Add IFDEFs for video recording
Stepan777 <stepik-777@mail.ru>
parents:
7180
diff
changeset
|
279 |
// set quality |
5debd5fe526e
1. Add IFDEFs for video recording
Stepan777 <stepik-777@mail.ru>
parents:
7180
diff
changeset
|
280 |
if (g_VQuality > 100) |
5debd5fe526e
1. Add IFDEFs for video recording
Stepan777 <stepik-777@mail.ru>
parents:
7180
diff
changeset
|
281 |
g_pVideo->bit_rate = g_VQuality; |
5debd5fe526e
1. Add IFDEFs for video recording
Stepan777 <stepik-777@mail.ru>
parents:
7180
diff
changeset
|
282 |
else |
5debd5fe526e
1. Add IFDEFs for video recording
Stepan777 <stepik-777@mail.ru>
parents:
7180
diff
changeset
|
283 |
{ |
11295
210650fc7182
Update libav API, keeping forward and backward compatibility
Vittorio Giovara <vittorio.giovara@gmail.com>
parents:
11046
diff
changeset
|
284 |
g_pVideo->flags |= AV_CODEC_FLAG_QSCALE; |
7198
5debd5fe526e
1. Add IFDEFs for video recording
Stepan777 <stepik-777@mail.ru>
parents:
7180
diff
changeset
|
285 |
g_pVideo->global_quality = g_VQuality*FF_QP2LAMBDA; |
5debd5fe526e
1. Add IFDEFs for video recording
Stepan777 <stepik-777@mail.ru>
parents:
7180
diff
changeset
|
286 |
} |
5debd5fe526e
1. Add IFDEFs for video recording
Stepan777 <stepik-777@mail.ru>
parents:
7180
diff
changeset
|
287 |
|
7180 | 288 |
// some formats want stream headers to be separate |
289 |
if (g_pFormat->flags & AVFMT_GLOBALHEADER) |
|
11295
210650fc7182
Update libav API, keeping forward and backward compatibility
Vittorio Giovara <vittorio.giovara@gmail.com>
parents:
11046
diff
changeset
|
290 |
g_pVideo->flags |= AV_CODEC_FLAG_GLOBAL_HEADER; |
7180 | 291 |
|
8065 | 292 |
#if LIBAVCODEC_VERSION_MAJOR < 53 |
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
|
293 |
// 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
|
294 |
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
|
295 |
{ |
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
|
296 |
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
|
297 |
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
|
298 |
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
|
299 |
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
|
300 |
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
|
301 |
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
|
302 |
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
|
303 |
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
|
304 |
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
|
305 |
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
|
306 |
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
|
307 |
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
|
308 |
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
|
309 |
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
|
310 |
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
|
311 |
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
|
312 |
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
|
313 |
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
|
314 |
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
|
315 |
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
|
316 |
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
|
317 |
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
|
318 |
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
|
319 |
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
|
320 |
} |
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
|
321 |
#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
|
322 |
|
7180 | 323 |
// open the codec |
7359
8bb4da06b065
Fix compilation of hwengine on ffmpeg 0.7.13.
Stepan777 <stepik-777@mail.ru>
parents:
7356
diff
changeset
|
324 |
#if LIBAVCODEC_VERSION_MAJOR >= 53 |
8bb4da06b065
Fix compilation of hwengine on ffmpeg 0.7.13.
Stepan777 <stepik-777@mail.ru>
parents:
7356
diff
changeset
|
325 |
AVDictionary* pDict = NULL; |
8bb4da06b065
Fix compilation of hwengine on ffmpeg 0.7.13.
Stepan777 <stepik-777@mail.ru>
parents:
7356
diff
changeset
|
326 |
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
|
327 |
av_dict_set(&pDict, "preset", "medium", 0); |
11295
210650fc7182
Update libav API, keeping forward and backward compatibility
Vittorio Giovara <vittorio.giovara@gmail.com>
parents:
11046
diff
changeset
|
328 |
#endif |
7359
8bb4da06b065
Fix compilation of hwengine on ffmpeg 0.7.13.
Stepan777 <stepik-777@mail.ru>
parents:
7356
diff
changeset
|
329 |
|
7180 | 330 |
if (avcodec_open2(g_pVideo, g_pVCodec, &pDict) < 0) |
9925
113e61a8cadc
Fixed avwrapper exit calls, fixing issue 752
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents:
9224
diff
changeset
|
331 |
return FatalError("Could not open video codec %s", g_pVCodec->long_name); |
7180 | 332 |
|
11295
210650fc7182
Update libav API, keeping forward and backward compatibility
Vittorio Giovara <vittorio.giovara@gmail.com>
parents:
11046
diff
changeset
|
333 |
g_pVFrame = av_frame_alloc(); |
7180 | 334 |
if (!g_pVFrame) |
9925
113e61a8cadc
Fixed avwrapper exit calls, fixing issue 752
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents:
9224
diff
changeset
|
335 |
return FatalError("Could not allocate frame"); |
7180 | 336 |
|
11595
9a17a39eccdc
videorec: Fully set frame properties
Vittorio Giovara <vittorio.giovara@gmail.com>
parents:
11594
diff
changeset
|
337 |
g_pVFrame->width = g_Width; |
9a17a39eccdc
videorec: Fully set frame properties
Vittorio Giovara <vittorio.giovara@gmail.com>
parents:
11594
diff
changeset
|
338 |
g_pVFrame->height = g_Height; |
9a17a39eccdc
videorec: Fully set frame properties
Vittorio Giovara <vittorio.giovara@gmail.com>
parents:
11594
diff
changeset
|
339 |
g_pVFrame->format = AV_PIX_FMT_YUV420P; |
7180 | 340 |
g_pVFrame->linesize[0] = g_Width; |
341 |
g_pVFrame->linesize[1] = g_Width/2; |
|
342 |
g_pVFrame->linesize[2] = g_Width/2; |
|
343 |
g_pVFrame->linesize[3] = 0; |
|
9925
113e61a8cadc
Fixed avwrapper exit calls, fixing issue 752
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents:
9224
diff
changeset
|
344 |
return 0; |
7180 | 345 |
} |
346 |
||
7280
fd707afbc3a2
pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents:
7235
diff
changeset
|
347 |
static int WriteFrame(AVFrame* pFrame) |
7180 | 348 |
{ |
349 |
double AudioTime, VideoTime; |
|
9925
113e61a8cadc
Fixed avwrapper exit calls, fixing issue 752
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents:
9224
diff
changeset
|
350 |
int ret; |
7180 | 351 |
// write interleaved audio frame |
352 |
if (g_pAStream) |
|
353 |
{ |
|
11295
210650fc7182
Update libav API, keeping forward and backward compatibility
Vittorio Giovara <vittorio.giovara@gmail.com>
parents:
11046
diff
changeset
|
354 |
VideoTime = (double)g_pVFrame->pts * g_pVStream->time_base.num/g_pVStream->time_base.den; |
7180 | 355 |
do |
9925
113e61a8cadc
Fixed avwrapper exit calls, fixing issue 752
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents:
9224
diff
changeset
|
356 |
{ |
11295
210650fc7182
Update libav API, keeping forward and backward compatibility
Vittorio Giovara <vittorio.giovara@gmail.com>
parents:
11046
diff
changeset
|
357 |
AudioTime = (double)g_pAFrame->pts * g_pAStream->time_base.num/g_pAStream->time_base.den; |
9925
113e61a8cadc
Fixed avwrapper exit calls, fixing issue 752
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents:
9224
diff
changeset
|
358 |
ret = WriteAudioFrame(); |
113e61a8cadc
Fixed avwrapper exit calls, fixing issue 752
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents:
9224
diff
changeset
|
359 |
} |
113e61a8cadc
Fixed avwrapper exit calls, fixing issue 752
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents:
9224
diff
changeset
|
360 |
while (AudioTime < VideoTime && ret); |
113e61a8cadc
Fixed avwrapper exit calls, fixing issue 752
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents:
9224
diff
changeset
|
361 |
if (ret < 0) |
113e61a8cadc
Fixed avwrapper exit calls, fixing issue 752
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents:
9224
diff
changeset
|
362 |
return ret; |
7180 | 363 |
} |
8811 | 364 |
|
7198
5debd5fe526e
1. Add IFDEFs for video recording
Stepan777 <stepik-777@mail.ru>
parents:
7180
diff
changeset
|
365 |
if (!g_pVStream) |
5debd5fe526e
1. Add IFDEFs for video recording
Stepan777 <stepik-777@mail.ru>
parents:
7180
diff
changeset
|
366 |
return 0; |
7180 | 367 |
|
368 |
AVPacket Packet; |
|
369 |
av_init_packet(&Packet); |
|
370 |
Packet.data = NULL; |
|
371 |
Packet.size = 0; |
|
372 |
||
373 |
g_pVFrame->pts++; |
|
11598
476cbbad88c0
videorec: Use future API for raw video encoding
Vittorio Giovara <vittorio.giovara@gmail.com>
parents:
11597
diff
changeset
|
374 |
#if LIBAVCODEC_VERSION_MAJOR < 58 |
7180 | 375 |
if (g_pFormat->flags & AVFMT_RAWPICTURE) |
376 |
{ |
|
377 |
/* raw video case. The API will change slightly in the near |
|
378 |
future for that. */ |
|
379 |
Packet.flags |= AV_PKT_FLAG_KEY; |
|
380 |
Packet.stream_index = g_pVStream->index; |
|
381 |
Packet.data = (uint8_t*)pFrame; |
|
382 |
Packet.size = sizeof(AVPicture); |
|
383 |
||
384 |
if (av_interleaved_write_frame(g_pContainer, &Packet) != 0) |
|
9925
113e61a8cadc
Fixed avwrapper exit calls, fixing issue 752
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents:
9224
diff
changeset
|
385 |
return FatalError("Error while writing video frame"); |
7180 | 386 |
return 0; |
387 |
} |
|
388 |
else |
|
11598
476cbbad88c0
videorec: Use future API for raw video encoding
Vittorio Giovara <vittorio.giovara@gmail.com>
parents:
11597
diff
changeset
|
389 |
#endif |
7180 | 390 |
{ |
391 |
#if LIBAVCODEC_VERSION_MAJOR >= 54 |
|
392 |
int got_packet; |
|
393 |
if (avcodec_encode_video2(g_pVideo, &Packet, pFrame, &got_packet) < 0) |
|
9925
113e61a8cadc
Fixed avwrapper exit calls, fixing issue 752
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents:
9224
diff
changeset
|
394 |
return FatalError("avcodec_encode_video2 failed"); |
7180 | 395 |
if (!got_packet) |
396 |
return 0; |
|
397 |
||
11597
4575b6990348
videorec: Appropriately rescale timestamps and duration
Vittorio Giovara <vittorio.giovara@gmail.com>
parents:
11596
diff
changeset
|
398 |
av_packet_rescale_ts(&Packet, g_pVideo->time_base, g_pVStream->time_base); |
8811 | 399 |
#else |
7180 | 400 |
Packet.size = avcodec_encode_video(g_pVideo, g_OutBuffer, OUTBUFFER_SIZE, pFrame); |
401 |
if (Packet.size < 0) |
|
9925
113e61a8cadc
Fixed avwrapper exit calls, fixing issue 752
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents:
9224
diff
changeset
|
402 |
return FatalError("avcodec_encode_video failed"); |
7180 | 403 |
if (Packet.size == 0) |
404 |
return 0; |
|
405 |
||
406 |
if( g_pVideo->coded_frame->pts != AV_NOPTS_VALUE) |
|
407 |
Packet.pts = av_rescale_q(g_pVideo->coded_frame->pts, g_pVideo->time_base, g_pVStream->time_base); |
|
408 |
if( g_pVideo->coded_frame->key_frame ) |
|
409 |
Packet.flags |= AV_PKT_FLAG_KEY; |
|
410 |
Packet.data = g_OutBuffer; |
|
411 |
#endif |
|
412 |
// write the compressed frame in the media file |
|
413 |
Packet.stream_index = g_pVStream->index; |
|
414 |
if (av_interleaved_write_frame(g_pContainer, &Packet) != 0) |
|
9925
113e61a8cadc
Fixed avwrapper exit calls, fixing issue 752
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents:
9224
diff
changeset
|
415 |
return FatalError("Error while writing video frame"); |
8811 | 416 |
|
7180 | 417 |
return 1; |
418 |
} |
|
419 |
} |
|
420 |
||
9925
113e61a8cadc
Fixed avwrapper exit calls, fixing issue 752
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents:
9224
diff
changeset
|
421 |
AVWRAP_DECL int AVWrapper_WriteFrame(uint8_t* pY, uint8_t* pCb, uint8_t* pCr) |
7180 | 422 |
{ |
423 |
g_pVFrame->data[0] = pY; |
|
424 |
g_pVFrame->data[1] = pCb; |
|
425 |
g_pVFrame->data[2] = pCr; |
|
9925
113e61a8cadc
Fixed avwrapper exit calls, fixing issue 752
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents:
9224
diff
changeset
|
426 |
return WriteFrame(g_pVFrame); |
7180 | 427 |
} |
428 |
||
9925
113e61a8cadc
Fixed avwrapper exit calls, fixing issue 752
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents:
9224
diff
changeset
|
429 |
AVWRAP_DECL int AVWrapper_Init( |
7198
5debd5fe526e
1. Add IFDEFs for video recording
Stepan777 <stepik-777@mail.ru>
parents:
7180
diff
changeset
|
430 |
void (*pAddFileLogRaw)(const char*), |
5debd5fe526e
1. Add IFDEFs for video recording
Stepan777 <stepik-777@mail.ru>
parents:
7180
diff
changeset
|
431 |
const char* pFilename, |
7280
fd707afbc3a2
pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents:
7235
diff
changeset
|
432 |
const char* pDesc, |
7198
5debd5fe526e
1. Add IFDEFs for video recording
Stepan777 <stepik-777@mail.ru>
parents:
7180
diff
changeset
|
433 |
const char* pSoundFile, |
5debd5fe526e
1. Add IFDEFs for video recording
Stepan777 <stepik-777@mail.ru>
parents:
7180
diff
changeset
|
434 |
const char* pFormatName, |
5debd5fe526e
1. Add IFDEFs for video recording
Stepan777 <stepik-777@mail.ru>
parents:
7180
diff
changeset
|
435 |
const char* pVCodecName, |
5debd5fe526e
1. Add IFDEFs for video recording
Stepan777 <stepik-777@mail.ru>
parents:
7180
diff
changeset
|
436 |
const char* pACodecName, |
5debd5fe526e
1. Add IFDEFs for video recording
Stepan777 <stepik-777@mail.ru>
parents:
7180
diff
changeset
|
437 |
int Width, int Height, |
5debd5fe526e
1. Add IFDEFs for video recording
Stepan777 <stepik-777@mail.ru>
parents:
7180
diff
changeset
|
438 |
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
|
439 |
int VQuality) |
8811 | 440 |
{ |
9925
113e61a8cadc
Fixed avwrapper exit calls, fixing issue 752
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents:
9224
diff
changeset
|
441 |
int ret; |
7180 | 442 |
AddFileLogRaw = pAddFileLogRaw; |
443 |
av_log_set_callback( &LogCallback ); |
|
444 |
||
7282
c65992e2d794
correctly fix odd dimensions (it was incorrectly fixed in previous commit)
Stepan777 <stepik-777@mail.ru>
parents:
7280
diff
changeset
|
445 |
g_Width = Width; |
c65992e2d794
correctly fix odd dimensions (it was incorrectly fixed in previous commit)
Stepan777 <stepik-777@mail.ru>
parents:
7280
diff
changeset
|
446 |
g_Height = Height; |
7198
5debd5fe526e
1. Add IFDEFs for video recording
Stepan777 <stepik-777@mail.ru>
parents:
7180
diff
changeset
|
447 |
g_Framerate.num = FramerateNum; |
5debd5fe526e
1. Add IFDEFs for video recording
Stepan777 <stepik-777@mail.ru>
parents:
7180
diff
changeset
|
448 |
g_Framerate.den = FramerateDen; |
5debd5fe526e
1. Add IFDEFs for video recording
Stepan777 <stepik-777@mail.ru>
parents:
7180
diff
changeset
|
449 |
g_VQuality = VQuality; |
7180 | 450 |
|
451 |
// initialize libav and register all codecs and formats |
|
452 |
av_register_all(); |
|
453 |
||
7198
5debd5fe526e
1. Add IFDEFs for video recording
Stepan777 <stepik-777@mail.ru>
parents:
7180
diff
changeset
|
454 |
// find format |
5debd5fe526e
1. Add IFDEFs for video recording
Stepan777 <stepik-777@mail.ru>
parents:
7180
diff
changeset
|
455 |
g_pFormat = av_guess_format(pFormatName, NULL, NULL); |
7180 | 456 |
if (!g_pFormat) |
9925
113e61a8cadc
Fixed avwrapper exit calls, fixing issue 752
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents:
9224
diff
changeset
|
457 |
return FatalError("Format \"%s\" was not found", pFormatName); |
7180 | 458 |
|
459 |
// allocate the output media context |
|
460 |
g_pContainer = avformat_alloc_context(); |
|
461 |
if (!g_pContainer) |
|
9925
113e61a8cadc
Fixed avwrapper exit calls, fixing issue 752
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents:
9224
diff
changeset
|
462 |
return FatalError("Could not allocate output context"); |
7180 | 463 |
|
7198
5debd5fe526e
1. Add IFDEFs for video recording
Stepan777 <stepik-777@mail.ru>
parents:
7180
diff
changeset
|
464 |
g_pContainer->oformat = g_pFormat; |
7180 | 465 |
|
7280
fd707afbc3a2
pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents:
7235
diff
changeset
|
466 |
// store description of file |
fd707afbc3a2
pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents:
7235
diff
changeset
|
467 |
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
|
468 |
|
7198
5debd5fe526e
1. Add IFDEFs for video recording
Stepan777 <stepik-777@mail.ru>
parents:
7180
diff
changeset
|
469 |
// 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
|
470 |
char ext[16]; |
baa69bd025d9
1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
7198
diff
changeset
|
471 |
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
|
472 |
ext[15] = 0; |
baa69bd025d9
1. Implement new page in frontend with options for video recording.
Stepan777 <stepik-777@mail.ru>
parents:
7198
diff
changeset
|
473 |
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
|
474 |
snprintf(g_pContainer->filename, sizeof(g_pContainer->filename), "%s.%s", pFilename, ext); |
7180 | 475 |
|
7198
5debd5fe526e
1. Add IFDEFs for video recording
Stepan777 <stepik-777@mail.ru>
parents:
7180
diff
changeset
|
476 |
// find codecs |
5debd5fe526e
1. Add IFDEFs for video recording
Stepan777 <stepik-777@mail.ru>
parents:
7180
diff
changeset
|
477 |
g_pVCodec = avcodec_find_encoder_by_name(pVCodecName); |
5debd5fe526e
1. Add IFDEFs for video recording
Stepan777 <stepik-777@mail.ru>
parents:
7180
diff
changeset
|
478 |
g_pACodec = avcodec_find_encoder_by_name(pACodecName); |
5debd5fe526e
1. Add IFDEFs for video recording
Stepan777 <stepik-777@mail.ru>
parents:
7180
diff
changeset
|
479 |
|
5debd5fe526e
1. Add IFDEFs for video recording
Stepan777 <stepik-777@mail.ru>
parents:
7180
diff
changeset
|
480 |
// add audio and video stream to container |
7180 | 481 |
g_pVStream = NULL; |
482 |
g_pAStream = NULL; |
|
7198
5debd5fe526e
1. Add IFDEFs for video recording
Stepan777 <stepik-777@mail.ru>
parents:
7180
diff
changeset
|
483 |
|
5debd5fe526e
1. Add IFDEFs for video recording
Stepan777 <stepik-777@mail.ru>
parents:
7180
diff
changeset
|
484 |
if (g_pVCodec) |
9925
113e61a8cadc
Fixed avwrapper exit calls, fixing issue 752
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents:
9224
diff
changeset
|
485 |
{ |
113e61a8cadc
Fixed avwrapper exit calls, fixing issue 752
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents:
9224
diff
changeset
|
486 |
ret = AddVideoStream(); |
113e61a8cadc
Fixed avwrapper exit calls, fixing issue 752
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents:
9224
diff
changeset
|
487 |
if (ret < 0) |
113e61a8cadc
Fixed avwrapper exit calls, fixing issue 752
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents:
9224
diff
changeset
|
488 |
return ret; |
113e61a8cadc
Fixed avwrapper exit calls, fixing issue 752
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents:
9224
diff
changeset
|
489 |
} |
7198
5debd5fe526e
1. Add IFDEFs for video recording
Stepan777 <stepik-777@mail.ru>
parents:
7180
diff
changeset
|
490 |
else |
5debd5fe526e
1. Add IFDEFs for video recording
Stepan777 <stepik-777@mail.ru>
parents:
7180
diff
changeset
|
491 |
Log("Video codec \"%s\" was not found; video will be ignored.\n", pVCodecName); |
7180 | 492 |
|
7198
5debd5fe526e
1. Add IFDEFs for video recording
Stepan777 <stepik-777@mail.ru>
parents:
7180
diff
changeset
|
493 |
if (g_pACodec) |
7280
fd707afbc3a2
pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents:
7235
diff
changeset
|
494 |
{ |
fd707afbc3a2
pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents:
7235
diff
changeset
|
495 |
g_pSoundFile = fopen(pSoundFile, "rb"); |
fd707afbc3a2
pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents:
7235
diff
changeset
|
496 |
if (g_pSoundFile) |
fd707afbc3a2
pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents:
7235
diff
changeset
|
497 |
{ |
fd707afbc3a2
pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents:
7235
diff
changeset
|
498 |
fread(&g_Frequency, 4, 1, g_pSoundFile); |
fd707afbc3a2
pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents:
7235
diff
changeset
|
499 |
fread(&g_Channels, 4, 1, g_pSoundFile); |
fd707afbc3a2
pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents:
7235
diff
changeset
|
500 |
AddAudioStream(); |
fd707afbc3a2
pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents:
7235
diff
changeset
|
501 |
} |
fd707afbc3a2
pagevideos is now much better that before:
Stepan777 <stepik-777@mail.ru>
parents:
7235
diff
changeset
|
502 |
else |
7306
3cff5c769509
Here they come - thumbnails.
Stepan777 <stepik-777@mail.ru>
parents:
7282
diff
changeset
|
503 |
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
|
504 |
} |
7198
5debd5fe526e
1. Add IFDEFs for video recording
Stepan777 <stepik-777@mail.ru>
parents:
7180
diff
changeset
|
505 |
else |
5debd5fe526e
1. Add IFDEFs for video recording
Stepan777 <stepik-777@mail.ru>
parents:
7180
diff
changeset
|
506 |
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
|
507 |
|
5debd5fe526e
1. Add IFDEFs for video recording
Stepan777 <stepik-777@mail.ru>
parents:
7180
diff
changeset
|
508 |
if (!g_pAStream && !g_pVStream) |
9925
113e61a8cadc
Fixed avwrapper exit calls, fixing issue 752
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents:
9224
diff
changeset
|
509 |
return FatalError("No video, no audio, aborting..."); |
7180 | 510 |
|
511 |
// write format info to log |
|
7198
5debd5fe526e
1. Add IFDEFs for video recording
Stepan777 <stepik-777@mail.ru>
parents:
7180
diff
changeset
|
512 |
av_dump_format(g_pContainer, 0, g_pContainer->filename, 1); |
7180 | 513 |
|
514 |
// open the output file, if needed |
|
515 |
if (!(g_pFormat->flags & AVFMT_NOFILE)) |
|
516 |
{ |
|
7198
5debd5fe526e
1. Add IFDEFs for video recording
Stepan777 <stepik-777@mail.ru>
parents:
7180
diff
changeset
|
517 |
if (avio_open(&g_pContainer->pb, g_pContainer->filename, AVIO_FLAG_WRITE) < 0) |
9925
113e61a8cadc
Fixed avwrapper exit calls, fixing issue 752
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents:
9224
diff
changeset
|
518 |
return FatalError("Could not open output file (%s)", g_pContainer->filename); |
7180 | 519 |
} |
520 |
||
521 |
// write the stream header, if any |
|
522 |
avformat_write_header(g_pContainer, NULL); |
|
7198
5debd5fe526e
1. Add IFDEFs for video recording
Stepan777 <stepik-777@mail.ru>
parents:
7180
diff
changeset
|
523 |
|
7180 | 524 |
g_pVFrame->pts = -1; |
9925
113e61a8cadc
Fixed avwrapper exit calls, fixing issue 752
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents:
9224
diff
changeset
|
525 |
return 0; |
7180 | 526 |
} |
527 |
||
9925
113e61a8cadc
Fixed avwrapper exit calls, fixing issue 752
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents:
9224
diff
changeset
|
528 |
AVWRAP_DECL int AVWrapper_Close() |
7180 | 529 |
{ |
9925
113e61a8cadc
Fixed avwrapper exit calls, fixing issue 752
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents:
9224
diff
changeset
|
530 |
int ret; |
7180 | 531 |
// output buffered frames |
11295
210650fc7182
Update libav API, keeping forward and backward compatibility
Vittorio Giovara <vittorio.giovara@gmail.com>
parents:
11046
diff
changeset
|
532 |
if (g_pVCodec->capabilities & AV_CODEC_CAP_DELAY) |
9925
113e61a8cadc
Fixed avwrapper exit calls, fixing issue 752
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents:
9224
diff
changeset
|
533 |
{ |
113e61a8cadc
Fixed avwrapper exit calls, fixing issue 752
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents:
9224
diff
changeset
|
534 |
do |
113e61a8cadc
Fixed avwrapper exit calls, fixing issue 752
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents:
9224
diff
changeset
|
535 |
ret = WriteFrame(NULL); |
11594
91d31e15f8f2
videorec: Fix flushing encoders
Vittorio Giovara <vittorio.giovara@gmail.com>
parents:
11593
diff
changeset
|
536 |
while (ret > 0); |
9925
113e61a8cadc
Fixed avwrapper exit calls, fixing issue 752
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents:
9224
diff
changeset
|
537 |
if (ret < 0) |
113e61a8cadc
Fixed avwrapper exit calls, fixing issue 752
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents:
9224
diff
changeset
|
538 |
return ret; |
113e61a8cadc
Fixed avwrapper exit calls, fixing issue 752
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents:
9224
diff
changeset
|
539 |
} |
7180 | 540 |
// output any remaining audio |
9925
113e61a8cadc
Fixed avwrapper exit calls, fixing issue 752
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents:
9224
diff
changeset
|
541 |
do |
113e61a8cadc
Fixed avwrapper exit calls, fixing issue 752
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents:
9224
diff
changeset
|
542 |
{ |
113e61a8cadc
Fixed avwrapper exit calls, fixing issue 752
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents:
9224
diff
changeset
|
543 |
ret = WriteAudioFrame(); |
113e61a8cadc
Fixed avwrapper exit calls, fixing issue 752
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents:
9224
diff
changeset
|
544 |
} |
11594
91d31e15f8f2
videorec: Fix flushing encoders
Vittorio Giovara <vittorio.giovara@gmail.com>
parents:
11593
diff
changeset
|
545 |
while(ret > 0); |
9925
113e61a8cadc
Fixed avwrapper exit calls, fixing issue 752
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents:
9224
diff
changeset
|
546 |
if (ret < 0) |
113e61a8cadc
Fixed avwrapper exit calls, fixing issue 752
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents:
9224
diff
changeset
|
547 |
return ret; |
7180 | 548 |
|
549 |
// write the trailer, if any. |
|
550 |
av_write_trailer(g_pContainer); |
|
551 |
||
7198
5debd5fe526e
1. Add IFDEFs for video recording
Stepan777 <stepik-777@mail.ru>
parents:
7180
diff
changeset
|
552 |
// close the output file |
5debd5fe526e
1. Add IFDEFs for video recording
Stepan777 <stepik-777@mail.ru>
parents:
7180
diff
changeset
|
553 |
if (!(g_pFormat->flags & AVFMT_NOFILE)) |
5debd5fe526e
1. Add IFDEFs for video recording
Stepan777 <stepik-777@mail.ru>
parents:
7180
diff
changeset
|
554 |
avio_close(g_pContainer->pb); |
5debd5fe526e
1. Add IFDEFs for video recording
Stepan777 <stepik-777@mail.ru>
parents:
7180
diff
changeset
|
555 |
|
5debd5fe526e
1. Add IFDEFs for video recording
Stepan777 <stepik-777@mail.ru>
parents:
7180
diff
changeset
|
556 |
// free everything |
5debd5fe526e
1. Add IFDEFs for video recording
Stepan777 <stepik-777@mail.ru>
parents:
7180
diff
changeset
|
557 |
if (g_pVStream) |
7180 | 558 |
{ |
7198
5debd5fe526e
1. Add IFDEFs for video recording
Stepan777 <stepik-777@mail.ru>
parents:
7180
diff
changeset
|
559 |
avcodec_close(g_pVideo); |
5debd5fe526e
1. Add IFDEFs for video recording
Stepan777 <stepik-777@mail.ru>
parents:
7180
diff
changeset
|
560 |
av_free(g_pVideo); |
5debd5fe526e
1. Add IFDEFs for video recording
Stepan777 <stepik-777@mail.ru>
parents:
7180
diff
changeset
|
561 |
av_free(g_pVStream); |
11295
210650fc7182
Update libav API, keeping forward and backward compatibility
Vittorio Giovara <vittorio.giovara@gmail.com>
parents:
11046
diff
changeset
|
562 |
av_frame_free(&g_pVFrame); |
7180 | 563 |
} |
7198
5debd5fe526e
1. Add IFDEFs for video recording
Stepan777 <stepik-777@mail.ru>
parents:
7180
diff
changeset
|
564 |
if (g_pAStream) |
7180 | 565 |
{ |
7198
5debd5fe526e
1. Add IFDEFs for video recording
Stepan777 <stepik-777@mail.ru>
parents:
7180
diff
changeset
|
566 |
avcodec_close(g_pAudio); |
5debd5fe526e
1. Add IFDEFs for video recording
Stepan777 <stepik-777@mail.ru>
parents:
7180
diff
changeset
|
567 |
av_free(g_pAudio); |
5debd5fe526e
1. Add IFDEFs for video recording
Stepan777 <stepik-777@mail.ru>
parents:
7180
diff
changeset
|
568 |
av_free(g_pAStream); |
11295
210650fc7182
Update libav API, keeping forward and backward compatibility
Vittorio Giovara <vittorio.giovara@gmail.com>
parents:
11046
diff
changeset
|
569 |
av_frame_free(&g_pAFrame); |
7180 | 570 |
av_free(g_pSamples); |
571 |
fclose(g_pSoundFile); |
|
572 |
} |
|
573 |
||
574 |
av_free(g_pContainer); |
|
9925
113e61a8cadc
Fixed avwrapper exit calls, fixing issue 752
Gianfranco Costamagna <costamagnagianfranco@yahoo.it>
parents:
9224
diff
changeset
|
575 |
return 0; |
7180 | 576 |
} |