Added
Link Here
|
1 |
--- src/common/ffmpeg.cpp.orig 2015-09-19 15:58:26 UTC |
2 |
+++ src/common/ffmpeg.cpp |
3 |
@@ -58,7 +58,7 @@ static void avformat_free_context(AVForm |
4 |
#define priv_AVOutputFormat AVOutputFormat |
5 |
#define priv_AVFrame AVFrame |
6 |
#define priv_SwsContext SwsContext |
7 |
-#define priv_PixelFormat PixelFormat |
8 |
+#define priv_PixelFormat AVPixelFormat |
9 |
#include "ffmpeg.h" |
10 |
|
11 |
// I have no idea what size to make these buffers |
12 |
@@ -78,7 +78,7 @@ MediaRecorder::MediaRecorder() : oc(0), |
13 |
did_init = true; |
14 |
av_register_all(); |
15 |
} |
16 |
- pic = avcodec_alloc_frame(); |
17 |
+ pic = av_frame_alloc(); |
18 |
} |
19 |
|
20 |
MediaRet MediaRecorder::setup_sound_stream(const char *fname, AVOutputFormat *fmt) |
21 |
@@ -89,7 +89,7 @@ MediaRet MediaRecorder::setup_sound_stre |
22 |
oc->oformat = fmt; |
23 |
strncpy(oc->filename, fname, sizeof(oc->filename) - 1); |
24 |
oc->filename[sizeof(oc->filename) - 1] = 0; |
25 |
- if(fmt->audio_codec == CODEC_ID_NONE) |
26 |
+ if(fmt->audio_codec == AV_CODEC_ID_NONE) |
27 |
return MRET_OK; |
28 |
|
29 |
AVCodecContext *ctx; |
30 |
@@ -157,14 +157,14 @@ MediaRet MediaRecorder::setup_video_stre |
31 |
switch(d) { |
32 |
case 16: |
33 |
// FIXME: test & make endian-neutral |
34 |
- pixfmt = PIX_FMT_RGB565LE; |
35 |
+ pixfmt = AV_PIX_FMT_RGB565LE; |
36 |
break; |
37 |
case 24: |
38 |
- pixfmt = PIX_FMT_RGB24; |
39 |
+ pixfmt = AV_PIX_FMT_RGB24; |
40 |
break; |
41 |
case 32: |
42 |
default: // should never be anything else |
43 |
- pixfmt = PIX_FMT_RGBA; |
44 |
+ pixfmt = AV_PIX_FMT_RGBA; |
45 |
break; |
46 |
} |
47 |
ctx->pix_fmt = pixfmt; |
48 |
@@ -177,7 +177,7 @@ MediaRet MediaRecorder::setup_video_stre |
49 |
AVCodec *codec = avcodec_find_encoder(oc->oformat->video_codec); |
50 |
// make sure RGB is supported (mostly not) |
51 |
if(codec->pix_fmts) { |
52 |
- const enum PixelFormat *p; |
53 |
+ const enum AVPixelFormat *p; |
54 |
#if LIBAVCODEC_VERSION_MAJOR < 55 |
55 |
int64_t mask = 0; |
56 |
#endif |
57 |
@@ -205,7 +205,7 @@ MediaRet MediaRecorder::setup_video_stre |
58 |
#endif |
59 |
if(dp == -1) |
60 |
dp = codec->pix_fmts[0]; |
61 |
- if(!(convpic = avcodec_alloc_frame()) || |
62 |
+ if(!(convpic = av_frame_alloc()) || |
63 |
avpicture_alloc((AVPicture *)convpic, dp, w, h) < 0) { |
64 |
avformat_free_context(oc); |
65 |
oc = NULL; |
66 |
@@ -254,10 +254,10 @@ MediaRet MediaRecorder::finish_setup(con |
67 |
frame_len = aud_st->codec->frame_size * 4; |
68 |
sample_len = soundGetSampleRate() * 4 / 60; |
69 |
switch(aud_st->codec->codec_id) { |
70 |
- case CODEC_ID_PCM_S16LE: |
71 |
- case CODEC_ID_PCM_S16BE: |
72 |
- case CODEC_ID_PCM_U16LE: |
73 |
- case CODEC_ID_PCM_U16BE: |
74 |
+ case AV_CODEC_ID_PCM_S16LE: |
75 |
+ case AV_CODEC_ID_PCM_S16BE: |
76 |
+ case AV_CODEC_ID_PCM_U16LE: |
77 |
+ case AV_CODEC_ID_PCM_U16BE: |
78 |
frame_len = sample_len; |
79 |
} |
80 |
audio_buf = (u8 *)malloc(AUDIO_BUF_LEN); |
81 |
@@ -307,7 +307,7 @@ MediaRet MediaRecorder::Record(const cha |
82 |
AVOutputFormat *fmt = av_guess_format(NULL, fname, NULL); |
83 |
if(!fmt) |
84 |
fmt = av_guess_format("avi", NULL, NULL); |
85 |
- if(!fmt || fmt->video_codec == CODEC_ID_NONE) |
86 |
+ if(!fmt || fmt->video_codec == AV_CODEC_ID_NONE) |
87 |
return MRET_ERR_FMTGUESS; |
88 |
MediaRet ret; |
89 |
if((ret = setup_sound_stream(fname, fmt)) == MRET_OK && |
90 |
@@ -324,7 +324,7 @@ MediaRet MediaRecorder::Record(const cha |
91 |
AVOutputFormat *fmt = av_guess_format(NULL, fname, NULL); |
92 |
if(!fmt) |
93 |
fmt = av_guess_format("wav", NULL, NULL); |
94 |
- if(!fmt || fmt->audio_codec == CODEC_ID_NONE) |
95 |
+ if(!fmt || fmt->audio_codec == AV_CODEC_ID_NONE) |
96 |
return MRET_ERR_FMTGUESS; |
97 |
MediaRet ret; |
98 |
if((ret = setup_sound_stream(fname, fmt)) == MRET_OK) |
99 |
@@ -392,7 +392,7 @@ MediaRet MediaRecorder::AddFrame(const u |
100 |
tbord = 1; rbord = 1; break; |
101 |
} |
102 |
avpicture_fill((AVPicture *)pic, (uint8_t *)vid + tbord * (linesize + pixsize * rbord), |
103 |
- (PixelFormat)pixfmt, ctx->width + rbord, ctx->height); |
104 |
+ (AVPixelFormat)pixfmt, ctx->width + rbord, ctx->height); |
105 |
// satisfy stupid sws_scale()'s integrity check |
106 |
pic->data[1] = pic->data[2] = pic->data[3] = pic->data[0]; |
107 |
pic->linesize[1] = pic->linesize[2] = pic->linesize[3] = pic->linesize[0]; |
108 |
@@ -413,8 +413,12 @@ MediaRet MediaRecorder::AddFrame(const u |
109 |
pkt.data = f->data[0]; |
110 |
pkt.size = linesize * ctx->height; |
111 |
} else { |
112 |
- pkt.size = avcodec_encode_video(ctx, video_buf, VIDEO_BUF_LEN, f); |
113 |
- if(!pkt.size) |
114 |
+ pkt.data = video_buf; |
115 |
+ pkt.size = VIDEO_BUF_LEN; |
116 |
+ |
117 |
+ int got_packet = 0; |
118 |
+ int ret = avcodec_encode_video2(ctx, &pkt, f, &got_packet); |
119 |
+ if(ret < 0 || !got_packet || pkt.size <= 0) |
120 |
return MRET_OK; |
121 |
if(ctx->coded_frame && ctx->coded_frame->pts != AV_NOPTS_VALUE) |
122 |
pkt.pts = av_rescale_q(ctx->coded_frame->pts, ctx->time_base, vid_st->time_base); |
123 |
@@ -425,7 +429,6 @@ MediaRet MediaRecorder::AddFrame(const u |
124 |
} |
125 |
if(ctx->coded_frame->key_frame) |
126 |
pkt.flags |= AV_PKT_FLAG_KEY; |
127 |
- pkt.data = video_buf; |
128 |
} |
129 |
if(av_interleaved_write_frame(oc, &pkt) < 0) { |
130 |
avformat_free_context(oc); |