Author Topic: Amcrest camera image rename and move php script? Help please.  (Read 600 times)

0 Members and 1 Guest are viewing this topic.

Offline tripper22

  • Member
  • *
  • Posts: 25
Re: Amcrest camera image rename and move php script? Help please.
« Reply #25 on: November 13, 2017, 04:50:12 PM »
Maybe a for loop that would look for every hour (0-23) and nested loop for each hour (0-59) and then get the folder content via the glob function and then save them all in an array, sort it and find the latest. Then delete the files, though this is even trickier because PHP cannot delete a folder unless it is empty, so you would need to delete the individual files, then delete the "minute" folder, once it is empty, delete the "hour" folder

Thanks Jachym. If the files can't be deleted automatically that's okay. I could delete them manually every week.

Offline SteveFitz1

  • Forecaster
  • *****
  • Posts: 308
    • http://www.TylerTexasWeather.Com
Re: Amcrest camera image rename and move php script? Help please.
« Reply #26 on: November 13, 2017, 04:59:15 PM »
Thanks Steve. The camera is in a remote location that won't allow for a windows box unfortunately.

It doesn't have to be Windows. You would simply need to write a small script that used CURL (available on multiple platforms) to get the current image and you can save it by any name. Within that same script you could FTP that image whose name you know directly to your host.

Steve

Online bchwdlks

  • Senior Member
  • **
  • Posts: 76
Re: Amcrest camera image rename and move php script? Help please.
« Reply #27 on: November 13, 2017, 05:00:50 PM »
Can you put another ip device at your remote location ? If so you have an easy fix:

  • put a raspberry pi on the remote network
  • collect the images from the camera on the raspberry
  • watch the image directory on the raspberry with inotifywait
  • when it sees a new image let the raspberry ftp it to your web server with any name that works

Thanks bch. I was hoping I wouldn't have to go out there. It's a long way. It's possible. I have an older Raspberry Pi lying around. Is there a tutorial that you know of that I can use?

tripper22

I do not have a tutorial but this script is what I am using in a similar situation. Every 4th file added to the /home/pi/ButterflyCam directory causes a buzzer to sound. In your situation I believe you could do a 'mv $file NEWNAME' and follow that with a ftp to the server that you want the file to go to.

        inotifywait -m -e CLOSE_WRITE /home/pi/ButterflyCam/ | while read path action file
          do
                        echo "'$file' @ [`date +%Y/%m/%d\ %H:%M:%S`]"
                        case $PLAY in
                        4 )

                                SOUND=/home/pi/Music/buzzthruloud.wav
                                echo "$SOUND"
                                aplay $SOUND

                                PLAY=1
                                ;;
                        * )
                                echo "NO SOUND"
                                PLAY=`expr ${PLAY} + 1`
                                ;;
                        esac
          done

Offline tripper22

  • Member
  • *
  • Posts: 25
Re: Amcrest camera image rename and move php script? Help please.
« Reply #28 on: November 13, 2017, 05:17:34 PM »
Thanks Steve. The camera is in a remote location that won't allow for a windows box unfortunately.

It doesn't have to be Windows. You would simply need to write a small script that used CURL (available on multiple platforms) to get the current image and you can save it by any name. Within that same script you could FTP that image whose name you know directly to your host.

Steve

I guess it could be done with a Raspberry Pi like bchwdlks suggested. I would have to get the Raspberry Pi to capture an image with a static filename every x minutes then upload it to the server every 10 minutes. I have to admit I was hoping for something easier lol.
« Last Edit: November 13, 2017, 05:30:03 PM by tripper22 »

Offline Jáchym

  • Meteotemplate Developer
  • Forecaster
  • *****
  • Posts: 8531
    • Meteotemplate
Re: Amcrest camera image rename and move php script? Help please.
« Reply #29 on: November 13, 2017, 05:37:32 PM »
Theoretically.... but I cant really tell because I dont know the exact structure of your server

$images = array();
for($i=0;$i<24;$i++){
    for($j=0;$j<60;$j++){
         if(file_exists("/webcam/AMC000X5_3R286G/".date("Y-m-d")."/001/jpg/".$i."/".$j."/01[R][0@0][0].jpg")){
               $images[] = "/webcam/AMC000X5_3R286G/".date("Y-m-d")."/001/jpg/".$i."/".$j."/01[R][0@0][0].jpg";
         }
    }
}

rsort($images);
file_put_contents("/webcam/image.jpg", file_get_contents($images[0]));



This should theoretically find the latest image and save it in webcam as "image.jpg", but I have no way to test this. Also I have no idea if the day and month in the date uses leading zero, which is crucial

Offline tripper22

  • Member
  • *
  • Posts: 25
Re: Amcrest camera image rename and move php script? Help please.
« Reply #30 on: November 13, 2017, 06:03:11 PM »
Theoretically.... but I cant really tell because I dont know the exact structure of your server

$images = array();
for($i=0;$i<24;$i++){
    for($j=0;$j<60;$j++){
         if(file_exists("/webcam/AMC000X5_3R286G/".date("Y-m-d")."/001/jpg/".$i."/".$j."/01[R][0@0][0].jpg")){
               $images[] = "/webcam/AMC000X5_3R286G/".date("Y-m-d")."/001/jpg/".$i."/".$j."/01[R][0@0][0].jpg";
         }
    }
}

rsort($images);
file_put_contents("/webcam/image.jpg", file_get_contents($images[0]));



This should theoretically find the latest image and save it in webcam as "image.jpg", but I have no way to test this. Also I have no idea if the day and month in the date uses leading zero, which is crucial

Thanks very much Jachym. I am happy to test it. What needs to be done so that I can upload and run it?

Offline tripper22

  • Member
  • *
  • Posts: 25
Re: Amcrest camera image rename and move php script? Help please.
« Reply #31 on: November 13, 2017, 06:18:18 PM »
Theoretically.... but I cant really tell because I dont know the exact structure of your server

$images = array();
for($i=0;$i<24;$i++){
    for($j=0;$j<60;$j++){
         if(file_exists("/webcam/AMC000X5_3R286G/".date("Y-m-d")."/001/jpg/".$i."/".$j."/01[R][0@0][0].jpg")){
               $images[] = "/webcam/AMC000X5_3R286G/".date("Y-m-d")."/001/jpg/".$i."/".$j."/01[R][0@0][0].jpg";
         }
    }
}

rsort($images);
file_put_contents("/webcam/image.jpg", file_get_contents($images[0]));



This should theoretically find the latest image and save it in webcam as "image.jpg", but I have no way to test this. Also I have no idea if the day and month in the date uses leading zero, which is crucial

Thanks very much Jachym. I am happy to test it. What needs to be done so that I can upload and run it?

I think I figured it out. I placed it in the webcam folder. This is what I get

Warning: file_get_contents(): Filename cannot be empty in /home/content/45/3170445/html/krb/wp-content/uploads/webcam/jach.php on line 12

Warning: file_put_contents(/webcam/image.jpg): failed to open stream: No such file or directory in /home/content/45/3170445/html/krb/wp-content/uploads/webcam/jach.php on line 12

Offline Jáchym

  • Meteotemplate Developer
  • Forecaster
  • *****
  • Posts: 8531
    • Meteotemplate
Re: Amcrest camera image rename and move php script? Help please.
« Reply #32 on: November 13, 2017, 06:20:59 PM »
OK, that means it did not find any images, which would suggest the path is incorrect, this could be for example down to the leading zeros, because "01" and "1" makes a difference

Offline tripper22

  • Member
  • *
  • Posts: 25
Re: Amcrest camera image rename and move php script? Help please.
« Reply #33 on: November 13, 2017, 06:26:42 PM »
OK, that means it did not find any images, which would suggest the path is incorrect, this could be for example down to the leading zeros, because "01" and "1" makes a difference

My root folder is the webcam folder. The AMC000X5_3R286G folder is the only folder in there with the file structure we discussed earlier if that helps you.

Offline tripper22

  • Member
  • *
  • Posts: 25
Re: Amcrest camera image rename and move php script? Help please.
« Reply #34 on: November 13, 2017, 06:37:06 PM »
OK, that means it did not find any images, which would suggest the path is incorrect, this could be for example down to the leading zeros, because "01" and "1" makes a difference

My root folder is the webcam folder. The AMC000X5_3R286G folder is the only folder in there with the file structure we discussed earlier if that helps you.

I changed where to look for the folder and where to write the image.jpg. When it's run an empty image.jpg file is created in the root of webcam and I get the following error.

Warning: file_get_contents(): Filename cannot be empty in /home/content/45/3170445/html/krb/wp-content/uploads/webcam/jach.php on line 12

With my changes:

Code: [Select]
<?php
$images 
= array();
for(
$i=0;$i<24;$i++){
    for(
$j=0;$j<60;$j++){
         if(
file_exists("./AMC000X5_3R286G/".date("Y-m-d")."/001/jpg/".$i."/".$j."/01[R][0@0][0].jpg")){
               
$images[] = "./AMC000X5_3R286G/".date("Y-m-d")."/001/jpg/".$i."/".$j."/01[R][0@0][0].jpg";
         }
    }
}

rsort($images);
file_put_contents("./image.jpg"file_get_contents($images[0]));
?>

Offline Jáchym

  • Meteotemplate Developer
  • Forecaster
  • *****
  • Posts: 8531
    • Meteotemplate
Re: Amcrest camera image rename and move php script? Help please.
« Reply #35 on: November 13, 2017, 06:44:24 PM »
Yes, still the same problem it didnt find any image in the folders, so there is some problem in the path to the files, as I said, it could be leading zeros or the name of the file is a bit different. You could add an echo there that would show you the image it is looking for

$images = array();
for($i=0;$i<24;$i++){
    for($j=0;$j<60;$j++){
         echo "./AMC000X5_3R286G/".date("Y-m-d")."/001/jpg/".$i."/".$j."/01[R][0@0][0].jpg<br>";
         if(file_exists("./AMC000X5_3R286G/".date("Y-m-d")."/001/jpg/".$i."/".$j."/01[R][0@0][0].jpg")){
               $images[] = "./AMC000X5_3R286G/".date("Y-m-d")."/001/jpg/".$i."/".$j."/01[R][0@0][0].jpg";
         }
    }
}

Offline tripper22

  • Member
  • *
  • Posts: 25
Re: Amcrest camera image rename and move php script? Help please.
« Reply #36 on: November 13, 2017, 07:15:12 PM »
Yes, still the same problem it didnt find any image in the folders, so there is some problem in the path to the files, as I said, it could be leading zeros or the name of the file is a bit different. You could add an echo there that would show you the image it is looking for

$images = array();
for($i=0;$i<24;$i++){
    for($j=0;$j<60;$j++){
         echo "./AMC000X5_3R286G/".date("Y-m-d")."/001/jpg/".$i."/".$j."/01[R][0@0][0].jpg<br>";
         if(file_exists("./AMC000X5_3R286G/".date("Y-m-d")."/001/jpg/".$i."/".$j."/01[R][0@0][0].jpg")){
               $images[] = "./AMC000X5_3R286G/".date("Y-m-d")."/001/jpg/".$i."/".$j."/01[R][0@0][0].jpg";
         }
    }
}

Bad news. The file name has changed so I changed it in the script 02[R][0@0][0].jpg So the file name will change. If there was a way to just grab the newest jpg though...

This what I get:

./AMC000X5_3R286G/2017-11-13/001/jpg/0/0/02[R][0@0][0].jpg
./AMC000X5_3R286G/2017-11-13/001/jpg/0/1/02[R][0@0][0].jpg
./AMC000X5_3R286G/2017-11-13/001/jpg/0/2/02[R][0@0][0].jpg
./AMC000X5_3R286G/2017-11-13/001/jpg/0/3/02[R][0@0][0].jpg
Etc.

I changed the script to reflect the filename change and I still get this error.

Warning: file_get_contents(): Filename cannot be empty in /home/content/45/3170445/html/krb/wp-content/uploads/webcam/jach.php on line 12

I really appreciate all of your help Jachym but maybe this is getting to be a bit ridiculous.  ](*,)

Offline Jáchym

  • Meteotemplate Developer
  • Forecaster
  • *****
  • Posts: 8531
    • Meteotemplate
Re: Amcrest camera image rename and move php script? Help please.
« Reply #37 on: November 13, 2017, 07:30:38 PM »
Right, well Im afraid if even this already complicated file name is not final, there is not much you can do, the naming of the file by your webcam is almost unbelievable, I mean 01[R][0@0][0].jpg   ](*,)

Offline tripper22

  • Member
  • *
  • Posts: 25
Re: Amcrest camera image rename and move php script? Help please.
« Reply #38 on: November 13, 2017, 07:34:16 PM »
Right, well Im afraid if even this already complicated file name is not final, there is not much you can do, the naming of the file by your webcam is almost unbelievable, I mean 01[R][0@0][0].jpg   ](*,)

Well I thank you very sincerely for all of your time and effort. I give up. I'm going to purchase another camera. Does anyone have any recommendations?
« Last Edit: November 14, 2017, 12:05:08 AM by tripper22 »

Offline tripper22

  • Member
  • *
  • Posts: 25
Re: Amcrest camera image rename and move php script? Help please.
« Reply #39 on: November 14, 2017, 12:04:02 AM »
Can you pull a image directly from the camera:
http://[ip]/cgi-bin/snapshot.cgi?loginuse=[USERNAME]&loginpas=[PASSWORD]

Remove [] and insert info.

?

Hey droid. I was able to capture a snapshot of the image using the information you provided above.

I have decided to continue with this adventure after doing some more research and it appears that a Raspberry Pi will be the best solution. I was able to borrow the exact same camera for testing. I have an RP3 ready to go. I have some basic knowledge of how the Raspberry Pi's work and how to install software. But obviously nothing about scripts lol.

Offline tripper22

  • Member
  • *
  • Posts: 25
Re: Amcrest camera image rename and move php script? Help please.
« Reply #40 on: November 14, 2017, 12:10:41 AM »
Can you put another ip device at your remote location ? If so you have an easy fix:

  • put a raspberry pi on the remote network
  • collect the images from the camera on the raspberry
  • watch the image directory on the raspberry with inotifywait
  • when it sees a new image let the raspberry ftp it to your web server with any name that works

Thanks bch. I was hoping I wouldn't have to go out there. It's a long way. It's possible. I have an older Raspberry Pi lying around. Is there a tutorial that you know of that I can use?

tripper22

I do not have a tutorial but this script is what I am using in a similar situation. Every 4th file added to the /home/pi/ButterflyCam directory causes a buzzer to sound. In your situation I believe you could do a 'mv $file NEWNAME' and follow that with a ftp to the server that you want the file to go to.

        inotifywait -m -e CLOSE_WRITE /home/pi/ButterflyCam/ | while read path action file
          do
                        echo "'$file' @ [`date +%Y/%m/%d\ %H:%M:%S`]"
                        case $PLAY in
                        4 )

                                SOUND=/home/pi/Music/buzzthruloud.wav
                                echo "$SOUND"
                                aplay $SOUND

                                PLAY=1
                                ;;
                        * )
                                echo "NO SOUND"
                                PLAY=`expr ${PLAY} + 1`
                                ;;
                        esac
          done

Bch I have decided to go the Raspberry Pi route. I have a borrowed camera and everything I need to build and test it at home before driving out and installing it. Thanks.

Offline droiddk

  • Senior Contributor
  • ****
  • Posts: 215
Re: Amcrest camera image rename and move php script? Help please.
« Reply #41 on: November 14, 2017, 03:32:32 AM »

Hey droid. I was able to capture a snapshot of the image using the information you provided above.


Ok, can you post the url (hide the sensitive data)? It needs to end with .jpg or .png

Maybe you can get the image by the url and save it with another filename, using PHP, something like this:

<?php

  $input = 'http://www.ip.com/.xx.png';
  $output = 'image.jpg';

  if (file_put_contents($output, file_get_contents($input))) {

    echo " Get Succes $output";

  }

?>

Regards

Offline tripper22

  • Member
  • *
  • Posts: 25
Re: Amcrest camera image rename and move php script? Help please.
« Reply #42 on: November 14, 2017, 01:51:25 PM »

Hey droid. I was able to capture a snapshot of the image using the information you provided above.


Ok, can you post the url (hide the sensitive data)? It needs to end with .jpg or .png

Maybe you can get the image by the url and save it with another filename, using PHP, something like this:

<?php

  $input = 'http://www.ip.com/.xx.png';
  $output = 'image.jpg';

  if (file_put_contents($output, file_get_contents($input))) {

    echo " Get Succes $output";

  }

?>

Regards

Thanks for the help droid. How do I do this test with a windows machine?

Offline droiddk

  • Senior Contributor
  • ****
  • Posts: 215
Re: Amcrest camera image rename and move php script? Help please.
« Reply #43 on: November 14, 2017, 02:17:22 PM »
Can you post the url (hide the sensitive data)? It needs to end with .jpg or .png

Regards

Offline tripper22

  • Member
  • *
  • Posts: 25
Re: Amcrest camera image rename and move php script? Help please.
« Reply #44 on: November 14, 2017, 02:25:42 PM »
It's an internal ip. I'm testing this at home with a borrowed camera. Sorry I guess i'm not understanding you.

Offline droiddk

  • Senior Contributor
  • ****
  • Posts: 215
Re: Amcrest camera image rename and move php script? Help please.
« Reply #45 on: November 14, 2017, 02:27:01 PM »
Ok. Then it wont work. Has to be able to show image from there camera you want to show image from.

Regards

 

anything