OpenShot / libopenshot

OpenShot Video Library (libopenshot) is a free, open-source project dedicated to delivering high quality video editing, animation, and playback solutions to the world. API currently supports C++, Python, and Ruby.
http://www.openshot.org
GNU Lesser General Public License v3.0
1.26k stars 271 forks source link

Infinite loop using QtTextReader and Timeline sample rate of 48000 #914

Closed jeffski closed 1 year ago

jeffski commented 1 year ago

The following script will hang and appears to be caught in an infinite loop. The Timeline sample rate is set to 48000. Setting it to 44100, it will not hang.

#include "QApplication"
#include "OpenShot.h"
using namespace openshot;

int main(int argc, char *argv[]) {
    QApplication a(argc, argv);

        Timeline timeline(1280, 720, Fraction(25,1), 48000, 2, LAYOUT_STEREO);
    timeline.color = Color("#000000");

    QFont qFont;
    qFont = QFont("Arial");

    Clip clip1(new QtTextReader(1280, 720, 0, 0, GRAVITY_CENTER, "Hello World", qFont, "#ffffff", "transparent"));
    clip1.Position(0);
    clip1.Layer(1);
    clip1.Start(0);
    clip1.End(5);

        timeline.AddClip(&clip1);
    timeline.Open();

    FFmpegWriter writer("test.mp4");
    writer.SetAudioOptions(true, "aac", 48000, 2, LAYOUT_STEREO, 0);
    writer.SetVideoOptions(true, "libx264", Fraction(25, 1), 1280, 720, Fraction(1,1), false, false, 0);
    writer.PrepareStreams();
    writer.SetOption(VIDEO_STREAM, "crf", "23" );
    writer.WriteHeader();
    writer.Open();
    writer.WriteFrame(&timeline, 0, 25);
    writer.WriteTrailer();
    writer.Close();

    timeline.Close();

    return 0;
}

When debugging, in the int Frame::GetSamplesPerFrame(int64_t number, Fraction fps, int sample_rate, int channels) function (Frame.cpp, L456), number counts up to 25 (i.e. frame number 25), it then resets to 1 and then counts up forever. See the screenshot below from Eclipse, number is 29657368 but there should only be 25 frames being written.

image

jeffski commented 1 year ago

Possibly related to: #913

jeffski commented 1 year ago

I've been working of a recent version of develop, from the last week. I just noticed this commit which I am ahead of: https://github.com/OpenShot/libopenshot/commit/d104664da38da62e600a70ba15b0429182b77182

I am going to build off the tagged version v0.3.0 which is before this commit and see if that is working as expected.

jeffski commented 1 year ago

Tag v0.3.0 seems to work OK. I tried commit https://github.com/OpenShot/libopenshot/commit/8f92bac0b787c54503142054da1890c2f56a910b which is the one before https://github.com/OpenShot/libopenshot/commit/d104664da38da62e600a70ba15b0429182b77182 and got the error below so for now I'm just going to go with the tagged version. But it does look like there issues with QtTextReader and QtHtmlReader that need fixed after more recent commits.

terminate called after throwing an instance of 'openshot::ErrorEncodingVideo'
  what():  Error while resampling audio in frame mapper
Caught signal 6 (SIGABRT)
---- Unhandled Exception: Stack Trace ----
  /lib/x86_64-linux-gnu/libc.so.6 ( abort                                     + 0x141 )  [0x7f0b0d3e07f1]
  /usr/lib/x86_64-linux-gnu/libstdc++.so.6 (                                           + 0x8c957)  [0x7f0b0da35957]
  /usr/lib/x86_64-linux-gnu/libstdc++.so.6 (                                           + 0x92ae6)  [0x7f0b0da3bae6]
  /usr/lib/x86_64-linux-gnu/libstdc++.so.6 (                                           + 0x92b21)  [0x7f0b0da3bb21]
  /usr/lib/x86_64-linux-gnu/libstdc++.so.6 (                                           + 0x92d54)  [0x7f0b0da3bd54]
  /usr/local/lib/libopenshot.so.23 ( openshot::FrameMapper::ResampleMappedAudio(std::shared_ptr<openshot::Frame>, long)  + 0xbf3 )  [0x7f0b0fea3c5b]
  /usr/local/lib/libopenshot.so.23 ( openshot::FrameMapper::GetFrame(long)     + 0x129b)  [0x7f0b0fea14ff]
  /usr/local/lib/libopenshot.so.23 ( openshot::Clip::GetOrCreateFrame(long)    + 0x2ea )  [0x7f0b0fe3b664]
  /usr/local/lib/libopenshot.so.23 ( openshot::Clip::GetFrame(std::shared_ptr<openshot::Frame>, long, openshot::TimelineInfoStruct*)  + 0x1da )  [0x7f0b0fe39cd8]
  /usr/local/lib/libopenshot.so.23 ( openshot::Timeline::GetOrCreateFrame(std::shared_ptr<openshot::Frame>, openshot::Clip*, long, openshot::TimelineInfoStruct*)  + 0x371 )  [0x7f0b0febf84f]
  /usr/local/lib/libopenshot.so.23 ( openshot::Timeline::add_layer(std::shared_ptr<openshot::Frame>, openshot::Clip*, long, bool, float)  + 0xd7  )  [0x7f0b0febfe99]
  /usr/local/lib/libopenshot.so.23 ( openshot::Timeline::GetFrame(long)        + 0x1d52)  [0x7f0b0fec4db2]
  /usr/local/lib/libopenshot.so.23 ( openshot::FFmpegWriter::WriteFrame(openshot::ReaderBase*, long, long)  + 0x311 )  [0x7f0b0fe7ef4f]
  /home/jeff/Documents/projects/shotstack/eclipse/scratchpad/Debug/scratchpad (                                           + 0x8412)  [0x55725e4b1412]
  /lib/x86_64-linux-gnu/libc.so.6 ( __libc_start_main                         + 0xe7  )  [0x7f0b0d3c1c87]
  /home/jeff/Documents/projects/shotstack/eclipse/scratchpad/Debug/scratchpad (                                           + 0x7baa)  [0x55725e4b0baa]
---- End of Stack Trace ----
stale[bot] commented 1 year ago

Thank you so much for submitting an issue to help improve OpenShot Video Editor. We are sorry about this, but this particular issue has gone unnoticed for quite some time. To help keep the OpenShot GitHub Issue Tracker organized and focused, we must ensure that every issue is correctly labelled and triaged, to get the proper attention.

This issue will be closed, as it meets the following criteria:

We'd like to ask you to help us out and determine whether this issue should be reopened.

Thanks again for your help!