Fixed bug in AddImage() method on a frame, to copy the image instead of just pointing to it. This fixed many issues in the FrameMapper as well, which copies images alot.

This commit is contained in:
Jonathan Thomas
2013-11-04 15:16:19 -06:00
parent 1bdea062d6
commit 1e7cd7ddbb
4 changed files with 30 additions and 49 deletions

View File

@@ -160,14 +160,6 @@ namespace openshot
/// Close the internal reader
void Close();
/// @brief This method de-interlaces a frame which has alternating fields. In other words
/// alternating horizontal lines, that represent 2 different points of time.
///
/// @returns The de-interlaced frame of video
/// @param frame The frame which needs to be de-interlaced
/// @param isOdd Use the odd horizontal lines (if false, the Even lines are used)
tr1::shared_ptr<Frame> DeInterlaceFrame(tr1::shared_ptr<Frame> frame, bool isOdd);
/// Get a frame based on the target frame rate and the new frame number of a frame
MappedFrame GetMappedFrame(int TargetFrameNumber) throw(OutOfBoundsFrame);

View File

@@ -512,7 +512,7 @@ void Frame::AddImage(int width, int height, const string map, const Magick::Stor
void Frame::AddImage(tr1::shared_ptr<Magick::Image> new_image)
{
// assign image data
image = new_image;
image = tr1::shared_ptr<Magick::Image>(new Magick::Image(*new_image.get()));
// Update height and width
width = image->columns();
@@ -524,7 +524,7 @@ void Frame::AddImage(tr1::shared_ptr<Magick::Image> new_image, bool only_odd_lin
{
// Replace image (if needed)
if (image->columns() == 1)
image = new_image;
image = tr1::shared_ptr<Magick::Image>(new Magick::Image(*new_image.get()));
// Loop through each odd or even line, and copy it to the image
int starting_row = 0;
@@ -557,7 +557,7 @@ void Frame::AddImage(tr1::shared_ptr<Magick::Image> new_image, float alpha)
{
// Replace image (if needed)
if (image->columns() == 1)
image = new_image;
image = tr1::shared_ptr<Magick::Image>(new Magick::Image(*new_image.get()));
else
{
// Calculate opacity of new image

View File

@@ -420,28 +420,6 @@ int FrameMapper::GetSamplesPerFrame(int frame_number, Fraction rate)
return samples_per_frame;
}
// De-interlace a frame
tr1::shared_ptr<Frame> FrameMapper::DeInterlaceFrame(tr1::shared_ptr<Frame> frame, bool isOdd)
{
// Calculate the new size (used to shrink and expand the image, to remove interlacing)
Magick::Geometry original_size = frame->GetImage()->size();
Magick::Geometry frame_size = frame->GetImage()->size();
frame_size.aspect(false); // allow the image to be re-sized to an invalid aspect ratio
frame_size.height(frame_size.height() / 2.0); // height set to 50% of original height
if (isOdd)
// Roll the image by 1 pixel, to use the ODD horizontal lines (instead of the even ones)
frame->GetImage()->roll(0,1);
// Resample the image to 50% height (to remove every other line)
frame->GetImage()->sample(frame_size);
// Resize image back to original height
frame->GetImage()->resize(original_size);
return frame;
}
void FrameMapper::PrintMapping()
{
// Get the difference (in frames) between the original and target frame rates

View File

@@ -42,33 +42,33 @@ using namespace tr1;
int main(int argc, char* argv[])
{
// Image of interlaced frame
ImageReader ir("/home/jonathan/apps/libopenshot/src/examples/interlaced.png");
ir.Open();
// FrameMapper to de-interlace frame
//FrameMapper fm(&ir, Framerate(24,1), PULLDOWN_NONE);
//fm.DeInterlaceFrame(ir.GetFrame(1), true)->Display();
Deinterlace de(false);
de.GetFrame(ir.GetFrame(1), 1)->Display();
return 0;
// ImageReader ir("/home/jonathan/apps/libopenshot/src/examples/interlaced.png");
// ir.Open();
//
// // FrameMapper to de-interlace frame
// //FrameMapper fm(&ir, Framerate(24,1), PULLDOWN_NONE);
// //fm.DeInterlaceFrame(ir.GetFrame(1), true)->Display();
// Deinterlace de(false);
// de.GetFrame(ir.GetFrame(1), 1)->Display();
//
//
// return 0;
// Reader
FFmpegReader r1("/home/jonathan/Videos/sintel_trailer-720p.mp4");
FFmpegReader r1("/home/jonathan/colors-24-converted-to-29-97-fps-pulldown-advanced.mp4");
r1.Open();
// FrameMapper
FrameMapper r(&r1, Framerate(100,1), PULLDOWN_NONE);
//r.PrintMapping();
FrameMapper r(&r1, Framerate(24,1), PULLDOWN_ADVANCED);
r.PrintMapping();
/* WRITER ---------------- */
FFmpegWriter w("/home/jonathan/output.mp4");
// Set options
//w.SetAudioOptions(true, "libvorbis", 48000, 2, 188000);
w.SetAudioOptions(true, "libmp3lame", 44100, 2, 128000);
//w.SetAudioOptions(true, "libmp3lame", 44100, 2, 128000);
//w.SetVideoOptions(true, "libvpx", Fraction(24,1), 1280, 720, Fraction(1,1), false, false, 30000000);
w.SetVideoOptions(true, "mpeg4", r.info.fps, 1280, 720, Fraction(1,1), false, false, 3000000);
@@ -82,8 +82,18 @@ int main(int argc, char* argv[])
w.OutputStreamInfo();
//for (int frame = 3096; frame <= 3276; frame++)
for (int frame = 1; frame <= 1500; frame++)
for (int frame = 1; frame <= 20; frame++)
{
// tr1::shared_ptr<Frame> f(new Frame(frame, 1280, 720, "#000000", 44100, 2));
// if (frame % 2 == 0)
// f->AddColor(1280, 720, "Yellow");
// else
// f->AddColor(1280, 720, "Black");
//
// f->AddOverlayNumber(f->number);
// cout << f->number << endl;
// w.WriteFrame(f);
tr1::shared_ptr<Frame> f = r.GetFrame(frame);
if (f)
{
@@ -93,6 +103,7 @@ int main(int argc, char* argv[])
//f->Display();
// Write frame
f->Display();
cout << "queue frame " << frame << " (" << f->number << ", " << f << ")" << endl;
w.WriteFrame(f);
}