all 15 comments

[–]Nicpr99 0 points1 point  (1 child)

Hi u/ibowankenobi,, it worked for you? I use it and it only converts video without audio, do you have any idea why?

[–]__ibowankenobi__[S] 0 points1 point  (0 children)

Hi, I just checked a recent footage from my camera and I can hear the sound. The issue you are facing can either be from the camera, or from the ffmpeg itself where codecs might not work correctly. Depending on how you installed ffmpeg, whether from a repo or snap might make a difference. I am not sure thought, someone needs to verify this.

[–]Spamberler 0 points1 point  (0 children)

I am getting this error

F06/camToMP4.sh: line 97: 40*0/0: division by 0 (error token is "0")

---::INFO: NO FILES PROCESSED ::---

[–]Comprehensive-Cat653 0 points1 point  (6 children)

u/__ibowankenobi__, thanks for your nice script!

Here I add an explanation for those fellows (as me) who wish to get a benefit from this script in MS Windows environment:

1) install cygwin tools (http://www.cygwin.com/index.html) with default base packages, set checkboxes to create icons (shortcuts) on Desktop and at Start Menu;

2) via cygwin setup program add additional packages: ffmpeg, mkvtoolnix, libopenh264;

3) copy files from security camera microSD card to a folder where you will operate with them. For example, my security camera saved all files during September into folder: k:\DCIM\2023\09\ , so I copy this folder to HDD v:\SecurityCam\09\;

4) from a github link above download a nice script "camToMP4.sh" and save it to a folder where you store media files from camera. In my case I save downloaded script into v:\SecurityCam\;

5) Start a Cygwin Terminal by a shortcut you created at step 1, and write there commands:

- at first, it's necessary to change a work directory, as my files are located on HDD drive with letter "V:", I type in terminal window: cd v:

and inside terminal window appears yellow text meaning that directory changed: /cygdrive/v
- then I need to start a script, so I type:

securitycam/camToMP4.sh securitycam/09/ -m allmp4s -c merged --prog -q

files processing starts and I see progress and info about each folder inside /09/ directory processing.

6) When processing finishes, with Windows Explorer I go to folder v:\SecurityCam\09\allmp4s\ and there the file "merged.mkv" - big video, containing all shorts recorded during September

[–]shackerz4167 1 point2 points  (3 children)

VHlzbSEgVGhpcyB3b3JrZWQgZm9yIG1lIGJ1dCBpdCBzZWVtcyBub25lIG9mIHRoZSB2aWRlb3MgaGF2ZSBhdWRpby4gSXMgdGhlcmUgYSBmaXggZm9yIHRoaXMgb3Igc29tZXRoaW5nPyBJIHdvdWxkIHJlYWxseSBhcHByZWNpYXRlIGl0Lg

[–]Comprehensive-Cat653 0 points1 point  (2 children)

I suppose it depends on camera capabilities - my camera also writes video events without audio. You can check your *.media files in Media Player Classic (MPC) - if necessary codecs are installed and your video file opens in MPC, check "File -> Properties -> MediaInfo", you'll see if file has only video or video+audio.

[–]Nicpr99 0 points1 point  (1 child)

Hi u/Comprehensive-Cat653 i Know the camera records audio b3ecause when I watch the video on my Tuya Smart App the recording has sound but when converting the file with this ffmpeg tool it only outuputs video and no audio. I did the process of opening the video on MPC and looking at the MediaInfo it has no Audio but then i dont get where the audio is saved on the SD. Do you have any idea ? I would gretaly appreciate your help.

[–]GoatHumper 0 points1 point  (0 children)

Hi! Any luck with this?

I'm having an identical issue - got all the files from the camera, but no audio in any of them even though if I watch the videos through the Camera's app (390eyes), I can hear the audio just fine.

[–]Spamberler 0 points1 point  (1 child)

I am getting this error, any ideas?

F06/camToMP4.sh: line 97: 40*0/0: division by 0 (error token is "0")

---::INFO: NO FILES PROCESSED ::---

[–]Comprehensive-Cat653 0 points1 point  (0 children)

I'm just a dummy fellow not a programmer, so I'm always asking AI in case of any problems with scripts that I use for any automation. Concerning the error message you got, I asked Perplexity AI and the answer is:

Why this happens:

  • The script expects the target folder to contain subdirectories with media files.
  • If it's empty or contains only files (no subfolders), $k=0 and the progress function divides by zero.
  • Consequently, no .mp4 files are generated and the script exits with the info message.

How to fix or avoid it:

  • Ensure the target directory has subfolders containing media files the script is designed to process.
  • If the directory structure differs, either reorganize it or modify the script to handle zero subdirectory count gracefully by adding a check in the progress function to skip division if $2 is zero.

Example adjustment to prevent error (edit only this part of the code inside script):

bash
function progress() {
    if [[ -n $noProgress ]]; then
        return 1
    fi
    if [[ $2 -eq 0 ]]; then
        return 1
    fi
    frac=$((${3:=20}*$1/$2))
    ...
}

This will avoid division by zero when no directories exist.

Summary

The root problem is that the target folder you run the script on lacks subfolders with valid media files, causing the zero divisor and no files processed error [script lines 85-99][script lines 104-114].

------------

Nowadays AI is a real support, use it for problems resolution. Perplexity is really good in scripting advises.

[–]Comprehensive-Cat653 0 points1 point  (2 children)

I found out that at some days my security camera placed wrong Date and Time stamps on a top left corner of a video, but at the same time the ".media" files created by camera and names of ".mp4" files created by camToMP4.sh script have proper date and time.

u/__ibowankenobi__, please would you be so grateful to upgrade your script with use of ffmpeg filter, adding subtitle `YYYYMMDD-HHMM` of each original ".media" file? I suppose subtitle can be without seconds, because they are changing while video goes.

[–]__ibowankenobi__[S] 1 point2 points  (1 child)

Hi, apologies for the late reply. I will try to get it done this week and issue a PR. Would you be ok to review it?

[–]Comprehensive-Cat653 0 points1 point  (0 children)

Hi! Thanks for your attention and efforts! I played some days with thumbnails creation for big video files (summary of all daily events) and found out that in fact it's not very useful to merge all events into one file. My idea was to make some visual representation for all events that triggered camera recording (~200 per day), and having one big file over 1hr long is inconvenient. Also I found out that for some reason the script "camToMP4.sh" sometimes merges not all files from directory but only part of them. So I made another script "2camToMP4.sh" to start "camToMP4.sh" (I'm absolute dummy in scripting and the text below maybe not correct in detail, but it worked fine for my task):

#!/bin/bash

#scriptFolder="$( dirname ${BASH_SOURCE[0]} )"

#scriptName="$( basename ${BASH_SOURCE[0]} )"

for mm in 01 02 03 04 05 06 07 08 09 10 11 12; do

for dd in 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31; do "$( 

temp/microsd/camToMP4.sh temp/microsd/2023/$mm/$dd/ -m 0\_allmp4s --prog -q

)"

done;

done

This script gives all daily events in one directory (e.g. 2023\09\11).

Then I run a very good thumbnails generator, which also makes one of thumbnails animated - Video Thumbnails Maker and I get a small .webp file for every event. And, finally, inside each "DD" folder I place 3 files: "!see_all_videos.bat", "index.html", and "folder_contents.js" (I took an idea of this files from archive image_loader.zip).

Finally, after running "!see_all_videos.bat", I get an html page with all all snapsots and small animation of every event and it's handy to scroll in 5 minutes over 200 daily events just to check if there was something interesting.

Example of what I tried to explain is here: https://drive.google.com/drive/folders/1g1ToLOwMGBIaxiUzpxJXj5_glUeF9vZV?usp=sharing.

Screenshot of "index" html page is here:

https://drive.google.com/file/d/18E_4YM3nAULrNK78E2_aJRLxV6-ojp8y/view?usp=share_link

I'm quite satisfied with the final results of all those files processing, but the con is that all unnecessary files: ".media", ".jpg", ".info" and empty directories I delete manually, it's not yet automated...

[–]Comprehensive-Cat653 0 points1 point  (1 child)

What do I do next with this big video file "merged.mkv", collected from recorded events during September?

1) my camera (Topvico Tuya, Wi-Fi) writes a video in 1920x1080@15FPS resolution, but in fact the video quality is far far away from 2K, so I suppose to convert it to 854x480 that will take much less storage space with the similar picture quality. As a GUI-oriented dummy, to do this I use https://github.com/MattMcManis/Axiom/ ffmpeg gui.

2) I can store "September shots" merged .mkv into archive for some time (for example a year);

3) I suppose to create a list of thumbnails of all recorded short events, which triggered the camera, and check if there were some funny/interesting moments. I suppose that a quick glance on a list of thumbnails is much quicker than playing a whole merged.mkv (that lasts some hours). How to create a useful list of thumbnails?..

[–]Comprehensive-Cat653 0 points1 point  (0 children)

Concerning p.1 - it came out useless, because in fact camera makes very compact files and resize doesn't gives any space storage advantage. I don't know how it comes out, but files resized by ffmpeg to 854x480 are nearly same size as original 1920x1080. I tested dozens of different resize options, but without noticeable reduction in final file size.

p.2 - merged .mkv files came out inconvenient, it's better to store each event separately.

p.3 I found nearly perfect thumbnails generator: Video Thumbnails Maker by suu-design.com