diff --git a/ffmpeg-myth.scm b/ffmpeg-myth.scm index 73cc25b..f5e7f82 100755 --- a/ffmpeg-myth.scm +++ b/ffmpeg-myth.scm @@ -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)