Skip to main content
December 2, 2008
Question

recorded a stream, but can't rename the resulting flv

  • December 2, 2008
  • 6 replies
  • 2005 views
I have a simple server-side app that creates a Stream, creates a NetConnection, and then plays a live stream from that NetConnection. I record the resulting stream into a file, say "recordstream.flv"

When I get an UnpublishNotify, I stop recording. When I see NetStream.Record.Stop, I create a File object that points to recordstream.flv, and try to rename it to a different filename with File.renameTo().

This worked in FMS2, but not in FMS3. In FMS3, I get an error that the renameTo() failed. Interestingly, copyTo() the same new filename works, so it is not a directory protection issue or something like that. It appears that FMS3 is forbidding me from fiddling with the file; File.canRead returns false on the file. Is there any way to get FMS3 to release the file? Or should I give up and just use copyTo()?
    This topic has been closed for replies.

    6 replies

    December 18, 2008
    I see what you are saying. By the way, I was testing with FMS 2.0.5 and FMS 3.0.something.

    The reason I expected renameTo() to work like copyTo() is a Unix expectation. In fact it works more like Windows:

    On Unix/Linux:

    $ mkdir d
    $ touch d/foo.txt
    $ mv d/foo.txt d/bar.txt # works

    But on Windows:

    C:\> mkdir d
    C:\> edit d\foo.txt
    C:\> rename d\foo.txt d\bar.txt # doesn't work
    The syntax of the command is incorrect.
    C:\> rename d\foo.txt bar.txt # works, renames in d\

    The documentation of the two functions is almost identical in the FMS doc. So perhaps this is a caveat to add to the doc. In any case, thank you.
    December 17, 2008
    osipls,

    Sorry for the delay in replying. Here are three versions of an extremely simple program:

    //RELPATH
    application.onAppStart = function() {
    var file = new File("myfile"); // top level dir
    file.open("text","create");
    file.close();
    file.copyTo("myfile.copy");
    file.renameTo("myfile.renamed");
    }

    //RELPATHWITHDIR
    application.onAppStart = function() {
    var file = new File("mydir/myfile"); // in subdir, with relative path
    file.open("text","create");
    file.close();
    file.copyTo("mydir/myfile.copy");
    file.renameTo("mydir/myfile.renamed");
    }

    //ABSPATHWITHDIR
    application.onAppStart = function() {
    var file = new File("/mydir/myfile"); // in subdir, with absolute path
    file.open("text","create");
    file.close();
    file.copyTo("/mydir/myfile.copy");
    file.renameTo("/mydir/myfile.renamed");
    }


    On FMS2, all three work: RELPATH, RELPATHWITHDIR, and ABSPATHWITHDIR.

    On FMS3, RELPATH and ABSPATHWITHDIR wors. But in RELPATHWITHDIR, the copyTo() works, but the renameTo() fails.

    So I find it odd that copyTo() will handle the relative pathname, but renameTo() does not. I would expect them to work (or not) consistently. It's also weird that RELPATH works, but not the quite similar RELPATHWITHDIR.


    [Of course, mydir must have proper ownership/protection so you can write into it.]
    Participating Frequently
    December 18, 2008
    Hello,

    Well, I checked FMS 2.5 and 3.0 and behavior absolutely identical on Linux as well as Window.

    As you pointed in your script
    //RELPATHWITHDIR
    application.onAppStart = function() {
    var file = new File("mydir/myfile"); // in subdir, with relative path
    file.open("text","create");
    file.close();
    file.copyTo("mydir/myfile.copy");
    file.renameTo("mydir/myfile.renamed");
    }

    //ABSPATHWITHDIR
    application.onAppStart = function() {
    var file = new File("/mydir/myfile"); // in subdir, with absolute path
    file.open("text","create");
    file.close();
    file.copyTo("/mydir/myfile.copy");
    file.renameTo("/mydir/myfile.renamed");
    }

    that ABSPATHWITHDIR works for you but RELPATHWITHDIR does not. That is also true, but as I mentioned before

    in ABSPATHWITHDIR
    file.copyTo("/mydir/myfile.copy");
    file.renameTo("/mydir/myfile.renamed");

    They both having leading /. In this case under your app/mydir you could find
    app/mydir/ myfile.renamed //myfile renamed to myfile.renamed in same directory!
    app/mydir/ myfile.copy

    in RELPATHWITHDIR
    file.copyTo("mydir/myfile.copy");
    file.renameTo("mydir/myfile.renamed");

    They both do not have leading /.
    In this case file.copyTo works as before and you could find myfile.copy in app/mydir
    But file.renameTo works differently and failed since app/mydir/mydir does not exisit and renameTo failed. If you create extra subdirectory app/mydir/mydir rename to will succeeded and you could find

    app/mydir/ myfile.copy
    app/mydir/mydir/ myfile.renamed

    So that means file.copyTo works always same manner but
    file.renameTo is sensitive to leading / and by that you could control behavior which is protecting you from renaming same file if you purposely do not specify / in front.

    Conclusion is: you could not expect same behavior from file.renameTo and file.copyTo since they are 2 different functions!

    Thanks
    December 10, 2008
    Sorry, I was simplifying and sanitizing my sample program and made some typos. I did not actually run the exact code above. I meant something like:

    ...
    else if (info.code == "NetStream.Record.Stop") {
    // application.ns.record(false) has done its work.
    var file = new File("streams/_definst_/recordstream.flv");
    trace("file.canRead: " + file.canRead);
    trace("file.exists: " + file.exists);

    var filename = "streams/_definst_/renamed.flv";
    // file.copyTo(filename); // Works on FMS2 and FMS3
    file.renameTo(filename); // Works on FMS2, gets "renameTo failed" on FMS3

    I know the file is there because file.exists returns true.
    Participating Frequently
    December 10, 2008
    Thanks for your reply.
    It does not matter what instance you are using. I also have same script as you using _definst_ instead. And I verified your scenario it works well if var filename = "/streams/_definst_/renamed.flv"; - there is leading / compare to yours. In this case you rename file sitting in same directory from recordstream.flv to renamed.flv. For instance my directory in this case is streams/_definst_
    If leading / is missing in your script var filename = "streams/_definst_/renamed.flv" it his case
    is streams/_definst_/ recordstream.flv will be renamed to streams/_definst_/ streams/_definst_/ renamed.flv and if directory streams/_definst_/ streams/_definst_/ not exist renameTo will fail. Please confirm.
    Thanks
    Participating Frequently
    December 18, 2008
    Thanks for reply and details. I will try to reproduce this issue and will get back to you.
    December 8, 2008
    Btw what is the build number for FMS and can you give the version (major and minor version) too.
    December 8, 2008
    quote:

    Originally posted by: mohammep
    Btw what is the build number for FMS and can you give the version (major and minor version) too.

    It is FMS_3_0_1_R123, unpacked from the latest Development Server build a few days ago, running on Scientific Linux 4.2 i686 (RHEL 4 clone).

    December 9, 2008
    Hi Dhalbert,

    Thanks for the prompt response. Do you have a script handy which we can use to repro the bug ? It would help to havethe script you are using or a code snippet thereof which we can use to repro the bug.

    thanks,
    Mo

    December 8, 2008
    It seems that this might be a bug in FMS, which will need further investigation. I have filled a bug detailing what you explained. That way we can have resources allocated to it. The bug number for our internal bug database is : 1935018.
    December 5, 2008
    Hi,

    What platform are you running on ? If the platform is Windows, then this is most probably happening because Windows thinks that the file is still open under FMS. What happens if you wait for a while before trying to rename the file. Does that work ?

    You can also verify whehter Windows thinks that FMS still has the file open by trying the following :
    1) If you haven't got it installed yet, install process explorer. You can find it at :
    http://technet.microsoft.com/en-us/sysinternals/bb896653.aspx
    2) Search for your file name. Process explorer will tell you which process is still using the file.

    thanks,
    Mo



    quote:

    Originally posted by: dhalbert
    I have a simple server-side app that creates a Stream, creates a NetConnection, and then plays a live stream from that NetConnection. I record the resulting stream into a file, say "recordstream.flv"

    When I get an UnpublishNotify, I stop recording. When I see NetStream.Record.Stop, I create a File object that points to recordstream.flv, and try to rename it to a different filename with File.renameTo().

    This worked in FMS2, but not in FMS3. In FMS3, I get an error that the renameTo() failed. Interestingly, copyTo() the same new filename works, so it is not a directory protection issue or something like that. It appears that FMS3 is forbidding me from fiddling with the file; File.canRead returns false on the file. Is there any way to get FMS3 to release the file? Or should I give up and just use copyTo()?


    December 5, 2008
    quote:

    What platform are you running on ?
    Thanks for the reply. No, it's Linux, so that's why I found it so odd. It seems that File.renameTo() is making some extra check about the file being associated with a stream. Normally a rename should be just fine.

    I have since restructured my code so that the problem is moot, but still, it's an open question.