I'm not sure if I have such very advanced subflows but this is how I now have been able to reduce. For each source, I have a tab like below. All configuration params are currently in the inject button but I plan to move that to some external configuration data set of some kind. The flow below is just a sub component of a larger flow system and handles the startup of the stream as well as incoming commands to start recordings and/or take snapshots to be forwarded to various consumers
The benefit now is that this flow is easy to reduce, you just copy the tab as many times as you have ip sources and change the related params in the inject node. I tried to put even more of the nodes into the subflows but some things I could not figure out, I had to keep them outside for the time being. Maybe I could even merge the two subflows into one but for readability, it's not so bad to keep them separated
[{"id":"eb003283.c28bf","type":"subflow","name":"HSS_mp4frag subflow","info":"","category":"","in":[{"x":100,"y":200,"wires":[{"id":"62ea8138.a1ecc"}]}],"out":[{"x":840,"y":200,"wires":[{"id":"43fff5e2.62047c","port":1}]},{"x":840,"y":320,"wires":[{"id":"832a7a83.3b8028","port":0}]},{"x":360,"y":400,"wires":[{"id":"62ea8138.a1ecc","port":0},{"id":"62ea8138.a1ecc","port":1}]}],"env":[],"meta":{},"color":"#DDAA99","status":{"x":1140,"y":400,"wires":[{"id":"f8c3cfdc.2e315","port":0},{"id":"9814715a.7517e","port":0}]}},{"id":"43fff5e2.62047c","type":"mp4frag","z":"eb003283.c28bf","name":"","migrate":2e-9,"hlsPlaylistSize":4,"hlsPlaylistExtra":0,"basePath":"id","repeated":"false","timeLimit":10000,"preBuffer":1,"x":570,"y":160,"wires":[["5e775a0d.d46554","1f3151ed.cd8ebe"],[]]},{"id":"1b11edc3.1378a2","type":"ffmpeg-spawn","z":"eb003283.c28bf","name":"","outputs":2,"cmdPath":"ffmpeg","cmdArgs":"[]","cmdOutputs":1,"killSignal":"SIGTERM","x":540,"y":240,"wires":[["43fff5e2.62047c"],["43fff5e2.62047c"]]},{"id":"5e775a0d.d46554","type":"switch","z":"eb003283.c28bf","name":"","property":"payload.hlsPlaylist","propertyType":"msg","rules":[{"t":"nempty"}],"checkall":"true","repair":false,"outputs":1,"x":510,"y":400,"wires":[["a09fcfcc.52157"]]},{"id":"a09fcfcc.52157","type":"join","z":"eb003283.c28bf","name":"","mode":"custom","build":"array","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":false,"timeout":"","count":"2","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":510,"y":320,"wires":[["832a7a83.3b8028"]]},{"id":"62ea8138.a1ecc","type":"switch","z":"eb003283.c28bf","name":"","property":"topic","propertyType":"msg","rules":[{"t":"eq","v":"Snapshot","vt":"str"},{"t":"eq","v":"Recording","vt":"str"},{"t":"else"}],"checkall":"true","repair":false,"outputs":3,"x":230,"y":200,"wires":[["43fff5e2.62047c"],["43fff5e2.62047c"],["1b11edc3.1378a2","a09fcfcc.52157"]]},{"id":"832a7a83.3b8028","type":"function","z":"eb003283.c28bf","name":"","func":"let hss = global.get(\"hss.cameras\");\nlet cam = msg.payload[0];\nlet url = msg.payload[1].hlsPlaylist;\n//node.warn(url);\nlet camera = hss[cam];\ncamera.url = url;\n//node.warn(camera.url);\nhss[cam] = camera;\n//node.warn(hss[cam]);\nglobal.set(\"hss.cameras\", hss);\nmsg.payload = hss[cam];\nmsg.camera = cam;\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":700,"y":320,"wires":[["f8c3cfdc.2e315"]]},{"id":"f8c3cfdc.2e315","type":"change","z":"eb003283.c28bf","name":"the url","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload.url","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":810,"y":400,"wires":[[]]},{"id":"1f3151ed.cd8ebe","type":"switch","z":"eb003283.c28bf","name":"","property":"payload","propertyType":"msg","rules":[{"t":"empty"}],"checkall":"true","repair":false,"outputs":1,"x":870,"y":120,"wires":[["9814715a.7517e"]]},{"id":"9814715a.7517e","type":"change","z":"eb003283.c28bf","name":"the url","rules":[{"t":"set","p":"payload","pt":"msg","to":"stopped","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":1010,"y":120,"wires":[[]]},{"id":"26ed31e3.2fdffe","type":"subflow","name":"Recordings & Snapshots","info":"","category":"","in":[{"x":60,"y":80,"wires":[{"id":"d72ee6ae.b58e28"}]}],"out":[{"x":600,"y":320,"wires":[{"id":"d0b16878.6536b8","port":0}]},{"x":600,"y":380,"wires":[{"id":"736eff4.ea988","port":0}]},{"x":600,"y":760,"wires":[{"id":"a6a407d6.5d4148","port":0}]},{"x":600,"y":820,"wires":[{"id":"a6a407d6.5d4148","port":1}]},{"x":600,"y":880,"wires":[{"id":"a6a407d6.5d4148","port":2}]}],"env":[],"meta":{},"color":"#DDAA99"},{"id":"4bf8e63f.4271a8","type":"file","z":"26ed31e3.2fdffe","name":"Save file","filename":"","appendNewline":false,"createDir":false,"overwriteFile":"false","encoding":"none","x":400,"y":260,"wires":[["d0b16878.6536b8"]]},{"id":"d0b16878.6536b8","type":"trigger","z":"26ed31e3.2fdffe","name":"","op1":"","op2":"true","op1type":"nul","op2type":"bool","duration":"5","extend":true,"overrideDelay":false,"units":"s","reset":"","bytopic":"all","topic":"topic","outputs":1,"x":400,"y":320,"wires":[["736eff4.ea988"]]},{"id":"f7cfc57.a602638","type":"function","z":"26ed31e3.2fdffe","name":"","func":"let ts = flow.get('ts') || undefined;\n\nif (ts == undefined) {\n //get new time stamp\n const d = new Date();\n\n let year = d.getFullYear().toString();\n let month = (d.getMonth() + 1).toString();\n if (month.length < 2) {\n month = '0' + month;\n }\n let day = d.getDate().toString();\n if (day.length < 2) {\n day = '0' + day;\n }\n let hour = d.getHours().toString();\n if (hour.length < 2) {\n hour = '0' + hour;\n }\n let minute = d.getMinutes().toString();\n if (minute.length < 2) {\n minute = '0' + minute;\n }\n let seconds = d.getSeconds().toString();\n if (seconds.length < 2) {\n seconds = '0' + seconds;\n }\n\n ts = year + '-' + month + '-' + day + '-' + hour + minute + seconds;\n flow.set('ts', ts);\n}\n\n// build the payload for recording\nvar hss = global.get(\"hss\");\nlet fn = hss.http_path + \"/hss_media/recordings/\" + ts + '.' + hss.recording_format;\nglobal.set(\"hss.latest_recording\", fn);\nconst { payload, action } = msg;\n\nif (Buffer.isBuffer(payload)) {\n msg.filename = fn;\n return msg;\n}\n\n","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":400,"y":200,"wires":[["4bf8e63f.4271a8"]]},{"id":"38926008.f5cfd","type":"change","z":"26ed31e3.2fdffe","name":"","rules":[{"t":"set","p":"action","pt":"msg","to":"{\"command\":\"stop\"}","tot":"json"}],"action":"","property":"","from":"","to":"","reg":false,"x":420,"y":620,"wires":[[]]},{"id":"31706103.689ede","type":"trigger","z":"26ed31e3.2fdffe","name":"","op1":"","op2":"true","op1type":"nul","op2type":"bool","duration":"1","extend":false,"overrideDelay":false,"units":"s","reset":"","bytopic":"all","topic":"topic","outputs":1,"x":400,"y":680,"wires":[["38926008.f5cfd"]]},{"id":"736eff4.ea988","type":"change","z":"26ed31e3.2fdffe","name":"Recording done","rules":[{"t":"set","p":"topic","pt":"msg","to":"RECORDING","tot":"str"},{"t":"set","p":"payload","pt":"msg","to":"Recording for IP source done","tot":"str"},{"t":"delete","p":"ts","pt":"flow"}],"action":"","property":"","from":"","to":"","reg":false,"x":420,"y":380,"wires":[[]]},{"id":"a6a407d6.5d4148","type":"switch","z":"26ed31e3.2fdffe","name":"","property":"notification_type","propertyType":"global","rules":[{"t":"eq","v":"Snapshot","vt":"str"},{"t":"eq","v":"Telegram","vt":"str"},{"t":"eq","v":"Email","vt":"str"}],"checkall":"true","repair":false,"outputs":3,"x":390,"y":820,"wires":[[],[],[]]},{"id":"ba6d86bf.bf3f88","type":"delay","z":"26ed31e3.2fdffe","name":"","pauseType":"rate","timeout":"5","timeoutUnits":"seconds","rate":"1","nbRateUnits":"2","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":true,"x":420,"y":740,"wires":[["a6a407d6.5d4148"]]},{"id":"d72ee6ae.b58e28","type":"switch","z":"26ed31e3.2fdffe","name":"","property":"writeMode","propertyType":"global","rules":[{"t":"eq","v":"recording","vt":"str"},{"t":"eq","v":"snapshot","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":190,"y":80,"wires":[["f7cfc57.a602638","73993c36.5d8b04"],["be2268d5.bb84a8"]]},{"id":"32900339.aea3ac","type":"comment","z":"26ed31e3.2fdffe","name":"Create mp4 file and image required for making the thumbnail","info":"","x":560,"y":160,"wires":[]},{"id":"c6dbcf14.e78bc","type":"comment","z":"26ed31e3.2fdffe","name":"Create jpg image snapshot","info":"","x":450,"y":520,"wires":[]},{"id":"8c08be50.ead39","type":"file","z":"26ed31e3.2fdffe","name":"","filename":"","appendNewline":false,"createDir":false,"overwriteFile":"true","encoding":"none","x":750,"y":560,"wires":[[]]},{"id":"7a9a3954.3459c8","type":"function","z":"26ed31e3.2fdffe","name":"","func":"// build the payload for recording thumb nail\nvar hss = global.get(\"hss\");\nlet fn = hss.latest_recording.split(hss.recording_format)[0] + hss.recording_format + '.jpg';\n\nconst { payload, action } = msg;\n\nif (Buffer.isBuffer(payload)) {\n msg.filename = fn;\n return msg;\n}\n\n","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":760,"y":500,"wires":[["8c08be50.ead39"]]},{"id":"96d62f8a.517a","type":"change","z":"26ed31e3.2fdffe","name":"","rules":[{"t":"set","p":"action","pt":"msg","to":"{\"command\":\"stop\"}","tot":"json"}],"action":"","property":"","from":"","to":"","reg":false,"x":760,"y":320,"wires":[["d97a4806.92b288"]]},{"id":"753ee470.28695c","type":"trigger","z":"26ed31e3.2fdffe","name":"","op1":"","op2":"true","op1type":"nul","op2type":"bool","duration":"1","extend":false,"overrideDelay":false,"units":"s","reset":"","bytopic":"all","topic":"topic","outputs":1,"x":760,"y":380,"wires":[["96d62f8a.517a"]]},{"id":"ba9c87a7.1071e8","type":"delay","z":"26ed31e3.2fdffe","name":"","pauseType":"rate","timeout":"5","timeoutUnits":"seconds","rate":"1","nbRateUnits":"2","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":true,"x":760,"y":440,"wires":[["7a9a3954.3459c8"]]},{"id":"d97a4806.92b288","type":"ffmpeg-spawn","z":"26ed31e3.2fdffe","name":"","outputs":2,"cmdPath":"ffmpeg","cmdArgs":"[\"-i\",\"pipe:0\",\"-f\",\"image2pipe\",\"pipe:1\"]","cmdOutputs":1,"killSignal":"SIGTERM","x":760,"y":260,"wires":[[],["753ee470.28695c","ba9c87a7.1071e8"]]},{"id":"be2268d5.bb84a8","type":"ffmpeg-spawn","z":"26ed31e3.2fdffe","name":"","outputs":2,"cmdPath":"ffmpeg","cmdArgs":"[\"-i\",\"pipe:0\",\"-f\",\"image2pipe\",\"pipe:1\"]","cmdOutputs":1,"killSignal":"SIGTERM","x":420,"y":560,"wires":[[],["31706103.689ede","ba6d86bf.bf3f88"]]},{"id":"73993c36.5d8b04","type":"delay","z":"26ed31e3.2fdffe","name":"","pauseType":"delay","timeout":"100","timeoutUnits":"milliseconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":750,"y":200,"wires":[["d97a4806.92b288"]]},{"id":"50ed257.677f8dc","type":"tab","label":"IP CAM","disabled":false,"info":""},{"id":"879d3f10.ec9b1","type":"inject","z":"50ed257.677f8dc","name":"stop","props":[{"p":"action","v":"{\"command\":\"stop\"}","vt":"json"},{"p":"reset","v":"true","vt":"bool"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":390,"y":440,"wires":[["3d29d905.6efda6"]]},{"id":"345eaad9.172a66","type":"link in","z":"50ed257.677f8dc","name":"IP_Record_IN","links":["2bf661f0.22225e","7be3e5c2.4b909c"],"x":95,"y":180,"wires":[["d40da575.efc358"]]},{"id":"1e9db784.31f758","type":"inject","z":"50ed257.677f8dc","name":"TearsOfSteel","props":[{"p":"action","v":"{\"command\":\"start\",\"args\":[\"-loglevel\",\"error\",\"-nostats\",\"-f\",\"hls\",\"-http_multiple\",\"1\",\"-re\",\"-i\",\"http://commondatastorage.googleapis.com/gtv-videos-bucket/CastVideos/hls/TearsOfSteel.m3u8\",\"-c:v\",\"copy\",\"-c:a\",\"aac\",\"-f\",\"mp4\",\"-movflags\",\"+frag_keyframe+empty_moov+default_base_moof\",\"pipe:1\",\"-progress\",\"pipe:3\"]}","vt":"json"},{"p":"payload"}],"repeat":"","crontab":"","once":true,"onceDelay":"1","topic":"","payload":"cam9","payloadType":"str","x":370,"y":380,"wires":[["3d29d905.6efda6"]]},{"id":"45151bef.478344","type":"comment","z":"50ed257.677f8dc","name":"HSS mp4frag video sources and recording","info":"","x":240,"y":40,"wires":[]},{"id":"c641e406.a7d448","type":"comment","z":"50ed257.677f8dc","name":"Switch to trigger recordings","info":"","x":200,"y":140,"wires":[]},{"id":"afb78f7f.3e5d6","type":"link in","z":"50ed257.677f8dc","name":"IP_Snapshot_IN","links":["c88b87e1.f21c88","5ec907a2.8da2c8","384bbc7d.b10064","1a01ed2f.d1a463","70fcd40e.1dd2bc","cb480b0b.f22248","9bae2e46.deaa8"],"x":95,"y":300,"wires":[["96e4bb8b.55df88"]]},{"id":"d56bcde6.7387d","type":"comment","z":"50ed257.677f8dc","name":"Switch to trigger snapshots","info":"","x":200,"y":260,"wires":[]},{"id":"96e4bb8b.55df88","type":"change","z":"50ed257.677f8dc","name":"","rules":[{"t":"set","p":"action","pt":"msg","to":"{\"subject\":\"write\",\"command\":\"start\",\"repeated\":false,\"timeLimit\":1,\"preBuffer\":3}","tot":"json"},{"t":"set","p":"notification_type","pt":"global","to":"topic","tot":"msg"},{"t":"set","p":"writeMode","pt":"global","to":"snapshot","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":220,"y":300,"wires":[["2d92a4a2.a2fabc"]]},{"id":"d40da575.efc358","type":"change","z":"50ed257.677f8dc","name":"","rules":[{"t":"set","p":"action","pt":"msg","to":"{\"subject\":\"write\",\"command\":\"start\",\"timeLimit\":0,\"repeated\":false,\"preBuffer\":$globalContext(\"recording_duration\")}","tot":"jsonata"},{"t":"set","p":"writeMode","pt":"global","to":"recording","tot":"str"},{"t":"set","p":"topic","pt":"msg","to":"Recording","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":220,"y":180,"wires":[["4f66394b.0789b8"]]},{"id":"9cfb2750.e2c338","type":"subflow:26ed31e3.2fdffe","z":"50ed257.677f8dc","x":950,"y":240,"wires":[["3d4d5c03.736554"],["dc602675.e7d388"],["6bb6ba9e.15fb34"],["e7da0b83.7cff68"],["4ddece85.fce61"]]},{"id":"27abd8e6.7afc28","type":"comment","z":"50ed257.677f8dc","name":"Version 11","info":"v11 2021/08/25 - WK\n- reworked ip cam flow tab using subflows\n\nv10 2021/08/19 - WK\n- reworked ip cam flow tab\n\nv09 2021/08/16 - WK\n- starting sources at init\n\nv08 2021/08/15 - WK\n- using 'hss.latest_recording' when setting file name of thumb nails\n\nv07 2021/08/08 - WK\n- using 'recording_format' for setting compatible format for video files\n\nv06 2021/08/07 - WK\n- added thumb nails to recordings\n\nv05 2021/08/04 - WK\n- adopting to use browsing of recordings & snapshots\n\nv04 2021/07/31 - WK\n- restructuring and design modifications\n\nv03 2021/07/29 - WK\n- added support for triggering of telegrams and emails\n\nv02 2021/07/29 - WK\n- first version supporting triggering of snapshots\n\nv01 2021/07/09 - WK\n- first version supporting mp4frag video sources and triggering of recording\n\n\n","x":140,"y":80,"wires":[]},{"id":"6bb6ba9e.15fb34","type":"link out","z":"50ed257.677f8dc","name":"to_snapshot_ip_cams","links":["d3160b3d.d839c8"],"x":1155,"y":240,"wires":[]},{"id":"4ddece85.fce61","type":"link out","z":"50ed257.677f8dc","name":"to_email_ip_cams","links":["14c6814f.7c12bf"],"x":1155,"y":320,"wires":[]},{"id":"e7da0b83.7cff68","type":"link out","z":"50ed257.677f8dc","name":"to_telegram_ip_cams","links":["6098bf0f.b236e"],"x":1155,"y":280,"wires":[]},{"id":"3d4d5c03.736554","type":"link out","z":"50ed257.677f8dc","name":"to_recording_done","links":["d6065808.b6b018"],"x":1155,"y":160,"wires":[]},{"id":"dc602675.e7d388","type":"link out","z":"50ed257.677f8dc","name":"to_show_notification","links":["63e8b119.a294d"],"x":1155,"y":200,"wires":[]},{"id":"3d29d905.6efda6","type":"subflow:eb003283.c28bf","z":"50ed257.677f8dc","name":"","x":620,"y":240,"wires":[["9cfb2750.e2c338"],["a8881dfc.aa0bb","5b906553.b6483c"],["734e9b05.181cc4"]]},{"id":"a8881dfc.aa0bb","type":"debug","z":"50ed257.677f8dc","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":890,"y":380,"wires":[]},{"id":"734e9b05.181cc4","type":"debug","z":"50ed257.677f8dc","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":890,"y":440,"wires":[]},{"id":"5b906553.b6483c","type":"change","z":"50ed257.677f8dc","name":"","rules":[{"t":"set","p":"mp4frag_url","pt":"flow","to":"payload.url","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":940,"y":320,"wires":[[]]},{"id":"4f66394b.0789b8","type":"switch","z":"50ed257.677f8dc","name":"","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"mp4frag_url","vt":"flow"}],"checkall":"true","repair":false,"outputs":1,"x":390,"y":180,"wires":[["3d29d905.6efda6"]]},{"id":"2d92a4a2.a2fabc","type":"switch","z":"50ed257.677f8dc","name":"","property":"url","propertyType":"msg","rules":[{"t":"eq","v":"mp4frag_url","vt":"flow"}],"checkall":"true","repair":false,"outputs":1,"x":390,"y":300,"wires":[["3d29d905.6efda6"]]}]