add MYTH-MERGE-TWO-RECORDINGS and FFMPEG-REMUX-TO-H264-TS

MYTH-MERGE-TWO-RECORDINGS takes a recording chanid and starttime and
finds the next recording on that same chanid and uses the concat muxer
to merge the two files. The recording information is updated in
mythconverg.

We should check for compatibility, but don't at the moment.

FFMPEG-REMUX-TO-H264-TS remuxes a recording into an mpegts
container. The name is somewhat wrong, because it does not transcode
to h264, but the main use is in converting matroska to mpegts
containers, and all my mkvs use h264-encoded video.
This commit is contained in:
Leo Butler 2021-04-18 06:58:31 -05:00
parent 23d4e73ed6
commit 72a5d896ee
1 changed files with 38 additions and 3 deletions

View File

@ -459,15 +459,50 @@
(if mv? (shell-command-to-string (simple-format #f "touch --reference='~a' '~a' && mv '~a' '~a'" input-file input-tr-file input-tr-file recordings-directory)))
(mysql-commit (simple-format #f "update recorded set cutlist=0, commflagged=0, bookmark=0, transcoded=1, filesize=~a, basename=\"~a\" where chanid=~a and starttime=~a;" tr-filesize tr-basename chanid starttime))))
(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)))
(bn1 (caadr rec1+2))
(bn2 (caaddr rec1+2))
(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 ~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)))
(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))))
cmd))
(define (ffmpeg-remux-to-h264-ts chanid starttime)
(let* ((r (mythconverg-get-recorded chanid starttime))
(bn (assv-ref r 'basename))
(infile (simple-format #f "~a/~a" recordings-directory bn))
(outfile (simple-format #f "~a/~a" working-directory (recording-new-file-name bn remuxed-ts-file-ending)))
(remux-cmd (simple-format #f "~a -y -i ~a -codec copy -map 0 -f mpegts ~a && touch --reference='~a' ~a && mv ~a ~a/." ffmpeg-bin infile outfile infile outfile outfile recordings-directory))
(bn-cmd (simple-format #f "update recorded set basename='~a' where chanid=~a and starttime='~a';" (recording-new-file-name bn remuxed-ts-file-ending) chanid starttime)))
(shell-command-to-string remux-cmd)
(mythconverg-execute bn-cmd)
(mythutil-rebuild (re-create-record-data r))))
(define (ffmpeg-remux->concat chanid starttime)
(let* ((r (mythconverg-get-recorded chanid starttime))
(bn (assv-ref r 'basename))
(infile (simple-format #f "~a/~a" recordings-directory bn))
(outfile (simple-format #f "~a/~a" working-directory (recording-new-file-name bn transcoded-file-ending)))
(remux-cmd (simple-format #f "~a -y -i ~a -codec copy -map 0 -f mpegts ~a && touch --reference='~a' ~a && mv ~a ~a/." ffmpeg-bin infile outfile infile outfile outfile recordings-directory)))
(shell-command-to-string remux-cmd)
(mythutil-rebuild (re-create-record-data r))))
(define (mythutil-rebuild rec)
(let* ((chanid (recording-chanid rec))
(starttime (recording-starttime rec)))
(define (rebuild tbl)
(shell-command-to-string (simple-format #f "mythutil --chanid=~a --starttime=~a --clear~a" chanid starttime tbl)))
(map rebuild '(skiplist cutlist))))
(shell-command-to-string (simple-format #f "mythutil --chanid=~a --starttime='~a' --clear~a" chanid starttime tbl)))
(map rebuild '(skiplist cutlist seektable))
(shell-command-to-string (simple-format #f "mythcommflag --chanid=~a --starttime='~a' --rebuild" chanid starttime))))
(define* (mythconverg-pending-jobs #:optional (days 7))
(let ((basenames (mythconverg-execute+parse (simple-format #f "select basename from recorded where cutlist=1 and lastmodified>=now() - interval ~a day and not(recgroup = 'Deleted');" days))))
(let ((basenames (mythconverg-execute+parse (simple-format #f "select basename from recorded where cutlist=1 and lastmodified>=now() - interval ~a day and not(recgroup = 'Deleted') order by starttime;" days))))
(define (parse-basename bn)
(read-from-string (string-split (car (string-split (car bn) #\.)) #\_)))
(cond ((null? basenames)