myth-merge-two-recordings now outsources to finding the next or

or previous recording on the same channel, that may overlap or abut
the current one.

To avoid error in the concatenation, we drop unknown streams and data streams.
This commit is contained in:
Leo Butler 2022-05-12 11:43:31 -05:00
parent 9ce8047004
commit 1e8a1d861f
1 changed files with 23 additions and 3 deletions

View File

@ -501,14 +501,34 @@
(mythconverg-update-deleted-ltbtranscodedtobedeleted
(myth-clean-recording-directory expiration-date shell-cmd) continuation))
(define (myth-merge-two-recordings chanid starttime)
(let* ((rec1+2 (mythconverg-execute+parse (simple-format #f "select basename,title from recorded where chanid=~a and starttime >= ~a order by starttime limit 2;" chanid starttime)))
(define* (myth-find-adjacent-recording chanid starttime #:optional (order 'default))
(let* ((endtime (caadr (mythconverg-execute+parse (simple-format #f "select endtime from recorded where chanid=~a and starttime = ~a;" chanid starttime))))
(next-rec0 (cdr (mythconverg-execute+parse (simple-format #f "select basename,title from recorded where chanid=~a and starttime >= ~a and starttime <= '~a' order by starttime limit 2;" chanid starttime endtime))))
(prev-rec0 (cdr (mythconverg-execute+parse (simple-format #f "select basename,title from recorded where chanid=~a and endtime >= ~a and starttime <= ~a order by starttime limit 2;" chanid starttime starttime))))
(next-rec (cons 'after next-rec0))
(prev-rec (cons 'before prev-rec0))
)
;;(list 'next next-rec (length next-rec) 'before prev-rec (length prev-rec))
(case order
((after)
(if (eq? (length next-rec) 3) next-rec '()))
((before)
(if (eq? (length prev-rec) 3) prev-rec '()))
((default)
(cond ((eqv? (length next-rec) 3) next-rec)
((eqv? (length prev-rec) 3) prev-rec)
(else '())))
(else '()))))
(define* (myth-merge-two-recordings chanid starttime #:optional (order 'default))
(let* ((rec1+2 (myth-find-adjacent-recording chanid starttime order))
(bn1 (caadr rec1+2))
(bn2 (caaddr rec1+2))
(bn (if (eq? 'after (car rec1+2)) bn1 bn2))
(concat (simple-format #f "ffconcat version 1.0\nfile ~a/~a\nfile ~a/~a\n" recordings-directory bn1 recordings-directory bn2))
(port (mkstemp! (mythconverg-input-file-name)))
(tmpfile (port-filename port))
(cmd (simple-format #f "~a -y -safe 0 -f concat -i ~a -codec copy -map 0 -map -0:d ~a/~a && touch --reference='~a/~a' ~a/~a && mv ~a/~a ~a/~a.premerge && mv ~a/~a ~a/." ffmpeg-bin tmpfile working-directory bn1 recordings-directory bn1 working-directory bn1 recordings-directory bn1 recordings-directory bn1 working-directory bn1 recordings-directory)))
(cmd (simple-format #f "~a -y -safe 0 -f concat -i ~a -codec copy -ignore_unknown -map 0 -map -0:d ~a/~a && touch --reference='~a/~a' ~a/~a && mv ~a/~a ~a/~a.premerge && mv ~a/~a ~a/." ffmpeg-bin tmpfile working-directory bn recordings-directory bn working-directory bn recordings-directory bn recordings-directory bn working-directory bn recordings-directory)))
(simple-format port concat) (force-output port) (close-port port)
(shell-command-to-string cmd)
(mythutil-rebuild (re-create-record-data (list (cons 'chanid chanid) (cons 'starttime starttime))))