@@ -6,11 +6,18 @@ Recorder::Recorder() : m_width(1280), m_height(720), m_fps(60) {}
66
77void Recorder::start (const std::string& path) {
88 m_recording = true ;
9+ m_finished_level = false ;
910 m_last_frame_t = m_extra_t = 0 ;
11+ m_after_end_extra_time = 0 .f ;
1012 m_renderer.m_width = m_width;
1113 m_renderer.m_height = m_height;
1214 m_renderer.begin ();
13- std::thread ([&, path]() {
15+ auto play_layer = gd::GameManager::sharedState ()->getPlayLayer ();
16+ auto song_file = play_layer->m_level ->getAudioFileName ();
17+ // these are always false???
18+ auto fade_in = play_layer->m_levelSettings ->m_fadeIn ;
19+ auto fade_out = play_layer->m_levelSettings ->m_fadeOut ;
20+ std::thread ([&, path, song_file]() {
1421 std::stringstream stream;
1522 stream << " ffmpeg -y -f rawvideo -pix_fmt rgb24 -s " << m_width << " x" << m_height << " -r " << m_fps
1623 << " -i - " ;
@@ -23,6 +30,7 @@ void Recorder::start(const std::string& path) {
2330 else
2431 stream << " -pix_fmt yuv420p " ;
2532 stream << " -vf \" vflip\" -an \" " << path << " \" " ; // i hope just putting it in "" escapes it
33+ std::cout << " executing: " << stream.str () << std::endl;
2634 auto process = subprocess::Popen (stream.str ());
2735 while (m_recording) {
2836 m_lock.lock ();
@@ -35,6 +43,20 @@ void Recorder::start(const std::string& path) {
3543 }
3644 process.close ();
3745 std::cout << " should be done now!" << std::endl;
46+ std::cout << " sike" << std::endl;
47+ auto total_time = m_last_frame_t ; // 1 frame too short?
48+ {
49+ std::stringstream stream;
50+ stream << " ffmpeg -y -ss " << m_song_start_offset << " -i \" " << song_file
51+ << " \" -i \" " << path << " \" -t " << total_time << " -c:v copy "
52+ << " -filter:a \" " ;
53+ std::cout << " in " << fade_in << " out " << fade_out << std::endl;
54+ stream << " afade=t=in:d=0.5[out];[out]afade=t=out:d=0.5:st=" << (total_time - 0 .5f - 3 .f - 1 .f );
55+ stream << " \" " << path << " .sound.mp4" ;
56+ std::cout << " executing: " << stream.str () << std::endl;
57+ auto process = subprocess::Popen (stream.str ());
58+ process.close ();
59+ }
3860 }).detach ();
3961}
4062
@@ -99,4 +121,24 @@ void Recorder::capture_frame() {
99121 m_lock.lock ();
100122 m_frames.push (frame);
101123 m_lock.unlock ();
124+ }
125+
126+ void Recorder::handle_recording (gd::PlayLayer* play_layer, float dt) {
127+ if (!play_layer->m_hasLevelCompleteMenu || m_after_end_extra_time < 3 .f ) {
128+ if (play_layer->m_hasLevelCompleteMenu ) {
129+ m_after_end_extra_time += dt;
130+ m_finished_level = true ;
131+ }
132+ auto frame_dt = 1 . / static_cast <double >(m_fps);
133+ auto time = play_layer->m_time + m_extra_t - m_last_frame_t ;
134+ if (time >= frame_dt) {
135+ gd::FMODAudioEngine::sharedEngine ()->setBackgroundMusicTime (
136+ play_layer->m_time + m_song_start_offset);
137+ m_extra_t = time - frame_dt;
138+ m_last_frame_t = play_layer->m_time ;
139+ capture_frame ();
140+ }
141+ } else {
142+ stop ();
143+ }
102144}
0 commit comments