Using HDR FOX T2 as a DVR with network IP cameras

rodp

Member
Hi All,

A sort of follow on from this link: https://hummy.tv/forum/threads/fox-t2-and-webcam.7118/

I came across an FFMPEG thread (https://superuser.com/questions/142...live-stream-into-one-minute-stand-alone-files) that talked about using an FFMPEG command line to record minute interval video files from an IP camera using RSTP transport / protocol. I have an old IP camera (640 x 480 pixels) which I think would do this that I used to use with a PC when stop motion screen shots but wonder if this could be used via the Humax. I ask this as the Humax most of the time remains powered whilst my PCs don't.


This was the final command line the user in the thread gave. I am assuming that the FFMPEG version installed in the humax includes the commands?

Code:
ffmpeg -rtsp_transport tcp -reorder_queue_size 8000 -vsync drop -i rtsp://192.168.10.203:554/11 -map 0 -r 30 -vcodec copy -acodec copy -f segment -segment_time 60 -reset_timestamps 1 -strftime 1 "/path/%d-%m-%Y__%H_%M_test.avi"

I'd guess instead of recording 30 fps, I could reduce that to 1fps or something?

Other than getting the command line working and making sure it restarts itself if the humax reboots, is there enough power / system resource to do this? I'm not asking it to convert to MPEG4 or anything, just save what comes down the line as it were.

Thanks

Rodp
 
The simple answer is try it and see.
You can use telnet, putty or the webif diagnostics webshell to give you a command line interface,
You would obviously need to adjust the ip address and recording path but once you have that basics working and checked it doesn't interefere with normal operations then you can automate it later quite easily.
 
Just want to check, How would you write the path to save to the normal my videos folder? still get confused between when you use / or \ or whether you have to start at mnt or sda2.

Thanks

Rodp
 
You start at the root of the filesystem, which is '/', and then drill down from there, so in this case

Code:
"/mnt/hd2/My Video"

The quotes are important because of the space in 'My Video', without which the command line interpreter would not see the whole thing as one entity. Alternatively you can 'escape' a space with a preceding backslash and dispense with the quotes

Code:
/mnt/hd2/My\ Video

You can substitute /media as an alternative to /mnt/hd2 as well, since the /media folder contains a symlink to the very same folder above, so for example

Code:
/media/My\ Video
 
Last edited:
Hi All,

So I've played around abit and this is what I've found. Firslty the IP camera is old and so I've had to customise the script according to that. Newer IP camera probably work differently.... my camera is a D-Link DCS 900 and sends out MJPEG stream.

There was a need to keep humax CPU usage to a minimum and so copying the MJPEG stream into an MKV container seemed to work. At first I was trying AVI but another forum suggested to use MKV and this seemed to be much better. I don't know why though. Playing around with this is not easy by the way, VLC didn't always want to know and I've had better luck using BS player on an android phone to view the resulting files. I am still left with the the problem of not being able to scan forward or speed it up. Any suggestions on a better container?

In addition to this I wanted segment the files. The below command will copy at about 12-13fps and segment evey 10 seconds. No Audio. '-r 1' was an attempt to write 1 framer per second but this didn't work - see below for better solution.

Code:
ffmpeg -use_wallclock_as_timestamps 1 -i http://<user>:<pwd>@192.168.x.x/video.cgi -vcodec copy -map 0 -f segment -segment_time 10 -reset_timestamps 1 -strftime 1 -an -r 1 "mnt/hd2/My Video/[temp]/test_%Y-%m-%d_%H_%M_%S.mkv"

to control the frame rate I found out that using a filter would allow you to exclude specific frames meaning I could then get 1 frame in 25 added to the video. The below example therefore runs at 1fps AND only records the 25th frame. ie it takes a frame every 25 seconds. I did try to combine the two -vf parts together but there was a parsing error which kept occuring so gave up, in the end and separated them.

Code:
-vf "select='not(mod(n,25))'" -vf "setpts=0.04*PTS"

the first part, only selects the 25th Frame that comes through and the setpts bit is the resulting timeframe you see when watching the video. it goes hand in hand. 0.04 is 1/25th. When doing -vf stuff I learnt that you can't use -vcodec copy. You have to select a specific codec. So in this case I could choose MJPEG with a mkv container or actually use either mpeg4 or mpeg2 as because it was only capturing a frame every 25 seconds it would not impact cpu resource. However, again the mp4 extension is a problem with the DNLA index and hangs the humax / makes the tv / remote control unresponsve so I'm back to using .ts or mpeg2. Can anyone suggest a different codec / container?

One thing to watch out for those is if you implement the -vf the segment_time (below it's 30) actually means the length of the resulting video so it will actually record for a lot longer than 30 seconds real time before it creates the next file.

resulting command: (warning: humax can hang if you use mp4 - not sure what the next best alternative is though, any thoughts??)

Code:
ffmpeg -use_wallclock_as_timestamps 1 -i http://<user>:<pwd>@192.168.x.x/video.cgi -vf "select='not(mod(n,25))'" -vf "setpts=0.04*PTS" -vcodec mpeg4 -map 0 -f segment -segment_time 30 -reset_timestamps 1 -strftime 1 -an -r 1 "mnt/hd2/My Video/[temp]/test_%Y-%m-%d_%H_%M_%S.mp4"

This code is not perfect as again this doesn't really play well on VLC but will play ok android BS Player.

Please let me know if you have any remarks about the codec and container that could be used in the latter code to make sure it can play in VLC, on the humax and be seakable. (i'll keep trying in the mean time!)

Thanks

Rodp
 
If you want the file to be playable while you're writing to it, do what the system does and use m2ts (give it a .ts extension), something like this -- I put h264 instead of mpeg4 for the codec, but perhaps you had a good reason for the older format:
Code:
ffmpeg -hide_banner -use_wallclock_as_timestamps 1 -i http://<user>:<pwd>@192.168.x.x/video.cgi -vf "select='not(mod(n,25))'" -vf "setpts=0.04*PTS" -vcodec h264 -map 0 -f segment -segment_time 30 -reset_timestamps 1 -strftime 1 -an -r 1 -mpegts_m2ts_mode true "mnt/hd2/My Video/[temp]/test_%Y-%m-%d_%H_%M_%S.ts"
 
Last edited:
/df...Does h264 work for you? Ffmpeg just returns unknown encoder 'h264'. That's why I had to choose the (old) mpeg4. I'll try mpeg2 in .ts container though.

For mpeg4 the cpu process is running about 50% so that's ok but obviously would like to try and get it lower but using a filter means you can't use 'copy'. I'll see if mpeg2 differs.

Thanks

Rodp
 
I guess another way to reduce cpu resources is to use a timer which records the still image from the ip camera and saves it in a folder every minute which at the end of the day ffmpeg could then compile into a video file?
 
/df...Does h264 work for you? Ffmpeg just returns unknown encoder 'h264'. That's why I had to choose the (old) mpeg4. I'll try mpeg2 in .ts container though.
...
No, you're right. The repo version of ffmpeg doesn't have H.264 encoder built-in. IIRC the encoder brings in all sorts of dependencies each of which is difficult to build. Possibly there is a more targeted subset of codecs that could be chosen for the build so as to reduce the size of the rest of the program in memory and allow for the encoder. We would need the H.264 encoder in order to implement the (suggested elsewhere) "smart edit" function that would allow cutting and joining at non-I-frame boundaries by re-encoding from the last I-frame to the next one.
I guess another way to reduce cpu resources is to use a timer which records the still image from the ip camera and saves it in a folder every minute which at the end of the day ffmpeg could then compile into a video file?
Absolutely.
 
Ran into a more problems. Codec mpeg-ts is unknown so using mpeg2video a go but then the humax complained about there being no audio so tried to add a silent audio in but so far it's not worked.

Tried using something like what i found here https://stackoverflow.com/questions/12368151/adding-silent-audio-in-ffmpeg

But the map 0 and map 1 thing mentioned i don't think is right or I'vemisinterpreted it.

I have to stay away from mp4 extension so guess I'll have to go back to avi or mkv? The purpose being to get it to play on the humax.
 
The repo version of ffmpeg doesn't have H.264 encoder built-in.
I know you (or somebody) said the HDR can re-encode video, but it's gotta be compute-intensive and H.264 especially so.

The purpose being to get it to play on the humax.
I suggest concentrating on getting it to record on the HDR - the primary purpose being to capture on a device that is generally turned on anyway rather than having to keep a PC turned on all the time. So long as the files are accessible by SMB, at least they are available to view even if that has to be by PC.

If you must view them on HDR, they could be post-processed (possibly as a batch from the PC). I don't think trying to transcode in real time on capture is a runner (although the reduced frame rate might make this possible).

As an alternative, you could consider dedicating an RPi to the job. Much more grunt, and the development process would be very similar (being Linux-based), but with the full-fat tools available. Files could be available to the HDR as a pseudo-USB drive, and if you were to mount the pseudo-USB into My Video (problems thereof notwithstanding), .TS (M2TS, possibly with a dummy or real .HMT) could make the RPi files playable while recording. Or the RPi could just be a "set-top box" plumbed directly to spare TV HDMI port.
 
Last edited:
...Tried using something like what i found here https://stackoverflow.com/questions/12368151/adding-silent-audio-in-ffmpeg

But the map 0 and map 1 thing mentioned i don't think is right or I've misinterpreted it.
...
You don't have existing audio, so the example with -map isn't helpful. The previous example suggests (update from rpb424's post #13 below):
Code:
ffmpeg -hide_banner -use_wallclock_as_timestamps 1 -f lavfi -i anullsrc=channel_layout=stereo:sample_rate=44100 -i http://<user>:<pwd>@192.168.x.x/video.cgi  -acodec mp2 -vf "select='not(mod(n,25))'" -vf "setpts=0.04*PTS" -vcodec mpeg2video -f segment -segment_time 30 -reset_timestamps 1 -strftime 1 -r 1 -mpegts_m2ts_mode true -shortest "/mnt/hd2/My Video/[temp]/test_%Y-%m-%d_%H_%M_%S.ts"
mov is a good choice for the extension to avoid DLNA indexing, which looks for these extensions in the "My Video" directory (and children): mpg, avi, mkv, ts, wmv, tp, mp4, asf, mpeg, trp.

To make the output container what it would have been (say) if its name had a ts extension, you can use -f mpegts before the output file name (pick the container code from the list displayed with ffmpeg -formats).
 
Last edited:
A couple of observations

The '-an' switch is going to result in a file with no audio regardless of what you specify the audio source to be

The output file path is missing the '/' from the beginning of 'mnt'. That's fine if you are running ffmpeg whilst sitting in the root folder as the full path will be correct relative to that, but running it from within any other folder will result in an error message that the output path can't be found, as it is then looking for a non-existent 'mnt' folder below where you currently are.
 
Back
Top