2006-02-05 19:14:46 +00:00
|
|
|
/*
|
2012-04-30 14:24:11 +00:00
|
|
|
* ***** BEGIN GPL LICENSE BLOCK *****
|
2011-02-23 18:03:40 +00:00
|
|
|
*
|
2012-04-30 14:24:11 +00:00
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
2006-02-05 19:14:46 +00:00
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
2012-04-30 14:24:11 +00:00
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software Foundation,
|
|
|
|
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
|
|
|
*
|
|
|
|
* Partial Copyright (c) 2006 Peter Schlaile
|
|
|
|
*
|
|
|
|
* ***** END GPL LICENSE BLOCK *****
|
2006-02-05 19:14:46 +00:00
|
|
|
*/
|
|
|
|
|
2011-10-10 09:38:02 +00:00
|
|
|
/** \file blender/blenkernel/intern/writeffmpeg.c
|
|
|
|
* \ingroup bke
|
|
|
|
*/
|
|
|
|
|
2006-02-05 19:14:46 +00:00
|
|
|
#ifdef WITH_FFMPEG
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
2006-11-18 02:48:18 +00:00
|
|
|
|
2009-04-20 15:06:46 +00:00
|
|
|
#include <libavformat/avformat.h>
|
|
|
|
#include <libavcodec/avcodec.h>
|
|
|
|
#include <libavutil/rational.h>
|
2012-06-18 10:29:11 +00:00
|
|
|
#include <libavutil/samplefmt.h>
|
2009-04-20 15:06:46 +00:00
|
|
|
#include <libswscale/swscale.h>
|
2006-02-05 19:14:46 +00:00
|
|
|
|
|
|
|
#include "MEM_guardedalloc.h"
|
2009-12-22 12:01:32 +00:00
|
|
|
|
|
|
|
#include "DNA_scene_types.h"
|
|
|
|
|
2006-02-05 19:14:46 +00:00
|
|
|
#include "BLI_blenlib.h"
|
|
|
|
|
2011-06-23 09:27:56 +00:00
|
|
|
#ifdef WITH_AUDASPACE
|
2017-08-18 08:24:12 +02:00
|
|
|
# include <AUD_Device.h>
|
|
|
|
# include <AUD_Special.h>
|
2011-06-23 09:27:56 +00:00
|
|
|
#endif
|
2009-12-22 12:01:32 +00:00
|
|
|
|
2012-02-07 17:11:56 +00:00
|
|
|
#include "BLI_utildefines.h"
|
|
|
|
|
2006-02-05 19:14:46 +00:00
|
|
|
#include "BKE_global.h"
|
2008-05-11 20:40:55 +00:00
|
|
|
#include "BKE_idprop.h"
|
2018-04-05 16:31:59 +02:00
|
|
|
#include "BKE_image.h"
|
2009-12-22 12:01:32 +00:00
|
|
|
#include "BKE_main.h"
|
|
|
|
#include "BKE_report.h"
|
|
|
|
#include "BKE_sound.h"
|
|
|
|
#include "BKE_writeffmpeg.h"
|
2006-02-05 19:14:46 +00:00
|
|
|
|
|
|
|
#include "IMB_imbuf.h"
|
|
|
|
|
2011-05-27 23:33:40 +00:00
|
|
|
#include "ffmpeg_compat.h"
|
2011-05-27 07:47:42 +00:00
|
|
|
|
2018-04-05 16:31:59 +02:00
|
|
|
struct StampData;
|
|
|
|
|
2015-04-06 10:40:12 -03:00
|
|
|
typedef struct FFMpegContext {
|
|
|
|
int ffmpeg_type;
|
|
|
|
int ffmpeg_codec;
|
|
|
|
int ffmpeg_audio_codec;
|
|
|
|
int ffmpeg_video_bitrate;
|
|
|
|
int ffmpeg_audio_bitrate;
|
|
|
|
int ffmpeg_gop_size;
|
FFmpeg interface improvements
This patch changes a couple of things in the video output encoding.
{F362527}
- Clearer separation between container and codec. No more "format", as this is
too ambiguous. As a result, codecs were removed from the container list.
- Added FFmpeg speed presets, so the user can choosen from the range "Very
slow" to "Ultra fast". By default no preset is used.
- Added Constant Rate Factor (CRF) mode, which allows changing the bit-rate
depending on the desired quality and the input. This generally produces the
best quality videos, at the expense of not knowing the exact bit-rate and
file size.
- Added optional maximum of non-B-frames between B-frames (`max_b_frames`).
- Presets were adjusted for these changes, and new presets added. One of the
new presets is [recommended](https://trac.ffmpeg.org/wiki/Encode/VFX#H.264)
for reviewing videos, as it allows players to scrub through it easily. Might
be nice in weeklies. This preset also requires control over the
`max_b_frames` setting.
GUI-only changes:
- Renamed "MPEG" in the output file format menu with "FFmpeg", as this is more
accurate. After all, FFmpeg is used when this option is chosen, which can
also output non-MPEG files.
- Certain parts of the GUI are disabled when not in use:
- bit rate options are not used when a constant rate factor is given.
- audio bitrate & volume are not used when no audio is exported.
Note that I did not touch `BKE_ffmpeg_preset_set()`. There are currently two
preset systems for FFmpeg (`BKE_ffmpeg_preset_set()` and the Python preset
system). Before we do more work on `BKE_ffmpeg_preset_set()`, I think it's a
good idea to determine whether we want to keep it at all.
After this patch has been accepted, I'd be happy to go through the code and
remove any then-obsolete bits, such as the handling of "XVID" as a container
format.
Reviewers: sergey, mont29, brecht
Subscribers: mpan3, Blendify, brecht, fsiddi
Tags: #bf_blender
Differential Revision: https://developer.blender.org/D2242
2016-09-21 15:01:51 +02:00
|
|
|
int ffmpeg_max_b_frames;
|
2015-04-06 10:40:12 -03:00
|
|
|
int ffmpeg_autosplit;
|
|
|
|
int ffmpeg_autosplit_count;
|
|
|
|
bool ffmpeg_preview;
|
|
|
|
|
FFmpeg interface improvements
This patch changes a couple of things in the video output encoding.
{F362527}
- Clearer separation between container and codec. No more "format", as this is
too ambiguous. As a result, codecs were removed from the container list.
- Added FFmpeg speed presets, so the user can choosen from the range "Very
slow" to "Ultra fast". By default no preset is used.
- Added Constant Rate Factor (CRF) mode, which allows changing the bit-rate
depending on the desired quality and the input. This generally produces the
best quality videos, at the expense of not knowing the exact bit-rate and
file size.
- Added optional maximum of non-B-frames between B-frames (`max_b_frames`).
- Presets were adjusted for these changes, and new presets added. One of the
new presets is [recommended](https://trac.ffmpeg.org/wiki/Encode/VFX#H.264)
for reviewing videos, as it allows players to scrub through it easily. Might
be nice in weeklies. This preset also requires control over the
`max_b_frames` setting.
GUI-only changes:
- Renamed "MPEG" in the output file format menu with "FFmpeg", as this is more
accurate. After all, FFmpeg is used when this option is chosen, which can
also output non-MPEG files.
- Certain parts of the GUI are disabled when not in use:
- bit rate options are not used when a constant rate factor is given.
- audio bitrate & volume are not used when no audio is exported.
Note that I did not touch `BKE_ffmpeg_preset_set()`. There are currently two
preset systems for FFmpeg (`BKE_ffmpeg_preset_set()` and the Python preset
system). Before we do more work on `BKE_ffmpeg_preset_set()`, I think it's a
good idea to determine whether we want to keep it at all.
After this patch has been accepted, I'd be happy to go through the code and
remove any then-obsolete bits, such as the handling of "XVID" as a container
format.
Reviewers: sergey, mont29, brecht
Subscribers: mpan3, Blendify, brecht, fsiddi
Tags: #bf_blender
Differential Revision: https://developer.blender.org/D2242
2016-09-21 15:01:51 +02:00
|
|
|
int ffmpeg_crf; /* set to 0 to not use CRF mode; we have another flag for lossless anyway. */
|
2017-10-17 13:43:10 +11:00
|
|
|
int ffmpeg_preset; /* see eFFMpegPreset */
|
FFmpeg interface improvements
This patch changes a couple of things in the video output encoding.
{F362527}
- Clearer separation between container and codec. No more "format", as this is
too ambiguous. As a result, codecs were removed from the container list.
- Added FFmpeg speed presets, so the user can choosen from the range "Very
slow" to "Ultra fast". By default no preset is used.
- Added Constant Rate Factor (CRF) mode, which allows changing the bit-rate
depending on the desired quality and the input. This generally produces the
best quality videos, at the expense of not knowing the exact bit-rate and
file size.
- Added optional maximum of non-B-frames between B-frames (`max_b_frames`).
- Presets were adjusted for these changes, and new presets added. One of the
new presets is [recommended](https://trac.ffmpeg.org/wiki/Encode/VFX#H.264)
for reviewing videos, as it allows players to scrub through it easily. Might
be nice in weeklies. This preset also requires control over the
`max_b_frames` setting.
GUI-only changes:
- Renamed "MPEG" in the output file format menu with "FFmpeg", as this is more
accurate. After all, FFmpeg is used when this option is chosen, which can
also output non-MPEG files.
- Certain parts of the GUI are disabled when not in use:
- bit rate options are not used when a constant rate factor is given.
- audio bitrate & volume are not used when no audio is exported.
Note that I did not touch `BKE_ffmpeg_preset_set()`. There are currently two
preset systems for FFmpeg (`BKE_ffmpeg_preset_set()` and the Python preset
system). Before we do more work on `BKE_ffmpeg_preset_set()`, I think it's a
good idea to determine whether we want to keep it at all.
After this patch has been accepted, I'd be happy to go through the code and
remove any then-obsolete bits, such as the handling of "XVID" as a container
format.
Reviewers: sergey, mont29, brecht
Subscribers: mpan3, Blendify, brecht, fsiddi
Tags: #bf_blender
Differential Revision: https://developer.blender.org/D2242
2016-09-21 15:01:51 +02:00
|
|
|
|
2015-04-06 10:40:12 -03:00
|
|
|
AVFormatContext *outfile;
|
|
|
|
AVStream *video_stream;
|
|
|
|
AVStream *audio_stream;
|
|
|
|
AVFrame *current_frame;
|
|
|
|
struct SwsContext *img_convert_ctx;
|
|
|
|
|
|
|
|
uint8_t *audio_input_buffer;
|
|
|
|
uint8_t *audio_deinterleave_buffer;
|
|
|
|
int audio_input_samples;
|
2013-04-19 17:23:08 +00:00
|
|
|
#ifndef FFMPEG_HAVE_ENCODE_AUDIO2
|
2015-04-06 10:40:12 -03:00
|
|
|
uint8_t *audio_output_buffer;
|
|
|
|
int audio_outbuf_size;
|
2013-04-19 17:23:08 +00:00
|
|
|
#endif
|
2015-04-06 10:40:12 -03:00
|
|
|
double audio_time;
|
|
|
|
bool audio_deinterleave;
|
|
|
|
int audio_sample_size;
|
2006-02-05 19:14:46 +00:00
|
|
|
|
2018-04-05 16:31:59 +02:00
|
|
|
struct StampData *stamp_data;
|
|
|
|
|
2011-06-23 16:10:48 +00:00
|
|
|
#ifdef WITH_AUDASPACE
|
2015-04-06 10:40:12 -03:00
|
|
|
AUD_Device *audio_mixdown_device;
|
2011-06-23 16:10:48 +00:00
|
|
|
#endif
|
2015-04-06 10:40:12 -03:00
|
|
|
} FFMpegContext;
|
2009-08-09 21:16:39 +00:00
|
|
|
|
2006-02-05 19:14:46 +00:00
|
|
|
#define FFMPEG_AUTOSPLIT_SIZE 2000000000
|
|
|
|
|
2012-08-26 11:01:14 +00:00
|
|
|
#define PRINT if (G.debug & G_DEBUG_FFMPEG) printf
|
|
|
|
|
2014-02-17 20:50:42 +06:00
|
|
|
static void ffmpeg_dict_set_int(AVDictionary **dict, const char *key, int value);
|
|
|
|
static void ffmpeg_dict_set_float(AVDictionary **dict, const char *key, float value);
|
2014-05-28 16:11:59 +06:00
|
|
|
static void ffmpeg_set_expert_options(RenderData *rd);
|
2015-04-06 10:40:12 -03:00
|
|
|
static void ffmpeg_filepath_get(FFMpegContext *context, char *string, struct RenderData *rd, bool preview, const char *suffix);
|
2014-02-17 20:50:42 +06:00
|
|
|
|
2006-02-05 19:14:46 +00:00
|
|
|
/* Delete a picture buffer */
|
|
|
|
|
2012-05-12 16:11:34 +00:00
|
|
|
static void delete_picture(AVFrame *f)
|
2006-02-05 19:14:46 +00:00
|
|
|
{
|
|
|
|
if (f) {
|
|
|
|
if (f->data[0]) MEM_freeN(f->data[0]);
|
|
|
|
av_free(f);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
Patch #34204: [Render Animation] Fails with "Error: Specified sample_fmt is not supported" with ogg vorbis
Patch by Jehan Pages (pardon for mis-typing, emacs-nox works not so good with
urf-8 buffers here), with some own modifications. Thanks!
From the patch tracker:
The problem is because of several versions of ffmpeg, but even more because of
the fork situation libav/ffmpeg. So there are some installed versions out there
where you *must* use a float sample for some codec; whereas oppositely on some
other installations, you *must* use the int sample. So for some people, one
works not the other, and reciprocally.
As a consequence, you can't just have a switch codec-based, like in current
code, which decides on the float or int implementation, you must necessarily
have a runtime test because you won't know until then if ogg vorbis will use
one or another sample (note: that's true also for AC3 as I fixed the exact same
bug in DVDStyler for AC3 encoding a few months ago; and I guess it would be same
for AAC).
Some notes from self:
- New FFmpeg requires using FLTP for AAC, AC3 and Vorbis, it's not supported
by audaspace and result in this case would be just wrong. Throw an error
in cases FLTP is trying to be used.
- Moved strict_std_compliance a bit upper. When we'll support FLTP both
FLT and FLTP for AAC would need to be using FF_COMPLIANCE_EXPERIMENTAL.
- It is nice to have such check of supported by codec formats anyway.
2013-03-12 16:57:14 +00:00
|
|
|
static int request_float_audio_buffer(int codec_id)
|
2012-11-21 11:57:35 +00:00
|
|
|
{
|
Patch #34204: [Render Animation] Fails with "Error: Specified sample_fmt is not supported" with ogg vorbis
Patch by Jehan Pages (pardon for mis-typing, emacs-nox works not so good with
urf-8 buffers here), with some own modifications. Thanks!
From the patch tracker:
The problem is because of several versions of ffmpeg, but even more because of
the fork situation libav/ffmpeg. So there are some installed versions out there
where you *must* use a float sample for some codec; whereas oppositely on some
other installations, you *must* use the int sample. So for some people, one
works not the other, and reciprocally.
As a consequence, you can't just have a switch codec-based, like in current
code, which decides on the float or int implementation, you must necessarily
have a runtime test because you won't know until then if ogg vorbis will use
one or another sample (note: that's true also for AC3 as I fixed the exact same
bug in DVDStyler for AC3 encoding a few months ago; and I guess it would be same
for AAC).
Some notes from self:
- New FFmpeg requires using FLTP for AAC, AC3 and Vorbis, it's not supported
by audaspace and result in this case would be just wrong. Throw an error
in cases FLTP is trying to be used.
- Moved strict_std_compliance a bit upper. When we'll support FLTP both
FLT and FLTP for AAC would need to be using FF_COMPLIANCE_EXPERIMENTAL.
- It is nice to have such check of supported by codec formats anyway.
2013-03-12 16:57:14 +00:00
|
|
|
/* If any of these codecs, we prefer the float sample format (if supported) */
|
2014-01-16 15:40:37 +01:00
|
|
|
return codec_id == AV_CODEC_ID_AAC || codec_id == AV_CODEC_ID_AC3 || codec_id == AV_CODEC_ID_VORBIS;
|
2012-11-21 11:57:35 +00:00
|
|
|
}
|
|
|
|
|
2011-06-23 16:10:48 +00:00
|
|
|
#ifdef WITH_AUDASPACE
|
2015-04-06 10:40:12 -03:00
|
|
|
static int write_audio_frame(FFMpegContext *context)
|
2006-07-09 13:05:09 +00:00
|
|
|
{
|
2012-05-12 16:11:34 +00:00
|
|
|
AVCodecContext *c = NULL;
|
2006-02-05 19:14:46 +00:00
|
|
|
AVPacket pkt;
|
2013-04-19 17:23:08 +00:00
|
|
|
AVFrame *frame = NULL;
|
2013-04-01 15:31:27 +00:00
|
|
|
int got_output = 0;
|
2006-02-05 19:14:46 +00:00
|
|
|
|
2015-04-06 10:40:12 -03:00
|
|
|
c = context->audio_stream->codec;
|
2006-02-05 19:14:46 +00:00
|
|
|
|
|
|
|
av_init_packet(&pkt);
|
2010-02-07 23:41:17 +00:00
|
|
|
pkt.size = 0;
|
2013-04-01 15:31:27 +00:00
|
|
|
pkt.data = NULL;
|
|
|
|
|
2014-11-13 00:33:28 +13:00
|
|
|
AUD_Device_read(context->audio_mixdown_device, context->audio_input_buffer, context->audio_input_samples);
|
2015-04-06 10:40:12 -03:00
|
|
|
context->audio_time += (double) context->audio_input_samples / (double) c->sample_rate;
|
2013-04-19 17:23:08 +00:00
|
|
|
|
|
|
|
#ifdef FFMPEG_HAVE_ENCODE_AUDIO2
|
2016-02-16 12:32:42 +01:00
|
|
|
frame = av_frame_alloc();
|
|
|
|
av_frame_unref(frame);
|
2015-04-06 10:40:12 -03:00
|
|
|
frame->pts = context->audio_time / av_q2d(c->time_base);
|
|
|
|
frame->nb_samples = context->audio_input_samples;
|
2013-04-01 15:31:27 +00:00
|
|
|
frame->format = c->sample_fmt;
|
2013-04-01 20:51:52 +00:00
|
|
|
#ifdef FFMPEG_HAVE_FRAME_CHANNEL_LAYOUT
|
2013-04-01 15:31:27 +00:00
|
|
|
frame->channel_layout = c->channel_layout;
|
2013-04-01 20:51:52 +00:00
|
|
|
#endif
|
2010-02-07 23:41:17 +00:00
|
|
|
|
2015-04-06 10:40:12 -03:00
|
|
|
if (context->audio_deinterleave) {
|
2013-04-01 15:31:27 +00:00
|
|
|
int channel, i;
|
2013-04-03 01:36:00 +00:00
|
|
|
uint8_t *temp;
|
2013-04-01 15:31:27 +00:00
|
|
|
|
2013-04-03 01:36:00 +00:00
|
|
|
for (channel = 0; channel < c->channels; channel++) {
|
|
|
|
for (i = 0; i < frame->nb_samples; i++) {
|
2015-04-06 10:40:12 -03:00
|
|
|
memcpy(context->audio_deinterleave_buffer + (i + channel * frame->nb_samples) * context->audio_sample_size,
|
2018-01-16 11:40:43 +11:00
|
|
|
context->audio_input_buffer + (c->channels * i + channel) * context->audio_sample_size, context->audio_sample_size);
|
2013-04-01 15:31:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-06 10:40:12 -03:00
|
|
|
temp = context->audio_deinterleave_buffer;
|
|
|
|
context->audio_deinterleave_buffer = context->audio_input_buffer;
|
|
|
|
context->audio_input_buffer = temp;
|
2013-04-01 15:31:27 +00:00
|
|
|
}
|
|
|
|
|
2015-04-06 10:40:12 -03:00
|
|
|
avcodec_fill_audio_frame(frame, c->channels, c->sample_fmt, context->audio_input_buffer,
|
|
|
|
context->audio_input_samples * c->channels * context->audio_sample_size, 1);
|
2010-02-07 23:41:17 +00:00
|
|
|
|
2013-04-03 01:36:00 +00:00
|
|
|
if (avcodec_encode_audio2(c, &pkt, frame, &got_output) < 0) {
|
2010-02-07 23:41:17 +00:00
|
|
|
// XXX error("Error writing audio packet");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2013-04-19 17:23:08 +00:00
|
|
|
if (!got_output) {
|
2016-02-16 12:32:42 +01:00
|
|
|
av_frame_free(&frame);
|
2013-04-19 17:23:08 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#else
|
2015-04-06 10:40:12 -03:00
|
|
|
pkt.size = avcodec_encode_audio(c, context->audio_output_buffer, context->audio_outbuf_size, (short *) context->audio_input_buffer);
|
2013-04-19 17:23:08 +00:00
|
|
|
|
|
|
|
if (pkt.size < 0) {
|
|
|
|
// XXX error("Error writing audio packet");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2015-04-06 10:40:12 -03:00
|
|
|
pkt.data = context->audio_output_buffer;
|
2013-04-19 17:23:08 +00:00
|
|
|
got_output = 1;
|
|
|
|
#endif
|
|
|
|
|
2013-04-03 01:36:00 +00:00
|
|
|
if (got_output) {
|
2014-01-22 22:11:13 +06:00
|
|
|
if (pkt.pts != AV_NOPTS_VALUE)
|
2015-04-06 10:40:12 -03:00
|
|
|
pkt.pts = av_rescale_q(pkt.pts, c->time_base, context->audio_stream->time_base);
|
2014-01-22 22:11:13 +06:00
|
|
|
if (pkt.dts != AV_NOPTS_VALUE)
|
2015-04-06 10:40:12 -03:00
|
|
|
pkt.dts = av_rescale_q(pkt.dts, c->time_base, context->audio_stream->time_base);
|
2014-01-22 22:11:13 +06:00
|
|
|
if (pkt.duration > 0)
|
2015-04-06 10:40:12 -03:00
|
|
|
pkt.duration = av_rescale_q(pkt.duration, c->time_base, context->audio_stream->time_base);
|
2010-02-07 23:41:17 +00:00
|
|
|
|
2015-04-06 10:40:12 -03:00
|
|
|
pkt.stream_index = context->audio_stream->index;
|
2006-07-09 13:05:09 +00:00
|
|
|
|
2013-04-01 15:31:27 +00:00
|
|
|
pkt.flags |= AV_PKT_FLAG_KEY;
|
2011-05-26 21:57:02 +00:00
|
|
|
|
2015-04-06 10:40:12 -03:00
|
|
|
if (av_interleaved_write_frame(context->outfile, &pkt) != 0) {
|
2013-04-01 15:31:27 +00:00
|
|
|
fprintf(stderr, "Error writing audio packet!\n");
|
2013-04-19 17:23:08 +00:00
|
|
|
if (frame)
|
2016-02-16 12:32:42 +01:00
|
|
|
av_frame_free(&frame);
|
2013-04-01 15:31:27 +00:00
|
|
|
return -1;
|
|
|
|
}
|
2011-05-26 21:57:02 +00:00
|
|
|
|
2013-04-01 15:31:27 +00:00
|
|
|
av_free_packet(&pkt);
|
2006-02-05 19:14:46 +00:00
|
|
|
}
|
2013-04-01 15:31:27 +00:00
|
|
|
|
2013-04-19 17:23:08 +00:00
|
|
|
if (frame)
|
2016-02-16 12:32:42 +01:00
|
|
|
av_frame_free(&frame);
|
2013-04-01 15:31:27 +00:00
|
|
|
|
2006-02-05 19:14:46 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2011-06-23 16:10:48 +00:00
|
|
|
#endif // #ifdef WITH_AUDASPACE
|
2006-02-05 19:14:46 +00:00
|
|
|
|
|
|
|
/* Allocate a temporary frame */
|
2012-05-12 16:11:34 +00:00
|
|
|
static AVFrame *alloc_picture(int pix_fmt, int width, int height)
|
2006-02-05 19:14:46 +00:00
|
|
|
{
|
2012-05-12 16:11:34 +00:00
|
|
|
AVFrame *f;
|
|
|
|
uint8_t *buf;
|
2006-02-05 19:14:46 +00:00
|
|
|
int size;
|
|
|
|
|
|
|
|
/* allocate space for the struct */
|
2016-02-16 12:32:42 +01:00
|
|
|
f = av_frame_alloc();
|
2006-02-05 19:14:46 +00:00
|
|
|
if (!f) return NULL;
|
|
|
|
size = avpicture_get_size(pix_fmt, width, height);
|
|
|
|
/* allocate the actual picture buffer */
|
|
|
|
buf = MEM_mallocN(size, "AVFrame buffer");
|
|
|
|
if (!buf) {
|
|
|
|
free(f);
|
|
|
|
return NULL;
|
|
|
|
}
|
2012-05-12 16:11:34 +00:00
|
|
|
avpicture_fill((AVPicture *)f, buf, pix_fmt, width, height);
|
2006-02-05 19:14:46 +00:00
|
|
|
return f;
|
|
|
|
}
|
|
|
|
|
2006-07-09 13:05:09 +00:00
|
|
|
/* Get the correct file extensions for the requested format,
|
2012-04-22 11:54:53 +00:00
|
|
|
* first is always desired guess_format parameter */
|
2012-05-12 16:11:34 +00:00
|
|
|
static const char **get_file_extensions(int format)
|
2006-02-05 19:14:46 +00:00
|
|
|
{
|
2012-04-28 06:31:57 +00:00
|
|
|
switch (format) {
|
2012-09-08 08:59:47 +00:00
|
|
|
case FFMPEG_DV:
|
|
|
|
{
|
2012-05-12 16:11:34 +00:00
|
|
|
static const char *rv[] = { ".dv", NULL };
|
|
|
|
return rv;
|
|
|
|
}
|
2012-09-08 08:59:47 +00:00
|
|
|
case FFMPEG_MPEG1:
|
|
|
|
{
|
2012-05-12 16:11:34 +00:00
|
|
|
static const char *rv[] = { ".mpg", ".mpeg", NULL };
|
|
|
|
return rv;
|
|
|
|
}
|
2012-09-08 08:59:47 +00:00
|
|
|
case FFMPEG_MPEG2:
|
|
|
|
{
|
2012-08-26 11:01:18 +00:00
|
|
|
static const char *rv[] = { ".dvd", ".vob", ".mpg", ".mpeg", NULL };
|
2012-05-12 16:11:34 +00:00
|
|
|
return rv;
|
|
|
|
}
|
2012-09-08 08:59:47 +00:00
|
|
|
case FFMPEG_MPEG4:
|
|
|
|
{
|
2012-05-12 16:11:34 +00:00
|
|
|
static const char *rv[] = { ".mp4", ".mpg", ".mpeg", NULL };
|
|
|
|
return rv;
|
|
|
|
}
|
2012-09-08 08:59:47 +00:00
|
|
|
case FFMPEG_AVI:
|
|
|
|
{
|
2012-05-12 16:11:34 +00:00
|
|
|
static const char *rv[] = { ".avi", NULL };
|
|
|
|
return rv;
|
|
|
|
}
|
2012-09-08 08:59:47 +00:00
|
|
|
case FFMPEG_MOV:
|
|
|
|
{
|
2012-05-12 16:11:34 +00:00
|
|
|
static const char *rv[] = { ".mov", NULL };
|
|
|
|
return rv;
|
|
|
|
}
|
2012-09-08 08:59:47 +00:00
|
|
|
case FFMPEG_H264:
|
|
|
|
{
|
2012-05-12 16:11:34 +00:00
|
|
|
/* FIXME: avi for now... */
|
|
|
|
static const char *rv[] = { ".avi", NULL };
|
|
|
|
return rv;
|
|
|
|
}
|
2006-02-05 19:14:46 +00:00
|
|
|
|
2012-09-08 08:59:47 +00:00
|
|
|
case FFMPEG_XVID:
|
|
|
|
{
|
2012-05-12 16:11:34 +00:00
|
|
|
/* FIXME: avi for now... */
|
|
|
|
static const char *rv[] = { ".avi", NULL };
|
|
|
|
return rv;
|
|
|
|
}
|
2012-09-08 08:59:47 +00:00
|
|
|
case FFMPEG_FLV:
|
|
|
|
{
|
2012-05-12 16:11:34 +00:00
|
|
|
static const char *rv[] = { ".flv", NULL };
|
|
|
|
return rv;
|
|
|
|
}
|
2012-09-08 08:59:47 +00:00
|
|
|
case FFMPEG_MKV:
|
|
|
|
{
|
2012-05-12 16:11:34 +00:00
|
|
|
static const char *rv[] = { ".mkv", NULL };
|
|
|
|
return rv;
|
|
|
|
}
|
2012-09-08 08:59:47 +00:00
|
|
|
case FFMPEG_OGG:
|
|
|
|
{
|
2013-10-31 21:00:55 +00:00
|
|
|
static const char *rv[] = { ".ogv", ".ogg", NULL };
|
2012-05-12 16:11:34 +00:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
return NULL;
|
2006-02-05 19:14:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Write a frame to the output file */
|
2015-04-06 10:40:12 -03:00
|
|
|
static int write_video_frame(FFMpegContext *context, RenderData *rd, int cfra, AVFrame *frame, ReportList *reports)
|
2006-07-09 13:05:09 +00:00
|
|
|
{
|
2014-01-16 15:40:37 +01:00
|
|
|
int got_output;
|
2012-05-12 16:11:34 +00:00
|
|
|
int ret, success = 1;
|
2015-04-06 10:40:12 -03:00
|
|
|
AVCodecContext *c = context->video_stream->codec;
|
2014-01-16 15:40:37 +01:00
|
|
|
AVPacket packet = { 0 };
|
|
|
|
|
|
|
|
av_init_packet(&packet);
|
2011-05-26 21:57:02 +00:00
|
|
|
|
2012-01-13 09:20:13 +00:00
|
|
|
frame->pts = cfra;
|
2011-05-26 21:57:02 +00:00
|
|
|
|
2014-01-16 15:40:37 +01:00
|
|
|
ret = avcodec_encode_video2(c, &packet, frame, &got_output);
|
2006-02-05 19:14:46 +00:00
|
|
|
|
2014-01-16 15:40:37 +01:00
|
|
|
if (ret >= 0 && got_output) {
|
|
|
|
if (packet.pts != AV_NOPTS_VALUE) {
|
2015-04-06 10:40:12 -03:00
|
|
|
packet.pts = av_rescale_q(packet.pts, c->time_base, context->video_stream->time_base);
|
2012-08-26 11:01:14 +00:00
|
|
|
PRINT("Video Frame PTS: %d\n", (int)packet.pts);
|
2012-03-24 06:18:31 +00:00
|
|
|
}
|
|
|
|
else {
|
2012-08-26 11:01:14 +00:00
|
|
|
PRINT("Video Frame PTS: not set\n");
|
2008-10-05 17:31:33 +00:00
|
|
|
}
|
2014-01-16 15:40:37 +01:00
|
|
|
if (packet.dts != AV_NOPTS_VALUE) {
|
2015-04-06 10:40:12 -03:00
|
|
|
packet.dts = av_rescale_q(packet.dts, c->time_base, context->video_stream->time_base);
|
2014-01-16 15:40:37 +01:00
|
|
|
PRINT("Video Frame DTS: %d\n", (int)packet.dts);
|
2014-01-28 23:00:28 +11:00
|
|
|
}
|
|
|
|
else {
|
2014-01-16 15:40:37 +01:00
|
|
|
PRINT("Video Frame DTS: not set\n");
|
|
|
|
}
|
|
|
|
|
2015-04-06 10:40:12 -03:00
|
|
|
packet.stream_index = context->video_stream->index;
|
|
|
|
ret = av_interleaved_write_frame(context->outfile, &packet);
|
2012-02-07 17:11:56 +00:00
|
|
|
success = (ret == 0);
|
2012-03-24 06:18:31 +00:00
|
|
|
}
|
2014-01-16 15:40:37 +01:00
|
|
|
else if (ret < 0) {
|
2012-02-07 17:11:56 +00:00
|
|
|
success = 0;
|
2010-09-27 07:37:36 +00:00
|
|
|
}
|
2009-12-22 12:01:32 +00:00
|
|
|
|
2012-02-07 17:11:56 +00:00
|
|
|
if (!success)
|
2012-10-21 14:02:30 +00:00
|
|
|
BKE_report(reports, RPT_ERROR, "Error writing frame");
|
2009-12-22 12:01:32 +00:00
|
|
|
|
|
|
|
return success;
|
2006-02-05 19:14:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* read and encode a frame of audio from the buffer */
|
2015-04-06 10:40:12 -03:00
|
|
|
static AVFrame *generate_video_frame(FFMpegContext *context, uint8_t *pixels, ReportList *reports)
|
2006-02-05 19:14:46 +00:00
|
|
|
{
|
2012-05-12 16:11:34 +00:00
|
|
|
uint8_t *rendered_frame;
|
2006-02-05 19:14:46 +00:00
|
|
|
|
2015-04-06 10:40:12 -03:00
|
|
|
AVCodecContext *c = context->video_stream->codec;
|
2006-02-05 19:14:46 +00:00
|
|
|
int width = c->width;
|
|
|
|
int height = c->height;
|
2012-05-12 16:11:34 +00:00
|
|
|
AVFrame *rgb_frame;
|
2006-02-05 19:14:46 +00:00
|
|
|
|
2016-02-16 12:32:42 +01:00
|
|
|
if (c->pix_fmt != AV_PIX_FMT_BGR32) {
|
|
|
|
rgb_frame = alloc_picture(AV_PIX_FMT_BGR32, width, height);
|
2006-02-05 19:14:46 +00:00
|
|
|
if (!rgb_frame) {
|
2012-10-21 14:02:30 +00:00
|
|
|
BKE_report(reports, RPT_ERROR, "Could not allocate temporary frame");
|
2006-02-05 19:14:46 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
2012-03-24 06:18:31 +00:00
|
|
|
}
|
|
|
|
else {
|
2015-04-06 10:40:12 -03:00
|
|
|
rgb_frame = context->current_frame;
|
2006-02-05 19:14:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
rendered_frame = pixels;
|
|
|
|
|
|
|
|
/* Do RGBA-conversion and flipping in one step depending
|
2012-04-22 11:54:53 +00:00
|
|
|
* on CPU-Endianess */
|
2006-02-05 19:14:46 +00:00
|
|
|
|
2008-12-19 19:11:02 +00:00
|
|
|
if (ENDIAN_ORDER == L_ENDIAN) {
|
2006-02-05 19:14:46 +00:00
|
|
|
int y;
|
|
|
|
for (y = 0; y < height; y++) {
|
2012-05-12 16:11:34 +00:00
|
|
|
uint8_t *target = rgb_frame->data[0] + width * 4 * (height - y - 1);
|
|
|
|
uint8_t *src = rendered_frame + width * 4 * y;
|
|
|
|
uint8_t *end = src + width * 4;
|
2006-02-05 19:14:46 +00:00
|
|
|
while (src != end) {
|
|
|
|
target[3] = src[3];
|
2009-04-20 15:06:46 +00:00
|
|
|
target[2] = src[2];
|
2006-02-05 19:14:46 +00:00
|
|
|
target[1] = src[1];
|
2009-04-20 15:06:46 +00:00
|
|
|
target[0] = src[0];
|
2006-02-05 19:14:46 +00:00
|
|
|
|
|
|
|
target += 4;
|
|
|
|
src += 4;
|
|
|
|
}
|
|
|
|
}
|
2012-03-24 06:18:31 +00:00
|
|
|
}
|
|
|
|
else {
|
2006-02-05 19:14:46 +00:00
|
|
|
int y;
|
|
|
|
for (y = 0; y < height; y++) {
|
2012-05-12 16:11:34 +00:00
|
|
|
uint8_t *target = rgb_frame->data[0] + width * 4 * (height - y - 1);
|
|
|
|
uint8_t *src = rendered_frame + width * 4 * y;
|
|
|
|
uint8_t *end = src + width * 4;
|
2006-02-05 19:14:46 +00:00
|
|
|
while (src != end) {
|
2009-04-20 15:06:46 +00:00
|
|
|
target[3] = src[0];
|
2006-02-05 19:14:46 +00:00
|
|
|
target[2] = src[1];
|
2009-04-20 15:06:46 +00:00
|
|
|
target[1] = src[2];
|
2006-02-05 19:14:46 +00:00
|
|
|
target[0] = src[3];
|
|
|
|
|
|
|
|
target += 4;
|
|
|
|
src += 4;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-02-16 12:32:42 +01:00
|
|
|
if (c->pix_fmt != AV_PIX_FMT_BGR32) {
|
2015-04-06 10:40:12 -03:00
|
|
|
sws_scale(context->img_convert_ctx, (const uint8_t *const *) rgb_frame->data,
|
2011-11-11 13:09:14 +00:00
|
|
|
rgb_frame->linesize, 0, c->height,
|
2015-04-06 10:40:12 -03:00
|
|
|
context->current_frame->data, context->current_frame->linesize);
|
2006-02-05 19:14:46 +00:00
|
|
|
delete_picture(rgb_frame);
|
|
|
|
}
|
2014-07-09 15:39:41 +06:00
|
|
|
|
2016-02-16 12:32:42 +01:00
|
|
|
context->current_frame->format = AV_PIX_FMT_BGR32;
|
2015-04-06 10:40:12 -03:00
|
|
|
context->current_frame->width = width;
|
|
|
|
context->current_frame->height = height;
|
2014-07-09 15:39:41 +06:00
|
|
|
|
2015-04-06 10:40:12 -03:00
|
|
|
return context->current_frame;
|
2006-02-05 19:14:46 +00:00
|
|
|
}
|
|
|
|
|
2014-02-17 20:50:42 +06:00
|
|
|
static void set_ffmpeg_property_option(AVCodecContext *c, IDProperty *prop, AVDictionary **dictionary)
|
2008-05-11 20:40:55 +00:00
|
|
|
{
|
|
|
|
char name[128];
|
2012-05-12 16:11:34 +00:00
|
|
|
char *param;
|
2008-05-11 20:40:55 +00:00
|
|
|
|
2012-08-26 11:01:14 +00:00
|
|
|
PRINT("FFMPEG expert option: %s: ", prop->name);
|
2008-05-11 20:40:55 +00:00
|
|
|
|
2010-04-18 09:12:18 +00:00
|
|
|
BLI_strncpy(name, prop->name, sizeof(name));
|
2008-05-11 20:40:55 +00:00
|
|
|
|
|
|
|
param = strchr(name, ':');
|
|
|
|
|
|
|
|
if (param) {
|
2017-01-11 00:08:16 +01:00
|
|
|
*param++ = '\0';
|
2008-05-11 20:40:55 +00:00
|
|
|
}
|
|
|
|
|
2012-04-28 06:31:57 +00:00
|
|
|
switch (prop->type) {
|
2012-05-12 16:11:34 +00:00
|
|
|
case IDP_STRING:
|
2012-08-26 11:01:14 +00:00
|
|
|
PRINT("%s.\n", IDP_String(prop));
|
2014-02-17 20:50:42 +06:00
|
|
|
av_dict_set(dictionary, name, IDP_String(prop), 0);
|
2012-05-12 16:11:34 +00:00
|
|
|
break;
|
|
|
|
case IDP_FLOAT:
|
2012-08-26 11:01:14 +00:00
|
|
|
PRINT("%g.\n", IDP_Float(prop));
|
2014-02-17 20:50:42 +06:00
|
|
|
ffmpeg_dict_set_float(dictionary, prop->name, IDP_Float(prop));
|
2012-05-12 16:11:34 +00:00
|
|
|
break;
|
|
|
|
case IDP_INT:
|
2012-08-26 11:01:14 +00:00
|
|
|
PRINT("%d.\n", IDP_Int(prop));
|
2012-05-12 16:11:34 +00:00
|
|
|
|
|
|
|
if (param) {
|
|
|
|
if (IDP_Int(prop)) {
|
2014-02-17 20:50:42 +06:00
|
|
|
av_dict_set(dictionary, name, param, 0);
|
2012-05-12 16:11:34 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
return;
|
|
|
|
}
|
2012-03-24 06:18:31 +00:00
|
|
|
}
|
|
|
|
else {
|
2014-02-17 20:50:42 +06:00
|
|
|
ffmpeg_dict_set_int(dictionary, prop->name, IDP_Int(prop));
|
2008-05-11 20:40:55 +00:00
|
|
|
}
|
2012-05-12 16:11:34 +00:00
|
|
|
break;
|
2008-05-11 20:40:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-10-23 17:52:20 +00:00
|
|
|
static int ffmpeg_proprty_valid(AVCodecContext *c, const char *prop_name, IDProperty *curr)
|
|
|
|
{
|
2012-05-12 16:11:34 +00:00
|
|
|
int valid = 1;
|
2011-10-23 17:52:20 +00:00
|
|
|
|
2015-01-26 16:03:11 +01:00
|
|
|
if (STREQ(prop_name, "video")) {
|
|
|
|
if (STREQ(curr->name, "bf")) {
|
2011-10-23 17:52:20 +00:00
|
|
|
/* flash codec doesn't support b frames */
|
2014-01-16 15:40:37 +01:00
|
|
|
valid &= c->codec_id != AV_CODEC_ID_FLV1;
|
2011-10-23 17:52:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return valid;
|
|
|
|
}
|
|
|
|
|
2014-02-17 20:50:42 +06:00
|
|
|
static void set_ffmpeg_properties(RenderData *rd, AVCodecContext *c, const char *prop_name,
|
|
|
|
AVDictionary **dictionary)
|
2008-05-11 20:40:55 +00:00
|
|
|
{
|
2012-05-12 16:11:34 +00:00
|
|
|
IDProperty *prop;
|
|
|
|
IDProperty *curr;
|
2008-05-11 20:40:55 +00:00
|
|
|
|
2014-05-28 16:11:59 +06:00
|
|
|
/* TODO(sergey): This is actually rather stupid, because changing
|
|
|
|
* codec settings in render panel would also set expert options.
|
|
|
|
*
|
|
|
|
* But we need ti here in order to get rid of deprecated settings
|
|
|
|
* when opening old files in new blender.
|
|
|
|
*
|
|
|
|
* For as long we don't allow editing properties in the interface
|
|
|
|
* it's all good. bug if we allow editing them, we'll need to
|
2014-12-02 10:30:03 +01:00
|
|
|
* replace it with some smarter code which would port settings
|
2014-05-28 16:11:59 +06:00
|
|
|
* from deprecated to new one.
|
|
|
|
*/
|
|
|
|
ffmpeg_set_expert_options(rd);
|
|
|
|
|
2009-01-04 14:14:06 +00:00
|
|
|
if (!rd->ffcodecdata.properties) {
|
2008-05-11 20:40:55 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-10-21 08:16:15 +00:00
|
|
|
prop = IDP_GetPropertyFromGroup(rd->ffcodecdata.properties, prop_name);
|
2008-05-11 20:40:55 +00:00
|
|
|
if (!prop) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-11-03 17:04:12 +01:00
|
|
|
for (curr = prop->data.group.first; curr; curr = curr->next) {
|
2012-03-24 06:18:31 +00:00
|
|
|
if (ffmpeg_proprty_valid(c, prop_name, curr))
|
2014-02-17 20:50:42 +06:00
|
|
|
set_ffmpeg_property_option(c, curr, dictionary);
|
2008-05-11 20:40:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-02-05 19:14:46 +00:00
|
|
|
/* prepare a video stream for the output file */
|
|
|
|
|
2015-04-06 10:40:12 -03:00
|
|
|
static AVStream *alloc_video_stream(FFMpegContext *context, RenderData *rd, int codec_id, AVFormatContext *of,
|
2012-08-26 11:01:14 +00:00
|
|
|
int rectx, int recty, char *error, int error_size)
|
2006-02-05 19:14:46 +00:00
|
|
|
{
|
2012-05-12 16:11:34 +00:00
|
|
|
AVStream *st;
|
|
|
|
AVCodecContext *c;
|
|
|
|
AVCodec *codec;
|
2014-02-17 20:50:42 +06:00
|
|
|
AVDictionary *opts = NULL;
|
2012-08-26 11:01:14 +00:00
|
|
|
|
|
|
|
error[0] = '\0';
|
|
|
|
|
2013-01-12 12:51:10 +00:00
|
|
|
st = avformat_new_stream(of, NULL);
|
2006-02-05 19:14:46 +00:00
|
|
|
if (!st) return NULL;
|
2013-01-12 12:51:10 +00:00
|
|
|
st->id = 0;
|
2006-02-05 19:14:46 +00:00
|
|
|
|
|
|
|
/* Set up the codec context */
|
|
|
|
|
2011-05-26 21:57:02 +00:00
|
|
|
c = st->codec;
|
2006-02-05 19:14:46 +00:00
|
|
|
c->codec_id = codec_id;
|
2011-05-26 21:57:02 +00:00
|
|
|
c->codec_type = AVMEDIA_TYPE_VIDEO;
|
2006-02-05 19:14:46 +00:00
|
|
|
|
|
|
|
/* Get some values from the current render settings */
|
|
|
|
|
|
|
|
c->width = rectx;
|
|
|
|
c->height = recty;
|
|
|
|
|
|
|
|
/* FIXME: Really bad hack (tm) for NTSC support */
|
2015-04-06 10:40:12 -03:00
|
|
|
if (context->ffmpeg_type == FFMPEG_DV && rd->frs_sec != 25) {
|
2006-02-06 19:27:24 +00:00
|
|
|
c->time_base.den = 2997;
|
|
|
|
c->time_base.num = 100;
|
2012-03-24 06:18:31 +00:00
|
|
|
}
|
2012-11-09 16:15:00 +00:00
|
|
|
else if ((float) ((int) rd->frs_sec_base) == rd->frs_sec_base) {
|
2009-01-04 14:14:06 +00:00
|
|
|
c->time_base.den = rd->frs_sec;
|
|
|
|
c->time_base.num = (int) rd->frs_sec_base;
|
2012-03-24 06:18:31 +00:00
|
|
|
}
|
|
|
|
else {
|
2009-01-04 14:14:06 +00:00
|
|
|
c->time_base.den = rd->frs_sec * 100000;
|
|
|
|
c->time_base.num = ((double) rd->frs_sec_base) * 100000;
|
2006-02-05 19:14:46 +00:00
|
|
|
}
|
|
|
|
|
2015-04-06 10:40:12 -03:00
|
|
|
c->gop_size = context->ffmpeg_gop_size;
|
FFmpeg interface improvements
This patch changes a couple of things in the video output encoding.
{F362527}
- Clearer separation between container and codec. No more "format", as this is
too ambiguous. As a result, codecs were removed from the container list.
- Added FFmpeg speed presets, so the user can choosen from the range "Very
slow" to "Ultra fast". By default no preset is used.
- Added Constant Rate Factor (CRF) mode, which allows changing the bit-rate
depending on the desired quality and the input. This generally produces the
best quality videos, at the expense of not knowing the exact bit-rate and
file size.
- Added optional maximum of non-B-frames between B-frames (`max_b_frames`).
- Presets were adjusted for these changes, and new presets added. One of the
new presets is [recommended](https://trac.ffmpeg.org/wiki/Encode/VFX#H.264)
for reviewing videos, as it allows players to scrub through it easily. Might
be nice in weeklies. This preset also requires control over the
`max_b_frames` setting.
GUI-only changes:
- Renamed "MPEG" in the output file format menu with "FFmpeg", as this is more
accurate. After all, FFmpeg is used when this option is chosen, which can
also output non-MPEG files.
- Certain parts of the GUI are disabled when not in use:
- bit rate options are not used when a constant rate factor is given.
- audio bitrate & volume are not used when no audio is exported.
Note that I did not touch `BKE_ffmpeg_preset_set()`. There are currently two
preset systems for FFmpeg (`BKE_ffmpeg_preset_set()` and the Python preset
system). Before we do more work on `BKE_ffmpeg_preset_set()`, I think it's a
good idea to determine whether we want to keep it at all.
After this patch has been accepted, I'd be happy to go through the code and
remove any then-obsolete bits, such as the handling of "XVID" as a container
format.
Reviewers: sergey, mont29, brecht
Subscribers: mpan3, Blendify, brecht, fsiddi
Tags: #bf_blender
Differential Revision: https://developer.blender.org/D2242
2016-09-21 15:01:51 +02:00
|
|
|
c->max_b_frames = context->ffmpeg_max_b_frames;
|
|
|
|
|
|
|
|
if (context->ffmpeg_crf >= 0) {
|
|
|
|
ffmpeg_dict_set_int(&opts, "crf", context->ffmpeg_crf);
|
2017-03-13 04:25:21 +11:00
|
|
|
}
|
|
|
|
else {
|
FFmpeg interface improvements
This patch changes a couple of things in the video output encoding.
{F362527}
- Clearer separation between container and codec. No more "format", as this is
too ambiguous. As a result, codecs were removed from the container list.
- Added FFmpeg speed presets, so the user can choosen from the range "Very
slow" to "Ultra fast". By default no preset is used.
- Added Constant Rate Factor (CRF) mode, which allows changing the bit-rate
depending on the desired quality and the input. This generally produces the
best quality videos, at the expense of not knowing the exact bit-rate and
file size.
- Added optional maximum of non-B-frames between B-frames (`max_b_frames`).
- Presets were adjusted for these changes, and new presets added. One of the
new presets is [recommended](https://trac.ffmpeg.org/wiki/Encode/VFX#H.264)
for reviewing videos, as it allows players to scrub through it easily. Might
be nice in weeklies. This preset also requires control over the
`max_b_frames` setting.
GUI-only changes:
- Renamed "MPEG" in the output file format menu with "FFmpeg", as this is more
accurate. After all, FFmpeg is used when this option is chosen, which can
also output non-MPEG files.
- Certain parts of the GUI are disabled when not in use:
- bit rate options are not used when a constant rate factor is given.
- audio bitrate & volume are not used when no audio is exported.
Note that I did not touch `BKE_ffmpeg_preset_set()`. There are currently two
preset systems for FFmpeg (`BKE_ffmpeg_preset_set()` and the Python preset
system). Before we do more work on `BKE_ffmpeg_preset_set()`, I think it's a
good idea to determine whether we want to keep it at all.
After this patch has been accepted, I'd be happy to go through the code and
remove any then-obsolete bits, such as the handling of "XVID" as a container
format.
Reviewers: sergey, mont29, brecht
Subscribers: mpan3, Blendify, brecht, fsiddi
Tags: #bf_blender
Differential Revision: https://developer.blender.org/D2242
2016-09-21 15:01:51 +02:00
|
|
|
c->bit_rate = context->ffmpeg_video_bitrate * 1000;
|
|
|
|
c->rc_max_rate = rd->ffcodecdata.rc_max_rate * 1000;
|
|
|
|
c->rc_min_rate = rd->ffcodecdata.rc_min_rate * 1000;
|
|
|
|
c->rc_buffer_size = rd->ffcodecdata.rc_buffer_size * 1024;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (context->ffmpeg_preset) {
|
2018-04-09 15:27:11 +02:00
|
|
|
/* 'preset' is used by h.264, 'deadline' is used by webm/vp9. I'm not
|
|
|
|
* setting those properties conditionally based on the video codec,
|
|
|
|
* as the FFmpeg encoder simply ignores unknown settings anyway. */
|
|
|
|
char const *preset_name = NULL; /* used by h.264 */
|
|
|
|
char const *deadline_name = NULL; /* used by webm/vp9 */
|
2017-03-13 04:25:21 +11:00
|
|
|
switch (context->ffmpeg_preset) {
|
2018-04-09 15:27:11 +02:00
|
|
|
case FFM_PRESET_GOOD:
|
|
|
|
preset_name = "medium";
|
|
|
|
deadline_name = "good";
|
|
|
|
break;
|
|
|
|
case FFM_PRESET_BEST:
|
|
|
|
preset_name = "slower";
|
|
|
|
deadline_name = "best";
|
|
|
|
break;
|
|
|
|
case FFM_PRESET_REALTIME:
|
|
|
|
preset_name = "superfast";
|
|
|
|
deadline_name = "realtime";
|
|
|
|
break;
|
FFmpeg interface improvements
This patch changes a couple of things in the video output encoding.
{F362527}
- Clearer separation between container and codec. No more "format", as this is
too ambiguous. As a result, codecs were removed from the container list.
- Added FFmpeg speed presets, so the user can choosen from the range "Very
slow" to "Ultra fast". By default no preset is used.
- Added Constant Rate Factor (CRF) mode, which allows changing the bit-rate
depending on the desired quality and the input. This generally produces the
best quality videos, at the expense of not knowing the exact bit-rate and
file size.
- Added optional maximum of non-B-frames between B-frames (`max_b_frames`).
- Presets were adjusted for these changes, and new presets added. One of the
new presets is [recommended](https://trac.ffmpeg.org/wiki/Encode/VFX#H.264)
for reviewing videos, as it allows players to scrub through it easily. Might
be nice in weeklies. This preset also requires control over the
`max_b_frames` setting.
GUI-only changes:
- Renamed "MPEG" in the output file format menu with "FFmpeg", as this is more
accurate. After all, FFmpeg is used when this option is chosen, which can
also output non-MPEG files.
- Certain parts of the GUI are disabled when not in use:
- bit rate options are not used when a constant rate factor is given.
- audio bitrate & volume are not used when no audio is exported.
Note that I did not touch `BKE_ffmpeg_preset_set()`. There are currently two
preset systems for FFmpeg (`BKE_ffmpeg_preset_set()` and the Python preset
system). Before we do more work on `BKE_ffmpeg_preset_set()`, I think it's a
good idea to determine whether we want to keep it at all.
After this patch has been accepted, I'd be happy to go through the code and
remove any then-obsolete bits, such as the handling of "XVID" as a container
format.
Reviewers: sergey, mont29, brecht
Subscribers: mpan3, Blendify, brecht, fsiddi
Tags: #bf_blender
Differential Revision: https://developer.blender.org/D2242
2016-09-21 15:01:51 +02:00
|
|
|
default:
|
|
|
|
printf("Unknown preset number %i, ignoring.\n", context->ffmpeg_preset);
|
|
|
|
}
|
|
|
|
if (preset_name != NULL) {
|
|
|
|
av_dict_set(&opts, "preset", preset_name, 0);
|
|
|
|
}
|
2018-04-09 15:27:11 +02:00
|
|
|
if (deadline_name != NULL) {
|
|
|
|
av_dict_set(&opts, "deadline", deadline_name, 0);
|
|
|
|
}
|
FFmpeg interface improvements
This patch changes a couple of things in the video output encoding.
{F362527}
- Clearer separation between container and codec. No more "format", as this is
too ambiguous. As a result, codecs were removed from the container list.
- Added FFmpeg speed presets, so the user can choosen from the range "Very
slow" to "Ultra fast". By default no preset is used.
- Added Constant Rate Factor (CRF) mode, which allows changing the bit-rate
depending on the desired quality and the input. This generally produces the
best quality videos, at the expense of not knowing the exact bit-rate and
file size.
- Added optional maximum of non-B-frames between B-frames (`max_b_frames`).
- Presets were adjusted for these changes, and new presets added. One of the
new presets is [recommended](https://trac.ffmpeg.org/wiki/Encode/VFX#H.264)
for reviewing videos, as it allows players to scrub through it easily. Might
be nice in weeklies. This preset also requires control over the
`max_b_frames` setting.
GUI-only changes:
- Renamed "MPEG" in the output file format menu with "FFmpeg", as this is more
accurate. After all, FFmpeg is used when this option is chosen, which can
also output non-MPEG files.
- Certain parts of the GUI are disabled when not in use:
- bit rate options are not used when a constant rate factor is given.
- audio bitrate & volume are not used when no audio is exported.
Note that I did not touch `BKE_ffmpeg_preset_set()`. There are currently two
preset systems for FFmpeg (`BKE_ffmpeg_preset_set()` and the Python preset
system). Before we do more work on `BKE_ffmpeg_preset_set()`, I think it's a
good idea to determine whether we want to keep it at all.
After this patch has been accepted, I'd be happy to go through the code and
remove any then-obsolete bits, such as the handling of "XVID" as a container
format.
Reviewers: sergey, mont29, brecht
Subscribers: mpan3, Blendify, brecht, fsiddi
Tags: #bf_blender
Differential Revision: https://developer.blender.org/D2242
2016-09-21 15:01:51 +02:00
|
|
|
}
|
2012-12-18 17:46:59 +00:00
|
|
|
|
|
|
|
#if 0
|
|
|
|
/* this options are not set in ffmpeg.c and leads to artifacts with MPEG-4
|
|
|
|
* see #33586: Encoding to mpeg4 makes first frame(s) blocky
|
|
|
|
*/
|
2012-05-09 09:24:15 +00:00
|
|
|
c->rc_initial_buffer_occupancy = rd->ffcodecdata.rc_buffer_size * 3 / 4;
|
2006-02-05 19:14:46 +00:00
|
|
|
c->rc_buffer_aggressivity = 1.0;
|
2012-12-18 17:46:59 +00:00
|
|
|
#endif
|
|
|
|
|
2018-05-08 16:00:52 +02:00
|
|
|
/* Deprecated and not doing anything since July 2015, deleted in recent ffmpeg */
|
|
|
|
//c->me_method = ME_EPZS;
|
2006-02-05 19:14:46 +00:00
|
|
|
|
|
|
|
codec = avcodec_find_encoder(c->codec_id);
|
2012-08-26 11:01:18 +00:00
|
|
|
if (!codec)
|
|
|
|
return NULL;
|
2006-02-05 19:14:46 +00:00
|
|
|
|
|
|
|
/* Be sure to use the correct pixel format(e.g. RGB, YUV) */
|
2012-02-07 17:11:56 +00:00
|
|
|
|
2006-02-05 19:14:46 +00:00
|
|
|
if (codec->pix_fmts) {
|
|
|
|
c->pix_fmt = codec->pix_fmts[0];
|
2012-03-24 06:18:31 +00:00
|
|
|
}
|
|
|
|
else {
|
2006-02-05 19:14:46 +00:00
|
|
|
/* makes HuffYUV happy ... */
|
2016-02-16 12:32:42 +01:00
|
|
|
c->pix_fmt = AV_PIX_FMT_YUV422P;
|
2006-02-05 19:14:46 +00:00
|
|
|
}
|
2006-06-09 19:48:50 +00:00
|
|
|
|
2015-04-06 10:40:12 -03:00
|
|
|
if (context->ffmpeg_type == FFMPEG_XVID) {
|
2006-06-09 19:48:50 +00:00
|
|
|
/* arghhhh ... */
|
2016-02-16 12:32:42 +01:00
|
|
|
c->pix_fmt = AV_PIX_FMT_YUV420P;
|
2012-05-12 16:11:34 +00:00
|
|
|
c->codec_tag = (('D' << 24) + ('I' << 16) + ('V' << 8) + 'X');
|
2006-06-09 19:48:50 +00:00
|
|
|
}
|
2010-05-04 00:28:41 +00:00
|
|
|
|
2014-01-16 15:40:37 +01:00
|
|
|
if (codec_id == AV_CODEC_ID_H264) {
|
2010-05-04 00:28:41 +00:00
|
|
|
/* correct wrong default ffmpeg param which crash x264 */
|
2012-05-12 16:11:34 +00:00
|
|
|
c->qmin = 10;
|
|
|
|
c->qmax = 51;
|
2010-05-04 00:28:41 +00:00
|
|
|
}
|
2006-02-05 19:14:46 +00:00
|
|
|
|
2012-07-07 22:51:57 +00:00
|
|
|
/* Keep lossless encodes in the RGB domain. */
|
2014-01-16 15:40:37 +01:00
|
|
|
if (codec_id == AV_CODEC_ID_HUFFYUV) {
|
2014-12-24 18:54:38 +05:00
|
|
|
if (rd->im_format.planes == R_IMF_PLANES_RGBA) {
|
2016-02-16 12:32:42 +01:00
|
|
|
c->pix_fmt = AV_PIX_FMT_BGRA;
|
2014-12-24 18:54:38 +05:00
|
|
|
}
|
|
|
|
else {
|
2016-02-16 12:32:42 +01:00
|
|
|
c->pix_fmt = AV_PIX_FMT_RGB32;
|
2014-12-24 18:54:38 +05:00
|
|
|
}
|
2011-10-03 03:25:05 +00:00
|
|
|
}
|
|
|
|
|
2014-01-16 15:40:37 +01:00
|
|
|
if (codec_id == AV_CODEC_ID_FFV1) {
|
2016-02-16 12:32:42 +01:00
|
|
|
c->pix_fmt = AV_PIX_FMT_RGB32;
|
2012-02-24 09:49:44 +00:00
|
|
|
}
|
|
|
|
|
2014-01-16 15:40:37 +01:00
|
|
|
if (codec_id == AV_CODEC_ID_QTRLE) {
|
2012-05-20 19:49:27 +00:00
|
|
|
if (rd->im_format.planes == R_IMF_PLANES_RGBA) {
|
2016-02-16 12:32:42 +01:00
|
|
|
c->pix_fmt = AV_PIX_FMT_ARGB;
|
2012-02-07 17:11:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-01-16 15:40:37 +01:00
|
|
|
if (codec_id == AV_CODEC_ID_PNG) {
|
2013-03-12 16:09:23 +00:00
|
|
|
if (rd->im_format.planes == R_IMF_PLANES_RGBA) {
|
2016-02-16 12:32:42 +01:00
|
|
|
c->pix_fmt = AV_PIX_FMT_RGBA;
|
2013-03-12 16:09:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-04-20 15:06:46 +00:00
|
|
|
if ((of->oformat->flags & AVFMT_GLOBALHEADER)
|
2014-01-21 01:19:51 +11:00
|
|
|
#if 0
|
2015-01-26 16:03:11 +01:00
|
|
|
|| STREQ(of->oformat->name, "mp4")
|
|
|
|
|| STREQ(of->oformat->name, "mov")
|
|
|
|
|| STREQ(of->oformat->name, "3gp")
|
2014-01-21 01:19:51 +11:00
|
|
|
#endif
|
2012-05-20 19:49:27 +00:00
|
|
|
)
|
|
|
|
{
|
2012-08-26 11:01:14 +00:00
|
|
|
PRINT("Using global header\n");
|
2006-02-05 19:14:46 +00:00
|
|
|
c->flags |= CODEC_FLAG_GLOBAL_HEADER;
|
|
|
|
}
|
|
|
|
|
2008-05-11 20:40:55 +00:00
|
|
|
/* xasp & yasp got float lately... */
|
|
|
|
|
2012-08-26 11:01:18 +00:00
|
|
|
st->sample_aspect_ratio = c->sample_aspect_ratio = av_d2q(((double) rd->xasp / (double) rd->yasp), 255);
|
2017-09-19 11:30:37 +05:00
|
|
|
st->avg_frame_rate = av_inv_q(c->time_base);
|
2008-05-11 20:40:55 +00:00
|
|
|
|
2014-02-17 20:50:42 +06:00
|
|
|
set_ffmpeg_properties(rd, c, "video", &opts);
|
|
|
|
|
|
|
|
if (avcodec_open2(c, codec, &opts) < 0) {
|
2012-08-26 11:01:14 +00:00
|
|
|
BLI_strncpy(error, IMB_ffmpeg_last_error(), error_size);
|
2014-02-17 20:50:42 +06:00
|
|
|
av_dict_free(&opts);
|
2006-02-05 19:14:46 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
2014-02-17 20:50:42 +06:00
|
|
|
av_dict_free(&opts);
|
2006-02-05 19:14:46 +00:00
|
|
|
|
2015-04-06 10:40:12 -03:00
|
|
|
context->current_frame = alloc_picture(c->pix_fmt, c->width, c->height);
|
2007-09-23 14:05:22 +00:00
|
|
|
|
2016-02-16 12:32:42 +01:00
|
|
|
context->img_convert_ctx = sws_getContext(c->width, c->height, AV_PIX_FMT_BGR32, c->width, c->height, c->pix_fmt, SWS_BICUBIC,
|
|
|
|
NULL, NULL, NULL);
|
2006-02-05 19:14:46 +00:00
|
|
|
return st;
|
|
|
|
}
|
|
|
|
|
2015-04-06 10:40:12 -03:00
|
|
|
static AVStream *alloc_audio_stream(FFMpegContext *context, RenderData *rd, int codec_id, AVFormatContext *of, char *error, int error_size)
|
2006-02-05 19:14:46 +00:00
|
|
|
{
|
2012-05-12 16:11:34 +00:00
|
|
|
AVStream *st;
|
|
|
|
AVCodecContext *c;
|
|
|
|
AVCodec *codec;
|
2014-02-17 20:50:42 +06:00
|
|
|
AVDictionary *opts = NULL;
|
2006-02-05 19:14:46 +00:00
|
|
|
|
2012-11-19 17:22:40 +00:00
|
|
|
error[0] = '\0';
|
|
|
|
|
2013-01-12 12:51:10 +00:00
|
|
|
st = avformat_new_stream(of, NULL);
|
2006-02-05 19:14:46 +00:00
|
|
|
if (!st) return NULL;
|
2013-01-12 12:51:10 +00:00
|
|
|
st->id = 1;
|
2006-02-05 19:14:46 +00:00
|
|
|
|
2011-05-26 21:57:02 +00:00
|
|
|
c = st->codec;
|
2006-02-05 19:14:46 +00:00
|
|
|
c->codec_id = codec_id;
|
2011-05-26 21:57:02 +00:00
|
|
|
c->codec_type = AVMEDIA_TYPE_AUDIO;
|
2006-02-05 19:14:46 +00:00
|
|
|
|
2009-09-20 14:00:00 +00:00
|
|
|
c->sample_rate = rd->ffcodecdata.audio_mixrate;
|
2015-04-06 10:40:12 -03:00
|
|
|
c->bit_rate = context->ffmpeg_audio_bitrate * 1000;
|
2012-06-18 10:29:11 +00:00
|
|
|
c->sample_fmt = AV_SAMPLE_FMT_S16;
|
2011-06-21 20:39:41 +00:00
|
|
|
c->channels = rd->ffcodecdata.audio_channels;
|
Patch #34204: [Render Animation] Fails with "Error: Specified sample_fmt is not supported" with ogg vorbis
Patch by Jehan Pages (pardon for mis-typing, emacs-nox works not so good with
urf-8 buffers here), with some own modifications. Thanks!
From the patch tracker:
The problem is because of several versions of ffmpeg, but even more because of
the fork situation libav/ffmpeg. So there are some installed versions out there
where you *must* use a float sample for some codec; whereas oppositely on some
other installations, you *must* use the int sample. So for some people, one
works not the other, and reciprocally.
As a consequence, you can't just have a switch codec-based, like in current
code, which decides on the float or int implementation, you must necessarily
have a runtime test because you won't know until then if ogg vorbis will use
one or another sample (note: that's true also for AC3 as I fixed the exact same
bug in DVDStyler for AC3 encoding a few months ago; and I guess it would be same
for AAC).
Some notes from self:
- New FFmpeg requires using FLTP for AAC, AC3 and Vorbis, it's not supported
by audaspace and result in this case would be just wrong. Throw an error
in cases FLTP is trying to be used.
- Moved strict_std_compliance a bit upper. When we'll support FLTP both
FLT and FLTP for AAC would need to be using FF_COMPLIANCE_EXPERIMENTAL.
- It is nice to have such check of supported by codec formats anyway.
2013-03-12 16:57:14 +00:00
|
|
|
|
|
|
|
if (request_float_audio_buffer(codec_id)) {
|
|
|
|
/* mainly for AAC codec which is experimental */
|
2012-11-21 11:57:35 +00:00
|
|
|
c->strict_std_compliance = FF_COMPLIANCE_EXPERIMENTAL;
|
|
|
|
c->sample_fmt = AV_SAMPLE_FMT_FLT;
|
|
|
|
}
|
Patch #34204: [Render Animation] Fails with "Error: Specified sample_fmt is not supported" with ogg vorbis
Patch by Jehan Pages (pardon for mis-typing, emacs-nox works not so good with
urf-8 buffers here), with some own modifications. Thanks!
From the patch tracker:
The problem is because of several versions of ffmpeg, but even more because of
the fork situation libav/ffmpeg. So there are some installed versions out there
where you *must* use a float sample for some codec; whereas oppositely on some
other installations, you *must* use the int sample. So for some people, one
works not the other, and reciprocally.
As a consequence, you can't just have a switch codec-based, like in current
code, which decides on the float or int implementation, you must necessarily
have a runtime test because you won't know until then if ogg vorbis will use
one or another sample (note: that's true also for AC3 as I fixed the exact same
bug in DVDStyler for AC3 encoding a few months ago; and I guess it would be same
for AAC).
Some notes from self:
- New FFmpeg requires using FLTP for AAC, AC3 and Vorbis, it's not supported
by audaspace and result in this case would be just wrong. Throw an error
in cases FLTP is trying to be used.
- Moved strict_std_compliance a bit upper. When we'll support FLTP both
FLT and FLTP for AAC would need to be using FF_COMPLIANCE_EXPERIMENTAL.
- It is nice to have such check of supported by codec formats anyway.
2013-03-12 16:57:14 +00:00
|
|
|
|
2006-02-05 19:14:46 +00:00
|
|
|
codec = avcodec_find_encoder(c->codec_id);
|
|
|
|
if (!codec) {
|
2008-01-02 12:35:30 +00:00
|
|
|
//XXX error("Couldn't find a valid audio codec");
|
2006-02-05 19:14:46 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
2008-05-11 20:40:55 +00:00
|
|
|
|
Patch #34204: [Render Animation] Fails with "Error: Specified sample_fmt is not supported" with ogg vorbis
Patch by Jehan Pages (pardon for mis-typing, emacs-nox works not so good with
urf-8 buffers here), with some own modifications. Thanks!
From the patch tracker:
The problem is because of several versions of ffmpeg, but even more because of
the fork situation libav/ffmpeg. So there are some installed versions out there
where you *must* use a float sample for some codec; whereas oppositely on some
other installations, you *must* use the int sample. So for some people, one
works not the other, and reciprocally.
As a consequence, you can't just have a switch codec-based, like in current
code, which decides on the float or int implementation, you must necessarily
have a runtime test because you won't know until then if ogg vorbis will use
one or another sample (note: that's true also for AC3 as I fixed the exact same
bug in DVDStyler for AC3 encoding a few months ago; and I guess it would be same
for AAC).
Some notes from self:
- New FFmpeg requires using FLTP for AAC, AC3 and Vorbis, it's not supported
by audaspace and result in this case would be just wrong. Throw an error
in cases FLTP is trying to be used.
- Moved strict_std_compliance a bit upper. When we'll support FLTP both
FLT and FLTP for AAC would need to be using FF_COMPLIANCE_EXPERIMENTAL.
- It is nice to have such check of supported by codec formats anyway.
2013-03-12 16:57:14 +00:00
|
|
|
if (codec->sample_fmts) {
|
2014-10-23 10:38:14 +02:00
|
|
|
/* check if the preferred sample format for this codec is supported.
|
Patch #34204: [Render Animation] Fails with "Error: Specified sample_fmt is not supported" with ogg vorbis
Patch by Jehan Pages (pardon for mis-typing, emacs-nox works not so good with
urf-8 buffers here), with some own modifications. Thanks!
From the patch tracker:
The problem is because of several versions of ffmpeg, but even more because of
the fork situation libav/ffmpeg. So there are some installed versions out there
where you *must* use a float sample for some codec; whereas oppositely on some
other installations, you *must* use the int sample. So for some people, one
works not the other, and reciprocally.
As a consequence, you can't just have a switch codec-based, like in current
code, which decides on the float or int implementation, you must necessarily
have a runtime test because you won't know until then if ogg vorbis will use
one or another sample (note: that's true also for AC3 as I fixed the exact same
bug in DVDStyler for AC3 encoding a few months ago; and I guess it would be same
for AAC).
Some notes from self:
- New FFmpeg requires using FLTP for AAC, AC3 and Vorbis, it's not supported
by audaspace and result in this case would be just wrong. Throw an error
in cases FLTP is trying to be used.
- Moved strict_std_compliance a bit upper. When we'll support FLTP both
FLT and FLTP for AAC would need to be using FF_COMPLIANCE_EXPERIMENTAL.
- It is nice to have such check of supported by codec formats anyway.
2013-03-12 16:57:14 +00:00
|
|
|
* this is because, depending on the version of libav, and with the whole ffmpeg/libav fork situation,
|
|
|
|
* you have various implementations around. float samples in particular are not always supported.
|
|
|
|
*/
|
|
|
|
const enum AVSampleFormat *p = codec->sample_fmts;
|
2014-08-12 10:31:07 +10:00
|
|
|
for (; *p != -1; p++) {
|
Patch #34204: [Render Animation] Fails with "Error: Specified sample_fmt is not supported" with ogg vorbis
Patch by Jehan Pages (pardon for mis-typing, emacs-nox works not so good with
urf-8 buffers here), with some own modifications. Thanks!
From the patch tracker:
The problem is because of several versions of ffmpeg, but even more because of
the fork situation libav/ffmpeg. So there are some installed versions out there
where you *must* use a float sample for some codec; whereas oppositely on some
other installations, you *must* use the int sample. So for some people, one
works not the other, and reciprocally.
As a consequence, you can't just have a switch codec-based, like in current
code, which decides on the float or int implementation, you must necessarily
have a runtime test because you won't know until then if ogg vorbis will use
one or another sample (note: that's true also for AC3 as I fixed the exact same
bug in DVDStyler for AC3 encoding a few months ago; and I guess it would be same
for AAC).
Some notes from self:
- New FFmpeg requires using FLTP for AAC, AC3 and Vorbis, it's not supported
by audaspace and result in this case would be just wrong. Throw an error
in cases FLTP is trying to be used.
- Moved strict_std_compliance a bit upper. When we'll support FLTP both
FLT and FLTP for AAC would need to be using FF_COMPLIANCE_EXPERIMENTAL.
- It is nice to have such check of supported by codec formats anyway.
2013-03-12 16:57:14 +00:00
|
|
|
if (*p == st->codec->sample_fmt)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (*p == -1) {
|
|
|
|
/* sample format incompatible with codec. Defaulting to a format known to work */
|
|
|
|
st->codec->sample_fmt = codec->sample_fmts[0];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (codec->supported_samplerates) {
|
|
|
|
const int *p = codec->supported_samplerates;
|
|
|
|
int best = 0;
|
|
|
|
int best_dist = INT_MAX;
|
2013-03-12 21:46:33 +00:00
|
|
|
for (; *p; p++) {
|
Patch #34204: [Render Animation] Fails with "Error: Specified sample_fmt is not supported" with ogg vorbis
Patch by Jehan Pages (pardon for mis-typing, emacs-nox works not so good with
urf-8 buffers here), with some own modifications. Thanks!
From the patch tracker:
The problem is because of several versions of ffmpeg, but even more because of
the fork situation libav/ffmpeg. So there are some installed versions out there
where you *must* use a float sample for some codec; whereas oppositely on some
other installations, you *must* use the int sample. So for some people, one
works not the other, and reciprocally.
As a consequence, you can't just have a switch codec-based, like in current
code, which decides on the float or int implementation, you must necessarily
have a runtime test because you won't know until then if ogg vorbis will use
one or another sample (note: that's true also for AC3 as I fixed the exact same
bug in DVDStyler for AC3 encoding a few months ago; and I guess it would be same
for AAC).
Some notes from self:
- New FFmpeg requires using FLTP for AAC, AC3 and Vorbis, it's not supported
by audaspace and result in this case would be just wrong. Throw an error
in cases FLTP is trying to be used.
- Moved strict_std_compliance a bit upper. When we'll support FLTP both
FLT and FLTP for AAC would need to be using FF_COMPLIANCE_EXPERIMENTAL.
- It is nice to have such check of supported by codec formats anyway.
2013-03-12 16:57:14 +00:00
|
|
|
int dist = abs(st->codec->sample_rate - *p);
|
2013-03-12 21:46:33 +00:00
|
|
|
if (dist < best_dist) {
|
Patch #34204: [Render Animation] Fails with "Error: Specified sample_fmt is not supported" with ogg vorbis
Patch by Jehan Pages (pardon for mis-typing, emacs-nox works not so good with
urf-8 buffers here), with some own modifications. Thanks!
From the patch tracker:
The problem is because of several versions of ffmpeg, but even more because of
the fork situation libav/ffmpeg. So there are some installed versions out there
where you *must* use a float sample for some codec; whereas oppositely on some
other installations, you *must* use the int sample. So for some people, one
works not the other, and reciprocally.
As a consequence, you can't just have a switch codec-based, like in current
code, which decides on the float or int implementation, you must necessarily
have a runtime test because you won't know until then if ogg vorbis will use
one or another sample (note: that's true also for AC3 as I fixed the exact same
bug in DVDStyler for AC3 encoding a few months ago; and I guess it would be same
for AAC).
Some notes from self:
- New FFmpeg requires using FLTP for AAC, AC3 and Vorbis, it's not supported
by audaspace and result in this case would be just wrong. Throw an error
in cases FLTP is trying to be used.
- Moved strict_std_compliance a bit upper. When we'll support FLTP both
FLT and FLTP for AAC would need to be using FF_COMPLIANCE_EXPERIMENTAL.
- It is nice to have such check of supported by codec formats anyway.
2013-03-12 16:57:14 +00:00
|
|
|
best_dist = dist;
|
|
|
|
best = *p;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* best is the closest supported sample rate (same as selected if best_dist == 0) */
|
|
|
|
st->codec->sample_rate = best;
|
|
|
|
}
|
|
|
|
|
2014-02-17 18:08:53 +06:00
|
|
|
if (of->oformat->flags & AVFMT_GLOBALHEADER) {
|
|
|
|
c->flags |= CODEC_FLAG_GLOBAL_HEADER;
|
|
|
|
}
|
|
|
|
|
2014-02-17 20:50:42 +06:00
|
|
|
set_ffmpeg_properties(rd, c, "audio", &opts);
|
2008-05-11 20:40:55 +00:00
|
|
|
|
2014-02-17 20:50:42 +06:00
|
|
|
if (avcodec_open2(c, codec, &opts) < 0) {
|
2008-01-02 12:35:30 +00:00
|
|
|
//XXX error("Couldn't initialize audio codec");
|
2012-11-19 17:22:40 +00:00
|
|
|
BLI_strncpy(error, IMB_ffmpeg_last_error(), error_size);
|
2014-02-17 20:50:42 +06:00
|
|
|
av_dict_free(&opts);
|
2006-02-05 19:14:46 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
2014-02-17 20:50:42 +06:00
|
|
|
av_dict_free(&opts);
|
2006-02-05 19:14:46 +00:00
|
|
|
|
2011-10-04 12:30:26 +00:00
|
|
|
/* need to prevent floating point exception when using vorbis audio codec,
|
2015-09-14 02:21:15 +10:00
|
|
|
* initialize this value in the same way as it's done in FFmpeg itself (sergey) */
|
2012-05-12 16:11:34 +00:00
|
|
|
st->codec->time_base.num = 1;
|
|
|
|
st->codec->time_base.den = st->codec->sample_rate;
|
2011-10-04 12:30:26 +00:00
|
|
|
|
2013-04-19 17:23:08 +00:00
|
|
|
#ifndef FFMPEG_HAVE_ENCODE_AUDIO2
|
2015-04-06 10:40:12 -03:00
|
|
|
context->audio_outbuf_size = FF_MIN_BUFFER_SIZE;
|
2013-04-19 17:23:08 +00:00
|
|
|
#endif
|
|
|
|
|
2013-04-01 15:31:27 +00:00
|
|
|
if (c->frame_size == 0)
|
2013-06-13 11:59:28 +00:00
|
|
|
// used to be if ((c->codec_id >= CODEC_ID_PCM_S16LE) && (c->codec_id <= CODEC_ID_PCM_DVD))
|
2013-04-01 15:31:27 +00:00
|
|
|
// not sure if that is needed anymore, so let's try out if there are any
|
|
|
|
// complaints regarding some ffmpeg versions users might have
|
2015-04-06 10:40:12 -03:00
|
|
|
context->audio_input_samples = FF_MIN_BUFFER_SIZE * 8 / c->bits_per_coded_sample / c->channels;
|
2012-03-06 18:40:15 +00:00
|
|
|
else {
|
2015-04-06 10:40:12 -03:00
|
|
|
context->audio_input_samples = c->frame_size;
|
2013-04-19 17:23:08 +00:00
|
|
|
#ifndef FFMPEG_HAVE_ENCODE_AUDIO2
|
2015-04-06 10:40:12 -03:00
|
|
|
if (c->frame_size * c->channels * sizeof(int16_t) * 4 > context->audio_outbuf_size)
|
|
|
|
context->audio_outbuf_size = c->frame_size * c->channels * sizeof(int16_t) * 4;
|
2013-04-19 17:23:08 +00:00
|
|
|
#endif
|
2010-02-14 15:38:05 +00:00
|
|
|
}
|
|
|
|
|
2015-04-06 10:40:12 -03:00
|
|
|
context->audio_deinterleave = av_sample_fmt_is_planar(c->sample_fmt);
|
2006-02-05 19:14:46 +00:00
|
|
|
|
2015-04-06 10:40:12 -03:00
|
|
|
context->audio_sample_size = av_get_bytes_per_sample(c->sample_fmt);
|
2013-04-01 15:31:27 +00:00
|
|
|
|
2015-04-06 10:40:12 -03:00
|
|
|
context->audio_input_buffer = (uint8_t *) av_malloc(context->audio_input_samples * c->channels * context->audio_sample_size);
|
2013-04-19 17:23:08 +00:00
|
|
|
#ifndef FFMPEG_HAVE_ENCODE_AUDIO2
|
2015-04-06 10:40:12 -03:00
|
|
|
context->audio_output_buffer = (uint8_t *) av_malloc(context->audio_outbuf_size);
|
2013-04-19 17:23:08 +00:00
|
|
|
#endif
|
2013-04-01 15:31:27 +00:00
|
|
|
|
2015-04-06 10:40:12 -03:00
|
|
|
if (context->audio_deinterleave)
|
|
|
|
context->audio_deinterleave_buffer = (uint8_t *) av_malloc(context->audio_input_samples * c->channels * context->audio_sample_size);
|
2006-02-05 19:14:46 +00:00
|
|
|
|
2015-04-06 10:40:12 -03:00
|
|
|
context->audio_time = 0.0f;
|
2010-02-07 23:41:17 +00:00
|
|
|
|
2006-02-05 19:14:46 +00:00
|
|
|
return st;
|
|
|
|
}
|
|
|
|
/* essential functions -- start, append, end */
|
|
|
|
|
2012-06-18 10:29:11 +00:00
|
|
|
static void ffmpeg_dict_set_int(AVDictionary **dict, const char *key, int value)
|
|
|
|
{
|
|
|
|
char buffer[32];
|
|
|
|
|
|
|
|
BLI_snprintf(buffer, sizeof(buffer), "%d", value);
|
|
|
|
|
|
|
|
av_dict_set(dict, key, buffer, 0);
|
|
|
|
}
|
|
|
|
|
2014-02-17 20:50:42 +06:00
|
|
|
static void ffmpeg_dict_set_float(AVDictionary **dict, const char *key, float value)
|
|
|
|
{
|
|
|
|
char buffer[32];
|
|
|
|
|
|
|
|
BLI_snprintf(buffer, sizeof(buffer), "%.8f", value);
|
|
|
|
|
|
|
|
av_dict_set(dict, key, buffer, 0);
|
|
|
|
}
|
|
|
|
|
2018-04-05 16:31:59 +02:00
|
|
|
static void ffmpeg_add_metadata_callback(void *data, const char *propname, char *propvalue, int len)
|
|
|
|
{
|
|
|
|
AVDictionary **metadata = (AVDictionary **)data;
|
|
|
|
av_dict_set(metadata, propname, propvalue, 0);
|
|
|
|
}
|
|
|
|
|
2015-04-06 10:40:12 -03:00
|
|
|
static int start_ffmpeg_impl(FFMpegContext *context, struct RenderData *rd, int rectx, int recty, const char *suffix, ReportList *reports)
|
2006-02-05 19:14:46 +00:00
|
|
|
{
|
|
|
|
/* Handle to the output file */
|
2012-05-12 16:11:34 +00:00
|
|
|
AVFormatContext *of;
|
|
|
|
AVOutputFormat *fmt;
|
2012-06-18 10:29:11 +00:00
|
|
|
AVDictionary *opts = NULL;
|
2015-10-23 18:27:26 +11:00
|
|
|
char name[FILE_MAX], error[1024];
|
2012-05-12 16:11:34 +00:00
|
|
|
const char **exts;
|
2006-02-05 19:14:46 +00:00
|
|
|
|
2015-04-06 10:40:12 -03:00
|
|
|
context->ffmpeg_type = rd->ffcodecdata.type;
|
|
|
|
context->ffmpeg_codec = rd->ffcodecdata.codec;
|
|
|
|
context->ffmpeg_audio_codec = rd->ffcodecdata.audio_codec;
|
|
|
|
context->ffmpeg_video_bitrate = rd->ffcodecdata.video_bitrate;
|
|
|
|
context->ffmpeg_audio_bitrate = rd->ffcodecdata.audio_bitrate;
|
|
|
|
context->ffmpeg_gop_size = rd->ffcodecdata.gop_size;
|
|
|
|
context->ffmpeg_autosplit = rd->ffcodecdata.flags & FFMPEG_AUTOSPLIT_OUTPUT;
|
FFmpeg interface improvements
This patch changes a couple of things in the video output encoding.
{F362527}
- Clearer separation between container and codec. No more "format", as this is
too ambiguous. As a result, codecs were removed from the container list.
- Added FFmpeg speed presets, so the user can choosen from the range "Very
slow" to "Ultra fast". By default no preset is used.
- Added Constant Rate Factor (CRF) mode, which allows changing the bit-rate
depending on the desired quality and the input. This generally produces the
best quality videos, at the expense of not knowing the exact bit-rate and
file size.
- Added optional maximum of non-B-frames between B-frames (`max_b_frames`).
- Presets were adjusted for these changes, and new presets added. One of the
new presets is [recommended](https://trac.ffmpeg.org/wiki/Encode/VFX#H.264)
for reviewing videos, as it allows players to scrub through it easily. Might
be nice in weeklies. This preset also requires control over the
`max_b_frames` setting.
GUI-only changes:
- Renamed "MPEG" in the output file format menu with "FFmpeg", as this is more
accurate. After all, FFmpeg is used when this option is chosen, which can
also output non-MPEG files.
- Certain parts of the GUI are disabled when not in use:
- bit rate options are not used when a constant rate factor is given.
- audio bitrate & volume are not used when no audio is exported.
Note that I did not touch `BKE_ffmpeg_preset_set()`. There are currently two
preset systems for FFmpeg (`BKE_ffmpeg_preset_set()` and the Python preset
system). Before we do more work on `BKE_ffmpeg_preset_set()`, I think it's a
good idea to determine whether we want to keep it at all.
After this patch has been accepted, I'd be happy to go through the code and
remove any then-obsolete bits, such as the handling of "XVID" as a container
format.
Reviewers: sergey, mont29, brecht
Subscribers: mpan3, Blendify, brecht, fsiddi
Tags: #bf_blender
Differential Revision: https://developer.blender.org/D2242
2016-09-21 15:01:51 +02:00
|
|
|
context->ffmpeg_crf = rd->ffcodecdata.constant_rate_factor;
|
|
|
|
context->ffmpeg_preset = rd->ffcodecdata.ffmpeg_preset;
|
|
|
|
|
|
|
|
if ((rd->ffcodecdata.flags & FFMPEG_USE_MAX_B_FRAMES) != 0) {
|
|
|
|
context->ffmpeg_max_b_frames = rd->ffcodecdata.max_b_frames;
|
|
|
|
}
|
2015-04-06 10:40:12 -03:00
|
|
|
|
2006-02-05 19:14:46 +00:00
|
|
|
/* Determine the correct filename */
|
2015-04-06 10:40:12 -03:00
|
|
|
ffmpeg_filepath_get(context, name, rd, context->ffmpeg_preview, suffix);
|
2012-08-26 11:01:14 +00:00
|
|
|
PRINT("Starting output to %s(ffmpeg)...\n"
|
2012-05-12 16:11:34 +00:00
|
|
|
" Using type=%d, codec=%d, audio_codec=%d,\n"
|
|
|
|
" video_bitrate=%d, audio_bitrate=%d,\n"
|
|
|
|
" gop_size=%d, autosplit=%d\n"
|
|
|
|
" render width=%d, render height=%d\n",
|
2015-04-06 10:40:12 -03:00
|
|
|
name, context->ffmpeg_type, context->ffmpeg_codec, context->ffmpeg_audio_codec,
|
|
|
|
context->ffmpeg_video_bitrate, context->ffmpeg_audio_bitrate,
|
|
|
|
context->ffmpeg_gop_size, context->ffmpeg_autosplit, rectx, recty);
|
2006-02-05 19:14:46 +00:00
|
|
|
|
2015-04-06 10:40:12 -03:00
|
|
|
exts = get_file_extensions(context->ffmpeg_type);
|
2006-07-09 13:05:09 +00:00
|
|
|
if (!exts) {
|
2012-10-21 14:02:30 +00:00
|
|
|
BKE_report(reports, RPT_ERROR, "No valid formats found");
|
2009-12-22 12:01:32 +00:00
|
|
|
return 0;
|
2006-07-09 13:05:09 +00:00
|
|
|
}
|
2011-05-26 21:57:02 +00:00
|
|
|
fmt = av_guess_format(NULL, exts[0], NULL);
|
2006-02-05 19:14:46 +00:00
|
|
|
if (!fmt) {
|
2012-10-21 14:02:30 +00:00
|
|
|
BKE_report(reports, RPT_ERROR, "No valid formats found");
|
2009-12-22 12:01:32 +00:00
|
|
|
return 0;
|
2006-02-05 19:14:46 +00:00
|
|
|
}
|
|
|
|
|
2011-05-26 21:57:02 +00:00
|
|
|
of = avformat_alloc_context();
|
2006-02-05 19:14:46 +00:00
|
|
|
if (!of) {
|
2009-12-22 12:01:32 +00:00
|
|
|
BKE_report(reports, RPT_ERROR, "Error opening output file");
|
|
|
|
return 0;
|
2006-02-05 19:14:46 +00:00
|
|
|
}
|
2015-10-23 18:36:46 +11:00
|
|
|
|
|
|
|
|
|
|
|
/* Returns after this must 'goto fail;' */
|
|
|
|
|
2006-02-05 19:14:46 +00:00
|
|
|
of->oformat = fmt;
|
FFmpeg interface improvements
This patch changes a couple of things in the video output encoding.
{F362527}
- Clearer separation between container and codec. No more "format", as this is
too ambiguous. As a result, codecs were removed from the container list.
- Added FFmpeg speed presets, so the user can choosen from the range "Very
slow" to "Ultra fast". By default no preset is used.
- Added Constant Rate Factor (CRF) mode, which allows changing the bit-rate
depending on the desired quality and the input. This generally produces the
best quality videos, at the expense of not knowing the exact bit-rate and
file size.
- Added optional maximum of non-B-frames between B-frames (`max_b_frames`).
- Presets were adjusted for these changes, and new presets added. One of the
new presets is [recommended](https://trac.ffmpeg.org/wiki/Encode/VFX#H.264)
for reviewing videos, as it allows players to scrub through it easily. Might
be nice in weeklies. This preset also requires control over the
`max_b_frames` setting.
GUI-only changes:
- Renamed "MPEG" in the output file format menu with "FFmpeg", as this is more
accurate. After all, FFmpeg is used when this option is chosen, which can
also output non-MPEG files.
- Certain parts of the GUI are disabled when not in use:
- bit rate options are not used when a constant rate factor is given.
- audio bitrate & volume are not used when no audio is exported.
Note that I did not touch `BKE_ffmpeg_preset_set()`. There are currently two
preset systems for FFmpeg (`BKE_ffmpeg_preset_set()` and the Python preset
system). Before we do more work on `BKE_ffmpeg_preset_set()`, I think it's a
good idea to determine whether we want to keep it at all.
After this patch has been accepted, I'd be happy to go through the code and
remove any then-obsolete bits, such as the handling of "XVID" as a container
format.
Reviewers: sergey, mont29, brecht
Subscribers: mpan3, Blendify, brecht, fsiddi
Tags: #bf_blender
Differential Revision: https://developer.blender.org/D2242
2016-09-21 15:01:51 +02:00
|
|
|
|
|
|
|
/* Only bother with setting packet size & mux rate when CRF is not used. */
|
|
|
|
if (context->ffmpeg_crf == 0) {
|
|
|
|
of->packet_size = rd->ffcodecdata.mux_packet_size;
|
|
|
|
if (context->ffmpeg_audio_codec != AV_CODEC_ID_NONE) {
|
|
|
|
ffmpeg_dict_set_int(&opts, "muxrate", rd->ffcodecdata.mux_rate);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
av_dict_set(&opts, "muxrate", "0", 0);
|
|
|
|
}
|
2006-02-05 19:14:46 +00:00
|
|
|
}
|
|
|
|
|
2012-06-18 10:29:11 +00:00
|
|
|
ffmpeg_dict_set_int(&opts, "preload", (int)(0.5 * AV_TIME_BASE));
|
|
|
|
|
2012-05-12 16:11:34 +00:00
|
|
|
of->max_delay = (int)(0.7 * AV_TIME_BASE);
|
2006-05-21 12:20:45 +00:00
|
|
|
|
2015-04-06 10:40:12 -03:00
|
|
|
fmt->audio_codec = context->ffmpeg_audio_codec;
|
2010-02-07 23:41:17 +00:00
|
|
|
|
2013-03-14 10:39:18 +00:00
|
|
|
BLI_strncpy(of->filename, name, sizeof(of->filename));
|
2006-02-05 19:14:46 +00:00
|
|
|
/* set the codec to the user's selection */
|
2015-04-06 10:40:12 -03:00
|
|
|
switch (context->ffmpeg_type) {
|
2012-05-12 16:11:34 +00:00
|
|
|
case FFMPEG_AVI:
|
|
|
|
case FFMPEG_MOV:
|
|
|
|
case FFMPEG_MKV:
|
2015-04-06 10:40:12 -03:00
|
|
|
fmt->video_codec = context->ffmpeg_codec;
|
2012-05-12 16:11:34 +00:00
|
|
|
break;
|
|
|
|
case FFMPEG_OGG:
|
2014-01-16 15:40:37 +01:00
|
|
|
fmt->video_codec = AV_CODEC_ID_THEORA;
|
2012-05-12 16:11:34 +00:00
|
|
|
break;
|
|
|
|
case FFMPEG_DV:
|
2014-01-16 15:40:37 +01:00
|
|
|
fmt->video_codec = AV_CODEC_ID_DVVIDEO;
|
2012-05-12 16:11:34 +00:00
|
|
|
break;
|
|
|
|
case FFMPEG_MPEG1:
|
2014-01-16 15:40:37 +01:00
|
|
|
fmt->video_codec = AV_CODEC_ID_MPEG1VIDEO;
|
2012-05-12 16:11:34 +00:00
|
|
|
break;
|
|
|
|
case FFMPEG_MPEG2:
|
2014-01-16 15:40:37 +01:00
|
|
|
fmt->video_codec = AV_CODEC_ID_MPEG2VIDEO;
|
2012-05-12 16:11:34 +00:00
|
|
|
break;
|
|
|
|
case FFMPEG_H264:
|
2014-01-16 15:40:37 +01:00
|
|
|
fmt->video_codec = AV_CODEC_ID_H264;
|
2012-05-12 16:11:34 +00:00
|
|
|
break;
|
|
|
|
case FFMPEG_XVID:
|
2014-01-16 15:40:37 +01:00
|
|
|
fmt->video_codec = AV_CODEC_ID_MPEG4;
|
2012-05-12 16:11:34 +00:00
|
|
|
break;
|
|
|
|
case FFMPEG_FLV:
|
2014-01-16 15:40:37 +01:00
|
|
|
fmt->video_codec = AV_CODEC_ID_FLV1;
|
2012-05-12 16:11:34 +00:00
|
|
|
break;
|
|
|
|
case FFMPEG_MPEG4:
|
|
|
|
default:
|
2015-08-25 08:51:04 +10:00
|
|
|
fmt->video_codec = context->ffmpeg_codec;
|
2012-05-12 16:11:34 +00:00
|
|
|
break;
|
2006-02-05 19:14:46 +00:00
|
|
|
}
|
2014-01-16 15:40:37 +01:00
|
|
|
if (fmt->video_codec == AV_CODEC_ID_DVVIDEO) {
|
2006-06-07 12:53:51 +00:00
|
|
|
if (rectx != 720) {
|
2009-12-22 12:01:32 +00:00
|
|
|
BKE_report(reports, RPT_ERROR, "Render width has to be 720 pixels for DV!");
|
2015-10-23 18:36:46 +11:00
|
|
|
goto fail;
|
2006-06-07 12:53:51 +00:00
|
|
|
}
|
2009-01-04 14:14:06 +00:00
|
|
|
if (rd->frs_sec != 25 && recty != 480) {
|
2009-12-22 12:01:32 +00:00
|
|
|
BKE_report(reports, RPT_ERROR, "Render height has to be 480 pixels for DV-NTSC!");
|
2015-10-23 18:36:46 +11:00
|
|
|
goto fail;
|
2006-06-07 12:53:51 +00:00
|
|
|
}
|
2009-01-04 14:14:06 +00:00
|
|
|
if (rd->frs_sec == 25 && recty != 576) {
|
2009-12-22 12:01:32 +00:00
|
|
|
BKE_report(reports, RPT_ERROR, "Render height has to be 576 pixels for DV-PAL!");
|
2015-10-23 18:36:46 +11:00
|
|
|
goto fail;
|
2006-06-07 12:53:51 +00:00
|
|
|
}
|
|
|
|
}
|
2008-04-22 07:40:04 +00:00
|
|
|
|
2015-04-06 10:40:12 -03:00
|
|
|
if (context->ffmpeg_type == FFMPEG_DV) {
|
2014-01-16 15:40:37 +01:00
|
|
|
fmt->audio_codec = AV_CODEC_ID_PCM_S16LE;
|
2015-04-06 10:40:12 -03:00
|
|
|
if (context->ffmpeg_audio_codec != AV_CODEC_ID_NONE && rd->ffcodecdata.audio_mixrate != 48000 && rd->ffcodecdata.audio_channels != 2) {
|
2009-12-22 12:01:32 +00:00
|
|
|
BKE_report(reports, RPT_ERROR, "FFMPEG only supports 48khz / stereo audio for DV!");
|
2015-10-23 18:36:46 +11:00
|
|
|
goto fail;
|
2006-06-07 12:53:51 +00:00
|
|
|
}
|
2006-02-05 19:14:46 +00:00
|
|
|
}
|
|
|
|
|
2014-01-16 15:40:37 +01:00
|
|
|
if (fmt->video_codec != AV_CODEC_ID_NONE) {
|
2015-04-06 10:40:12 -03:00
|
|
|
context->video_stream = alloc_video_stream(context, rd, fmt->video_codec, of, rectx, recty, error, sizeof(error));
|
|
|
|
PRINT("alloc video stream %p\n", context->video_stream);
|
|
|
|
if (!context->video_stream) {
|
2012-08-26 11:01:14 +00:00
|
|
|
if (error[0])
|
|
|
|
BKE_report(reports, RPT_ERROR, error);
|
|
|
|
else
|
2012-10-21 14:02:30 +00:00
|
|
|
BKE_report(reports, RPT_ERROR, "Error initializing video stream");
|
2015-10-23 18:36:46 +11:00
|
|
|
goto fail;
|
2010-02-07 23:41:17 +00:00
|
|
|
}
|
2006-02-05 19:14:46 +00:00
|
|
|
}
|
2010-02-07 23:41:17 +00:00
|
|
|
|
2015-04-06 10:40:12 -03:00
|
|
|
if (context->ffmpeg_audio_codec != AV_CODEC_ID_NONE) {
|
|
|
|
context->audio_stream = alloc_audio_stream(context, rd, fmt->audio_codec, of, error, sizeof(error));
|
|
|
|
if (!context->audio_stream) {
|
2012-11-19 17:22:40 +00:00
|
|
|
if (error[0])
|
|
|
|
BKE_report(reports, RPT_ERROR, error);
|
|
|
|
else
|
|
|
|
BKE_report(reports, RPT_ERROR, "Error initializing audio stream");
|
2015-10-23 18:36:46 +11:00
|
|
|
goto fail;
|
2006-02-05 19:14:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!(fmt->flags & AVFMT_NOFILE)) {
|
2011-05-26 21:57:02 +00:00
|
|
|
if (avio_open(&of->pb, name, AVIO_FLAG_WRITE) < 0) {
|
2012-10-21 14:02:30 +00:00
|
|
|
BKE_report(reports, RPT_ERROR, "Could not open file for writing");
|
2015-10-23 18:36:46 +11:00
|
|
|
goto fail;
|
2006-02-05 19:14:46 +00:00
|
|
|
}
|
|
|
|
}
|
2018-04-05 16:31:59 +02:00
|
|
|
|
|
|
|
if (context->stamp_data != NULL) {
|
|
|
|
BKE_stamp_info_callback(&of->metadata, context->stamp_data, ffmpeg_add_metadata_callback, false);
|
|
|
|
}
|
|
|
|
|
2012-06-18 10:29:11 +00:00
|
|
|
if (avformat_write_header(of, NULL) < 0) {
|
2012-10-21 14:02:30 +00:00
|
|
|
BKE_report(reports, RPT_ERROR, "Could not initialize streams, probably unsupported codec combination");
|
2015-10-23 18:36:46 +11:00
|
|
|
goto fail;
|
2011-10-04 12:30:26 +00:00
|
|
|
}
|
|
|
|
|
2015-04-06 10:40:12 -03:00
|
|
|
context->outfile = of;
|
2011-05-26 21:57:02 +00:00
|
|
|
av_dump_format(of, 0, name, 1);
|
2012-06-18 10:29:11 +00:00
|
|
|
av_dict_free(&opts);
|
2009-12-22 12:01:32 +00:00
|
|
|
|
|
|
|
return 1;
|
2015-10-23 18:36:46 +11:00
|
|
|
|
|
|
|
|
|
|
|
fail:
|
|
|
|
if (of->pb) {
|
|
|
|
avio_close(of->pb);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (context->video_stream && context->video_stream->codec) {
|
|
|
|
avcodec_close(context->video_stream->codec);
|
|
|
|
context->video_stream = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (context->audio_stream && context->audio_stream->codec) {
|
|
|
|
avcodec_close(context->audio_stream->codec);
|
|
|
|
context->audio_stream = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
av_dict_free(&opts);
|
|
|
|
avformat_free_context(of);
|
|
|
|
return 0;
|
2006-02-05 19:14:46 +00:00
|
|
|
}
|
|
|
|
|
2010-09-27 07:37:36 +00:00
|
|
|
/**
|
2018-06-01 18:19:39 +02:00
|
|
|
* Writes any delayed frames in the encoder. This function is called before
|
2010-09-27 07:37:36 +00:00
|
|
|
* closing the encoder.
|
|
|
|
*
|
|
|
|
* <p>
|
2018-06-01 18:19:39 +02:00
|
|
|
* Since an encoder may use both past and future frames to predict
|
|
|
|
* inter-frames (H.264 B-frames, for example), it can output the frames
|
2010-09-27 07:37:36 +00:00
|
|
|
* in a different order from the one it was given.
|
|
|
|
* For example, when sending frames 1, 2, 3, 4 to the encoder, it may write
|
2012-09-26 20:05:38 +00:00
|
|
|
* them in the order 1, 4, 2, 3 - first the two frames used for prediction,
|
2018-06-01 18:19:39 +02:00
|
|
|
* and then the bidirectionally-predicted frames. What this means in practice
|
|
|
|
* is that the encoder may not immediately produce one output frame for each
|
|
|
|
* input frame. These delayed frames must be flushed before we close the
|
|
|
|
* stream. We do this by calling avcodec_encode_video with NULL for the last
|
2010-09-27 07:37:36 +00:00
|
|
|
* parameter.
|
|
|
|
* </p>
|
|
|
|
*/
|
2015-04-06 10:40:12 -03:00
|
|
|
static void flush_ffmpeg(FFMpegContext *context)
|
2010-09-27 07:37:36 +00:00
|
|
|
{
|
|
|
|
int ret = 0;
|
|
|
|
|
2015-04-06 10:40:12 -03:00
|
|
|
AVCodecContext *c = context->video_stream->codec;
|
2010-09-27 07:37:36 +00:00
|
|
|
/* get the delayed frames */
|
|
|
|
while (1) {
|
2014-01-16 15:40:37 +01:00
|
|
|
int got_output;
|
|
|
|
AVPacket packet = { 0 };
|
2010-09-27 07:37:36 +00:00
|
|
|
av_init_packet(&packet);
|
|
|
|
|
2014-01-16 15:40:37 +01:00
|
|
|
ret = avcodec_encode_video2(c, &packet, NULL, &got_output);
|
|
|
|
if (ret < 0) {
|
|
|
|
fprintf(stderr, "Error encoding delayed frame %d\n", ret);
|
2010-09-27 07:37:36 +00:00
|
|
|
break;
|
|
|
|
}
|
2014-01-16 15:40:37 +01:00
|
|
|
if (!got_output) {
|
2010-09-27 07:37:36 +00:00
|
|
|
break;
|
|
|
|
}
|
2014-01-16 15:40:37 +01:00
|
|
|
if (packet.pts != AV_NOPTS_VALUE) {
|
2015-04-06 10:40:12 -03:00
|
|
|
packet.pts = av_rescale_q(packet.pts, c->time_base, context->video_stream->time_base);
|
2012-08-26 11:01:18 +00:00
|
|
|
PRINT("Video Frame PTS: %d\n", (int) packet.pts);
|
2012-03-24 06:18:31 +00:00
|
|
|
}
|
|
|
|
else {
|
2012-08-26 11:01:14 +00:00
|
|
|
PRINT("Video Frame PTS: not set\n");
|
2010-09-27 07:37:36 +00:00
|
|
|
}
|
2014-01-16 15:40:37 +01:00
|
|
|
if (packet.dts != AV_NOPTS_VALUE) {
|
2015-04-06 10:40:12 -03:00
|
|
|
packet.dts = av_rescale_q(packet.dts, c->time_base, context->video_stream->time_base);
|
2014-01-16 15:40:37 +01:00
|
|
|
PRINT("Video Frame DTS: %d\n", (int) packet.dts);
|
2014-01-28 23:00:28 +11:00
|
|
|
}
|
|
|
|
else {
|
2014-01-16 15:40:37 +01:00
|
|
|
PRINT("Video Frame DTS: not set\n");
|
2010-09-27 07:37:36 +00:00
|
|
|
}
|
2014-01-16 15:40:37 +01:00
|
|
|
|
2015-04-06 10:40:12 -03:00
|
|
|
packet.stream_index = context->video_stream->index;
|
|
|
|
ret = av_interleaved_write_frame(context->outfile, &packet);
|
2010-09-27 07:37:36 +00:00
|
|
|
if (ret != 0) {
|
|
|
|
fprintf(stderr, "Error writing delayed frame %d\n", ret);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2015-04-06 10:40:12 -03:00
|
|
|
avcodec_flush_buffers(context->video_stream->codec);
|
2010-09-27 07:37:36 +00:00
|
|
|
}
|
|
|
|
|
2006-07-09 13:05:09 +00:00
|
|
|
/* **********************************************************************
|
2012-04-22 11:54:53 +00:00
|
|
|
* * public interface
|
|
|
|
* ********************************************************************** */
|
2006-07-09 13:05:09 +00:00
|
|
|
|
|
|
|
/* Get the output filename-- similar to the other output formats */
|
2015-04-06 10:40:12 -03:00
|
|
|
static void ffmpeg_filepath_get(FFMpegContext *context, char *string, RenderData *rd, bool preview, const char *suffix)
|
2011-09-28 05:53:40 +00:00
|
|
|
{
|
2006-07-09 13:05:09 +00:00
|
|
|
char autosplit[20];
|
|
|
|
|
2012-05-12 16:11:34 +00:00
|
|
|
const char **exts = get_file_extensions(rd->ffcodecdata.type);
|
|
|
|
const char **fe = exts;
|
2015-03-26 14:49:59 +01:00
|
|
|
int sfra, efra;
|
2006-07-09 13:05:09 +00:00
|
|
|
|
|
|
|
if (!string || !exts) return;
|
|
|
|
|
2015-03-26 14:49:59 +01:00
|
|
|
if (preview) {
|
|
|
|
sfra = rd->psfra;
|
|
|
|
efra = rd->pefra;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
sfra = rd->sfra;
|
|
|
|
efra = rd->efra;
|
|
|
|
}
|
|
|
|
|
2009-01-04 14:14:06 +00:00
|
|
|
strcpy(string, rd->pic);
|
2010-10-18 06:41:16 +00:00
|
|
|
BLI_path_abs(string, G.main->name);
|
2006-07-09 13:05:09 +00:00
|
|
|
|
|
|
|
BLI_make_existing_file(string);
|
|
|
|
|
2017-01-11 00:08:16 +01:00
|
|
|
autosplit[0] = '\0';
|
2006-07-09 13:05:09 +00:00
|
|
|
|
2009-01-04 14:14:06 +00:00
|
|
|
if ((rd->ffcodecdata.flags & FFMPEG_AUTOSPLIT_OUTPUT) != 0) {
|
2015-04-06 10:40:12 -03:00
|
|
|
if (context) {
|
|
|
|
sprintf(autosplit, "_%03d", context->ffmpeg_autosplit_count);
|
|
|
|
}
|
2006-07-09 13:05:09 +00:00
|
|
|
}
|
|
|
|
|
2013-11-25 16:59:10 +11:00
|
|
|
if (rd->scemode & R_EXTENSION) {
|
|
|
|
while (*fe) {
|
|
|
|
if (BLI_strcasecmp(string + strlen(string) - strlen(*fe), *fe) == 0) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
fe++;
|
2006-07-09 13:05:09 +00:00
|
|
|
}
|
|
|
|
|
2013-11-25 16:59:10 +11:00
|
|
|
if (*fe == NULL) {
|
|
|
|
strcat(string, autosplit);
|
2010-01-26 21:41:38 +00:00
|
|
|
|
2015-03-26 14:49:59 +01:00
|
|
|
BLI_path_frame_range(string, sfra, efra, 4);
|
2013-11-25 16:59:10 +11:00
|
|
|
strcat(string, *exts);
|
|
|
|
}
|
|
|
|
else {
|
2017-01-11 00:08:16 +01:00
|
|
|
*(string + strlen(string) - strlen(*fe)) = '\0';
|
2013-11-25 16:59:10 +11:00
|
|
|
strcat(string, autosplit);
|
|
|
|
strcat(string, *fe);
|
|
|
|
}
|
2012-03-24 06:18:31 +00:00
|
|
|
}
|
|
|
|
else {
|
2013-11-25 16:59:10 +11:00
|
|
|
if (BLI_path_frame_check_chars(string)) {
|
2015-03-26 14:49:59 +01:00
|
|
|
BLI_path_frame_range(string, sfra, efra, 4);
|
2013-11-25 16:59:10 +11:00
|
|
|
}
|
|
|
|
|
2006-07-09 13:05:09 +00:00
|
|
|
strcat(string, autosplit);
|
|
|
|
}
|
2015-04-06 10:40:12 -03:00
|
|
|
|
|
|
|
BLI_path_suffix(string, FILE_MAX, suffix, "");
|
2006-07-09 13:05:09 +00:00
|
|
|
}
|
|
|
|
|
2015-04-06 10:40:12 -03:00
|
|
|
void BKE_ffmpeg_filepath_get(char *string, RenderData *rd, bool preview, const char *suffix)
|
|
|
|
{
|
|
|
|
ffmpeg_filepath_get(NULL, string, rd, preview, suffix);
|
|
|
|
}
|
|
|
|
|
|
|
|
int BKE_ffmpeg_start(void *context_v, struct Scene *scene, RenderData *rd, int rectx, int recty,
|
|
|
|
ReportList *reports, bool preview, const char *suffix)
|
2006-02-05 19:14:46 +00:00
|
|
|
{
|
2009-12-22 12:01:32 +00:00
|
|
|
int success;
|
2015-04-06 10:40:12 -03:00
|
|
|
FFMpegContext *context = context_v;
|
2009-12-22 12:01:32 +00:00
|
|
|
|
2015-04-06 10:40:12 -03:00
|
|
|
context->ffmpeg_autosplit_count = 0;
|
|
|
|
context->ffmpeg_preview = preview;
|
2018-04-05 16:31:59 +02:00
|
|
|
context->stamp_data = BKE_stamp_info_from_scene_static(scene);
|
2006-02-05 19:14:46 +00:00
|
|
|
|
2015-04-06 10:40:12 -03:00
|
|
|
success = start_ffmpeg_impl(context, rd, rectx, recty, suffix, reports);
|
2011-06-23 16:10:48 +00:00
|
|
|
#ifdef WITH_AUDASPACE
|
2015-04-06 10:40:12 -03:00
|
|
|
if (context->audio_stream) {
|
|
|
|
AVCodecContext *c = context->audio_stream->codec;
|
2010-01-01 05:09:30 +00:00
|
|
|
AUD_DeviceSpecs specs;
|
2009-08-09 21:16:39 +00:00
|
|
|
specs.channels = c->channels;
|
2013-04-01 15:31:27 +00:00
|
|
|
|
2013-04-03 01:36:00 +00:00
|
|
|
switch (av_get_packed_sample_fmt(c->sample_fmt)) {
|
2013-07-19 15:23:42 +00:00
|
|
|
case AV_SAMPLE_FMT_U8:
|
|
|
|
specs.format = AUD_FORMAT_U8;
|
|
|
|
break;
|
|
|
|
case AV_SAMPLE_FMT_S16:
|
|
|
|
specs.format = AUD_FORMAT_S16;
|
|
|
|
break;
|
|
|
|
case AV_SAMPLE_FMT_S32:
|
|
|
|
specs.format = AUD_FORMAT_S32;
|
|
|
|
break;
|
|
|
|
case AV_SAMPLE_FMT_FLT:
|
|
|
|
specs.format = AUD_FORMAT_FLOAT32;
|
|
|
|
break;
|
|
|
|
case AV_SAMPLE_FMT_DBL:
|
|
|
|
specs.format = AUD_FORMAT_FLOAT64;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return -31415;
|
2012-11-21 11:57:35 +00:00
|
|
|
}
|
2013-04-01 15:31:27 +00:00
|
|
|
|
2009-09-20 14:00:00 +00:00
|
|
|
specs.rate = rd->ffcodecdata.audio_mixrate;
|
2015-04-06 10:40:12 -03:00
|
|
|
context->audio_mixdown_device = BKE_sound_mixdown(scene, specs, preview ? rd->psfra : rd->sfra, rd->ffcodecdata.audio_volume);
|
2011-06-23 07:16:06 +00:00
|
|
|
#ifdef FFMPEG_CODEC_TIME_BASE
|
|
|
|
c->time_base.den = specs.rate;
|
|
|
|
c->time_base.num = 1;
|
|
|
|
#endif
|
2009-08-09 21:16:39 +00:00
|
|
|
}
|
2011-06-23 16:10:48 +00:00
|
|
|
#endif
|
2009-12-22 12:01:32 +00:00
|
|
|
return success;
|
2006-02-05 19:14:46 +00:00
|
|
|
}
|
|
|
|
|
2015-04-06 10:40:12 -03:00
|
|
|
static void end_ffmpeg_impl(FFMpegContext *context, int is_autosplit);
|
2006-02-05 19:14:46 +00:00
|
|
|
|
2011-06-23 16:10:48 +00:00
|
|
|
#ifdef WITH_AUDASPACE
|
2015-04-06 10:40:12 -03:00
|
|
|
static void write_audio_frames(FFMpegContext *context, double to_pts)
|
2007-01-28 18:45:53 +00:00
|
|
|
{
|
|
|
|
int finished = 0;
|
|
|
|
|
2015-04-06 10:40:12 -03:00
|
|
|
while (context->audio_stream && !finished) {
|
|
|
|
if ((context->audio_time >= to_pts) ||
|
|
|
|
(write_audio_frame(context)))
|
2012-05-20 19:49:27 +00:00
|
|
|
{
|
2007-01-28 18:45:53 +00:00
|
|
|
finished = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-06-23 16:10:48 +00:00
|
|
|
#endif
|
2007-01-28 18:45:53 +00:00
|
|
|
|
2015-04-06 10:40:12 -03:00
|
|
|
int BKE_ffmpeg_append(void *context_v, RenderData *rd, int start_frame, int frame, int *pixels,
|
|
|
|
int rectx, int recty, const char *suffix, ReportList *reports)
|
2006-02-05 19:14:46 +00:00
|
|
|
{
|
2015-04-06 10:40:12 -03:00
|
|
|
FFMpegContext *context = context_v;
|
2012-05-12 16:11:34 +00:00
|
|
|
AVFrame *avframe;
|
2010-02-07 23:41:17 +00:00
|
|
|
int success = 1;
|
2009-12-22 12:01:32 +00:00
|
|
|
|
2012-08-26 11:01:18 +00:00
|
|
|
PRINT("Writing frame %i, render width=%d, render height=%d\n", frame, rectx, recty);
|
2007-01-28 18:45:53 +00:00
|
|
|
|
2012-10-20 20:20:02 +00:00
|
|
|
/* why is this done before writing the video frame and again at end_ffmpeg? */
|
2010-02-07 23:41:17 +00:00
|
|
|
// write_audio_frames(frame / (((double)rd->frs_sec) / rd->frs_sec_base));
|
2009-12-22 12:01:32 +00:00
|
|
|
|
2015-04-06 10:40:12 -03:00
|
|
|
if (context->video_stream) {
|
|
|
|
avframe = generate_video_frame(context, (unsigned char *) pixels, reports);
|
|
|
|
success = (avframe && write_video_frame(context, rd, frame - start_frame, avframe, reports));
|
2010-02-07 23:41:17 +00:00
|
|
|
|
2015-04-06 10:40:12 -03:00
|
|
|
if (context->ffmpeg_autosplit) {
|
|
|
|
if (avio_tell(context->outfile->pb) > FFMPEG_AUTOSPLIT_SIZE) {
|
|
|
|
end_ffmpeg_impl(context, true);
|
|
|
|
context->ffmpeg_autosplit_count++;
|
|
|
|
success &= start_ffmpeg_impl(context, rd, rectx, recty, suffix, reports);
|
2010-02-07 23:41:17 +00:00
|
|
|
}
|
2006-02-05 19:14:46 +00:00
|
|
|
}
|
|
|
|
}
|
2009-12-22 12:01:32 +00:00
|
|
|
|
2011-06-23 16:10:48 +00:00
|
|
|
#ifdef WITH_AUDASPACE
|
2015-04-06 10:40:12 -03:00
|
|
|
write_audio_frames(context, (frame - start_frame) / (((double)rd->frs_sec) / (double)rd->frs_sec_base));
|
2011-06-23 16:10:48 +00:00
|
|
|
#endif
|
2009-12-22 12:01:32 +00:00
|
|
|
return success;
|
2006-02-05 19:14:46 +00:00
|
|
|
}
|
|
|
|
|
2015-04-06 10:40:12 -03:00
|
|
|
static void end_ffmpeg_impl(FFMpegContext *context, int is_autosplit)
|
2006-02-05 19:14:46 +00:00
|
|
|
{
|
2012-08-26 11:01:14 +00:00
|
|
|
PRINT("Closing ffmpeg...\n");
|
2006-02-05 19:14:46 +00:00
|
|
|
|
2012-06-04 20:11:09 +00:00
|
|
|
#if 0
|
2015-04-06 10:40:12 -03:00
|
|
|
if (context->audio_stream) { /* SEE UPPER */
|
|
|
|
write_audio_frames(context);
|
2012-06-04 20:11:09 +00:00
|
|
|
}
|
|
|
|
#endif
|
2009-08-09 21:16:39 +00:00
|
|
|
|
2011-06-23 16:10:48 +00:00
|
|
|
#ifdef WITH_AUDASPACE
|
2014-04-01 11:34:00 +11:00
|
|
|
if (is_autosplit == false) {
|
2015-04-06 10:40:12 -03:00
|
|
|
if (context->audio_mixdown_device) {
|
2014-11-13 00:33:28 +13:00
|
|
|
AUD_Device_free(context->audio_mixdown_device);
|
2017-01-11 00:08:16 +01:00
|
|
|
context->audio_mixdown_device = NULL;
|
2012-09-06 03:08:47 +00:00
|
|
|
}
|
2009-08-09 21:16:39 +00:00
|
|
|
}
|
2011-06-23 16:10:48 +00:00
|
|
|
#endif
|
|
|
|
|
2015-04-06 10:40:12 -03:00
|
|
|
if (context->video_stream && context->video_stream->codec) {
|
2012-08-26 11:01:14 +00:00
|
|
|
PRINT("Flushing delayed frames...\n");
|
2015-04-06 10:40:12 -03:00
|
|
|
flush_ffmpeg(context);
|
2010-09-27 07:37:36 +00:00
|
|
|
}
|
|
|
|
|
2015-04-06 10:40:12 -03:00
|
|
|
if (context->outfile) {
|
|
|
|
av_write_trailer(context->outfile);
|
2006-02-05 19:14:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Close the video codec */
|
|
|
|
|
2017-01-11 00:08:16 +01:00
|
|
|
if (context->video_stream != NULL && context->video_stream->codec != NULL) {
|
2015-04-06 10:40:12 -03:00
|
|
|
avcodec_close(context->video_stream->codec);
|
|
|
|
PRINT("zero video stream %p\n", context->video_stream);
|
2017-01-11 00:08:16 +01:00
|
|
|
context->video_stream = NULL;
|
2006-02-05 19:14:46 +00:00
|
|
|
}
|
|
|
|
|
2017-01-11 00:08:16 +01:00
|
|
|
if (context->audio_stream != NULL && context->audio_stream->codec != NULL) {
|
2015-10-23 18:36:46 +11:00
|
|
|
avcodec_close(context->audio_stream->codec);
|
2017-01-11 00:08:16 +01:00
|
|
|
context->audio_stream = NULL;
|
2015-10-23 18:36:46 +11:00
|
|
|
}
|
|
|
|
|
2006-02-05 19:14:46 +00:00
|
|
|
/* free the temp buffer */
|
2017-01-11 00:08:16 +01:00
|
|
|
if (context->current_frame != NULL) {
|
2015-04-06 10:40:12 -03:00
|
|
|
delete_picture(context->current_frame);
|
2017-01-11 00:08:16 +01:00
|
|
|
context->current_frame = NULL;
|
2006-02-05 19:14:46 +00:00
|
|
|
}
|
2017-01-11 00:08:16 +01:00
|
|
|
if (context->outfile != NULL && context->outfile->oformat) {
|
2015-04-06 10:40:12 -03:00
|
|
|
if (!(context->outfile->oformat->flags & AVFMT_NOFILE)) {
|
|
|
|
avio_close(context->outfile->pb);
|
2006-02-05 19:14:46 +00:00
|
|
|
}
|
|
|
|
}
|
2017-01-11 00:08:16 +01:00
|
|
|
if (context->outfile != NULL) {
|
2015-09-22 21:09:39 +05:00
|
|
|
avformat_free_context(context->outfile);
|
2017-01-11 00:08:16 +01:00
|
|
|
context->outfile = NULL;
|
2006-02-05 19:14:46 +00:00
|
|
|
}
|
2017-01-11 00:08:16 +01:00
|
|
|
if (context->audio_input_buffer != NULL) {
|
2015-04-06 10:40:12 -03:00
|
|
|
av_free(context->audio_input_buffer);
|
2017-01-11 00:08:16 +01:00
|
|
|
context->audio_input_buffer = NULL;
|
2006-02-05 19:14:46 +00:00
|
|
|
}
|
2013-04-19 17:23:08 +00:00
|
|
|
#ifndef FFMPEG_HAVE_ENCODE_AUDIO2
|
2017-01-11 00:08:16 +01:00
|
|
|
if (context->audio_output_buffer != NULL) {
|
2015-04-06 10:40:12 -03:00
|
|
|
av_free(context->audio_output_buffer);
|
2017-01-11 00:08:16 +01:00
|
|
|
context->audio_output_buffer = NULL;
|
2013-04-19 17:23:08 +00:00
|
|
|
}
|
|
|
|
#endif
|
2007-09-23 14:05:22 +00:00
|
|
|
|
2017-01-11 00:08:16 +01:00
|
|
|
if (context->audio_deinterleave_buffer != NULL) {
|
2015-04-06 10:40:12 -03:00
|
|
|
av_free(context->audio_deinterleave_buffer);
|
2017-01-11 00:08:16 +01:00
|
|
|
context->audio_deinterleave_buffer = NULL;
|
2013-04-01 15:31:27 +00:00
|
|
|
}
|
|
|
|
|
2017-01-11 00:08:16 +01:00
|
|
|
if (context->img_convert_ctx != NULL) {
|
2015-04-06 10:40:12 -03:00
|
|
|
sws_freeContext(context->img_convert_ctx);
|
2017-01-11 00:08:16 +01:00
|
|
|
context->img_convert_ctx = NULL;
|
2007-09-23 14:05:22 +00:00
|
|
|
}
|
2006-02-05 19:14:46 +00:00
|
|
|
}
|
2.5: Render
* UI layout for scene buttons has quite some changes, I tried to
better organize things according to the pipeline, and also showing
important properties by default, and collapsing less important ones.
Some changes compared to 2.4x:
* Panorama is now a Camera property.
* Sequence and Compositing are now enabled by default, but will only
do something when there is a node tree using nodes, or a strip in the
sequence editor.
* Enabling Full Sample now automatically enables Save Buffers too.
* Stamp option to include info in file is removed, it now simply always
does this if one of the stamp infos is enabled.
* Xvid, H.264 and Ogg Theora are now directly in the file format menu,
but still using FFMPEG. Unfortunately Ogg is broken at the moment
(also in 2.4x), so that's disabled. And Xvid crashes on 64bit linux,
maybe solvable by upgrading extern/xvidcore/, using ubuntu libs makes
it work.
* Organized file format menu by image/movie types.
Added:
* Render layers RNA wrapped, operatorized, layouted.
* FFMPEG format/codec options are now working.
Defaults changed:
* Compositing & Sequencer enabled.
* Tiles set to 8x8.
* Time/Date/Frame/Scene/Camera/Filename enabled for stamp.
2009-07-13 19:09:13 +00:00
|
|
|
|
2015-04-06 10:40:12 -03:00
|
|
|
void BKE_ffmpeg_end(void *context_v)
|
2012-09-06 03:08:47 +00:00
|
|
|
{
|
2015-04-06 10:40:12 -03:00
|
|
|
FFMpegContext *context = context_v;
|
|
|
|
end_ffmpeg_impl(context, false);
|
2012-09-06 03:08:47 +00:00
|
|
|
}
|
|
|
|
|
2.5: Render
* UI layout for scene buttons has quite some changes, I tried to
better organize things according to the pipeline, and also showing
important properties by default, and collapsing less important ones.
Some changes compared to 2.4x:
* Panorama is now a Camera property.
* Sequence and Compositing are now enabled by default, but will only
do something when there is a node tree using nodes, or a strip in the
sequence editor.
* Enabling Full Sample now automatically enables Save Buffers too.
* Stamp option to include info in file is removed, it now simply always
does this if one of the stamp infos is enabled.
* Xvid, H.264 and Ogg Theora are now directly in the file format menu,
but still using FFMPEG. Unfortunately Ogg is broken at the moment
(also in 2.4x), so that's disabled. And Xvid crashes on 64bit linux,
maybe solvable by upgrading extern/xvidcore/, using ubuntu libs makes
it work.
* Organized file format menu by image/movie types.
Added:
* Render layers RNA wrapped, operatorized, layouted.
* FFMPEG format/codec options are now working.
Defaults changed:
* Compositing & Sequencer enabled.
* Tiles set to 8x8.
* Time/Date/Frame/Scene/Camera/Filename enabled for stamp.
2009-07-13 19:09:13 +00:00
|
|
|
/* properties */
|
|
|
|
|
2012-05-07 09:30:15 +00:00
|
|
|
void BKE_ffmpeg_property_del(RenderData *rd, void *type, void *prop_)
|
2.5: Render
* UI layout for scene buttons has quite some changes, I tried to
better organize things according to the pipeline, and also showing
important properties by default, and collapsing less important ones.
Some changes compared to 2.4x:
* Panorama is now a Camera property.
* Sequence and Compositing are now enabled by default, but will only
do something when there is a node tree using nodes, or a strip in the
sequence editor.
* Enabling Full Sample now automatically enables Save Buffers too.
* Stamp option to include info in file is removed, it now simply always
does this if one of the stamp infos is enabled.
* Xvid, H.264 and Ogg Theora are now directly in the file format menu,
but still using FFMPEG. Unfortunately Ogg is broken at the moment
(also in 2.4x), so that's disabled. And Xvid crashes on 64bit linux,
maybe solvable by upgrading extern/xvidcore/, using ubuntu libs makes
it work.
* Organized file format menu by image/movie types.
Added:
* Render layers RNA wrapped, operatorized, layouted.
* FFMPEG format/codec options are now working.
Defaults changed:
* Compositing & Sequencer enabled.
* Tiles set to 8x8.
* Time/Date/Frame/Scene/Camera/Filename enabled for stamp.
2009-07-13 19:09:13 +00:00
|
|
|
{
|
|
|
|
struct IDProperty *prop = (struct IDProperty *) prop_;
|
2012-05-12 16:11:34 +00:00
|
|
|
IDProperty *group;
|
2.5: Render
* UI layout for scene buttons has quite some changes, I tried to
better organize things according to the pipeline, and also showing
important properties by default, and collapsing less important ones.
Some changes compared to 2.4x:
* Panorama is now a Camera property.
* Sequence and Compositing are now enabled by default, but will only
do something when there is a node tree using nodes, or a strip in the
sequence editor.
* Enabling Full Sample now automatically enables Save Buffers too.
* Stamp option to include info in file is removed, it now simply always
does this if one of the stamp infos is enabled.
* Xvid, H.264 and Ogg Theora are now directly in the file format menu,
but still using FFMPEG. Unfortunately Ogg is broken at the moment
(also in 2.4x), so that's disabled. And Xvid crashes on 64bit linux,
maybe solvable by upgrading extern/xvidcore/, using ubuntu libs makes
it work.
* Organized file format menu by image/movie types.
Added:
* Render layers RNA wrapped, operatorized, layouted.
* FFMPEG format/codec options are now working.
Defaults changed:
* Compositing & Sequencer enabled.
* Tiles set to 8x8.
* Time/Date/Frame/Scene/Camera/Filename enabled for stamp.
2009-07-13 19:09:13 +00:00
|
|
|
|
|
|
|
if (!rd->ffcodecdata.properties) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-10-21 08:16:15 +00:00
|
|
|
group = IDP_GetPropertyFromGroup(rd->ffcodecdata.properties, type);
|
2.5: Render
* UI layout for scene buttons has quite some changes, I tried to
better organize things according to the pipeline, and also showing
important properties by default, and collapsing less important ones.
Some changes compared to 2.4x:
* Panorama is now a Camera property.
* Sequence and Compositing are now enabled by default, but will only
do something when there is a node tree using nodes, or a strip in the
sequence editor.
* Enabling Full Sample now automatically enables Save Buffers too.
* Stamp option to include info in file is removed, it now simply always
does this if one of the stamp infos is enabled.
* Xvid, H.264 and Ogg Theora are now directly in the file format menu,
but still using FFMPEG. Unfortunately Ogg is broken at the moment
(also in 2.4x), so that's disabled. And Xvid crashes on 64bit linux,
maybe solvable by upgrading extern/xvidcore/, using ubuntu libs makes
it work.
* Organized file format menu by image/movie types.
Added:
* Render layers RNA wrapped, operatorized, layouted.
* FFMPEG format/codec options are now working.
Defaults changed:
* Compositing & Sequencer enabled.
* Tiles set to 8x8.
* Time/Date/Frame/Scene/Camera/Filename enabled for stamp.
2009-07-13 19:09:13 +00:00
|
|
|
if (group && prop) {
|
2013-10-16 05:29:28 +00:00
|
|
|
IDP_FreeFromGroup(group, prop);
|
2.5: Render
* UI layout for scene buttons has quite some changes, I tried to
better organize things according to the pipeline, and also showing
important properties by default, and collapsing less important ones.
Some changes compared to 2.4x:
* Panorama is now a Camera property.
* Sequence and Compositing are now enabled by default, but will only
do something when there is a node tree using nodes, or a strip in the
sequence editor.
* Enabling Full Sample now automatically enables Save Buffers too.
* Stamp option to include info in file is removed, it now simply always
does this if one of the stamp infos is enabled.
* Xvid, H.264 and Ogg Theora are now directly in the file format menu,
but still using FFMPEG. Unfortunately Ogg is broken at the moment
(also in 2.4x), so that's disabled. And Xvid crashes on 64bit linux,
maybe solvable by upgrading extern/xvidcore/, using ubuntu libs makes
it work.
* Organized file format menu by image/movie types.
Added:
* Render layers RNA wrapped, operatorized, layouted.
* FFMPEG format/codec options are now working.
Defaults changed:
* Compositing & Sequencer enabled.
* Tiles set to 8x8.
* Time/Date/Frame/Scene/Camera/Filename enabled for stamp.
2009-07-13 19:09:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-02-17 20:50:42 +06:00
|
|
|
static IDProperty *BKE_ffmpeg_property_add(RenderData *rd, const char *type, const AVOption *o, const AVOption *parent)
|
2.5: Render
* UI layout for scene buttons has quite some changes, I tried to
better organize things according to the pipeline, and also showing
important properties by default, and collapsing less important ones.
Some changes compared to 2.4x:
* Panorama is now a Camera property.
* Sequence and Compositing are now enabled by default, but will only
do something when there is a node tree using nodes, or a strip in the
sequence editor.
* Enabling Full Sample now automatically enables Save Buffers too.
* Stamp option to include info in file is removed, it now simply always
does this if one of the stamp infos is enabled.
* Xvid, H.264 and Ogg Theora are now directly in the file format menu,
but still using FFMPEG. Unfortunately Ogg is broken at the moment
(also in 2.4x), so that's disabled. And Xvid crashes on 64bit linux,
maybe solvable by upgrading extern/xvidcore/, using ubuntu libs makes
it work.
* Organized file format menu by image/movie types.
Added:
* Render layers RNA wrapped, operatorized, layouted.
* FFMPEG format/codec options are now working.
Defaults changed:
* Compositing & Sequencer enabled.
* Tiles set to 8x8.
* Time/Date/Frame/Scene/Camera/Filename enabled for stamp.
2009-07-13 19:09:13 +00:00
|
|
|
{
|
|
|
|
AVCodecContext c;
|
2012-05-12 16:11:34 +00:00
|
|
|
IDProperty *group;
|
|
|
|
IDProperty *prop;
|
2.5: Render
* UI layout for scene buttons has quite some changes, I tried to
better organize things according to the pipeline, and also showing
important properties by default, and collapsing less important ones.
Some changes compared to 2.4x:
* Panorama is now a Camera property.
* Sequence and Compositing are now enabled by default, but will only
do something when there is a node tree using nodes, or a strip in the
sequence editor.
* Enabling Full Sample now automatically enables Save Buffers too.
* Stamp option to include info in file is removed, it now simply always
does this if one of the stamp infos is enabled.
* Xvid, H.264 and Ogg Theora are now directly in the file format menu,
but still using FFMPEG. Unfortunately Ogg is broken at the moment
(also in 2.4x), so that's disabled. And Xvid crashes on 64bit linux,
maybe solvable by upgrading extern/xvidcore/, using ubuntu libs makes
it work.
* Organized file format menu by image/movie types.
Added:
* Render layers RNA wrapped, operatorized, layouted.
* FFMPEG format/codec options are now working.
Defaults changed:
* Compositing & Sequencer enabled.
* Tiles set to 8x8.
* Time/Date/Frame/Scene/Camera/Filename enabled for stamp.
2009-07-13 19:09:13 +00:00
|
|
|
IDPropertyTemplate val;
|
|
|
|
int idp_type;
|
|
|
|
char name[256];
|
2010-10-21 07:39:18 +00:00
|
|
|
|
|
|
|
val.i = 0;
|
2.5: Render
* UI layout for scene buttons has quite some changes, I tried to
better organize things according to the pipeline, and also showing
important properties by default, and collapsing less important ones.
Some changes compared to 2.4x:
* Panorama is now a Camera property.
* Sequence and Compositing are now enabled by default, but will only
do something when there is a node tree using nodes, or a strip in the
sequence editor.
* Enabling Full Sample now automatically enables Save Buffers too.
* Stamp option to include info in file is removed, it now simply always
does this if one of the stamp infos is enabled.
* Xvid, H.264 and Ogg Theora are now directly in the file format menu,
but still using FFMPEG. Unfortunately Ogg is broken at the moment
(also in 2.4x), so that's disabled. And Xvid crashes on 64bit linux,
maybe solvable by upgrading extern/xvidcore/, using ubuntu libs makes
it work.
* Organized file format menu by image/movie types.
Added:
* Render layers RNA wrapped, operatorized, layouted.
* FFMPEG format/codec options are now working.
Defaults changed:
* Compositing & Sequencer enabled.
* Tiles set to 8x8.
* Time/Date/Frame/Scene/Camera/Filename enabled for stamp.
2009-07-13 19:09:13 +00:00
|
|
|
|
2013-01-12 12:51:10 +00:00
|
|
|
avcodec_get_context_defaults3(&c, NULL);
|
2.5: Render
* UI layout for scene buttons has quite some changes, I tried to
better organize things according to the pipeline, and also showing
important properties by default, and collapsing less important ones.
Some changes compared to 2.4x:
* Panorama is now a Camera property.
* Sequence and Compositing are now enabled by default, but will only
do something when there is a node tree using nodes, or a strip in the
sequence editor.
* Enabling Full Sample now automatically enables Save Buffers too.
* Stamp option to include info in file is removed, it now simply always
does this if one of the stamp infos is enabled.
* Xvid, H.264 and Ogg Theora are now directly in the file format menu,
but still using FFMPEG. Unfortunately Ogg is broken at the moment
(also in 2.4x), so that's disabled. And Xvid crashes on 64bit linux,
maybe solvable by upgrading extern/xvidcore/, using ubuntu libs makes
it work.
* Organized file format menu by image/movie types.
Added:
* Render layers RNA wrapped, operatorized, layouted.
* FFMPEG format/codec options are now working.
Defaults changed:
* Compositing & Sequencer enabled.
* Tiles set to 8x8.
* Time/Date/Frame/Scene/Camera/Filename enabled for stamp.
2009-07-13 19:09:13 +00:00
|
|
|
|
|
|
|
if (!rd->ffcodecdata.properties) {
|
2012-05-09 09:24:15 +00:00
|
|
|
rd->ffcodecdata.properties = IDP_New(IDP_GROUP, &val, "ffmpeg");
|
2.5: Render
* UI layout for scene buttons has quite some changes, I tried to
better organize things according to the pipeline, and also showing
important properties by default, and collapsing less important ones.
Some changes compared to 2.4x:
* Panorama is now a Camera property.
* Sequence and Compositing are now enabled by default, but will only
do something when there is a node tree using nodes, or a strip in the
sequence editor.
* Enabling Full Sample now automatically enables Save Buffers too.
* Stamp option to include info in file is removed, it now simply always
does this if one of the stamp infos is enabled.
* Xvid, H.264 and Ogg Theora are now directly in the file format menu,
but still using FFMPEG. Unfortunately Ogg is broken at the moment
(also in 2.4x), so that's disabled. And Xvid crashes on 64bit linux,
maybe solvable by upgrading extern/xvidcore/, using ubuntu libs makes
it work.
* Organized file format menu by image/movie types.
Added:
* Render layers RNA wrapped, operatorized, layouted.
* FFMPEG format/codec options are now working.
Defaults changed:
* Compositing & Sequencer enabled.
* Tiles set to 8x8.
* Time/Date/Frame/Scene/Camera/Filename enabled for stamp.
2009-07-13 19:09:13 +00:00
|
|
|
}
|
|
|
|
|
2011-10-21 08:16:15 +00:00
|
|
|
group = IDP_GetPropertyFromGroup(rd->ffcodecdata.properties, type);
|
2.5: Render
* UI layout for scene buttons has quite some changes, I tried to
better organize things according to the pipeline, and also showing
important properties by default, and collapsing less important ones.
Some changes compared to 2.4x:
* Panorama is now a Camera property.
* Sequence and Compositing are now enabled by default, but will only
do something when there is a node tree using nodes, or a strip in the
sequence editor.
* Enabling Full Sample now automatically enables Save Buffers too.
* Stamp option to include info in file is removed, it now simply always
does this if one of the stamp infos is enabled.
* Xvid, H.264 and Ogg Theora are now directly in the file format menu,
but still using FFMPEG. Unfortunately Ogg is broken at the moment
(also in 2.4x), so that's disabled. And Xvid crashes on 64bit linux,
maybe solvable by upgrading extern/xvidcore/, using ubuntu libs makes
it work.
* Organized file format menu by image/movie types.
Added:
* Render layers RNA wrapped, operatorized, layouted.
* FFMPEG format/codec options are now working.
Defaults changed:
* Compositing & Sequencer enabled.
* Tiles set to 8x8.
* Time/Date/Frame/Scene/Camera/Filename enabled for stamp.
2009-07-13 19:09:13 +00:00
|
|
|
|
|
|
|
if (!group) {
|
2011-11-15 10:01:18 +00:00
|
|
|
group = IDP_New(IDP_GROUP, &val, type);
|
2.5: Render
* UI layout for scene buttons has quite some changes, I tried to
better organize things according to the pipeline, and also showing
important properties by default, and collapsing less important ones.
Some changes compared to 2.4x:
* Panorama is now a Camera property.
* Sequence and Compositing are now enabled by default, but will only
do something when there is a node tree using nodes, or a strip in the
sequence editor.
* Enabling Full Sample now automatically enables Save Buffers too.
* Stamp option to include info in file is removed, it now simply always
does this if one of the stamp infos is enabled.
* Xvid, H.264 and Ogg Theora are now directly in the file format menu,
but still using FFMPEG. Unfortunately Ogg is broken at the moment
(also in 2.4x), so that's disabled. And Xvid crashes on 64bit linux,
maybe solvable by upgrading extern/xvidcore/, using ubuntu libs makes
it work.
* Organized file format menu by image/movie types.
Added:
* Render layers RNA wrapped, operatorized, layouted.
* FFMPEG format/codec options are now working.
Defaults changed:
* Compositing & Sequencer enabled.
* Tiles set to 8x8.
* Time/Date/Frame/Scene/Camera/Filename enabled for stamp.
2009-07-13 19:09:13 +00:00
|
|
|
IDP_AddToGroup(rd->ffcodecdata.properties, group);
|
|
|
|
}
|
|
|
|
|
2014-02-17 20:50:42 +06:00
|
|
|
if (parent) {
|
2012-01-11 12:33:51 +00:00
|
|
|
BLI_snprintf(name, sizeof(name), "%s:%s", parent->name, o->name);
|
2012-03-24 06:18:31 +00:00
|
|
|
}
|
|
|
|
else {
|
2012-01-11 12:33:51 +00:00
|
|
|
BLI_strncpy(name, o->name, sizeof(name));
|
2.5: Render
* UI layout for scene buttons has quite some changes, I tried to
better organize things according to the pipeline, and also showing
important properties by default, and collapsing less important ones.
Some changes compared to 2.4x:
* Panorama is now a Camera property.
* Sequence and Compositing are now enabled by default, but will only
do something when there is a node tree using nodes, or a strip in the
sequence editor.
* Enabling Full Sample now automatically enables Save Buffers too.
* Stamp option to include info in file is removed, it now simply always
does this if one of the stamp infos is enabled.
* Xvid, H.264 and Ogg Theora are now directly in the file format menu,
but still using FFMPEG. Unfortunately Ogg is broken at the moment
(also in 2.4x), so that's disabled. And Xvid crashes on 64bit linux,
maybe solvable by upgrading extern/xvidcore/, using ubuntu libs makes
it work.
* Organized file format menu by image/movie types.
Added:
* Render layers RNA wrapped, operatorized, layouted.
* FFMPEG format/codec options are now working.
Defaults changed:
* Compositing & Sequencer enabled.
* Tiles set to 8x8.
* Time/Date/Frame/Scene/Camera/Filename enabled for stamp.
2009-07-13 19:09:13 +00:00
|
|
|
}
|
|
|
|
|
2014-02-17 20:50:42 +06:00
|
|
|
PRINT("ffmpeg_property_add: %s %s\n", type, name);
|
2.5: Render
* UI layout for scene buttons has quite some changes, I tried to
better organize things according to the pipeline, and also showing
important properties by default, and collapsing less important ones.
Some changes compared to 2.4x:
* Panorama is now a Camera property.
* Sequence and Compositing are now enabled by default, but will only
do something when there is a node tree using nodes, or a strip in the
sequence editor.
* Enabling Full Sample now automatically enables Save Buffers too.
* Stamp option to include info in file is removed, it now simply always
does this if one of the stamp infos is enabled.
* Xvid, H.264 and Ogg Theora are now directly in the file format menu,
but still using FFMPEG. Unfortunately Ogg is broken at the moment
(also in 2.4x), so that's disabled. And Xvid crashes on 64bit linux,
maybe solvable by upgrading extern/xvidcore/, using ubuntu libs makes
it work.
* Organized file format menu by image/movie types.
Added:
* Render layers RNA wrapped, operatorized, layouted.
* FFMPEG format/codec options are now working.
Defaults changed:
* Compositing & Sequencer enabled.
* Tiles set to 8x8.
* Time/Date/Frame/Scene/Camera/Filename enabled for stamp.
2009-07-13 19:09:13 +00:00
|
|
|
|
|
|
|
prop = IDP_GetPropertyFromGroup(group, name);
|
|
|
|
if (prop) {
|
|
|
|
return prop;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (o->type) {
|
2013-01-12 12:51:10 +00:00
|
|
|
case AV_OPT_TYPE_INT:
|
|
|
|
case AV_OPT_TYPE_INT64:
|
2012-05-12 16:11:34 +00:00
|
|
|
val.i = FFMPEG_DEF_OPT_VAL_INT(o);
|
|
|
|
idp_type = IDP_INT;
|
|
|
|
break;
|
2013-01-12 12:51:10 +00:00
|
|
|
case AV_OPT_TYPE_DOUBLE:
|
|
|
|
case AV_OPT_TYPE_FLOAT:
|
2012-05-12 16:11:34 +00:00
|
|
|
val.f = FFMPEG_DEF_OPT_VAL_DOUBLE(o);
|
|
|
|
idp_type = IDP_FLOAT;
|
|
|
|
break;
|
2013-01-12 12:51:10 +00:00
|
|
|
case AV_OPT_TYPE_STRING:
|
2012-05-12 16:11:34 +00:00
|
|
|
val.string.str = (char *)" ";
|
|
|
|
val.string.len = 80;
|
2011-11-15 10:01:18 +00:00
|
|
|
/* val.str = (char *)" ";*/
|
2012-05-12 16:11:34 +00:00
|
|
|
idp_type = IDP_STRING;
|
|
|
|
break;
|
2013-01-12 12:51:10 +00:00
|
|
|
case AV_OPT_TYPE_CONST:
|
2012-05-12 16:11:34 +00:00
|
|
|
val.i = 1;
|
|
|
|
idp_type = IDP_INT;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return NULL;
|
2.5: Render
* UI layout for scene buttons has quite some changes, I tried to
better organize things according to the pipeline, and also showing
important properties by default, and collapsing less important ones.
Some changes compared to 2.4x:
* Panorama is now a Camera property.
* Sequence and Compositing are now enabled by default, but will only
do something when there is a node tree using nodes, or a strip in the
sequence editor.
* Enabling Full Sample now automatically enables Save Buffers too.
* Stamp option to include info in file is removed, it now simply always
does this if one of the stamp infos is enabled.
* Xvid, H.264 and Ogg Theora are now directly in the file format menu,
but still using FFMPEG. Unfortunately Ogg is broken at the moment
(also in 2.4x), so that's disabled. And Xvid crashes on 64bit linux,
maybe solvable by upgrading extern/xvidcore/, using ubuntu libs makes
it work.
* Organized file format menu by image/movie types.
Added:
* Render layers RNA wrapped, operatorized, layouted.
* FFMPEG format/codec options are now working.
Defaults changed:
* Compositing & Sequencer enabled.
* Tiles set to 8x8.
* Time/Date/Frame/Scene/Camera/Filename enabled for stamp.
2009-07-13 19:09:13 +00:00
|
|
|
}
|
2011-11-15 10:01:18 +00:00
|
|
|
prop = IDP_New(idp_type, &val, name);
|
2.5: Render
* UI layout for scene buttons has quite some changes, I tried to
better organize things according to the pipeline, and also showing
important properties by default, and collapsing less important ones.
Some changes compared to 2.4x:
* Panorama is now a Camera property.
* Sequence and Compositing are now enabled by default, but will only
do something when there is a node tree using nodes, or a strip in the
sequence editor.
* Enabling Full Sample now automatically enables Save Buffers too.
* Stamp option to include info in file is removed, it now simply always
does this if one of the stamp infos is enabled.
* Xvid, H.264 and Ogg Theora are now directly in the file format menu,
but still using FFMPEG. Unfortunately Ogg is broken at the moment
(also in 2.4x), so that's disabled. And Xvid crashes on 64bit linux,
maybe solvable by upgrading extern/xvidcore/, using ubuntu libs makes
it work.
* Organized file format menu by image/movie types.
Added:
* Render layers RNA wrapped, operatorized, layouted.
* FFMPEG format/codec options are now working.
Defaults changed:
* Compositing & Sequencer enabled.
* Tiles set to 8x8.
* Time/Date/Frame/Scene/Camera/Filename enabled for stamp.
2009-07-13 19:09:13 +00:00
|
|
|
IDP_AddToGroup(group, prop);
|
|
|
|
return prop;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* not all versions of ffmpeg include that, so here we go ... */
|
|
|
|
|
2012-05-12 16:11:34 +00:00
|
|
|
int BKE_ffmpeg_property_add_string(RenderData *rd, const char *type, const char *str)
|
2.5: Render
* UI layout for scene buttons has quite some changes, I tried to
better organize things according to the pipeline, and also showing
important properties by default, and collapsing less important ones.
Some changes compared to 2.4x:
* Panorama is now a Camera property.
* Sequence and Compositing are now enabled by default, but will only
do something when there is a node tree using nodes, or a strip in the
sequence editor.
* Enabling Full Sample now automatically enables Save Buffers too.
* Stamp option to include info in file is removed, it now simply always
does this if one of the stamp infos is enabled.
* Xvid, H.264 and Ogg Theora are now directly in the file format menu,
but still using FFMPEG. Unfortunately Ogg is broken at the moment
(also in 2.4x), so that's disabled. And Xvid crashes on 64bit linux,
maybe solvable by upgrading extern/xvidcore/, using ubuntu libs makes
it work.
* Organized file format menu by image/movie types.
Added:
* Render layers RNA wrapped, operatorized, layouted.
* FFMPEG format/codec options are now working.
Defaults changed:
* Compositing & Sequencer enabled.
* Tiles set to 8x8.
* Time/Date/Frame/Scene/Camera/Filename enabled for stamp.
2009-07-13 19:09:13 +00:00
|
|
|
{
|
|
|
|
AVCodecContext c;
|
2017-01-11 00:08:16 +01:00
|
|
|
const AVOption *o = NULL;
|
|
|
|
const AVOption *p = NULL;
|
2.5: Render
* UI layout for scene buttons has quite some changes, I tried to
better organize things according to the pipeline, and also showing
important properties by default, and collapsing less important ones.
Some changes compared to 2.4x:
* Panorama is now a Camera property.
* Sequence and Compositing are now enabled by default, but will only
do something when there is a node tree using nodes, or a strip in the
sequence editor.
* Enabling Full Sample now automatically enables Save Buffers too.
* Stamp option to include info in file is removed, it now simply always
does this if one of the stamp infos is enabled.
* Xvid, H.264 and Ogg Theora are now directly in the file format menu,
but still using FFMPEG. Unfortunately Ogg is broken at the moment
(also in 2.4x), so that's disabled. And Xvid crashes on 64bit linux,
maybe solvable by upgrading extern/xvidcore/, using ubuntu libs makes
it work.
* Organized file format menu by image/movie types.
Added:
* Render layers RNA wrapped, operatorized, layouted.
* FFMPEG format/codec options are now working.
Defaults changed:
* Compositing & Sequencer enabled.
* Tiles set to 8x8.
* Time/Date/Frame/Scene/Camera/Filename enabled for stamp.
2009-07-13 19:09:13 +00:00
|
|
|
char name_[128];
|
2012-05-12 16:11:34 +00:00
|
|
|
char *name;
|
|
|
|
char *param;
|
2012-06-18 15:42:23 +00:00
|
|
|
IDProperty *prop = NULL;
|
2.5: Render
* UI layout for scene buttons has quite some changes, I tried to
better organize things according to the pipeline, and also showing
important properties by default, and collapsing less important ones.
Some changes compared to 2.4x:
* Panorama is now a Camera property.
* Sequence and Compositing are now enabled by default, but will only
do something when there is a node tree using nodes, or a strip in the
sequence editor.
* Enabling Full Sample now automatically enables Save Buffers too.
* Stamp option to include info in file is removed, it now simply always
does this if one of the stamp infos is enabled.
* Xvid, H.264 and Ogg Theora are now directly in the file format menu,
but still using FFMPEG. Unfortunately Ogg is broken at the moment
(also in 2.4x), so that's disabled. And Xvid crashes on 64bit linux,
maybe solvable by upgrading extern/xvidcore/, using ubuntu libs makes
it work.
* Organized file format menu by image/movie types.
Added:
* Render layers RNA wrapped, operatorized, layouted.
* FFMPEG format/codec options are now working.
Defaults changed:
* Compositing & Sequencer enabled.
* Tiles set to 8x8.
* Time/Date/Frame/Scene/Camera/Filename enabled for stamp.
2009-07-13 19:09:13 +00:00
|
|
|
|
2013-01-12 12:51:10 +00:00
|
|
|
avcodec_get_context_defaults3(&c, NULL);
|
2.5: Render
* UI layout for scene buttons has quite some changes, I tried to
better organize things according to the pipeline, and also showing
important properties by default, and collapsing less important ones.
Some changes compared to 2.4x:
* Panorama is now a Camera property.
* Sequence and Compositing are now enabled by default, but will only
do something when there is a node tree using nodes, or a strip in the
sequence editor.
* Enabling Full Sample now automatically enables Save Buffers too.
* Stamp option to include info in file is removed, it now simply always
does this if one of the stamp infos is enabled.
* Xvid, H.264 and Ogg Theora are now directly in the file format menu,
but still using FFMPEG. Unfortunately Ogg is broken at the moment
(also in 2.4x), so that's disabled. And Xvid crashes on 64bit linux,
maybe solvable by upgrading extern/xvidcore/, using ubuntu libs makes
it work.
* Organized file format menu by image/movie types.
Added:
* Render layers RNA wrapped, operatorized, layouted.
* FFMPEG format/codec options are now working.
Defaults changed:
* Compositing & Sequencer enabled.
* Tiles set to 8x8.
* Time/Date/Frame/Scene/Camera/Filename enabled for stamp.
2009-07-13 19:09:13 +00:00
|
|
|
|
2016-08-16 18:19:52 +02:00
|
|
|
BLI_strncpy(name_, str, sizeof(name_));
|
2.5: Render
* UI layout for scene buttons has quite some changes, I tried to
better organize things according to the pipeline, and also showing
important properties by default, and collapsing less important ones.
Some changes compared to 2.4x:
* Panorama is now a Camera property.
* Sequence and Compositing are now enabled by default, but will only
do something when there is a node tree using nodes, or a strip in the
sequence editor.
* Enabling Full Sample now automatically enables Save Buffers too.
* Stamp option to include info in file is removed, it now simply always
does this if one of the stamp infos is enabled.
* Xvid, H.264 and Ogg Theora are now directly in the file format menu,
but still using FFMPEG. Unfortunately Ogg is broken at the moment
(also in 2.4x), so that's disabled. And Xvid crashes on 64bit linux,
maybe solvable by upgrading extern/xvidcore/, using ubuntu libs makes
it work.
* Organized file format menu by image/movie types.
Added:
* Render layers RNA wrapped, operatorized, layouted.
* FFMPEG format/codec options are now working.
Defaults changed:
* Compositing & Sequencer enabled.
* Tiles set to 8x8.
* Time/Date/Frame/Scene/Camera/Filename enabled for stamp.
2009-07-13 19:09:13 +00:00
|
|
|
|
|
|
|
name = name_;
|
|
|
|
while (*name == ' ') name++;
|
|
|
|
|
|
|
|
param = strchr(name, ':');
|
|
|
|
|
|
|
|
if (!param) {
|
|
|
|
param = strchr(name, ' ');
|
|
|
|
}
|
|
|
|
if (param) {
|
2017-01-11 00:08:16 +01:00
|
|
|
*param++ = '\0';
|
2.5: Render
* UI layout for scene buttons has quite some changes, I tried to
better organize things according to the pipeline, and also showing
important properties by default, and collapsing less important ones.
Some changes compared to 2.4x:
* Panorama is now a Camera property.
* Sequence and Compositing are now enabled by default, but will only
do something when there is a node tree using nodes, or a strip in the
sequence editor.
* Enabling Full Sample now automatically enables Save Buffers too.
* Stamp option to include info in file is removed, it now simply always
does this if one of the stamp infos is enabled.
* Xvid, H.264 and Ogg Theora are now directly in the file format menu,
but still using FFMPEG. Unfortunately Ogg is broken at the moment
(also in 2.4x), so that's disabled. And Xvid crashes on 64bit linux,
maybe solvable by upgrading extern/xvidcore/, using ubuntu libs makes
it work.
* Organized file format menu by image/movie types.
Added:
* Render layers RNA wrapped, operatorized, layouted.
* FFMPEG format/codec options are now working.
Defaults changed:
* Compositing & Sequencer enabled.
* Tiles set to 8x8.
* Time/Date/Frame/Scene/Camera/Filename enabled for stamp.
2009-07-13 19:09:13 +00:00
|
|
|
while (*param == ' ') param++;
|
|
|
|
}
|
|
|
|
|
2014-02-17 20:50:42 +06:00
|
|
|
o = av_opt_find(&c, name, NULL, 0, AV_OPT_SEARCH_CHILDREN | AV_OPT_SEARCH_FAKE_OBJ);
|
2.5: Render
* UI layout for scene buttons has quite some changes, I tried to
better organize things according to the pipeline, and also showing
important properties by default, and collapsing less important ones.
Some changes compared to 2.4x:
* Panorama is now a Camera property.
* Sequence and Compositing are now enabled by default, but will only
do something when there is a node tree using nodes, or a strip in the
sequence editor.
* Enabling Full Sample now automatically enables Save Buffers too.
* Stamp option to include info in file is removed, it now simply always
does this if one of the stamp infos is enabled.
* Xvid, H.264 and Ogg Theora are now directly in the file format menu,
but still using FFMPEG. Unfortunately Ogg is broken at the moment
(also in 2.4x), so that's disabled. And Xvid crashes on 64bit linux,
maybe solvable by upgrading extern/xvidcore/, using ubuntu libs makes
it work.
* Organized file format menu by image/movie types.
Added:
* Render layers RNA wrapped, operatorized, layouted.
* FFMPEG format/codec options are now working.
Defaults changed:
* Compositing & Sequencer enabled.
* Tiles set to 8x8.
* Time/Date/Frame/Scene/Camera/Filename enabled for stamp.
2009-07-13 19:09:13 +00:00
|
|
|
if (!o) {
|
2014-02-17 20:50:42 +06:00
|
|
|
PRINT("Ignoring unknown expert option %s\n", str);
|
2.5: Render
* UI layout for scene buttons has quite some changes, I tried to
better organize things according to the pipeline, and also showing
important properties by default, and collapsing less important ones.
Some changes compared to 2.4x:
* Panorama is now a Camera property.
* Sequence and Compositing are now enabled by default, but will only
do something when there is a node tree using nodes, or a strip in the
sequence editor.
* Enabling Full Sample now automatically enables Save Buffers too.
* Stamp option to include info in file is removed, it now simply always
does this if one of the stamp infos is enabled.
* Xvid, H.264 and Ogg Theora are now directly in the file format menu,
but still using FFMPEG. Unfortunately Ogg is broken at the moment
(also in 2.4x), so that's disabled. And Xvid crashes on 64bit linux,
maybe solvable by upgrading extern/xvidcore/, using ubuntu libs makes
it work.
* Organized file format menu by image/movie types.
Added:
* Render layers RNA wrapped, operatorized, layouted.
* FFMPEG format/codec options are now working.
Defaults changed:
* Compositing & Sequencer enabled.
* Tiles set to 8x8.
* Time/Date/Frame/Scene/Camera/Filename enabled for stamp.
2009-07-13 19:09:13 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2013-01-12 12:51:10 +00:00
|
|
|
if (param && o->type == AV_OPT_TYPE_CONST) {
|
2.5: Render
* UI layout for scene buttons has quite some changes, I tried to
better organize things according to the pipeline, and also showing
important properties by default, and collapsing less important ones.
Some changes compared to 2.4x:
* Panorama is now a Camera property.
* Sequence and Compositing are now enabled by default, but will only
do something when there is a node tree using nodes, or a strip in the
sequence editor.
* Enabling Full Sample now automatically enables Save Buffers too.
* Stamp option to include info in file is removed, it now simply always
does this if one of the stamp infos is enabled.
* Xvid, H.264 and Ogg Theora are now directly in the file format menu,
but still using FFMPEG. Unfortunately Ogg is broken at the moment
(also in 2.4x), so that's disabled. And Xvid crashes on 64bit linux,
maybe solvable by upgrading extern/xvidcore/, using ubuntu libs makes
it work.
* Organized file format menu by image/movie types.
Added:
* Render layers RNA wrapped, operatorized, layouted.
* FFMPEG format/codec options are now working.
Defaults changed:
* Compositing & Sequencer enabled.
* Tiles set to 8x8.
* Time/Date/Frame/Scene/Camera/Filename enabled for stamp.
2009-07-13 19:09:13 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2013-01-12 12:51:10 +00:00
|
|
|
if (param && o->type != AV_OPT_TYPE_CONST && o->unit) {
|
2014-02-17 20:50:42 +06:00
|
|
|
p = av_opt_find(&c, param, o->unit, 0, AV_OPT_SEARCH_CHILDREN | AV_OPT_SEARCH_FAKE_OBJ);
|
2012-06-18 15:42:23 +00:00
|
|
|
if (p) {
|
2014-02-17 20:50:42 +06:00
|
|
|
prop = BKE_ffmpeg_property_add(rd, (char *) type, p, o);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
PRINT("Ignoring unknown expert option %s\n", str);
|
2012-06-18 15:42:23 +00:00
|
|
|
}
|
2012-03-24 06:18:31 +00:00
|
|
|
}
|
|
|
|
else {
|
2014-02-17 20:50:42 +06:00
|
|
|
prop = BKE_ffmpeg_property_add(rd, (char *) type, o, NULL);
|
2.5: Render
* UI layout for scene buttons has quite some changes, I tried to
better organize things according to the pipeline, and also showing
important properties by default, and collapsing less important ones.
Some changes compared to 2.4x:
* Panorama is now a Camera property.
* Sequence and Compositing are now enabled by default, but will only
do something when there is a node tree using nodes, or a strip in the
sequence editor.
* Enabling Full Sample now automatically enables Save Buffers too.
* Stamp option to include info in file is removed, it now simply always
does this if one of the stamp infos is enabled.
* Xvid, H.264 and Ogg Theora are now directly in the file format menu,
but still using FFMPEG. Unfortunately Ogg is broken at the moment
(also in 2.4x), so that's disabled. And Xvid crashes on 64bit linux,
maybe solvable by upgrading extern/xvidcore/, using ubuntu libs makes
it work.
* Organized file format menu by image/movie types.
Added:
* Render layers RNA wrapped, operatorized, layouted.
* FFMPEG format/codec options are now working.
Defaults changed:
* Compositing & Sequencer enabled.
* Tiles set to 8x8.
* Time/Date/Frame/Scene/Camera/Filename enabled for stamp.
2009-07-13 19:09:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (!prop) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (param && !p) {
|
|
|
|
switch (prop->type) {
|
2012-05-12 16:11:34 +00:00
|
|
|
case IDP_INT:
|
|
|
|
IDP_Int(prop) = atoi(param);
|
|
|
|
break;
|
|
|
|
case IDP_FLOAT:
|
|
|
|
IDP_Float(prop) = atof(param);
|
|
|
|
break;
|
|
|
|
case IDP_STRING:
|
|
|
|
strncpy(IDP_String(prop), param, prop->len);
|
|
|
|
break;
|
2.5: Render
* UI layout for scene buttons has quite some changes, I tried to
better organize things according to the pipeline, and also showing
important properties by default, and collapsing less important ones.
Some changes compared to 2.4x:
* Panorama is now a Camera property.
* Sequence and Compositing are now enabled by default, but will only
do something when there is a node tree using nodes, or a strip in the
sequence editor.
* Enabling Full Sample now automatically enables Save Buffers too.
* Stamp option to include info in file is removed, it now simply always
does this if one of the stamp infos is enabled.
* Xvid, H.264 and Ogg Theora are now directly in the file format menu,
but still using FFMPEG. Unfortunately Ogg is broken at the moment
(also in 2.4x), so that's disabled. And Xvid crashes on 64bit linux,
maybe solvable by upgrading extern/xvidcore/, using ubuntu libs makes
it work.
* Organized file format menu by image/movie types.
Added:
* Render layers RNA wrapped, operatorized, layouted.
* FFMPEG format/codec options are now working.
Defaults changed:
* Compositing & Sequencer enabled.
* Tiles set to 8x8.
* Time/Date/Frame/Scene/Camera/Filename enabled for stamp.
2009-07-13 19:09:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2012-02-07 17:11:56 +00:00
|
|
|
static void ffmpeg_set_expert_options(RenderData *rd)
|
2012-01-13 12:34:23 +00:00
|
|
|
{
|
2012-02-07 17:11:56 +00:00
|
|
|
int codec_id = rd->ffcodecdata.codec;
|
|
|
|
|
2012-03-24 06:18:31 +00:00
|
|
|
if (rd->ffcodecdata.properties)
|
2012-01-13 12:34:23 +00:00
|
|
|
IDP_FreeProperty(rd->ffcodecdata.properties);
|
|
|
|
|
2014-01-16 15:40:37 +01:00
|
|
|
if (codec_id == AV_CODEC_ID_H264) {
|
2012-01-13 12:34:23 +00:00
|
|
|
/*
|
|
|
|
* All options here are for x264, but must be set via ffmpeg.
|
|
|
|
* The names are therefore different - Search for "x264 to FFmpeg option mapping"
|
|
|
|
* to get a list.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Use CABAC coder. Using "coder:1", which should be equivalent,
|
|
|
|
* crashes Blender for some reason. Either way - this is no big deal.
|
|
|
|
*/
|
2012-05-07 09:30:15 +00:00
|
|
|
BKE_ffmpeg_property_add_string(rd, "video", "coder:vlc");
|
2012-01-13 12:34:23 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* The other options were taken from the libx264-default.preset
|
|
|
|
* included in the ffmpeg distribution.
|
|
|
|
*/
|
2012-02-16 11:52:02 +00:00
|
|
|
// ffmpeg_property_add_string(rd, "video", "flags:loop"); // this breaks compatibility for QT
|
2012-05-07 09:30:15 +00:00
|
|
|
BKE_ffmpeg_property_add_string(rd, "video", "cmp:chroma");
|
2014-02-17 20:50:42 +06:00
|
|
|
BKE_ffmpeg_property_add_string(rd, "video", "partitions:parti4x4"); // Deprecated.
|
|
|
|
BKE_ffmpeg_property_add_string(rd, "video", "partitions:partp8x8"); // Deprecated.
|
|
|
|
BKE_ffmpeg_property_add_string(rd, "video", "partitions:partb8x8"); // Deprecated.
|
2012-05-07 09:30:15 +00:00
|
|
|
BKE_ffmpeg_property_add_string(rd, "video", "me:hex");
|
|
|
|
BKE_ffmpeg_property_add_string(rd, "video", "subq:6");
|
|
|
|
BKE_ffmpeg_property_add_string(rd, "video", "me_range:16");
|
|
|
|
BKE_ffmpeg_property_add_string(rd, "video", "qdiff:4");
|
|
|
|
BKE_ffmpeg_property_add_string(rd, "video", "keyint_min:25");
|
|
|
|
BKE_ffmpeg_property_add_string(rd, "video", "sc_threshold:40");
|
|
|
|
BKE_ffmpeg_property_add_string(rd, "video", "i_qfactor:0.71");
|
|
|
|
BKE_ffmpeg_property_add_string(rd, "video", "b_strategy:1");
|
|
|
|
BKE_ffmpeg_property_add_string(rd, "video", "bf:3");
|
|
|
|
BKE_ffmpeg_property_add_string(rd, "video", "refs:2");
|
|
|
|
BKE_ffmpeg_property_add_string(rd, "video", "qcomp:0.6");
|
2014-02-17 20:50:42 +06:00
|
|
|
|
2012-05-07 09:30:15 +00:00
|
|
|
BKE_ffmpeg_property_add_string(rd, "video", "trellis:0");
|
2014-02-17 20:50:42 +06:00
|
|
|
BKE_ffmpeg_property_add_string(rd, "video", "weightb:1");
|
2014-04-15 00:15:09 +06:00
|
|
|
#ifdef FFMPEG_HAVE_DEPRECATED_FLAGS2
|
|
|
|
BKE_ffmpeg_property_add_string(rd, "video", "flags2:dct8x8");
|
|
|
|
BKE_ffmpeg_property_add_string(rd, "video", "directpred:3");
|
|
|
|
BKE_ffmpeg_property_add_string(rd, "video", "flags2:fastpskip");
|
|
|
|
BKE_ffmpeg_property_add_string(rd, "video", "flags2:wpred");
|
|
|
|
#else
|
2014-02-17 20:50:42 +06:00
|
|
|
BKE_ffmpeg_property_add_string(rd, "video", "8x8dct:1");
|
|
|
|
BKE_ffmpeg_property_add_string(rd, "video", "fast-pskip:1");
|
2012-05-07 09:30:15 +00:00
|
|
|
BKE_ffmpeg_property_add_string(rd, "video", "wpredp:2");
|
2014-04-15 00:15:09 +06:00
|
|
|
#endif
|
2012-01-13 12:34:23 +00:00
|
|
|
}
|
2014-01-16 15:40:37 +01:00
|
|
|
else if (codec_id == AV_CODEC_ID_DNXHD) {
|
2012-03-24 06:18:31 +00:00
|
|
|
if (rd->ffcodecdata.flags & FFMPEG_LOSSLESS_OUTPUT)
|
2012-08-26 11:01:14 +00:00
|
|
|
BKE_ffmpeg_property_add_string(rd, "video", "mbd:rd");
|
2012-02-07 17:11:56 +00:00
|
|
|
}
|
2012-01-13 12:34:23 +00:00
|
|
|
}
|
|
|
|
|
2012-05-07 09:30:15 +00:00
|
|
|
void BKE_ffmpeg_preset_set(RenderData *rd, int preset)
|
2.5: Render
* UI layout for scene buttons has quite some changes, I tried to
better organize things according to the pipeline, and also showing
important properties by default, and collapsing less important ones.
Some changes compared to 2.4x:
* Panorama is now a Camera property.
* Sequence and Compositing are now enabled by default, but will only
do something when there is a node tree using nodes, or a strip in the
sequence editor.
* Enabling Full Sample now automatically enables Save Buffers too.
* Stamp option to include info in file is removed, it now simply always
does this if one of the stamp infos is enabled.
* Xvid, H.264 and Ogg Theora are now directly in the file format menu,
but still using FFMPEG. Unfortunately Ogg is broken at the moment
(also in 2.4x), so that's disabled. And Xvid crashes on 64bit linux,
maybe solvable by upgrading extern/xvidcore/, using ubuntu libs makes
it work.
* Organized file format menu by image/movie types.
Added:
* Render layers RNA wrapped, operatorized, layouted.
* FFMPEG format/codec options are now working.
Defaults changed:
* Compositing & Sequencer enabled.
* Tiles set to 8x8.
* Time/Date/Frame/Scene/Camera/Filename enabled for stamp.
2009-07-13 19:09:13 +00:00
|
|
|
{
|
|
|
|
int isntsc = (rd->frs_sec != 25);
|
|
|
|
|
2012-03-24 06:18:31 +00:00
|
|
|
if (rd->ffcodecdata.properties)
|
2011-10-23 17:52:20 +00:00
|
|
|
IDP_FreeProperty(rd->ffcodecdata.properties);
|
|
|
|
|
2.5: Render
* UI layout for scene buttons has quite some changes, I tried to
better organize things according to the pipeline, and also showing
important properties by default, and collapsing less important ones.
Some changes compared to 2.4x:
* Panorama is now a Camera property.
* Sequence and Compositing are now enabled by default, but will only
do something when there is a node tree using nodes, or a strip in the
sequence editor.
* Enabling Full Sample now automatically enables Save Buffers too.
* Stamp option to include info in file is removed, it now simply always
does this if one of the stamp infos is enabled.
* Xvid, H.264 and Ogg Theora are now directly in the file format menu,
but still using FFMPEG. Unfortunately Ogg is broken at the moment
(also in 2.4x), so that's disabled. And Xvid crashes on 64bit linux,
maybe solvable by upgrading extern/xvidcore/, using ubuntu libs makes
it work.
* Organized file format menu by image/movie types.
Added:
* Render layers RNA wrapped, operatorized, layouted.
* FFMPEG format/codec options are now working.
Defaults changed:
* Compositing & Sequencer enabled.
* Tiles set to 8x8.
* Time/Date/Frame/Scene/Camera/Filename enabled for stamp.
2009-07-13 19:09:13 +00:00
|
|
|
switch (preset) {
|
2012-05-12 16:11:34 +00:00
|
|
|
case FFMPEG_PRESET_VCD:
|
|
|
|
rd->ffcodecdata.type = FFMPEG_MPEG1;
|
|
|
|
rd->ffcodecdata.video_bitrate = 1150;
|
|
|
|
rd->xsch = 352;
|
|
|
|
rd->ysch = isntsc ? 240 : 288;
|
|
|
|
rd->ffcodecdata.gop_size = isntsc ? 18 : 15;
|
|
|
|
rd->ffcodecdata.rc_max_rate = 1150;
|
|
|
|
rd->ffcodecdata.rc_min_rate = 1150;
|
|
|
|
rd->ffcodecdata.rc_buffer_size = 40 * 8;
|
|
|
|
rd->ffcodecdata.mux_packet_size = 2324;
|
|
|
|
rd->ffcodecdata.mux_rate = 2352 * 75 * 8;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case FFMPEG_PRESET_SVCD:
|
|
|
|
rd->ffcodecdata.type = FFMPEG_MPEG2;
|
|
|
|
rd->ffcodecdata.video_bitrate = 2040;
|
|
|
|
rd->xsch = 480;
|
|
|
|
rd->ysch = isntsc ? 480 : 576;
|
|
|
|
rd->ffcodecdata.gop_size = isntsc ? 18 : 15;
|
|
|
|
rd->ffcodecdata.rc_max_rate = 2516;
|
|
|
|
rd->ffcodecdata.rc_min_rate = 0;
|
|
|
|
rd->ffcodecdata.rc_buffer_size = 224 * 8;
|
|
|
|
rd->ffcodecdata.mux_packet_size = 2324;
|
|
|
|
rd->ffcodecdata.mux_rate = 0;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case FFMPEG_PRESET_DVD:
|
|
|
|
rd->ffcodecdata.type = FFMPEG_MPEG2;
|
|
|
|
rd->ffcodecdata.video_bitrate = 6000;
|
|
|
|
|
|
|
|
/* Don't set resolution, see [#21351]
|
|
|
|
* rd->xsch = 720;
|
|
|
|
* rd->ysch = isntsc ? 480 : 576; */
|
|
|
|
|
|
|
|
rd->ffcodecdata.gop_size = isntsc ? 18 : 15;
|
|
|
|
rd->ffcodecdata.rc_max_rate = 9000;
|
|
|
|
rd->ffcodecdata.rc_min_rate = 0;
|
|
|
|
rd->ffcodecdata.rc_buffer_size = 224 * 8;
|
|
|
|
rd->ffcodecdata.mux_packet_size = 2048;
|
|
|
|
rd->ffcodecdata.mux_rate = 10080000;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case FFMPEG_PRESET_DV:
|
|
|
|
rd->ffcodecdata.type = FFMPEG_DV;
|
|
|
|
rd->xsch = 720;
|
|
|
|
rd->ysch = isntsc ? 480 : 576;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case FFMPEG_PRESET_H264:
|
2.5: Render
* UI layout for scene buttons has quite some changes, I tried to
better organize things according to the pipeline, and also showing
important properties by default, and collapsing less important ones.
Some changes compared to 2.4x:
* Panorama is now a Camera property.
* Sequence and Compositing are now enabled by default, but will only
do something when there is a node tree using nodes, or a strip in the
sequence editor.
* Enabling Full Sample now automatically enables Save Buffers too.
* Stamp option to include info in file is removed, it now simply always
does this if one of the stamp infos is enabled.
* Xvid, H.264 and Ogg Theora are now directly in the file format menu,
but still using FFMPEG. Unfortunately Ogg is broken at the moment
(also in 2.4x), so that's disabled. And Xvid crashes on 64bit linux,
maybe solvable by upgrading extern/xvidcore/, using ubuntu libs makes
it work.
* Organized file format menu by image/movie types.
Added:
* Render layers RNA wrapped, operatorized, layouted.
* FFMPEG format/codec options are now working.
Defaults changed:
* Compositing & Sequencer enabled.
* Tiles set to 8x8.
* Time/Date/Frame/Scene/Camera/Filename enabled for stamp.
2009-07-13 19:09:13 +00:00
|
|
|
rd->ffcodecdata.type = FFMPEG_AVI;
|
2014-01-16 15:40:37 +01:00
|
|
|
rd->ffcodecdata.codec = AV_CODEC_ID_H264;
|
2012-05-12 16:11:34 +00:00
|
|
|
rd->ffcodecdata.video_bitrate = 6000;
|
|
|
|
rd->ffcodecdata.gop_size = isntsc ? 18 : 15;
|
|
|
|
rd->ffcodecdata.rc_max_rate = 9000;
|
|
|
|
rd->ffcodecdata.rc_min_rate = 0;
|
|
|
|
rd->ffcodecdata.rc_buffer_size = 224 * 8;
|
|
|
|
rd->ffcodecdata.mux_packet_size = 2048;
|
|
|
|
rd->ffcodecdata.mux_rate = 10080000;
|
|
|
|
|
|
|
|
break;
|
2.5: Render
* UI layout for scene buttons has quite some changes, I tried to
better organize things according to the pipeline, and also showing
important properties by default, and collapsing less important ones.
Some changes compared to 2.4x:
* Panorama is now a Camera property.
* Sequence and Compositing are now enabled by default, but will only
do something when there is a node tree using nodes, or a strip in the
sequence editor.
* Enabling Full Sample now automatically enables Save Buffers too.
* Stamp option to include info in file is removed, it now simply always
does this if one of the stamp infos is enabled.
* Xvid, H.264 and Ogg Theora are now directly in the file format menu,
but still using FFMPEG. Unfortunately Ogg is broken at the moment
(also in 2.4x), so that's disabled. And Xvid crashes on 64bit linux,
maybe solvable by upgrading extern/xvidcore/, using ubuntu libs makes
it work.
* Organized file format menu by image/movie types.
Added:
* Render layers RNA wrapped, operatorized, layouted.
* FFMPEG format/codec options are now working.
Defaults changed:
* Compositing & Sequencer enabled.
* Tiles set to 8x8.
* Time/Date/Frame/Scene/Camera/Filename enabled for stamp.
2009-07-13 19:09:13 +00:00
|
|
|
|
2012-05-12 16:11:34 +00:00
|
|
|
case FFMPEG_PRESET_THEORA:
|
|
|
|
case FFMPEG_PRESET_XVID:
|
|
|
|
if (preset == FFMPEG_PRESET_XVID) {
|
|
|
|
rd->ffcodecdata.type = FFMPEG_AVI;
|
2014-01-16 15:40:37 +01:00
|
|
|
rd->ffcodecdata.codec = AV_CODEC_ID_MPEG4;
|
2012-05-12 16:11:34 +00:00
|
|
|
}
|
|
|
|
else if (preset == FFMPEG_PRESET_THEORA) {
|
|
|
|
rd->ffcodecdata.type = FFMPEG_OGG; // XXX broken
|
2014-01-16 15:40:37 +01:00
|
|
|
rd->ffcodecdata.codec = AV_CODEC_ID_THEORA;
|
2012-05-12 16:11:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
rd->ffcodecdata.video_bitrate = 6000;
|
|
|
|
rd->ffcodecdata.gop_size = isntsc ? 18 : 15;
|
|
|
|
rd->ffcodecdata.rc_max_rate = 9000;
|
|
|
|
rd->ffcodecdata.rc_min_rate = 0;
|
|
|
|
rd->ffcodecdata.rc_buffer_size = 224 * 8;
|
|
|
|
rd->ffcodecdata.mux_packet_size = 2048;
|
|
|
|
rd->ffcodecdata.mux_rate = 10080000;
|
|
|
|
break;
|
2.5: Render
* UI layout for scene buttons has quite some changes, I tried to
better organize things according to the pipeline, and also showing
important properties by default, and collapsing less important ones.
Some changes compared to 2.4x:
* Panorama is now a Camera property.
* Sequence and Compositing are now enabled by default, but will only
do something when there is a node tree using nodes, or a strip in the
sequence editor.
* Enabling Full Sample now automatically enables Save Buffers too.
* Stamp option to include info in file is removed, it now simply always
does this if one of the stamp infos is enabled.
* Xvid, H.264 and Ogg Theora are now directly in the file format menu,
but still using FFMPEG. Unfortunately Ogg is broken at the moment
(also in 2.4x), so that's disabled. And Xvid crashes on 64bit linux,
maybe solvable by upgrading extern/xvidcore/, using ubuntu libs makes
it work.
* Organized file format menu by image/movie types.
Added:
* Render layers RNA wrapped, operatorized, layouted.
* FFMPEG format/codec options are now working.
Defaults changed:
* Compositing & Sequencer enabled.
* Tiles set to 8x8.
* Time/Date/Frame/Scene/Camera/Filename enabled for stamp.
2009-07-13 19:09:13 +00:00
|
|
|
|
|
|
|
}
|
2012-02-07 17:11:56 +00:00
|
|
|
|
|
|
|
ffmpeg_set_expert_options(rd);
|
2.5: Render
* UI layout for scene buttons has quite some changes, I tried to
better organize things according to the pipeline, and also showing
important properties by default, and collapsing less important ones.
Some changes compared to 2.4x:
* Panorama is now a Camera property.
* Sequence and Compositing are now enabled by default, but will only
do something when there is a node tree using nodes, or a strip in the
sequence editor.
* Enabling Full Sample now automatically enables Save Buffers too.
* Stamp option to include info in file is removed, it now simply always
does this if one of the stamp infos is enabled.
* Xvid, H.264 and Ogg Theora are now directly in the file format menu,
but still using FFMPEG. Unfortunately Ogg is broken at the moment
(also in 2.4x), so that's disabled. And Xvid crashes on 64bit linux,
maybe solvable by upgrading extern/xvidcore/, using ubuntu libs makes
it work.
* Organized file format menu by image/movie types.
Added:
* Render layers RNA wrapped, operatorized, layouted.
* FFMPEG format/codec options are now working.
Defaults changed:
* Compositing & Sequencer enabled.
* Tiles set to 8x8.
* Time/Date/Frame/Scene/Camera/Filename enabled for stamp.
2009-07-13 19:09:13 +00:00
|
|
|
}
|
|
|
|
|
2012-05-07 09:30:15 +00:00
|
|
|
void BKE_ffmpeg_image_type_verify(RenderData *rd, ImageFormatData *imf)
|
2.5: Render
* UI layout for scene buttons has quite some changes, I tried to
better organize things according to the pipeline, and also showing
important properties by default, and collapsing less important ones.
Some changes compared to 2.4x:
* Panorama is now a Camera property.
* Sequence and Compositing are now enabled by default, but will only
do something when there is a node tree using nodes, or a strip in the
sequence editor.
* Enabling Full Sample now automatically enables Save Buffers too.
* Stamp option to include info in file is removed, it now simply always
does this if one of the stamp infos is enabled.
* Xvid, H.264 and Ogg Theora are now directly in the file format menu,
but still using FFMPEG. Unfortunately Ogg is broken at the moment
(also in 2.4x), so that's disabled. And Xvid crashes on 64bit linux,
maybe solvable by upgrading extern/xvidcore/, using ubuntu libs makes
it work.
* Organized file format menu by image/movie types.
Added:
* Render layers RNA wrapped, operatorized, layouted.
* FFMPEG format/codec options are now working.
Defaults changed:
* Compositing & Sequencer enabled.
* Tiles set to 8x8.
* Time/Date/Frame/Scene/Camera/Filename enabled for stamp.
2009-07-13 19:09:13 +00:00
|
|
|
{
|
2012-05-12 16:11:34 +00:00
|
|
|
int audio = 0;
|
2.5: Render
* UI layout for scene buttons has quite some changes, I tried to
better organize things according to the pipeline, and also showing
important properties by default, and collapsing less important ones.
Some changes compared to 2.4x:
* Panorama is now a Camera property.
* Sequence and Compositing are now enabled by default, but will only
do something when there is a node tree using nodes, or a strip in the
sequence editor.
* Enabling Full Sample now automatically enables Save Buffers too.
* Stamp option to include info in file is removed, it now simply always
does this if one of the stamp infos is enabled.
* Xvid, H.264 and Ogg Theora are now directly in the file format menu,
but still using FFMPEG. Unfortunately Ogg is broken at the moment
(also in 2.4x), so that's disabled. And Xvid crashes on 64bit linux,
maybe solvable by upgrading extern/xvidcore/, using ubuntu libs makes
it work.
* Organized file format menu by image/movie types.
Added:
* Render layers RNA wrapped, operatorized, layouted.
* FFMPEG format/codec options are now working.
Defaults changed:
* Compositing & Sequencer enabled.
* Tiles set to 8x8.
* Time/Date/Frame/Scene/Camera/Filename enabled for stamp.
2009-07-13 19:09:13 +00:00
|
|
|
|
2012-03-24 06:18:31 +00:00
|
|
|
if (imf->imtype == R_IMF_IMTYPE_FFMPEG) {
|
|
|
|
if (rd->ffcodecdata.type <= 0 ||
|
2012-05-12 16:11:34 +00:00
|
|
|
rd->ffcodecdata.codec <= 0 ||
|
|
|
|
rd->ffcodecdata.audio_codec <= 0 ||
|
2012-05-20 19:49:27 +00:00
|
|
|
rd->ffcodecdata.video_bitrate <= 1)
|
|
|
|
{
|
FFmpeg interface improvements
This patch changes a couple of things in the video output encoding.
{F362527}
- Clearer separation between container and codec. No more "format", as this is
too ambiguous. As a result, codecs were removed from the container list.
- Added FFmpeg speed presets, so the user can choosen from the range "Very
slow" to "Ultra fast". By default no preset is used.
- Added Constant Rate Factor (CRF) mode, which allows changing the bit-rate
depending on the desired quality and the input. This generally produces the
best quality videos, at the expense of not knowing the exact bit-rate and
file size.
- Added optional maximum of non-B-frames between B-frames (`max_b_frames`).
- Presets were adjusted for these changes, and new presets added. One of the
new presets is [recommended](https://trac.ffmpeg.org/wiki/Encode/VFX#H.264)
for reviewing videos, as it allows players to scrub through it easily. Might
be nice in weeklies. This preset also requires control over the
`max_b_frames` setting.
GUI-only changes:
- Renamed "MPEG" in the output file format menu with "FFmpeg", as this is more
accurate. After all, FFmpeg is used when this option is chosen, which can
also output non-MPEG files.
- Certain parts of the GUI are disabled when not in use:
- bit rate options are not used when a constant rate factor is given.
- audio bitrate & volume are not used when no audio is exported.
Note that I did not touch `BKE_ffmpeg_preset_set()`. There are currently two
preset systems for FFmpeg (`BKE_ffmpeg_preset_set()` and the Python preset
system). Before we do more work on `BKE_ffmpeg_preset_set()`, I think it's a
good idea to determine whether we want to keep it at all.
After this patch has been accepted, I'd be happy to go through the code and
remove any then-obsolete bits, such as the handling of "XVID" as a container
format.
Reviewers: sergey, mont29, brecht
Subscribers: mpan3, Blendify, brecht, fsiddi
Tags: #bf_blender
Differential Revision: https://developer.blender.org/D2242
2016-09-21 15:01:51 +02:00
|
|
|
BKE_ffmpeg_preset_set(rd, FFMPEG_PRESET_H264);
|
|
|
|
rd->ffcodecdata.constant_rate_factor = FFM_CRF_MEDIUM;
|
2018-04-09 15:27:11 +02:00
|
|
|
rd->ffcodecdata.ffmpeg_preset = FFM_PRESET_GOOD;
|
FFmpeg interface improvements
This patch changes a couple of things in the video output encoding.
{F362527}
- Clearer separation between container and codec. No more "format", as this is
too ambiguous. As a result, codecs were removed from the container list.
- Added FFmpeg speed presets, so the user can choosen from the range "Very
slow" to "Ultra fast". By default no preset is used.
- Added Constant Rate Factor (CRF) mode, which allows changing the bit-rate
depending on the desired quality and the input. This generally produces the
best quality videos, at the expense of not knowing the exact bit-rate and
file size.
- Added optional maximum of non-B-frames between B-frames (`max_b_frames`).
- Presets were adjusted for these changes, and new presets added. One of the
new presets is [recommended](https://trac.ffmpeg.org/wiki/Encode/VFX#H.264)
for reviewing videos, as it allows players to scrub through it easily. Might
be nice in weeklies. This preset also requires control over the
`max_b_frames` setting.
GUI-only changes:
- Renamed "MPEG" in the output file format menu with "FFmpeg", as this is more
accurate. After all, FFmpeg is used when this option is chosen, which can
also output non-MPEG files.
- Certain parts of the GUI are disabled when not in use:
- bit rate options are not used when a constant rate factor is given.
- audio bitrate & volume are not used when no audio is exported.
Note that I did not touch `BKE_ffmpeg_preset_set()`. There are currently two
preset systems for FFmpeg (`BKE_ffmpeg_preset_set()` and the Python preset
system). Before we do more work on `BKE_ffmpeg_preset_set()`, I think it's a
good idea to determine whether we want to keep it at all.
After this patch has been accepted, I'd be happy to go through the code and
remove any then-obsolete bits, such as the handling of "XVID" as a container
format.
Reviewers: sergey, mont29, brecht
Subscribers: mpan3, Blendify, brecht, fsiddi
Tags: #bf_blender
Differential Revision: https://developer.blender.org/D2242
2016-09-21 15:01:51 +02:00
|
|
|
rd->ffcodecdata.type = FFMPEG_MKV;
|
2.5: Render
* UI layout for scene buttons has quite some changes, I tried to
better organize things according to the pipeline, and also showing
important properties by default, and collapsing less important ones.
Some changes compared to 2.4x:
* Panorama is now a Camera property.
* Sequence and Compositing are now enabled by default, but will only
do something when there is a node tree using nodes, or a strip in the
sequence editor.
* Enabling Full Sample now automatically enables Save Buffers too.
* Stamp option to include info in file is removed, it now simply always
does this if one of the stamp infos is enabled.
* Xvid, H.264 and Ogg Theora are now directly in the file format menu,
but still using FFMPEG. Unfortunately Ogg is broken at the moment
(also in 2.4x), so that's disabled. And Xvid crashes on 64bit linux,
maybe solvable by upgrading extern/xvidcore/, using ubuntu libs makes
it work.
* Organized file format menu by image/movie types.
Added:
* Render layers RNA wrapped, operatorized, layouted.
* FFMPEG format/codec options are now working.
Defaults changed:
* Compositing & Sequencer enabled.
* Tiles set to 8x8.
* Time/Date/Frame/Scene/Camera/Filename enabled for stamp.
2009-07-13 19:09:13 +00:00
|
|
|
}
|
2012-03-24 06:18:31 +00:00
|
|
|
if (rd->ffcodecdata.type == FFMPEG_OGG) {
|
2011-08-10 07:36:44 +00:00
|
|
|
rd->ffcodecdata.type = FFMPEG_MPEG2;
|
|
|
|
}
|
2.5: Render
* UI layout for scene buttons has quite some changes, I tried to
better organize things according to the pipeline, and also showing
important properties by default, and collapsing less important ones.
Some changes compared to 2.4x:
* Panorama is now a Camera property.
* Sequence and Compositing are now enabled by default, but will only
do something when there is a node tree using nodes, or a strip in the
sequence editor.
* Enabling Full Sample now automatically enables Save Buffers too.
* Stamp option to include info in file is removed, it now simply always
does this if one of the stamp infos is enabled.
* Xvid, H.264 and Ogg Theora are now directly in the file format menu,
but still using FFMPEG. Unfortunately Ogg is broken at the moment
(also in 2.4x), so that's disabled. And Xvid crashes on 64bit linux,
maybe solvable by upgrading extern/xvidcore/, using ubuntu libs makes
it work.
* Organized file format menu by image/movie types.
Added:
* Render layers RNA wrapped, operatorized, layouted.
* FFMPEG format/codec options are now working.
Defaults changed:
* Compositing & Sequencer enabled.
* Tiles set to 8x8.
* Time/Date/Frame/Scene/Camera/Filename enabled for stamp.
2009-07-13 19:09:13 +00:00
|
|
|
|
2012-05-12 16:11:34 +00:00
|
|
|
audio = 1;
|
2.5: Render
* UI layout for scene buttons has quite some changes, I tried to
better organize things according to the pipeline, and also showing
important properties by default, and collapsing less important ones.
Some changes compared to 2.4x:
* Panorama is now a Camera property.
* Sequence and Compositing are now enabled by default, but will only
do something when there is a node tree using nodes, or a strip in the
sequence editor.
* Enabling Full Sample now automatically enables Save Buffers too.
* Stamp option to include info in file is removed, it now simply always
does this if one of the stamp infos is enabled.
* Xvid, H.264 and Ogg Theora are now directly in the file format menu,
but still using FFMPEG. Unfortunately Ogg is broken at the moment
(also in 2.4x), so that's disabled. And Xvid crashes on 64bit linux,
maybe solvable by upgrading extern/xvidcore/, using ubuntu libs makes
it work.
* Organized file format menu by image/movie types.
Added:
* Render layers RNA wrapped, operatorized, layouted.
* FFMPEG format/codec options are now working.
Defaults changed:
* Compositing & Sequencer enabled.
* Tiles set to 8x8.
* Time/Date/Frame/Scene/Camera/Filename enabled for stamp.
2009-07-13 19:09:13 +00:00
|
|
|
}
|
2012-03-24 06:18:31 +00:00
|
|
|
else if (imf->imtype == R_IMF_IMTYPE_H264) {
|
2014-01-16 15:40:37 +01:00
|
|
|
if (rd->ffcodecdata.codec != AV_CODEC_ID_H264) {
|
2012-05-07 09:30:15 +00:00
|
|
|
BKE_ffmpeg_preset_set(rd, FFMPEG_PRESET_H264);
|
2012-05-12 16:11:34 +00:00
|
|
|
audio = 1;
|
2.5: Render
* UI layout for scene buttons has quite some changes, I tried to
better organize things according to the pipeline, and also showing
important properties by default, and collapsing less important ones.
Some changes compared to 2.4x:
* Panorama is now a Camera property.
* Sequence and Compositing are now enabled by default, but will only
do something when there is a node tree using nodes, or a strip in the
sequence editor.
* Enabling Full Sample now automatically enables Save Buffers too.
* Stamp option to include info in file is removed, it now simply always
does this if one of the stamp infos is enabled.
* Xvid, H.264 and Ogg Theora are now directly in the file format menu,
but still using FFMPEG. Unfortunately Ogg is broken at the moment
(also in 2.4x), so that's disabled. And Xvid crashes on 64bit linux,
maybe solvable by upgrading extern/xvidcore/, using ubuntu libs makes
it work.
* Organized file format menu by image/movie types.
Added:
* Render layers RNA wrapped, operatorized, layouted.
* FFMPEG format/codec options are now working.
Defaults changed:
* Compositing & Sequencer enabled.
* Tiles set to 8x8.
* Time/Date/Frame/Scene/Camera/Filename enabled for stamp.
2009-07-13 19:09:13 +00:00
|
|
|
}
|
|
|
|
}
|
2012-03-24 06:18:31 +00:00
|
|
|
else if (imf->imtype == R_IMF_IMTYPE_XVID) {
|
2014-01-16 15:40:37 +01:00
|
|
|
if (rd->ffcodecdata.codec != AV_CODEC_ID_MPEG4) {
|
2012-05-07 09:30:15 +00:00
|
|
|
BKE_ffmpeg_preset_set(rd, FFMPEG_PRESET_XVID);
|
2012-05-12 16:11:34 +00:00
|
|
|
audio = 1;
|
2.5: Render
* UI layout for scene buttons has quite some changes, I tried to
better organize things according to the pipeline, and also showing
important properties by default, and collapsing less important ones.
Some changes compared to 2.4x:
* Panorama is now a Camera property.
* Sequence and Compositing are now enabled by default, but will only
do something when there is a node tree using nodes, or a strip in the
sequence editor.
* Enabling Full Sample now automatically enables Save Buffers too.
* Stamp option to include info in file is removed, it now simply always
does this if one of the stamp infos is enabled.
* Xvid, H.264 and Ogg Theora are now directly in the file format menu,
but still using FFMPEG. Unfortunately Ogg is broken at the moment
(also in 2.4x), so that's disabled. And Xvid crashes on 64bit linux,
maybe solvable by upgrading extern/xvidcore/, using ubuntu libs makes
it work.
* Organized file format menu by image/movie types.
Added:
* Render layers RNA wrapped, operatorized, layouted.
* FFMPEG format/codec options are now working.
Defaults changed:
* Compositing & Sequencer enabled.
* Tiles set to 8x8.
* Time/Date/Frame/Scene/Camera/Filename enabled for stamp.
2009-07-13 19:09:13 +00:00
|
|
|
}
|
|
|
|
}
|
2012-03-24 06:18:31 +00:00
|
|
|
else if (imf->imtype == R_IMF_IMTYPE_THEORA) {
|
2014-01-16 15:40:37 +01:00
|
|
|
if (rd->ffcodecdata.codec != AV_CODEC_ID_THEORA) {
|
2012-05-07 09:30:15 +00:00
|
|
|
BKE_ffmpeg_preset_set(rd, FFMPEG_PRESET_THEORA);
|
2012-05-12 16:11:34 +00:00
|
|
|
audio = 1;
|
2.5: Render
* UI layout for scene buttons has quite some changes, I tried to
better organize things according to the pipeline, and also showing
important properties by default, and collapsing less important ones.
Some changes compared to 2.4x:
* Panorama is now a Camera property.
* Sequence and Compositing are now enabled by default, but will only
do something when there is a node tree using nodes, or a strip in the
sequence editor.
* Enabling Full Sample now automatically enables Save Buffers too.
* Stamp option to include info in file is removed, it now simply always
does this if one of the stamp infos is enabled.
* Xvid, H.264 and Ogg Theora are now directly in the file format menu,
but still using FFMPEG. Unfortunately Ogg is broken at the moment
(also in 2.4x), so that's disabled. And Xvid crashes on 64bit linux,
maybe solvable by upgrading extern/xvidcore/, using ubuntu libs makes
it work.
* Organized file format menu by image/movie types.
Added:
* Render layers RNA wrapped, operatorized, layouted.
* FFMPEG format/codec options are now working.
Defaults changed:
* Compositing & Sequencer enabled.
* Tiles set to 8x8.
* Time/Date/Frame/Scene/Camera/Filename enabled for stamp.
2009-07-13 19:09:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-24 06:18:31 +00:00
|
|
|
if (audio && rd->ffcodecdata.audio_codec < 0) {
|
2014-01-16 15:40:37 +01:00
|
|
|
rd->ffcodecdata.audio_codec = AV_CODEC_ID_NONE;
|
2.5: Render
* UI layout for scene buttons has quite some changes, I tried to
better organize things according to the pipeline, and also showing
important properties by default, and collapsing less important ones.
Some changes compared to 2.4x:
* Panorama is now a Camera property.
* Sequence and Compositing are now enabled by default, but will only
do something when there is a node tree using nodes, or a strip in the
sequence editor.
* Enabling Full Sample now automatically enables Save Buffers too.
* Stamp option to include info in file is removed, it now simply always
does this if one of the stamp infos is enabled.
* Xvid, H.264 and Ogg Theora are now directly in the file format menu,
but still using FFMPEG. Unfortunately Ogg is broken at the moment
(also in 2.4x), so that's disabled. And Xvid crashes on 64bit linux,
maybe solvable by upgrading extern/xvidcore/, using ubuntu libs makes
it work.
* Organized file format menu by image/movie types.
Added:
* Render layers RNA wrapped, operatorized, layouted.
* FFMPEG format/codec options are now working.
Defaults changed:
* Compositing & Sequencer enabled.
* Tiles set to 8x8.
* Time/Date/Frame/Scene/Camera/Filename enabled for stamp.
2009-07-13 19:09:13 +00:00
|
|
|
rd->ffcodecdata.audio_bitrate = 128;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-05-07 09:30:15 +00:00
|
|
|
void BKE_ffmpeg_codec_settings_verify(RenderData *rd)
|
2012-01-13 12:34:23 +00:00
|
|
|
{
|
2012-02-07 17:11:56 +00:00
|
|
|
ffmpeg_set_expert_options(rd);
|
2012-01-13 12:34:23 +00:00
|
|
|
}
|
|
|
|
|
2014-02-03 18:55:59 +11:00
|
|
|
bool BKE_ffmpeg_alpha_channel_is_supported(RenderData *rd)
|
2012-02-24 09:49:44 +00:00
|
|
|
{
|
|
|
|
int codec = rd->ffcodecdata.codec;
|
|
|
|
|
2014-01-16 15:40:37 +01:00
|
|
|
if (codec == AV_CODEC_ID_QTRLE)
|
2014-04-01 11:34:00 +11:00
|
|
|
return true;
|
2012-02-24 15:34:57 +00:00
|
|
|
|
2014-01-16 15:40:37 +01:00
|
|
|
if (codec == AV_CODEC_ID_PNG)
|
2014-04-01 11:34:00 +11:00
|
|
|
return true;
|
2013-03-12 16:09:23 +00:00
|
|
|
|
2014-12-24 18:54:38 +05:00
|
|
|
if (codec == AV_CODEC_ID_HUFFYUV)
|
|
|
|
return true;
|
|
|
|
|
2012-02-24 15:34:57 +00:00
|
|
|
#ifdef FFMPEG_FFV1_ALPHA_SUPPORTED
|
2014-01-16 15:40:37 +01:00
|
|
|
if (codec == AV_CODEC_ID_FFV1)
|
2014-04-01 11:34:00 +11:00
|
|
|
return true;
|
2012-02-24 15:34:57 +00:00
|
|
|
#endif
|
|
|
|
|
2014-04-01 11:34:00 +11:00
|
|
|
return false;
|
2012-02-24 09:49:44 +00:00
|
|
|
}
|
|
|
|
|
2015-04-06 10:40:12 -03:00
|
|
|
void *BKE_ffmpeg_context_create(void)
|
|
|
|
{
|
|
|
|
FFMpegContext *context;
|
|
|
|
|
|
|
|
/* new ffmpeg data struct */
|
|
|
|
context = MEM_callocN(sizeof(FFMpegContext), "new ffmpeg context");
|
|
|
|
|
|
|
|
context->ffmpeg_codec = AV_CODEC_ID_MPEG4;
|
|
|
|
context->ffmpeg_audio_codec = AV_CODEC_ID_NONE;
|
|
|
|
context->ffmpeg_video_bitrate = 1150;
|
|
|
|
context->ffmpeg_audio_bitrate = 128;
|
|
|
|
context->ffmpeg_gop_size = 12;
|
|
|
|
context->ffmpeg_autosplit = 0;
|
|
|
|
context->ffmpeg_autosplit_count = 0;
|
|
|
|
context->ffmpeg_preview = false;
|
2018-04-05 16:31:59 +02:00
|
|
|
context->stamp_data = NULL;
|
2015-04-06 10:40:12 -03:00
|
|
|
|
|
|
|
return context;
|
|
|
|
}
|
|
|
|
|
|
|
|
void BKE_ffmpeg_context_free(void *context_v)
|
|
|
|
{
|
|
|
|
FFMpegContext *context = context_v;
|
2018-04-05 16:31:59 +02:00
|
|
|
if (context == NULL) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (context->stamp_data) {
|
|
|
|
MEM_freeN(context->stamp_data);
|
2015-04-06 10:40:12 -03:00
|
|
|
}
|
2018-04-05 16:31:59 +02:00
|
|
|
MEM_freeN(context);
|
2015-04-06 10:40:12 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* WITH_FFMPEG */
|