// Constructor for DummyReader. Pass a framerate and samplerate. DummyReader::DummyReader(Fraction fps, int width, int height, int sample_rate, int channels, float duration) { // Set key info settings info.has_audio = false; info.has_video = true; info.file_size = width * height * sizeof(int); info.vcodec = "raw"; info.fps = fps; info.width = width; info.height = height; info.sample_rate = sample_rate; info.channels = channels; info.duration = duration; info.video_length = duration * fps.ToFloat(); info.pixel_ratio.num = 1; info.pixel_ratio.den = 1; info.video_timebase = fps.Reciprocal(); info.acodec = "raw"; // Calculate the DAR (display aspect ratio) Fraction size(info.width * info.pixel_ratio.num, info.height * info.pixel_ratio.den); // Reduce size fraction size.Reduce(); // Set the ratio based on the reduced fraction info.display_ratio.num = size.num; info.display_ratio.den = size.den; // Open and Close the reader, to populate it's attributes (such as height, width, etc...) Open(); Close(); }
// Default Constructor for the timeline (which sets the canvas width and height) Timeline::Timeline(int width, int height, Fraction fps, int sample_rate, int channels, ChannelLayout channel_layout) : is_open(false), auto_map_clips(true) { // Init viewport size (curve based, because it can be animated) viewport_scale = Keyframe(100.0); viewport_x = Keyframe(0.0); viewport_y = Keyframe(0.0); // Init background color color.red = Keyframe(0.0); color.green = Keyframe(0.0); color.blue = Keyframe(0.0); // Init FileInfo struct (clear all values) info.width = width; info.height = height; info.fps = fps; info.sample_rate = sample_rate; info.channels = channels; info.channel_layout = channel_layout; info.video_timebase = fps.Reciprocal(); info.duration = 60 * 30; // 30 minute default duration info.has_audio = true; info.has_video = true; info.video_length = info.fps.ToFloat() * info.duration; // Init cache final_cache.SetMaxBytesFromInfo(OPEN_MP_NUM_PROCESSORS * 3, info.width, info.height, info.sample_rate, info.channels); }
// Calculate the # of samples per video frame (for a specific frame number and frame rate) int Frame::GetSamplesPerFrame(long int number, Fraction fps, int sample_rate, int channels) { // Get the total # of samples for the previous frame, and the current frame (rounded) double fps_rate = fps.Reciprocal().ToDouble(); // Determine previous samples total, and make sure it's evenly divisible by the # of channels double previous_samples = (sample_rate * fps_rate) * (number - 1); double previous_samples_remainder = fmod(previous_samples, (double)channels); // subtract the remainder to the total (to make it evenly divisible) previous_samples -= previous_samples_remainder; // Determine the current samples total, and make sure it's evenly divisible by the # of channels double total_samples = (sample_rate * fps_rate) * number; double total_samples_remainder = fmod(total_samples, (double)channels); // subtract the remainder to the total (to make it evenly divisible) total_samples -= total_samples_remainder; // Subtract the previous frame's total samples with this frame's total samples. Not all sample rates can // be evenly divided into frames, so each frame can have have different # of samples. int samples_per_frame = round(total_samples - previous_samples); return samples_per_frame; }