Giter Club home page Giter Club logo

Comments (13)

kou avatar kou commented on June 17, 2024 1

There are 2 problems:

  1. GR should not call av_write_trailer() on initialization failure:
diff --git a/lib/gks/plugin/vc.c b/lib/gks/plugin/vc.c
index 6391d651..ccf76cf0 100644
--- a/lib/gks/plugin/vc.c
+++ b/lib/gks/plugin/vc.c
@@ -270,7 +270,10 @@ void vc_movie_finish(movie_t movie)
 
   if (movie->fmt_ctx && movie->cdc_ctx)
     {
-      av_write_trailer(movie->fmt_ctx);
+      if (movie->fmt_ctx->pb)
+        {
+          av_write_trailer(movie->fmt_ctx);
+        }
       avcodec_close(movie->cdc_ctx);
 
       if (!(movie->out_fmt->flags & AVFMT_NOFILE))

For example, movie->fmt_ctx->pb is NULL when avcocdec_open2() is failed: https://github.com/sciapp/gr/blob/master/lib/gks/plugin/vc.c#L185

It can be happen by specifying wrong video size (361 isn't mod 4): GKS_VIDEO_OPTS=361x240@25@2x

  1. save_videos.rb should specify GKS_VIDEO_OPTS before GR.beginprint:
diff --git a/examples/save_videos.rb b/examples/save_videos.rb
index d17dbc1..68bf6a3 100644
--- a/examples/save_videos.rb
+++ b/examples/save_videos.rb
@@ -21,6 +21,9 @@ epoch.times do |i|
   y <<  i**2 * Math.cos(i * Math::PI / 10.0) / 100.0
 end
 
+# configure video size
+ENV['GKS_VIDEO_OPTS'] = '360x240@25@2x'
+
 # start
 GR.beginprint('savefig/video.mov')
 
@@ -32,9 +35,6 @@ end
 # stop
 GR.endprint
 
-# configure video size
-ENV['GKS_VIDEO_OPTS'] = '360x240@25@2x'
-
 # You can use block
 GR.beginprint('savefig/video.mp4') do
   epoch.times do |j|

If it's not specified, width and height (ws_state_list::mem[0] and ws_state_list::mem[1]) may be updated by cairoplugin: https://github.com/sciapp/gr/blob/master/lib/gks/plugin/cairoplugin.c#L894-L895

It may set invalid width and/or height (not mod 4).

Could you report 1. to GR?

from gr.rb.

kou avatar kou commented on June 17, 2024 1

x264 that is used by ffmpeg requires "mod 4" in this case: https://code.videolan.org/videolan/x264/-/blob/master/encoder/encoder.c#L529

from gr.rb.

kojix2 avatar kojix2 commented on June 17, 2024

@fapdash
Thank you for your report.

According to the official website, the following dependent libraries are required to build GR.

https://gr-framework.org/building.html

The libraries related to video output are optional, not required. Therefore, they may not be included in the pre-built binaries managed by the package manager. For example, the libgr distributed via homebrew specifies only the following dependencies, so video output is not possible.

https://github.com/kojix2/homebrew-core/blob/c064504cd502b36feb3ca4ce625c0457efb2ba00/Formula/libgr.rb#L15-L21

  depends_on "cmake" => :build
  depends_on "cairo"
  depends_on "glfw"
  depends_on "libtiff"
  depends_on "qhull"
  depends_on "qt@5"
  depends_on "zeromq"

I guess Linux can't output video for the same reason...
But to be honest, I don't understand much about the lower layers.
I think I need to look into this more closely.

from gr.rb.

kojix2 avatar kojix2 commented on June 17, 2024

Parhaps, you may be able to output video by simply installing the following dependent libraries.

Libraries that may be related to video output are:

sudo apt install -y libavcodec-dev \
                    libavdevice-dev \
                    libavformat-dev \
                    libavutil-dev

from gr.rb.

kou avatar kou commented on June 17, 2024

What is your distribution?
I confirmed that it works well on Ubuntu 20.04.

from gr.rb.

fapdash avatar fapdash commented on June 17, 2024

I'm on Ubuntu 20.04 as well. The same error still happens after installing the packages mentioned in #46 (comment).

from gr.rb.

kojix2 avatar kojix2 commented on June 17, 2024

What about libavdevice-dev?
It's not in the Dockerfile list, but in my case Ubuntu can output with it. (Until then, similar error)

from gr.rb.

fapdash avatar fapdash commented on June 17, 2024

Mh, that's also already installed: libavdevice-dev is already the newest version (7:4.2.4-1ubuntu0.1).

from gr.rb.

kojix2 avatar kojix2 commented on June 17, 2024

I confirmed that the same error occurs when I set GKS_WSTYPE=100.
@kou Could you please set the environment variable GKS_WSTYPE=100 and check again?

from gr.rb.

kojix2 avatar kojix2 commented on June 17, 2024

@kou
Great investigation as always.
Can I ask you one question: what is mod 4?

from gr.rb.

kou avatar kou commented on June 17, 2024

Oh, sorry. It's abbreviation of "modulo 4":

from gr.rb.

kojix2 avatar kojix2 commented on June 17, 2024

Thank you.
I didn't know that x264 can only support video sizes that are divisible by 4.

from gr.rb.

kojix2 avatar kojix2 commented on June 17, 2024

Reported to sciapp/gr.

from gr.rb.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.