+
+static
+void
+check_ffmpeg_stream (boost::filesystem::path ref, boost::filesystem::path check, string stream)
+{
+ FILE* ref_file = popen(string("ffmpeg -loglevel error -i " + ref.string() + " -map 0:" + stream + " -f md5 -").c_str(), "r");
+ BOOST_REQUIRE (ref_file);
+ char ref_md5[64];
+ fscanf (ref_file, "%63s", ref_md5);
+ pclose (ref_file);
+
+ FILE* check_file = popen(string("ffmpeg -loglevel error -i " + check.string() + " -map 0:" + stream + " -f md5 -").c_str(), "r");
+ BOOST_REQUIRE (check_file);
+ char check_md5[64];
+ fscanf (check_file, "%63s", check_md5);
+ pclose (check_file);
+
+ BOOST_REQUIRE_EQUAL (strcmp(ref_md5, check_md5), 0);
+}
+
+void
+check_ffmpeg (boost::filesystem::path ref, boost::filesystem::path check)
+{
+ check_ffmpeg_stream (ref, check, "v");
+ check_ffmpeg_stream (ref, check, "a");
+}
+
+void
+check_one_frame (boost::filesystem::path dcp_dir, int64_t index, boost::filesystem::path ref)
+{
+ dcp::DCP dcp (dcp_dir);
+ dcp.read ();
+ shared_ptr<dcp::MonoPictureAsset> asset = dynamic_pointer_cast<dcp::MonoPictureAsset> (dcp.cpls().front()->reels().front()->main_picture()->asset());
+ BOOST_REQUIRE (asset);
+ shared_ptr<const dcp::MonoPictureFrame> frame = asset->start_read()->get_frame(index);
+
+ boost::uintmax_t const ref_size = boost::filesystem::file_size(ref);
+ BOOST_CHECK_EQUAL (frame->j2k_size(), ref_size);
+
+ FILE* ref_file = fopen_boost(ref, "rb");
+ BOOST_REQUIRE (ref_file);
+
+ uint8_t* ref_data = new uint8_t[ref_size];
+ fread (ref_data, ref_size, 1, ref_file);
+ fclose (ref_file);
+
+ BOOST_CHECK (memcmp(ref_data, frame->j2k_data(), ref_size) == 0);
+ delete[] ref_data;
+}
+
+boost::filesystem::path
+dcp_file (shared_ptr<const Film> film, string prefix)
+{
+ boost::filesystem::directory_iterator i = boost::filesystem::directory_iterator (film->dir(film->dcp_name()));
+ while (i != boost::filesystem::directory_iterator() && !boost::algorithm::starts_with (i->path().leaf().string(), prefix)) {
+ ++i;
+ }
+
+ BOOST_REQUIRE (i != boost::filesystem::directory_iterator());
+ return i->path();
+}