recording with ffmpeg not working  [Solved]

Easy to use, 100% Lua-based event scripting framework.

Moderator: leecollings

Post Reply
savage007
Posts: 19
Joined: Sunday 13 September 2015 20:24
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

recording with ffmpeg not working

Post by savage007 »

Hi, this script is not working, i get zero results, but when i put the command ls instead of ffmpeg.... i get the directory listing in domoticz log.

The ffmpeg command works at the commandline. I had to put in an escape \\ for the ! In my password.

I also tried another command, “rm ~/abc.avi” , this also didnt work.


Does anybody now how i can fix this?

This is the log with command "ls"

Code: Select all

2019-09-18 18:43:13.581 Status: User: Admin initiated a switch command (68/Alarm signaal/On)
2019-09-18 18:43:13.601 Status: dzVents: Info: Handling events for: "Alarm signaal", value: "Locked"
2019-09-18 18:43:13.601 Status: dzVents: Info: ------ Start internal script: Script #1: Device: "Alarm signaal (Dummy)", Index: 68
2019-09-18 18:43:13.604 Status: dzVents: backups
2019-09-18 18:43:13.604 Config
2019-09-18 18:43:13.604 domoticz
2019-09-18 18:43:13.604 domoticz_crash.log
2019-09-18 18:43:13.604 domoticz.db
2019-09-18 18:43:13.604 domoticz.db-shm
2019-09-18 18:43:13.604 domoticz.db-wal
2019-09-18 18:43:13.604 domoticz.sh
2019-09-18 18:43:13.604 dzVents
2019-09-18 18:43:13.604 History.txt
2019-09-18 18:43:13.604 License.txt
2019-09-18 18:43:13.604 plex
2019-09-18 18:43:13.604 plugins
2019-09-18 18:43:13.604 scripts
2019-09-18 18:43:13.604 server_cert.pem
2019-09-18 18:43:13.604 updatebeta
2019-09-18 18:43:13.604 updaterelease
2019-09-18 18:43:13.604 www
2019-09-18 18:43:13.604
2019-09-18 18:43:13.604 Status: dzVents: Info: Alarm Alarm signaal is afgegaan
2019-09-18 18:43:13.604 Status: dzVents: Info: ------ Finished Script #1

Code: Select all

return {
	on = {
		devices = {
			'Alarm signaal'
		}
	},
	execute = function(domoticz, device)
		cmd="ffmpeg -i rtsp://user:abc000\\[email protected]:88/videoMain -t 10 -acodec copy -vcodec copy abc.avi"
        local f = assert(io.popen(cmd, 'r'))
        s = assert(f:read('*a'))
        f:close()
        print(s)
		
		domoticz.log('Alarm ' .. device.name .. ' is afgegaan', domoticz.LOG_INFO)
	end
}
Here's the log with the ffmpeg command :

Code: Select all

2019-09-18 16:25:55.371 (Dummy) Lighting 1 (Alarm signaal)
2019-09-18 16:25:55.367 Status: User: Admin initiated a switch command (68/Alarm signaal/Off)
2019-09-18 16:25:55.388 Status: dzVents: Info: Handling events for: "Alarm signaal", value: "Unlocked"
2019-09-18 16:25:55.388 Status: dzVents: Info: ------ Start internal script: Script #1: Device: "Alarm signaal (Dummy)", Index: 68
2019-09-18 16:25:58.245 Status: dzVents:
2019-09-18 16:25:58.245 Status: dzVents: Info: Alarm Alarm signaal is afgegaan
2019-09-18 16:25:58.245 Status: dzVents: Info: ------ Finished Script #1
Last edited by savage007 on Wednesday 18 September 2019 18:48, edited 2 times in total.
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: recording with ffmpeg not working

Post by waaren »

savage007 wrote: Wednesday 18 September 2019 16:23 Hi, this script is not working, i get zero results, but when i put the command ls instead of ffmpeg
The ffmpeg command works at the commandline. I had to put in an escape \\ for the ! In my password.
I also tried another command, “rm ~/abc.avi” , this also didnt work.
Does anybody now how i can fix this?
Can you try this ? Explanation in script comments.
[EDIT] removed left behind echo command :oops:

Code: Select all

return {
    on = {
        devices = {
            'Alarm signaal'
        }
    },
    execute = function(dz, item )
        
        local scriptLog  = (_G.scriptsFolderPath):gsub('/scripts/dzVents/scripts','') .. '/scripts/dzVents/data/' .. 'ffmpeg.log' 
        
        local function popen(cmd)
            local f = assert(io.popen(cmd, 'r'))
            local s = assert(f:read('*a'))
            f:close()
            return s
        end
        
        -- original => potential problems:  other user, will block eventsystem for 10 seconds, \\ not escaped  
        -- cmd="ffmpeg -i rtsp://user:abc000\\[email protected]:88/videoMain -t 10 -acodec copy -vcodec copy abc.avi"  
           
        -- modified => use sudo to execute command, add a & to execute in background, escape \\ 
        ffmpeg_cmd=[[ sudo ffmpeg -i rtsp://user:abc000\\\\[email protected]:88/videoMain -t 10 -acodec copy -vcodec copy abc.avi & ]] 
        
        -- extra command to show in ffmpeg.log what the command will look like 
        echo_cmd=[[ sudo echo ffmpeg -i rtsp://user:abc000\\\\[email protected]:88/videoMain -t 10 -acodec copy -vcodec copy abc.avi > ]] .. scriptLog .. '&'

        dz.log('return from echo command: ' .. popen(echo_cmd) .. '\tCheck content of ' .. scriptLog, dz.LOG_FORCE)
        dz.log('return from ffmpeg command: ' .. popen(ffmpeg_cmd), dz.LOG_FORCE)
        
        dz.log('Alarm ' .. item.name .. ' is afgegaan', dz.LOG_FORCE)

    end
}
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
savage007
Posts: 19
Joined: Sunday 13 September 2015 20:24
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: recording with ffmpeg not working

Post by savage007 »

Here is the output from your script :
2019-09-19 08:44:16.920 Status: User: Admin initiated a switch command (68/Alarm signaal/On)
2019-09-19 08:44:16.939 Status: dzVents: Info: Handling events for: "Alarm signaal", value: "Locked"
2019-09-19 08:44:16.939 Status: dzVents: Info: ------ Start internal script: Script #1: Device: "Alarm signaal (Dummy)", Index: 68
2019-09-19 08:44:16.941 Status: dzVents: !Info: return from echo command: Check content of /home/edwin/domoticz/scripts/dzVents/data/ffmpeg.log
2019-09-19 08:44:16.952 Status: dzVents: !Info: return from ffmpeg command: ffmpeg -i rtsp://edwin:Efooes369\[email protected]:88/videoMain -t 10 -acodec copy -vcodec copy abc.avi
2019-09-19 08:44:16.952
2019-09-19 08:44:16.952 Status: dzVents: !Info: Alarm Alarm signaal is afgegaan
2019-09-19 08:44:16.952 Status: dzVents: Info: ------ Finished Script #1

As you can see the output is empty( i highlighted the time stamp ).

The escaping is alright now, i have checked this.
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: recording with ffmpeg not working

Post by waaren »

savage007 wrote: Thursday 19 September 2019 8:36 As you can see the output is empty( i highlighted the time stamp ).
Can you please try again ? I removed a left behind echo command in my previous post. :oops:
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
savage007
Posts: 19
Joined: Sunday 13 September 2015 20:24
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: recording with ffmpeg not working

Post by savage007 »

Stil nothing :

2019-09-24 15:27:33.061 Status: User: Admin initiated a switch command (68/Alarm signaal/Off)
2019-09-24 15:27:33.109 Status: dzVents: Info: Handling events for: "Alarm signaal", value: "Unlocked"
2019-09-24 15:27:33.109 Status: dzVents: Info: ------ Start internal script: Script #1: Device: "Alarm signaal (Dummy)", Index: 68
2019-09-24 15:27:33.113 Status: dzVents: !Info: return from echo command: Check content of /home/edwin/domoticz/scripts/dzVents/data/ffmpeg.log
2019-09-24 15:27:33.245 Status: dzVents: !Info: return from ffmpeg command:
2019-09-24 15:27:33.245 Status: dzVents: !Info: Alarm Alarm signaal is afgegaan
2019-09-24 15:27:33.245 Status: dzVents: Info: ------ Finished Script #1
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: recording with ffmpeg not working

Post by waaren »

savage007 wrote: Tuesday 24 September 2019 15:32 Stil nothing :

2019-09-24 15:27:33.061 Status: User: Admin initiated a switch command (68/Alarm signaal/Off)
2019-09-24 15:27:33.109 Status: dzVents: Info: Handling events for: "Alarm signaal", value: "Unlocked"
2019-09-24 15:27:33.109 Status: dzVents: Info: ------ Start internal script: Script #1: Device: "Alarm signaal (Dummy)", Index: 68
2019-09-24 15:27:33.113 Status: dzVents: !Info: return from echo command: Check content of /home/edwin/domoticz/scripts/dzVents/data/ffmpeg.log
2019-09-24 15:27:33.245 Status: dzVents: !Info: return from ffmpeg command:
2019-09-24 15:27:33.245 Status: dzVents: !Info: Alarm Alarm signaal is afgegaan
2019-09-24 15:27:33.245 Status: dzVents: Info: ------ Finished Script #1
Kind of hard to trouble shoot as I don't use ffmpeq myself and it does not seem to produce any error log, so it is a kind of point ans shoot..

Does the same command work if you try it as the same user that is the owner of the domoticz process ?
Did you try with and without sudo ?
can you put the command in an executable bash file and try to execute that from domoticz ?
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
savage007
Posts: 19
Joined: Sunday 13 September 2015 20:24
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: recording with ffmpeg not working  [Solved]

Post by savage007 »

I have tried it with a bash file it works! :-)

Thank you for your time !!
savage007
Posts: 19
Joined: Sunday 13 September 2015 20:24
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: recording with ffmpeg not working

Post by savage007 »

Here is my script for future reference

Code: Select all

#!/bin/bash

SnapVid="/home/edwin/snapvid.mp4"

#Make a 10 sec video
sudo -u edwin /snap/bin/ffmpeg -i rtsp://user:[email protected]:88/videoMain -t 10 -c:a aac -vsync 2 -map 0 -f segment -strftime 1 -segment_time 60 -segment_format mp4 $SnapVid


#send telegram video
sudo -u edwin /usr/bin/curl -v -F chat_id=xxxxxxxxx -F video=@$SnapVid -F caption="Beweging opgenomen" https://api.telegram.org/botxxxxx:xxxxxxxxx/sendVideo


#delete video file
/bin/rm $SnapVid
Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests