0

I have many video files that are split by Day, Camera Channel, Event time range (YYYY-MM-DD/VIDEOCHANNELNUMBER-EVENTIMERANGE.mp4)

/2021-07-03/ch2_main_20210703074010_20210703074154.mp4
/2021-07-03/ch2_main_20210703074156_20210703074357.mp4
/2021-07-03/ch2_main_20210703074446_20210703074537.mp4
/2021-07-03/ch2_main_20210703074618_20210703075119.mp4
/2021-07-03/ch2_main_20210703075153_20210703075312.mp4
/2021-07-03/ch2_main_20210703075337_20210703080422.mp4

I want to merge these clips by Day and Camera Channel only (ie /2021-04-03-CH1.mp4)

My process is:

  1. Iterate through each date folder (for VIDEODIR in */)
  2. Within each folder, iterate through each channel number (for VIDEOCHANNELNUMBER in 1 2 3 4 5 6; do)
  3. for each channel number, find all the video files to combine (for f in $VIDEODIR/ch$VIDEOCHANNELNUMBER*.mp4 ; do)
  4. FFMPEG combine and save this file into the root directory (ffmpeg -i $VIDEOLIST -c copy "$DATE-CH$VIDEOCHANNELNUMBER.mp4")
  5. When successful delete the directory of all the original clips. (if [ $? -eq 0 ]; then rm $VIDEODIR -r fi)

I'm stuck because Step 2 errors out when there are no matches due to that video channel being offline during that day for some reason. (zsh: no matches found: /2021-07-03/ch1*.mp4). This breaks the entire loop, rather than skip and continue.

Mr. Demetrius Michael
  • 2,326
  • 5
  • 28
  • 40
  • Aside: Instead of `ffmpeg...; if [ $? -eq 0 ]; then ...`, just run `if ffmpeg ...; then`. See [Why is testing `$?` to see if a command succeeded or not an antipattern?](https://stackoverflow.com/questions/36313216/why-is-testing-to-see-if-a-command-succeeded-or-not-an-anti-pattern) – Charles Duffy Jan 17 '23 at 21:23
  • Anyhow -- _in bash_, what you're looking for would be `shopt -s nullglob`. In zsh, there's a modifier that does the same thing, but I don't know it offhand. – Charles Duffy Jan 17 '23 at 21:24
  • I think the _no matches found_ belongs to step 3, not step 2. You could write the loop as `for f in $VIDEODIR/ch$VIDEOCHANNELNUMBER*.mp4(N)`. This would make the loop being skipped if there are no mp4 files. – user1934428 Jan 18 '23 at 09:24

0 Answers0