From: Torquil M. <to...@gm...> - 2008-01-21 23:52:11
|
Hello, sorry to ask so many questions... I am trying to get plplot to rewri= te=20 the plot to the same file several times (part of my quest to write to a pip= e=20 into ffmpeg). In between plots (plbop().....pleop()) I delete the file=20 (before I delete the file I send it into another ofstream that will pipe it= =20 into ffmpeg), and I expected plplot to recreate the file for the next plot = so=20 I can do it all over again. In the documentation is says that if using=20 plbop(): "For a file driver, the output file is opened if necessary." I'm now using the Debian Sid plplot, since I had segfault problems with the= =20 JPG-driver in the current SVN-version. I tried to reset the filename with=20 plsfnam() between the plots, using the same string as when running it befor= e=20 plinit(), but then I get a segfault. I have included a test program below. The part about piping the file into a= n=20 ofstream is not in this test program, but that has nothing to do with the=20 behaviour I'm discussing. I thought that a "1.jpg" would exist after the=20 program exits, but that is not the case. The file only exists until I delet= e=20 it in the program, it is not recreated at the next plbop(): Best regards, Torquil S=F8rensen #include <plplot/plplot.h> #include <cstdio> using namespace std; int main(int argc, char *argv[]) { double x[] =3D { 0.1, 0.5, 0.2, 0.4, 0.4 }; double y[] =3D { 0.5, 0.4, 0.4, 0.8, 0.9 }; plparseopts(&argc, argv, PL_PARSE_FULL); plsfnam("1.jpg"); plsdev("jpeg"); plinit(); plenv(0, 1, 0, 1, 1, -2); plbop(); plbox("bcinst", 0, 0, "bcinst", 0, 0); plline(5, x, y); pleop(); system("ls -l 1.jpg"); remove("1.jpg"); plbop(); plbox("bcinst", 0, 0, "bcinst", 0, 0); plline(5, x, y); pleop(); plend(); return(0); } |
From: Oliver B. <ol...@fi...> - 2008-01-22 00:04:18
|
Zitat von Torquil Macdonald Sørensen <to...@gm...>: [...] > > I have included a test program below. The part about piping the file > into an > ofstream is not in this test program, but that has nothing to do with > the > behaviour I'm discussing. I thought that a "1.jpg" would exist after > the > program exits, but that is not the case. The file only exists until I > delete > it in the program, it is not recreated at the next plbop(): > [...] When looking into the plplot-Lib I can see, that plbop() makes a new page. It does not open a new file. When the filehandle on the output file is open, then writing to the file means you write to the same file, even if it is removed. That you remove ot only means, it is not possible to see it with ls, because the entry in the directory is removed. The file will be removed, when all filehanldes on that file will be closed. This means: You have to say plplot that it has to write to another file (new name), so that it can close the old file. As long as you do not change the filename, I assume, plplot-lib will not close the filehandle and so both "pages" will be written to the same file. The first page will be written and you can see the file with ls; the sencond page will be written to the same file, even if you think it is deleted. There will be no new file created! Hope this helps, Ciao, Oliver |
From: Oliver B. <ol...@fi...> - 2008-01-22 07:08:02
|
Zitat von Oliver Bandel <ol...@fi...>: > Zitat von Torquil Macdonald Sørensen <to...@gm...>: > [...] > > > > > I have included a test program below. The part about piping the > file > > into an > > ofstream is not in this test program, but that has nothing to do > with > > the > > behaviour I'm discussing. I thought that a "1.jpg" would exist > after > > the > > program exits, but that is not the case. The file only exists until > I > > delete > > it in the program, it is not recreated at the next plbop(): > > > [...] > > > When looking into the plplot-Lib [...] (the documentation I meant). BTW: all my suggestions were with Unix-/Linux in mind. Today I saw you are using Windows. Possibly it behaves differently, I don't know. Let us know if it works there. Ciao, Oliver |
From: Oliver B. <ol...@fi...> - 2008-01-22 00:21:19
|
Zitat von Torquil Macdonald Sørensen <to...@gm...>: > Hello, sorry to ask so many questions... I am trying to get plplot to > rewrite > the plot to the same file several times (part of my quest to write to > a pipe > into ffmpeg). In between plots (plbop().....pleop()) I delete the > file [...] When you give the outputfile the name "-" plplot-lib will write to stdout!!! You can make your executable that writes a stream to stdout and then redirect the output of your file into the fifo! $ my-stream-generator > my_fifo But at the other end of the fifo, then you maybe have to cut the stream into seperated files... ...depends on your reading process / program, if it can read plplot-lib's output directly. Ciao, Oliver |
From: Torquil M. <to...@gm...> - 2008-01-22 10:22:52
|
On Tuesday 22 January 2008, Oliver Bandel wrote: > Zitat von Torquil Macdonald S=F8rensen <to...@gm...>: > > Hello, sorry to ask so many questions... I am trying to get plplot to > > rewrite > > the plot to the same file several times (part of my quest to write to > > a pipe > > into ffmpeg). In between plots (plbop().....pleop()) I delete the > > file > > [...] > > > When you give the outputfile the name "-" > plplot-lib will write to stdout!!! > > You can make your executable that writes > a stream to stdout and then redirect the output of > your file into the fifo! > > $ my-stream-generator > my_fifo > > > But at the other end of the fifo, > then you maybe have to cut the stream into seperated files... > ...depends on your reading process / program, if it can read > plplot-lib's output directly. Hello Oliver, thanks for your suggestion and explanation about how plbop()= =20 works with the JPG-driver. I had already tried using the STDOUT instead of = an=20 ordinary file in plplot, but it didn't work to use the data that plplot wro= te=20 to stdout as input to ffmpeg. From what I could understand it was not=20 equivalent to "cat *.jpg | ffmpeg_command". I ended ut with only one frame = in=20 the ffmpeg-generated video. But I have managed to find a workaround for now (it works but is a bit=20 inefficient). I start and stop plplot between each plot page with plinit()= =20 and plend(). Between each plot I then send the newly created "file.jpg" int= o=20 an ofstream that is really a FIFO-file "fifo.mjpeg" (which is equivalent to= =20 STDOUT, but nicer, I think). Then plplot overwrites "file.jpg" when I start= =20 it up again with plinit() and changes "file.jpg" to the next plot page, and= =20 the process goes on and on sending each newly created "file.jpg" into the=20 pipe going to ffmpeg. I think the main point here is that the pipe is alway= s=20 open until the program has ended, if I understand correctly. At the same time I have a ffmpeg skript reading from the FIFO-file. That wa= y I=20 am sure that the data going into my FIFO is equivalent to doing cat *.jpg >= =20 fifo.mjpeg. I have already gotten my ffmpeg-script to work with such input.= =20 The fifo.mjpeg must be created first, of course, using "mkfifo fifo.mjpeg".= I=20 will experiment some more trying do get the STDOUT from plplot to work=20 directly with the STDIN on ffmpeg, with out using an additional ofstream in= =20 the c++ code. But at least I have now reached my goal to create a video on the fly, witho= ut=20 temporary image files, I I'm really happy about that :-) I will post my example programs here later, in case somebody is interested = in=20 doing something similar. Thanks to everone on the list that helped me with all of this! Best regards, Torquil S=F8rensen |
From: Oliver B. <ol...@fi...> - 2008-01-22 19:14:03
|
Zitat von Torquil Macdonald Sørensen <to...@gm...>: > On Tuesday 22 January 2008, Oliver Bandel wrote: > > Zitat von Torquil Macdonald Sørensen <to...@gm...>: > > > Hello, sorry to ask so many questions... I am trying to get > plplot to > > > rewrite > > > the plot to the same file several times (part of my quest to > write to > > > a pipe > > > into ffmpeg). In between plots (plbop().....pleop()) I delete the > > > file > > > > [...] > > > > > > When you give the outputfile the name "-" > > plplot-lib will write to stdout!!! > > > > You can make your executable that writes > > a stream to stdout and then redirect the output of > > your file into the fifo! > > > > $ my-stream-generator > my_fifo > > > > > > But at the other end of the fifo, > > then you maybe have to cut the stream into seperated files... > > ...depends on your reading process / program, if it can read > > plplot-lib's output directly. > > Hello Oliver, thanks for your suggestion and explanation about how > plbop() > works with the JPG-driver. I had already tried using the STDOUT > instead of an > ordinary file in plplot, but it didn't work to use the data that > plplot wrote > to stdout as input to ffmpeg. From what I could understand it was not > equivalent to "cat *.jpg | ffmpeg_command". I ended ut with only one > frame in > the ffmpeg-generated video. > > But I have managed to find a workaround for now (it works but is a > bit > inefficient). I start and stop plplot between each plot page with > plinit() > and plend(). Between each plot I then send the newly created > "file.jpg" into > an ofstream that is really a FIFO-file "fifo.mjpeg" (which is > equivalent to > STDOUT, but nicer, I think). [...] Yes, sending the data directly to the FIFO makes sense. I think that is the best way to do it. I should have had that idea, and earlier also. ;-) Ciao, Oliver |