Sign in to follow this  
Followers 0
frank10

loop problem

8 posts in this topic

#1 ·  Posted (edited)

I am writing a video file to HD from a live stream using VideoLan.

I'm tryng to check the filesize of the file that is written on the HD in a while loop, to exit the loop if the file isn't writing anymore.

I do:

$file = FileOpen("Y:\log_capture.txt", 1)

; Check if file opened for writing OK
If $file = -1 Then
    MsgBox(0, "Error", "Unable to open file.")
    Exit
EndIf

_VLC();;;;;;; this is a function that initializes VideoLan

While 1
    $fileSize = FileGetSize("Y:\capture.asf")
    Sleep('3000')

     ;I display in the console and save in a file log, the filesize before and after, :

    ConsoleWrite($fileSize & @CR)
    FileWrite($file, $fileSize & @CRLF)
    
    $fileSize1 = FileGetSize("Y:\capture.asf")
    
    If $fileSize = $fileSize1 Then

        FileWrite($file, $fileSize1 & @CRLF & @CRLF)
        ConsoleWrite($fileSize1 & @CR & @CR)
        
;;;;;;;;;;  do some other code if filesize isn't greater than before: it has stopped recording

    EndIf
    
WEnd

I have two problems with this code:

1) sometimes the filesize returned from the fileGetSize is equal to the precedent call of the func BUT the real filesize isn't: it's recording so the second call should give greater result from the preceding.

2) I get the values on the console, BUT I can't save them in the log..

I don't really know what is wrong with this code??

Thanks in advance for your help.

Edited by frank10

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

I't may be that the file writing from video lan writes to a handle and doesn't 'close' the file until its done. This can have a adverse affect on the file size. Not to much you could do about it in this case...

Edited by evilertoaster

Share this post


Link to post
Share on other sites

I simplified the while loop to test the problem and I found this strange behaviour:

Global $file = FileOpen("Y:\log_capture.txt", 1)

; Check if file opened for writing OK
If $file = -1 Then
    MsgBox(0, "Error", "Unable to open file.")
    Exit
EndIf

$i = 0


;  this works:   

While $i <> 100
    
    Sleep('100')

    FileWrite($file, $i & @CRLF)
    
    $i += 1
WEnd

while if I write an endless loop like this:

;   this doesn't work:
While 1
    
    Sleep('100')

    FileWrite($file, $i & @CRLF)
    
    $i += 1
WEnd

the latter create the file on the HD but is always empty.

What can it be? I'm using 3.1.1.118

Share this post


Link to post
Share on other sites

You often have to close your file with FileClose() before the data is written...

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

I't may be that the file writing from video lan writes to a handle and doesn't 'close' the file until its done. This can have a adverse affect on the file size. Not to much you could do about it in this case...

I don't think it's a VLC problem because I can play that file with another istance of VLC, while it's in recording mode.

And if I refresh Explorer to see the filesize I can see every second the filesize incfreases.

Finally it must be something in autoit, like I described in my previous post.

Anyway thank you for the suggestion.

EDIT: we were writing together, so I will try your suggestion.

Edited by frank10

Share this post


Link to post
Share on other sites

Yes you were right. :D

I closed the file at some point and I could read it.

This solves the fileWrite issue.

But I introduced it to check why the fileGetSize doesn't update correctly.

So I'm at the start point.

Now I'm rethinking at your suggestion of VLC 'locking' the file while writing, but sometimes the reading is correct... And Explorer can also show the correct filesize... Why autoit can't?

Maybe making two reading at different time before deciding if VLC isn't writing anymore?

Or checking the drive space left?

Share this post


Link to post
Share on other sites

I think there was just a post here today or yesterday about finding out if a file was still in use. I recomended there using FileOpen() and seeing if it failed(becuase if it did it's in use) but i think w0uter had a btter way... check http://www.autoitscript.com/forum/index.php?showtopic=27930

Share this post


Link to post
Share on other sites

It's not 'used' because with FileOpen I don't get any error.

It seems to happen some random problem in the fileGetSize that lasts about 10sec, then it starts again correctly.

So, at the moment I used a greater range of seconds between the size checks. 2sec at first and 3sec the next.

This seems to work quite good now.

The point is I want to check if VLC stops recording because if I don't check, it restarts, after about 2min, to write over the previous file and I loose the first clip.

So filesize check is a good test.

Maybe another better approach could be to see the net (wan) traffic: if it stops there are problems. I don't know how to intercept this traffic in Autoit.

Any idea?

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0