- DCPOMATIC_ASSERT (size);
-
- AVFrame* frame = av_frame_alloc ();
- DCPOMATIC_ASSERT (frame);
-
- int const channels = _pending_audio->channels();
- DCPOMATIC_ASSERT (channels);
-
- int const buffer_size = av_samples_get_buffer_size (0, channels, size, _audio_codec_context->sample_fmt, 0);
- DCPOMATIC_ASSERT (buffer_size >= 0);
-
- void* samples = av_malloc (buffer_size);
- DCPOMATIC_ASSERT (samples);
-
- frame->nb_samples = size;
- int r = avcodec_fill_audio_frame (frame, channels, _audio_codec_context->sample_fmt, (const uint8_t *) samples, buffer_size, 0);
- DCPOMATIC_ASSERT (r >= 0);
-
- float** p = _pending_audio->data ();
- switch (_audio_codec_context->sample_fmt) {
- case AV_SAMPLE_FMT_S16:
- {
- int16_t* q = reinterpret_cast<int16_t*> (samples);
- for (int i = 0; i < size; ++i) {
- for (int j = 0; j < channels; ++j) {
- *q++ = p[j][i] * 32767;
- }
- }
- break;
- }
- case AV_SAMPLE_FMT_FLTP:
- {
- float* q = reinterpret_cast<float*> (samples);
- for (int i = 0; i < channels; ++i) {
- memcpy (q, p[i], sizeof(float) * size);
- q += size;
- }
- break;
- }
- default:
- DCPOMATIC_ASSERT (false);
- }
-
- AVPacket packet;
- av_init_packet (&packet);
- packet.data = 0;
- packet.size = 0;
-
- int got_packet;
- if (avcodec_encode_audio2 (_audio_codec_context, &packet, frame, &got_packet) < 0) {
- throw EncodeError ("FFmpeg audio encode failed");
- }
-
- if (got_packet && packet.size) {
- packet.stream_index = _audio_stream_index;
- av_interleaved_write_frame (_format_context, &packet);
- av_packet_unref (&packet);
+ if (three_d) {
+ /// TRANSLATORS: L here is an abbreviation for "left", to indicate the left-eye part of a 3D export
+ _encoders[EYES_LEFT] = shared_ptr<FFmpegFileEncoder>(
+ new FFmpegFileEncoder(video_frame_size, video_frame_rate, audio_frame_rate, channels, format, x264_crf, String::compose("%1_%2%3", output.string(), _("L"), extension)
+#ifdef DCPOMATIC_VARIANT_SWAROOP
+ , key, id
+#endif
+ )
+ );
+ /// TRANSLATORS: R here is an abbreviation for "right", to indicate the right-eye part of a 3D export
+ _encoders[EYES_RIGHT] = shared_ptr<FFmpegFileEncoder>(
+ new FFmpegFileEncoder(video_frame_size, video_frame_rate, audio_frame_rate, channels, format, x264_crf, String::compose("%1_%2%3", output.string(), _("R"), extension)
+#ifdef DCPOMATIC_VARIANT_SWAROOP
+ , key, id
+#endif
+ )
+ );
+ } else {
+ _encoders[EYES_BOTH] = shared_ptr<FFmpegFileEncoder>(
+ new FFmpegFileEncoder(video_frame_size, video_frame_rate, audio_frame_rate, channels, format, x264_crf, String::compose("%1%2", output.string(), extension)
+#ifdef DCPOMATIC_VARIANT_SWAROOP
+ , key, id
+#endif
+ )
+ );