34 # ifdef WITH_AUDASPACE
35 # include <AUD_Device.h>
36 # include <AUD_Special.h>
56 # include <libavcodec/avcodec.h>
57 # include <libavformat/avformat.h>
58 # include <libavutil/imgutils.h>
59 # include <libavutil/opt.h>
60 # include <libavutil/rational.h>
61 # include <libavutil/samplefmt.h>
62 # include <libswscale/swscale.h>
68 typedef struct FFMpegContext {
71 int ffmpeg_audio_codec;
72 int ffmpeg_video_bitrate;
73 int ffmpeg_audio_bitrate;
75 int ffmpeg_max_b_frames;
77 int ffmpeg_autosplit_count;
83 AVFormatContext *outfile;
84 AVCodecContext *video_codec;
85 AVCodecContext *audio_codec;
86 AVStream *video_stream;
87 AVStream *audio_stream;
88 AVFrame *current_frame;
92 AVFrame *img_convert_frame;
93 struct SwsContext *img_convert_ctx;
96 uint8_t *audio_deinterleave_buffer;
97 int audio_input_samples;
99 double audio_time_total;
100 bool audio_deinterleave;
101 int audio_sample_size;
105 # ifdef WITH_AUDASPACE
106 AUD_Device *audio_mixdown_device;
110 # define FFMPEG_AUTOSPLIT_SIZE 2000000000
113 if (G.debug & G_DEBUG_FFMPEG) \
116 static void ffmpeg_dict_set_int(AVDictionary **dict,
const char *key,
int value);
117 static void ffmpeg_dict_set_float(AVDictionary **dict,
const char *key,
float value);
118 static void ffmpeg_set_expert_options(
RenderData *rd);
119 static void ffmpeg_filepath_get(FFMpegContext *
context,
127 static void delete_picture(AVFrame *f)
137 static int request_float_audio_buffer(
int codec_id)
140 return codec_id == AV_CODEC_ID_AAC || codec_id == AV_CODEC_ID_AC3 ||
141 codec_id == AV_CODEC_ID_VORBIS;
144 # ifdef WITH_AUDASPACE
146 static int write_audio_frame(FFMpegContext *
context)
149 AVCodecContext *
c =
context->audio_codec;
154 frame = av_frame_alloc();
157 frame->format =
c->sample_fmt;
158 frame->channels =
c->channels;
159 frame->channel_layout =
c->channel_layout;
161 if (
context->audio_deinterleave) {
165 for (channel = 0; channel <
c->channels; channel++) {
166 for (i = 0; i <
frame->nb_samples; i++) {
167 memcpy(
context->audio_deinterleave_buffer +
168 (i + channel *
frame->nb_samples) *
context->audio_sample_size,
170 (
c->channels * i + channel) *
context->audio_sample_size,
175 temp =
context->audio_deinterleave_buffer;
177 context->audio_input_buffer = temp;
180 avcodec_fill_audio_frame(
frame,
184 context->audio_input_samples *
c->channels *
context->audio_sample_size,
192 fprintf(stderr,
"Can't send audio frame: %s\n", av_err2str(
ret));
196 AVPacket *pkt = av_packet_alloc();
200 ret = avcodec_receive_packet(
c, pkt);
201 if (
ret == AVERROR(EAGAIN) ||
ret == AVERROR_EOF) {
205 fprintf(stderr,
"Error encoding audio frame: %s\n", av_err2str(
ret));
209 pkt->stream_index =
context->audio_stream->index;
210 av_packet_rescale_ts(pkt,
c->time_base,
context->audio_stream->time_base);
211 # ifdef FFMPEG_USE_DURATION_WORKAROUND
215 pkt->flags |= AV_PKT_FLAG_KEY;
217 int write_ret = av_interleaved_write_frame(
context->outfile, pkt);
218 if (write_ret != 0) {
219 fprintf(stderr,
"Error writing audio packet: %s\n", av_err2str(write_ret));
225 av_packet_free(&pkt);
226 av_frame_free(&
frame);
233 static AVFrame *alloc_picture(
int pix_fmt,
int width,
int height)
240 f = av_frame_alloc();
252 av_image_fill_arrays(f->data, f->linesize, buf, pix_fmt,
width,
height, 1);
262 static const char **get_file_extensions(
int format)
266 static const char *rv[] = {
".dv",
NULL};
270 static const char *rv[] = {
".mpg",
".mpeg",
NULL};
274 static const char *rv[] = {
".dvd",
".vob",
".mpg",
".mpeg",
NULL};
278 static const char *rv[] = {
".mp4",
".mpg",
".mpeg",
NULL};
282 static const char *rv[] = {
".avi",
NULL};
286 static const char *rv[] = {
".mov",
NULL};
291 static const char *rv[] = {
".avi",
NULL};
297 static const char *rv[] = {
".avi",
NULL};
301 static const char *rv[] = {
".flv",
NULL};
305 static const char *rv[] = {
".mkv",
NULL};
309 static const char *rv[] = {
".ogv",
".ogg",
NULL};
313 static const char *rv[] = {
".webm",
NULL};
324 int ret, success = 1;
325 AVPacket *packet = av_packet_alloc();
327 AVCodecContext *
c =
context->video_codec;
335 fprintf(stderr,
"Can't send video frame: %s\n", av_err2str(
ret));
340 ret = avcodec_receive_packet(
c, packet);
342 if (
ret == AVERROR(EAGAIN) ||
ret == AVERROR_EOF) {
347 fprintf(stderr,
"Error encoding frame: %s\n", av_err2str(
ret));
351 packet->stream_index =
context->video_stream->index;
352 av_packet_rescale_ts(packet,
c->time_base,
context->video_stream->time_base);
353 # ifdef FFMPEG_USE_DURATION_WORKAROUND
357 if (av_interleaved_write_frame(
context->outfile, packet) != 0) {
365 PRINT(
"Error writing frame: %s\n", av_err2str(
ret));
368 av_packet_free(&packet);
374 static AVFrame *generate_video_frame(FFMpegContext *
context,
const uint8_t *pixels)
376 AVCodecParameters *codec =
context->video_stream->codecpar;
377 int height = codec->height;
382 rgb_frame =
context->img_convert_frame;
386 rgb_frame =
context->current_frame;
391 int linesize = rgb_frame->linesize[0];
393 uint8_t *target = rgb_frame->data[0] + linesize * (
height -
y - 1);
394 const uint8_t *src = pixels + linesize *
y;
396 # if ENDIAN_ORDER == L_ENDIAN
397 memcpy(target, src, linesize);
399 # elif ENDIAN_ORDER == B_ENDIAN
400 const uint8_t *end = src + linesize;
411 # error ENDIAN_ORDER should either be L_ENDIAN or B_ENDIAN.
418 sws_scale(
context->img_convert_ctx,
419 (
const uint8_t *
const *)rgb_frame->data,
424 context->current_frame->linesize);
430 static void set_ffmpeg_property_option(
IDProperty *prop, AVDictionary **dictionary)
435 PRINT(
"FFMPEG expert option: %s: ", prop->
name);
439 param = strchr(name,
':');
445 switch (prop->
type) {
448 av_dict_set(dictionary, name,
IDP_String(prop), 0);
452 ffmpeg_dict_set_float(dictionary, prop->
name,
IDP_Float(prop));
459 av_dict_set(dictionary, name, param, 0);
466 ffmpeg_dict_set_int(dictionary, prop->
name,
IDP_Int(prop));
472 static int ffmpeg_proprty_valid(AVCodecContext *
c,
const char *prop_name,
IDProperty *curr)
476 if (
STREQ(prop_name,
"video")) {
479 valid &=
c->codec_id != AV_CODEC_ID_FLV1;
486 static void set_ffmpeg_properties(
RenderData *rd,
488 const char *prop_name,
489 AVDictionary **dictionary)
505 ffmpeg_set_expert_options(rd);
517 if (ffmpeg_proprty_valid(
c, prop_name, curr)) {
518 set_ffmpeg_property_option(curr, dictionary);
523 static AVRational calc_time_base(
uint den,
double num,
int codec_id)
530 float eps = FLT_EPSILON;
531 const uint DENUM_MAX = (codec_id == AV_CODEC_ID_MPEG4) ? (1UL << 16) - 1 : (1UL << 31) - 1;
542 eps = (
float)(1 << num_integer_bits) * FLT_EPSILON;
546 const int max_num_shift =
fabsf(log10f(
eps));
548 const int max_den_shift = log10f(DENUM_MAX) - log10f(den);
549 const int max_iter =
min_ii(max_num_shift, max_den_shift);
551 for (
int i = 0; i < max_iter &&
fabs(num - round(num)) >
eps; i++) {
558 AVRational time_base;
560 time_base.num = (int)num;
567 static AVStream *alloc_video_stream(FFMpegContext *
context,
578 AVDictionary *opts =
NULL;
582 st = avformat_new_stream(of,
NULL);
590 context->video_codec = avcodec_alloc_context3(
NULL);
591 AVCodecContext *
c =
context->video_codec;
592 c->codec_id = codec_id;
593 c->codec_type = AVMEDIA_TYPE_VIDEO;
595 codec = avcodec_find_encoder(
c->codec_id);
597 fprintf(stderr,
"Couldn't find valid video codec\n");
598 avcodec_free_context(&
c);
604 avcodec_get_context_defaults3(
c, codec);
613 c->time_base.den = 2997;
614 c->time_base.num = 100;
630 if (
c->time_base.num != 1) {
631 AVRational new_time_base;
633 &new_time_base.num, &new_time_base.den,
c->time_base.num,
c->time_base.den, INT_MAX)) {
635 c->time_base = new_time_base;
639 st->time_base =
c->time_base;
641 c->gop_size =
context->ffmpeg_gop_size;
642 c->max_b_frames =
context->ffmpeg_max_b_frames;
644 if (
context->ffmpeg_type == FFMPEG_WEBM &&
context->ffmpeg_crf == 0) {
645 ffmpeg_dict_set_int(&opts,
"lossless", 1);
647 else if (
context->ffmpeg_crf >= 0) {
653 ffmpeg_dict_set_int(&opts,
"crf",
context->ffmpeg_crf);
656 c->bit_rate =
context->ffmpeg_video_bitrate * 1000;
666 char const *preset_name =
NULL;
667 char const *deadline_name =
NULL;
668 switch (
context->ffmpeg_preset) {
670 preset_name =
"medium";
671 deadline_name =
"good";
674 preset_name =
"slower";
675 deadline_name =
"best";
678 preset_name =
"superfast";
679 deadline_name =
"realtime";
682 printf(
"Unknown preset number %i, ignoring.\n",
context->ffmpeg_preset);
684 if (preset_name !=
NULL) {
685 av_dict_set(&opts,
"preset", preset_name, 0);
687 if (deadline_name !=
NULL) {
688 av_dict_set(&opts,
"deadline", deadline_name, 0);
694 if (codec->pix_fmts) {
695 c->pix_fmt = codec->pix_fmts[0];
699 c->pix_fmt = AV_PIX_FMT_YUV422P;
702 if (
context->ffmpeg_type == FFMPEG_XVID) {
704 c->pix_fmt = AV_PIX_FMT_YUV420P;
705 c->codec_tag = ((
'D' << 24) + (
'I' << 16) + (
'V' << 8) +
'X');
709 if (codec_id == AV_CODEC_ID_HUFFYUV) {
711 c->pix_fmt = AV_PIX_FMT_BGRA;
714 c->pix_fmt = AV_PIX_FMT_RGB32;
718 if (codec_id == AV_CODEC_ID_FFV1) {
719 c->pix_fmt = AV_PIX_FMT_RGB32;
722 if (codec_id == AV_CODEC_ID_QTRLE) {
724 c->pix_fmt = AV_PIX_FMT_ARGB;
728 if (codec_id == AV_CODEC_ID_VP9) {
730 c->pix_fmt = AV_PIX_FMT_YUVA420P;
734 if (codec_id == AV_CODEC_ID_PNG) {
736 c->pix_fmt = AV_PIX_FMT_RGBA;
740 if ((of->oformat->flags & AVFMT_GLOBALHEADER)) {
741 PRINT(
"Using global header\n");
742 c->flags |= AV_CODEC_FLAG_GLOBAL_HEADER;
747 st->sample_aspect_ratio =
c->sample_aspect_ratio = av_d2q(((
double)rd->
xasp / (
double)rd->
yasp),
749 st->avg_frame_rate = av_inv_q(
c->time_base);
751 set_ffmpeg_properties(rd,
c,
"video", &opts);
753 if (codec->capabilities & AV_CODEC_CAP_AUTO_THREADS) {
760 if (codec->capabilities & AV_CODEC_CAP_FRAME_THREADS) {
761 c->thread_type = FF_THREAD_FRAME;
763 else if (codec->capabilities & AV_CODEC_CAP_SLICE_THREADS) {
764 c->thread_type = FF_THREAD_SLICE;
767 int ret = avcodec_open2(
c, codec, &opts);
770 fprintf(stderr,
"Couldn't initialize video codec: %s\n", av_err2str(
ret));
773 avcodec_free_context(&
c);
780 context->current_frame = alloc_picture(
c->pix_fmt,
c->width,
c->height);
782 if (
c->pix_fmt == AV_PIX_FMT_RGBA) {
789 context->img_convert_frame = alloc_picture(AV_PIX_FMT_RGBA,
c->width,
c->height);
790 context->img_convert_ctx = sws_getContext(
c->width,
802 avcodec_parameters_from_context(st->codecpar,
c);
809 static AVStream *alloc_audio_stream(FFMpegContext *
context,
818 AVDictionary *opts =
NULL;
822 st = avformat_new_stream(of,
NULL);
828 context->audio_codec = avcodec_alloc_context3(
NULL);
829 AVCodecContext *
c =
context->audio_codec;
831 c->thread_type = FF_THREAD_SLICE;
833 c->codec_id = codec_id;
834 c->codec_type = AVMEDIA_TYPE_AUDIO;
836 codec = avcodec_find_encoder(
c->codec_id);
838 fprintf(stderr,
"Couldn't find valid audio codec\n");
839 avcodec_free_context(&
c);
845 avcodec_get_context_defaults3(
c, codec);
848 c->bit_rate =
context->ffmpeg_audio_bitrate * 1000;
849 c->sample_fmt = AV_SAMPLE_FMT_S16;
854 c->channel_layout = AV_CH_LAYOUT_MONO;
857 c->channel_layout = AV_CH_LAYOUT_STEREO;
860 c->channel_layout = AV_CH_LAYOUT_QUAD;
863 c->channel_layout = AV_CH_LAYOUT_5POINT1_BACK;
866 c->channel_layout = AV_CH_LAYOUT_7POINT1;
870 if (request_float_audio_buffer(codec_id)) {
872 c->strict_std_compliance = FF_COMPLIANCE_EXPERIMENTAL;
873 c->sample_fmt = AV_SAMPLE_FMT_FLT;
876 if (codec->sample_fmts) {
882 const enum AVSampleFormat *p = codec->sample_fmts;
883 for (; *p != -1; p++) {
884 if (*p ==
c->sample_fmt) {
890 c->sample_fmt = codec->sample_fmts[0];
894 if (codec->supported_samplerates) {
895 const int *p = codec->supported_samplerates;
897 int best_dist = INT_MAX;
899 int dist =
abs(
c->sample_rate - *p);
900 if (dist < best_dist) {
906 c->sample_rate = best;
909 if (of->oformat->flags & AVFMT_GLOBALHEADER) {
910 c->flags |= AV_CODEC_FLAG_GLOBAL_HEADER;
913 set_ffmpeg_properties(rd,
c,
"audio", &opts);
915 int ret = avcodec_open2(
c, codec, &opts);
918 fprintf(stderr,
"Couldn't initialize audio codec: %s\n", av_err2str(
ret));
921 avcodec_free_context(&
c);
929 c->time_base.num = 1;
930 c->time_base.den =
c->sample_rate;
932 if (
c->frame_size == 0) {
936 context->audio_input_samples = AV_INPUT_BUFFER_MIN_SIZE * 8 /
c->bits_per_coded_sample /
940 context->audio_input_samples =
c->frame_size;
943 context->audio_deinterleave = av_sample_fmt_is_planar(
c->sample_fmt);
945 context->audio_sample_size = av_get_bytes_per_sample(
c->sample_fmt);
949 if (
context->audio_deinterleave) {
951 context->audio_input_samples *
c->channels *
context->audio_sample_size);
956 avcodec_parameters_from_context(st->codecpar,
c);
962 static void ffmpeg_dict_set_int(AVDictionary **dict,
const char *key,
int value)
968 av_dict_set(dict, key,
buffer, 0);
971 static void ffmpeg_dict_set_float(AVDictionary **dict,
const char *key,
float value)
977 av_dict_set(dict, key,
buffer, 0);
980 static void ffmpeg_add_metadata_callback(
void *
data,
981 const char *propname,
985 AVDictionary **metadata = (AVDictionary **)
data;
986 av_dict_set(metadata, propname, propvalue, 0);
989 static int start_ffmpeg_impl(FFMpegContext *
context,
999 AVDictionary *opts =
NULL;
1018 ffmpeg_filepath_get(
context, name, rd,
context->ffmpeg_preview, suffix);
1020 "Starting output to %s(ffmpeg)...\n"
1021 " Using type=%d, codec=%d, audio_codec=%d,\n"
1022 " video_bitrate=%d, audio_bitrate=%d,\n"
1023 " gop_size=%d, autosplit=%d\n"
1024 " render width=%d, render height=%d\n",
1029 context->ffmpeg_video_bitrate,
1030 context->ffmpeg_audio_bitrate,
1036 exts = get_file_extensions(
context->ffmpeg_type);
1041 fmt = av_guess_format(
NULL, exts[0],
NULL);
1047 of = avformat_alloc_context();
1058 if (
context->ffmpeg_crf == 0) {
1060 if (
context->ffmpeg_audio_codec != AV_CODEC_ID_NONE) {
1064 av_dict_set(&opts,
"muxrate",
"0", 0);
1068 ffmpeg_dict_set_int(&opts,
"preload", (
int)(0.5 * AV_TIME_BASE));
1070 of->max_delay = (int)(0.7 * AV_TIME_BASE);
1072 fmt->audio_codec =
context->ffmpeg_audio_codec;
1074 of->url = av_strdup(name);
1076 switch (
context->ffmpeg_type) {
1080 fmt->video_codec =
context->ffmpeg_codec;
1083 fmt->video_codec = AV_CODEC_ID_THEORA;
1086 fmt->video_codec = AV_CODEC_ID_DVVIDEO;
1089 fmt->video_codec = AV_CODEC_ID_MPEG1VIDEO;
1092 fmt->video_codec = AV_CODEC_ID_MPEG2VIDEO;
1095 fmt->video_codec = AV_CODEC_ID_H264;
1098 fmt->video_codec = AV_CODEC_ID_MPEG4;
1101 fmt->video_codec = AV_CODEC_ID_FLV1;
1105 fmt->video_codec =
context->ffmpeg_codec;
1108 if (fmt->video_codec == AV_CODEC_ID_DVVIDEO) {
1113 if (rd->
frs_sec != 25 && recty != 480) {
1117 if (rd->
frs_sec == 25 && recty != 576) {
1123 if (
context->ffmpeg_type == FFMPEG_DV) {
1124 fmt->audio_codec = AV_CODEC_ID_PCM_S16LE;
1125 if (
context->ffmpeg_audio_codec != AV_CODEC_ID_NONE &&
1132 if (fmt->video_codec != AV_CODEC_ID_NONE) {
1133 context->video_stream = alloc_video_stream(
1135 PRINT(
"alloc video stream %p\n",
context->video_stream);
1143 PRINT(
"Error initializing video stream");
1149 if (
context->ffmpeg_audio_codec != AV_CODEC_ID_NONE) {
1150 context->audio_stream = alloc_audio_stream(
1159 PRINT(
"Error initializing audio stream");
1164 if (!(fmt->flags & AVFMT_NOFILE)) {
1165 if (avio_open(&of->pb, name, AVIO_FLAG_WRITE) < 0) {
1167 PRINT(
"Could not open file for writing\n");
1174 &of->metadata,
context->stamp_data, ffmpeg_add_metadata_callback,
false);
1177 int ret = avformat_write_header(of,
NULL);
1181 "Could not initialize streams, probably unsupported codec combination");
1182 PRINT(
"Could not write media header: %s\n", av_err2str(
ret));
1187 av_dump_format(of, 0, name, 1);
1188 av_dict_free(&opts);
1205 av_dict_free(&opts);
1206 avformat_free_context(of);
1227 static void flush_ffmpeg(AVCodecContext *
c, AVStream *stream, AVFormatContext *outfile)
1229 AVPacket *packet = av_packet_alloc();
1231 avcodec_send_frame(
c,
NULL);
1236 ret = avcodec_receive_packet(
c, packet);
1238 if (
ret == AVERROR(EAGAIN) ||
ret == AVERROR_EOF) {
1243 fprintf(stderr,
"Error encoding delayed frame: %s\n", av_err2str(
ret));
1247 packet->stream_index = stream->index;
1248 av_packet_rescale_ts(packet,
c->time_base, stream->time_base);
1249 # ifdef FFMPEG_USE_DURATION_WORKAROUND
1253 int write_ret = av_interleaved_write_frame(outfile, packet);
1254 if (write_ret != 0) {
1255 fprintf(stderr,
"Error writing delayed frame: %s\n", av_err2str(write_ret));
1260 av_packet_free(&packet);
1268 static void ffmpeg_filepath_get(
1269 FFMpegContext *
context,
char *
string,
const RenderData *rd,
bool preview,
const char *suffix)
1274 const char **fe = exts;
1277 if (!
string || !exts) {
1290 strcpy(
string, rd->
pic);
1295 autosplit[0] =
'\0';
1299 sprintf(autosplit,
"_%03d",
context->ffmpeg_autosplit_count);
1305 if (
BLI_strcasecmp(
string + strlen(
string) - strlen(*fe), *fe) == 0) {
1312 strcat(
string, autosplit);
1315 strcat(
string, *exts);
1318 *(
string + strlen(
string) - strlen(*fe)) =
'\0';
1319 strcat(
string, autosplit);
1320 strcat(
string, *fe);
1328 strcat(
string, autosplit);
1334 void BKE_ffmpeg_filepath_get(
char *
string,
const RenderData *rd,
bool preview,
const char *suffix)
1336 ffmpeg_filepath_get(
NULL,
string, rd, preview, suffix);
1339 int BKE_ffmpeg_start(
void *context_v,
1349 FFMpegContext *
context = context_v;
1351 context->ffmpeg_autosplit_count = 0;
1352 context->ffmpeg_preview = preview;
1355 success = start_ffmpeg_impl(
context, rd, rectx, recty, suffix, reports);
1356 # ifdef WITH_AUDASPACE
1358 AVCodecContext *
c =
context->audio_codec;
1360 AUD_DeviceSpecs specs;
1361 specs.channels =
c->channels;
1363 switch (av_get_packed_sample_fmt(
c->sample_fmt)) {
1364 case AV_SAMPLE_FMT_U8:
1365 specs.format = AUD_FORMAT_U8;
1367 case AV_SAMPLE_FMT_S16:
1368 specs.format = AUD_FORMAT_S16;
1370 case AV_SAMPLE_FMT_S32:
1371 specs.format = AUD_FORMAT_S32;
1373 case AV_SAMPLE_FMT_FLT:
1374 specs.format = AUD_FORMAT_FLOAT32;
1376 case AV_SAMPLE_FMT_DBL:
1377 specs.format = AUD_FORMAT_FLOAT64;
1384 context->audio_mixdown_device = BKE_sound_mixdown(
1391 static void end_ffmpeg_impl(FFMpegContext *
context,
int is_autosplit);
1393 # ifdef WITH_AUDASPACE
1394 static void write_audio_frames(FFMpegContext *
context,
double to_pts)
1396 AVCodecContext *
c =
context->audio_codec;
1398 while (
context->audio_stream) {
1399 if ((
context->audio_time_total >= to_pts) || !write_audio_frame(
context)) {
1408 int BKE_ffmpeg_append(
void *context_v,
1418 FFMpegContext *
context = context_v;
1422 PRINT(
"Writing frame %i, render width=%d, render height=%d\n",
frame, rectx, recty);
1425 avframe = generate_video_frame(
context, (
unsigned char *)pixels);
1426 success = (avframe && write_video_frame(
context, avframe, reports));
1427 # ifdef WITH_AUDASPACE
1433 if (
context->ffmpeg_autosplit) {
1434 if (avio_tell(
context->outfile->pb) > FFMPEG_AUTOSPLIT_SIZE) {
1435 end_ffmpeg_impl(
context,
true);
1436 context->ffmpeg_autosplit_count++;
1438 success &= start_ffmpeg_impl(
context, rd, rectx, recty, suffix, reports);
1446 static void end_ffmpeg_impl(FFMpegContext *
context,
int is_autosplit)
1448 PRINT(
"Closing ffmpeg...\n");
1450 # ifdef WITH_AUDASPACE
1451 if (is_autosplit ==
false) {
1452 if (
context->audio_mixdown_device) {
1453 AUD_Device_free(
context->audio_mixdown_device);
1460 PRINT(
"Flushing delayed video frames...\n");
1465 PRINT(
"Flushing delayed audio frames...\n");
1470 av_write_trailer(
context->outfile);
1476 PRINT(
"zero video stream %p\n",
context->video_stream);
1486 delete_picture(
context->current_frame);
1490 delete_picture(
context->img_convert_frame);
1495 if (!(
context->outfile->oformat->flags & AVFMT_NOFILE)) {
1496 avio_close(
context->outfile->pb);
1501 avcodec_free_context(&
context->video_codec);
1505 avcodec_free_context(&
context->audio_codec);
1510 avformat_free_context(
context->outfile);
1514 av_free(
context->audio_input_buffer);
1519 av_free(
context->audio_deinterleave_buffer);
1524 sws_freeContext(
context->img_convert_ctx);
1529 void BKE_ffmpeg_end(
void *context_v)
1531 FFMpegContext *
context = context_v;
1532 end_ffmpeg_impl(
context,
false);
1537 void BKE_ffmpeg_property_del(
RenderData *rd,
void *
type,
void *prop_)
1547 if (group && prop) {
1555 const AVOption *parent)
1566 avcodec_get_context_defaults3(&
c,
NULL);
1594 case AV_OPT_TYPE_INT:
1595 case AV_OPT_TYPE_INT64:
1596 val.
i = o->default_val.i64;
1599 case AV_OPT_TYPE_DOUBLE:
1600 case AV_OPT_TYPE_FLOAT:
1601 val.
f = o->default_val.dbl;
1604 case AV_OPT_TYPE_STRING:
1611 case AV_OPT_TYPE_CONST:
1625 int BKE_ffmpeg_property_add_string(
RenderData *rd,
const char *
type,
const char *
str)
1628 const AVOption *o =
NULL;
1629 const AVOption *p =
NULL;
1635 avcodec_get_context_defaults3(&
c,
NULL);
1640 while (*
name ==
' ') {
1644 param = strchr(
name,
':');
1647 param = strchr(
name,
' ');
1651 while (*param ==
' ') {
1656 o = av_opt_find(&
c,
name,
NULL, 0, AV_OPT_SEARCH_CHILDREN | AV_OPT_SEARCH_FAKE_OBJ);
1658 PRINT(
"Ignoring unknown expert option %s\n",
str);
1661 if (param && o->type == AV_OPT_TYPE_CONST) {
1664 if (param && o->type != AV_OPT_TYPE_CONST && o->unit) {
1665 p = av_opt_find(&
c, param, o->unit, 0, AV_OPT_SEARCH_CHILDREN | AV_OPT_SEARCH_FAKE_OBJ);
1667 prop = BKE_ffmpeg_property_add(rd, (
char *)
type, p, o);
1670 PRINT(
"Ignoring unknown expert option %s\n",
str);
1674 prop = BKE_ffmpeg_property_add(rd, (
char *)
type, o,
NULL);
1682 switch (prop->
type) {
1697 static void ffmpeg_set_expert_options(
RenderData *rd)
1705 if (codec_id == AV_CODEC_ID_DNXHD) {
1707 BKE_ffmpeg_property_add_string(rd,
"video",
"mbd:rd");
1712 void BKE_ffmpeg_preset_set(
RenderData *rd,
int preset)
1714 int isntsc = (rd->
frs_sec != 25);
1721 case FFMPEG_PRESET_VCD:
1725 rd->
ysch = isntsc ? 240 : 288;
1734 case FFMPEG_PRESET_SVCD:
1738 rd->
ysch = isntsc ? 480 : 576;
1747 case FFMPEG_PRESET_DVD:
1763 case FFMPEG_PRESET_DV:
1766 rd->
ysch = isntsc ? 480 : 576;
1769 case FFMPEG_PRESET_H264:
1782 case FFMPEG_PRESET_THEORA:
1783 case FFMPEG_PRESET_XVID:
1784 if (preset == FFMPEG_PRESET_XVID) {
1788 else if (preset == FFMPEG_PRESET_THEORA) {
1803 ffmpeg_set_expert_options(rd);
1813 BKE_ffmpeg_preset_set(rd, FFMPEG_PRESET_H264);
1826 BKE_ffmpeg_preset_set(rd, FFMPEG_PRESET_H264);
1832 BKE_ffmpeg_preset_set(rd, FFMPEG_PRESET_XVID);
1838 BKE_ffmpeg_preset_set(rd, FFMPEG_PRESET_THEORA);
1849 void BKE_ffmpeg_codec_settings_verify(
RenderData *rd)
1851 ffmpeg_set_expert_options(rd);
1854 bool BKE_ffmpeg_alpha_channel_is_supported(
const RenderData *rd)
1863 AV_CODEC_ID_HUFFYUV);
1866 void *BKE_ffmpeg_context_create(
void)
1873 context->ffmpeg_codec = AV_CODEC_ID_MPEG4;
1874 context->ffmpeg_audio_codec = AV_CODEC_ID_NONE;
1875 context->ffmpeg_video_bitrate = 1150;
1876 context->ffmpeg_audio_bitrate = 128;
1877 context->ffmpeg_gop_size = 12;
1878 context->ffmpeg_autosplit = 0;
1879 context->ffmpeg_autosplit_count = 0;
1880 context->ffmpeg_preview =
false;
1882 context->audio_time_total = 0.0;
1887 void BKE_ffmpeg_context_free(
void *context_v)
1889 FFMpegContext *
context = context_v;
typedef float(TangentPoint)[2]
void IDP_FreePropertyContent(struct IDProperty *prop)
bool IDP_AddToGroup(struct IDProperty *group, struct IDProperty *prop) ATTR_NONNULL()
struct IDProperty * IDP_GetPropertyFromGroup(const struct IDProperty *prop, const char *name) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
struct IDProperty * IDP_New(const char type, const IDPropertyTemplate *val, const char *name) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
void IDP_FreeFromGroup(struct IDProperty *group, struct IDProperty *prop) ATTR_NONNULL()
struct StampData * BKE_stamp_info_from_scene_static(const struct Scene *scene)
void BKE_stamp_info_callback(void *data, struct StampData *stamp_data, StampCallback callback, bool noskip)
const char * BKE_main_blendfile_path_from_global(void)
void BKE_report(ReportList *reports, ReportType type, const char *message)
void BLI_kdtree_nd_() free(KDTree *tree)
MINLINE int min_ii(int a, int b)
MINLINE unsigned int log2_floor_u(unsigned int x)
bool BLI_make_existing_file(const char *name)
bool BLI_path_frame_check_chars(const char *path) ATTR_NONNULL()
bool BLI_path_frame_range(char *path, int sta, int end, int digits) ATTR_NONNULL()
bool BLI_path_abs(char *path, const char *basepath) ATTR_NONNULL()
bool BLI_path_suffix(char *string, size_t maxlen, const char *suffix, const char *sep) ATTR_NONNULL()
int BLI_strcasecmp(const char *s1, const char *s2) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
size_t BLI_snprintf(char *__restrict dst, size_t maxncpy, const char *__restrict format,...) ATTR_NONNULL(1
char * BLI_strncpy(char *__restrict dst, const char *__restrict src, const size_t maxncpy) ATTR_NONNULL()
int BLI_system_thread_count(void)
typedef double(DMatrix)[4][4]
#define R_IMF_IMTYPE_FFMPEG
#define R_IMF_IMTYPE_H264
#define R_IMF_IMTYPE_THEORA
@ FFMPEG_AUTOSPLIT_OUTPUT
@ FFMPEG_USE_MAX_B_FRAMES
#define R_IMF_IMTYPE_XVID
#define R_IMF_PLANES_RGBA
@ FFM_CHANNELS_SURROUND51
@ FFM_CHANNELS_SURROUND71
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum const void *lists _GL_VOID_RET _GL_VOID const GLdouble *equation _GL_VOID_RET _GL_VOID GLdouble GLdouble blue _GL_VOID_RET _GL_VOID GLfloat GLfloat blue _GL_VOID_RET _GL_VOID GLint GLint blue _GL_VOID_RET _GL_VOID GLshort GLshort blue _GL_VOID_RET _GL_VOID GLubyte GLubyte blue _GL_VOID_RET _GL_VOID GLuint GLuint blue _GL_VOID_RET _GL_VOID GLushort GLushort blue _GL_VOID_RET _GL_VOID GLbyte GLbyte GLbyte alpha _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble alpha _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat alpha _GL_VOID_RET _GL_VOID GLint GLint GLint alpha _GL_VOID_RET _GL_VOID GLshort GLshort GLshort alpha _GL_VOID_RET _GL_VOID GLubyte GLubyte GLubyte alpha _GL_VOID_RET _GL_VOID GLuint GLuint GLuint alpha _GL_VOID_RET _GL_VOID GLushort GLushort GLushort alpha _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLint GLsizei width
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum type
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei height
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum const void *lists _GL_VOID_RET _GL_VOID const GLdouble *equation _GL_VOID_RET _GL_VOID GLdouble GLdouble blue _GL_VOID_RET _GL_VOID GLfloat GLfloat blue _GL_VOID_RET _GL_VOID GLint GLint blue _GL_VOID_RET _GL_VOID GLshort GLshort blue _GL_VOID_RET _GL_VOID GLubyte GLubyte blue _GL_VOID_RET _GL_VOID GLuint GLuint blue _GL_VOID_RET _GL_VOID GLushort GLushort blue _GL_VOID_RET _GL_VOID GLbyte GLbyte GLbyte alpha _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble alpha _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat alpha _GL_VOID_RET _GL_VOID GLint GLint GLint alpha _GL_VOID_RET _GL_VOID GLshort GLshort GLshort alpha _GL_VOID_RET _GL_VOID GLubyte GLubyte GLubyte alpha _GL_VOID_RET _GL_VOID GLuint GLuint GLuint alpha _GL_VOID_RET _GL_VOID GLushort GLushort GLushort alpha _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLint y
const char * IMB_ffmpeg_last_error(void)
Read Guarded memory(de)allocation.
static DBVT_INLINE btScalar size(const btDbvtVolume &a)
FFMPEG_INLINE void my_guess_pkt_duration(AVFormatContext *s, AVStream *st, AVPacket *pkt)
__kernel void ccl_constant KernelData ccl_global void ccl_global char ccl_global int ccl_global char ccl_global unsigned int ccl_global float * buffer
void(* MEM_freeN)(void *vmemh)
void *(* MEM_callocN)(size_t len, const char *str)
void *(* MEM_mallocN)(size_t len, const char *str)
static void error(const char *str)
#define PRINT(format,...)
struct SELECTID_Context context
struct ImageFormatData im_format
struct FFMpegCodecData ffcodecdata
struct IDPropertyTemplate::@27 string
__forceinline const avxi abs(const avxi &a)
ccl_device_inline float2 fabs(const float2 &a)