swaroop: support creation of H264 with 24-bit PCM.
authorCarl Hetherington <cth@carlh.net>
Mon, 22 Jul 2019 14:23:22 +0000 (15:23 +0100)
committerCarl Hetherington <cth@carlh.net>
Mon, 22 Jul 2019 14:23:22 +0000 (15:23 +0100)
src/lib/ffmpeg_file_encoder.cc
src/lib/types.h
src/tools/dcpomatic_ecinema.cc
src/wx/export_dialog.cc
test/ffmpeg_encoder_test.cc

index 7409482..cd5d473 100644 (file)
@@ -74,19 +74,25 @@ FFmpegFileEncoder::FFmpegFileEncoder (
                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;
+       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
-       int r = avformat_alloc_output_context2 (&_format_context, av_guess_format("mp4", 0, 0), 0, 0);
+       int r = avformat_alloc_output_context2 (&_format_context, av_guess_format("mov", 0, 0), 0, 0);
 #else
        int r = avformat_alloc_output_context2 (&_format_context, 0, 0, _output.string().c_str());
 #endif
@@ -155,7 +161,8 @@ FFmpegFileEncoder::pixel_format (ExportFormat format)
        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);
@@ -355,6 +362,16 @@ FFmpegFileEncoder::audio_frame (int size)
                }
                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);
index c9f68a2..ccb47dc 100644 (file)
@@ -170,7 +170,8 @@ extern TextType string_to_text_type (std::string s);
 enum ExportFormat
 {
        EXPORT_FORMAT_PRORES,
-       EXPORT_FORMAT_H264
+       EXPORT_FORMAT_H264_AAC,
+       EXPORT_FORMAT_H264_PCM
 };
 
 /** @struct Crop
index d6ac16e..286d61f 100644 (file)
@@ -298,7 +298,7 @@ convert_dcp (
        shared_ptr<TranscodeJob> job (new TranscodeJob(film));
        job->set_encoder (
                shared_ptr<FFmpegEncoder>(
-                       new FFmpegEncoder(film, job, output_file, EXPORT_FORMAT_H264, false, false, crf, key, id)
+                       new FFmpegEncoder(film, job, output_file, EXPORT_FORMAT_H264_PCM, false, false, crf, key, id)
                        )
                );
        jm->add (job);
index cb9127a..e906862 100644 (file)
@@ -46,7 +46,7 @@ wxString format_extensions[] = {
 
 ExportFormat formats[] = {
        EXPORT_FORMAT_PRORES,
-       EXPORT_FORMAT_H264,
+       EXPORT_FORMAT_H264_AAC
 };
 
 ExportDialog::ExportDialog (wxWindow* parent)
index 877e39d..d9a0261 100644 (file)
@@ -45,7 +45,7 @@ ffmpeg_content_test (int number, boost::filesystem::path content, ExportFormat f
        string name = "ffmpeg_encoder_";
        string extension;
        switch (format) {
-       case EXPORT_FORMAT_H264:
+       case EXPORT_FORMAT_H264_AAC:
                name += "h264";
                extension = "mp4";
                break;
@@ -180,7 +180,7 @@ BOOST_AUTO_TEST_CASE (ffmpeg_encoder_prores_test7)
 /** Red / green / blue MP4 -> H264 */
 BOOST_AUTO_TEST_CASE (ffmpeg_encoder_h264_test1)
 {
-       ffmpeg_content_test(1, "test/data/test.mp4", EXPORT_FORMAT_H264);
+       ffmpeg_content_test(1, "test/data/test.mp4", EXPORT_FORMAT_H264_AAC);
 }
 
 /** Just subtitles -> H264 */
@@ -200,7 +200,7 @@ BOOST_AUTO_TEST_CASE (ffmpeg_encoder_h264_test2)
        film->write_metadata();
 
        shared_ptr<Job> job (new TranscodeJob (film));
-       FFmpegEncoder encoder (film, job, "build/test/ffmpeg_encoder_h264_test2.mp4", EXPORT_FORMAT_H264, false, false, 23
+       FFmpegEncoder encoder (film, job, "build/test/ffmpeg_encoder_h264_test2.mp4", EXPORT_FORMAT_H264_AAC, false, false, 23
 #ifdef DCPOMATIC_VARIANT_SWAROOP
                               , optional<dcp::Key>(), optional<string>()
 #endif
@@ -229,7 +229,7 @@ BOOST_AUTO_TEST_CASE (ffmpeg_encoder_h264_test3)
        film->write_metadata();
 
        shared_ptr<Job> job (new TranscodeJob (film));
-       FFmpegEncoder encoder (film, job, "build/test/ffmpeg_encoder_h264_test3.mp4", EXPORT_FORMAT_H264, false, false, 23
+       FFmpegEncoder encoder (film, job, "build/test/ffmpeg_encoder_h264_test3.mp4", EXPORT_FORMAT_H264_AAC, false, false, 23
 #ifdef DCPOMATIC_VARIANT_SWAROOP
                               , optional<dcp::Key>(), optional<string>()
 #endif
@@ -247,7 +247,7 @@ BOOST_AUTO_TEST_CASE (ffmpeg_encoder_h264_test4)
        film->set_container(Ratio::from_id("185"));
 
        shared_ptr<Job> job(new TranscodeJob(film));
-       FFmpegEncoder encoder(film, job, "build/test/ffmpeg_encoder_h264_test4.mp4", EXPORT_FORMAT_H264, false, false, 23
+       FFmpegEncoder encoder(film, job, "build/test/ffmpeg_encoder_h264_test4.mp4", EXPORT_FORMAT_H264_AAC, false, false, 23
 #ifdef DCPOMATIC_VARIANT_SWAROOP
                               , optional<dcp::Key>(), optional<string>()
 #endif
@@ -305,7 +305,7 @@ BOOST_AUTO_TEST_CASE (ffmpeg_encoder_h264_test5)
        Rs->audio->set_mapping (map);
 
        shared_ptr<Job> job (new TranscodeJob (film));
-       FFmpegEncoder encoder (film, job, "build/test/ffmpeg_encoder_h264_test5.mp4", EXPORT_FORMAT_H264, true, false, 23
+       FFmpegEncoder encoder (film, job, "build/test/ffmpeg_encoder_h264_test5.mp4", EXPORT_FORMAT_H264_AAC, true, false, 23
 #ifdef DCPOMATIC_VARIANT_SWAROOP
                               , optional<dcp::Key>(), optional<string>()
 #endif
@@ -337,7 +337,7 @@ BOOST_AUTO_TEST_CASE (ffmpeg_encoder_h264_test6)
        }
 
        shared_ptr<Job> job (new TranscodeJob (film2));
-       FFmpegEncoder encoder (film2, job, "build/test/ffmpeg_encoder_h264_test6_vf.mp4", EXPORT_FORMAT_H264, true, false, 23
+       FFmpegEncoder encoder (film2, job, "build/test/ffmpeg_encoder_h264_test6_vf.mp4", EXPORT_FORMAT_H264_AAC, true, false, 23
 #ifdef DCPOMATIC_VARIANT_SWAROOP
                               , optional<dcp::Key>(), optional<string>()
 #endif