projects
/
dcpomatic.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Don't trust video timestamps from FFmpegDecoder.
[dcpomatic.git]
/
src
/
lib
/
ffmpeg_file_encoder.cc
diff --git
a/src/lib/ffmpeg_file_encoder.cc
b/src/lib/ffmpeg_file_encoder.cc
index af6066bfd4cfb524aefcd8ab240ea6d5b514a7a0..0c6bd96853858d97367a25a8d37239a21428328b 100644
(file)
--- a/
src/lib/ffmpeg_file_encoder.cc
+++ b/
src/lib/ffmpeg_file_encoder.cc
@@
-74,19
+74,25
@@
FFmpegFileEncoder::FFmpegFileEncoder (
av_dict_set (&_video_options, "profile", "3", 0);
av_dict_set (&_video_options, "threads", "auto", 0);
break;
av_dict_set (&_video_options, "profile", "3", 0);
av_dict_set (&_video_options, "threads", "auto", 0);
break;
- case EXPORT_FORMAT_H264:
+ case EXPORT_FORMAT_H264
_AAC
:
_sample_format = AV_SAMPLE_FMT_FLTP;
_video_codec_name = "libx264";
_audio_codec_name = "aac";
av_dict_set_int (&_video_options, "crf", x264_crf, 0);
break;
_sample_format = AV_SAMPLE_FMT_FLTP;
_video_codec_name = "libx264";
_audio_codec_name = "aac";
av_dict_set_int (&_video_options, "crf", x264_crf, 0);
break;
+ case EXPORT_FORMAT_H264_PCM:
+ _sample_format = AV_SAMPLE_FMT_S32;
+ _video_codec_name = "libx264";
+ _audio_codec_name = "pcm_s24le";
+ av_dict_set_int (&_video_options, "crf", x264_crf, 0);
+ break;
}
setup_video ();
setup_audio ();
#ifdef DCPOMATIC_VARIANT_SWAROOP
}
setup_video ();
setup_audio ();
#ifdef DCPOMATIC_VARIANT_SWAROOP
- int r = avformat_alloc_output_context2 (&_format_context, av_guess_format("m
p4
", 0, 0), 0, 0);
+ int r = avformat_alloc_output_context2 (&_format_context, av_guess_format("m
ov
", 0, 0), 0, 0);
#else
int r = avformat_alloc_output_context2 (&_format_context, 0, 0, _output.string().c_str());
#endif
#else
int r = avformat_alloc_output_context2 (&_format_context, 0, 0, _output.string().c_str());
#endif
@@
-125,9
+131,10
@@
FFmpegFileEncoder::FFmpegFileEncoder (
throw runtime_error ("could not open FFmpeg output file");
}
throw runtime_error ("could not open FFmpeg output file");
}
+ AVDictionary* options = 0;
+
#ifdef DCPOMATIC_VARIANT_SWAROOP
if (key) {
#ifdef DCPOMATIC_VARIANT_SWAROOP
if (key) {
- AVDictionary* options = 0;
av_dict_set (&options, "encryption_key", key->hex().c_str(), 0);
/* XXX: is this OK? */
av_dict_set (&options, "encryption_kid", "00000000000000000000000000000000", 0);
av_dict_set (&options, "encryption_key", key->hex().c_str(), 0);
/* XXX: is this OK? */
av_dict_set (&options, "encryption_kid", "00000000000000000000000000000000", 0);
@@
-141,7
+148,7
@@
FFmpegFileEncoder::FFmpegFileEncoder (
}
#endif
}
#endif
- if (avformat_write_header (_format_context,
0
) < 0) {
+ if (avformat_write_header (_format_context,
&options
) < 0) {
throw runtime_error ("could not write header to FFmpeg output file");
}
throw runtime_error ("could not write header to FFmpeg output file");
}
@@
-154,7
+161,8
@@
FFmpegFileEncoder::pixel_format (ExportFormat format)
switch (format) {
case EXPORT_FORMAT_PRORES:
return AV_PIX_FMT_YUV422P10;
switch (format) {
case EXPORT_FORMAT_PRORES:
return AV_PIX_FMT_YUV422P10;
- case EXPORT_FORMAT_H264:
+ case EXPORT_FORMAT_H264_AAC:
+ case EXPORT_FORMAT_H264_PCM:
return AV_PIX_FMT_YUV420P;
default:
DCPOMATIC_ASSERT (false);
return AV_PIX_FMT_YUV420P;
default:
DCPOMATIC_ASSERT (false);
@@
-203,7
+211,7
@@
FFmpegFileEncoder::setup_audio ()
avcodec_get_context_defaults3 (_audio_codec_context, _audio_codec);
/* XXX: configurable */
avcodec_get_context_defaults3 (_audio_codec_context, _audio_codec);
/* XXX: configurable */
- _audio_codec_context->bit_rate =
256
* 1024;
+ _audio_codec_context->bit_rate =
_audio_channels * 128
* 1024;
_audio_codec_context->sample_fmt = _sample_format;
_audio_codec_context->sample_rate = _audio_frame_rate;
_audio_codec_context->channel_layout = av_get_default_channel_layout (_audio_channels);
_audio_codec_context->sample_fmt = _sample_format;
_audio_codec_context->sample_rate = _audio_frame_rate;
_audio_codec_context->channel_layout = av_get_default_channel_layout (_audio_channels);
@@
-270,7
+278,11
@@
FFmpegFileEncoder::video (shared_ptr<PlayerVideo> video, DCPTime time)
AVFrame* frame = av_frame_alloc ();
DCPOMATIC_ASSERT (frame);
AVFrame* frame = av_frame_alloc ();
DCPOMATIC_ASSERT (frame);
- _pending_images[image->data()[0]] = image;
+ {
+ boost::mutex::scoped_lock lm (_pending_images_mutex);
+ _pending_images[image->data()[0]] = image;
+ }
+
for (int i = 0; i < 3; ++i) {
AVBufferRef* buffer = av_buffer_create(image->data()[i], image->stride()[i] * image->size().height, &buffer_free, this, 0);
frame->buf[i] = av_buffer_ref (buffer);
for (int i = 0; i < 3; ++i) {
AVBufferRef* buffer = av_buffer_create(image->data()[i], image->stride()[i] * image->size().height, &buffer_free, this, 0);
frame->buf[i] = av_buffer_ref (buffer);
@@
-354,6
+366,16
@@
FFmpegFileEncoder::audio_frame (int size)
}
break;
}
}
break;
}
+ case AV_SAMPLE_FMT_S32:
+ {
+ int32_t* q = reinterpret_cast<int32_t*> (samples);
+ for (int i = 0; i < size; ++i) {
+ for (int j = 0; j < channels; ++j) {
+ *q++ = p[j][i] * 2147483647;
+ }
+ }
+ break;
+ }
case AV_SAMPLE_FMT_FLTP:
{
float* q = reinterpret_cast<float*> (samples);
case AV_SAMPLE_FMT_FLTP:
{
float* q = reinterpret_cast<float*> (samples);
@@
-404,5
+426,8
@@
FFmpegFileEncoder::buffer_free (void* opaque, uint8_t* data)
void
FFmpegFileEncoder::buffer_free2 (uint8_t* data)
{
void
FFmpegFileEncoder::buffer_free2 (uint8_t* data)
{
- _pending_images.erase (data);
+ boost::mutex::scoped_lock lm (_pending_images_mutex);
+ if (_pending_images.find(data) != _pending_images.end()) {
+ _pending_images.erase (data);
+ }
}
}