sharpen transcoding options, add choice for muxer

In v31 of mythtv, playback and editing of matroska-formatted
containers does not work well--seeking is broken so bookmarks,
jumping, etc. do not work.

So, an option to set the container format/muxer has been added to
FFMPEG-SPLIT+TRANSCODE-RECORDING, namely FFMPEG-TRANSCODED-FILE-MUXER,
and this is set to mpegts by default.

Because we relied on defaults for the matroska container, we have made
some things explicit (like using libx264 for the video codec). The
preset is also now veryfast, rather than slow, which is a recommended
setting on the ffmpeg users' mailing list.

FFMPEG-SPLIT+TRANSCODE-RECORDING also uses FFMPEG-TRANSCODING-OPTIONS
now, rather than hard-coded options.
This commit is contained in:
Leo Butler 2021-04-18 06:34:59 -05:00
parent 265905ff90
commit af706d5d4b
1 changed files with 8 additions and 5 deletions

View File

@ -18,7 +18,8 @@
(define ffmpeg-bin "/usr/bin/ffmpeg")
(define ffprobe-bin "/usr/bin/ffprobe")
(define ffprobe-separator #\page) ;;
(define ffmpeg-transcoding-options "-preset slow -crf 21 -c:a ac3 -g 60 -keyint_min 30")
(define ffmpeg-transcoding-options "-c:v libx264 -preset veryfast -crf 21 -c:a ac3 -g 60 -keyint_min 30")
(define ffmpeg-transcoded-file-muxer 'mpegts) ;; 'matroska
(define recordings-directory "/var/lib/mythtv/recordings")
(define working-directory "/mnt/lvraid5/ffmpeg-cut-list.d")
(define mythtv-recorded-table->metadata-list '(chanid starttime endtime title subtitle description season episode recordid seriesid programid inetref previouslyshown originalairdate))
@ -389,20 +390,22 @@
(lambda(x) (set! i (+ 1 i)) (string-join (map (lambda(f) (simple-format #f f i)) concat-template) " "))
output-template)))
(define* (ffmpeg-split+transcode-recording rec #:optional (max-streams 4))
(define* (ffmpeg-split+transcode-recording rec #:optional (max-streams 4)
(transcoded-file-ending transcoded-file-ending)
(ffmpeg-transcoded-file-muxer ffmpeg-transcoded-file-muxer))
(let* ((basename (recording-basename rec))
(rootname+ext (string-split basename #\.))
(rootname (car rootname+ext)) (ext (cadr rootname+ext))
(rootname (car rootname+ext))
(in-file (simple-format #f "~a/~a" recordings-directory basename))
(out-file (simple-format #f "~a/~a.~a" working-directory rootname transcoded-file-ending))
(m-d (mythtv-recorded-table->metadata rec))
(m-d (if (eq? ffmpeg-transcoded-file-muxer 'matroska) (mythtv-recorded-table->metadata rec) ""))
(cut-times (myth-convert-i-frame-indices-to-times (recording-retain-list rec) (recording-i-frame-info rec)))
(seek-fn (lambda(c) (simple-format #f " -ss ~a -t ~a -i '~a'" (car c) (- (cdr c) (car c)) in-file)))
(concat-info (ffmpeg-outstreams-templates rec max-streams))
(instreams (string-join (map (car concat-info) cut-times) " "))
(outstreams (cdr concat-info))
(mappings (map (lambda (x) (simple-format #f " -map '~a'" x)) outstreams))
(cmd (simple-format #f "~a -y ~a -filter_complex '~a concat=n=~a:v=1:a=~a ~a' -preset slow -crf 21 -c:a ac3 -g 60 -keyint_min 30 ~a ~a ~a" ffmpeg-bin (string-join (map seek-fn cut-times)) instreams (length cut-times) (- (length outstreams) 1) (string-join outstreams) (string-join mappings) m-d out-file)))
(cmd (simple-format #f "~a -y ~a -filter_complex '~a concat=n=~a:v=1:a=~a ~a' ~a ~a ~a -f ~a ~a" ffmpeg-bin (string-join (map seek-fn cut-times)) instreams (length cut-times) (- (length outstreams) 1) (string-join outstreams) ffmpeg-transcoding-options (string-join mappings) m-d ffmpeg-transcoded-file-muxer out-file)))
(shell-command-to-string cmd)
cmd))