From 4718bf2f75fd637e75faf2f643017d8a2a722e27 Mon Sep 17 00:00:00 2001 From: Tong Sun Date: Fri, 26 May 2023 20:38:12 -0400 Subject: [PATCH] - [+] implement CPU shaping options support --- ffcvt.go | 6 ++++++ test/ffcvt_test.txt | 20 ++++++++++++++++++++ test/test-all.sh | 10 +++++----- test2/ffcvt_test.txt | 18 ++++++++++++++++++ 4 files changed, 49 insertions(+), 5 deletions(-) diff --git a/ffcvt.go b/ffcvt.go index a2f6f79..af94f9f 100644 --- a/ffcvt.go +++ b/ffcvt.go @@ -374,6 +374,12 @@ func transcodeVideos(startTime time.Time) { videoNdx, videosTotal, v.pct, filepath.Base(inputName), filepath.Dir(inputName)) transcodeFile(inputName) fmt.Printf("Time taken so far %s\n", time.Since(startTime)) + if Opts.MaxC != 0 && videoNdx >= Opts.MaxC { + debug("Max conversion count reached.", 1) + os.Exit(0) + } + debug("Taking a breath for: "+Opts.BreathTime.String(), 1) + time.Sleep(Opts.BreathTime) fmt.Printf("Finishing the remaining %d%% in %s\n", 100-v.pct, time.Duration(int64(float32(time.Since(startTime))* diff --git a/test/ffcvt_test.txt b/test/ffcvt_test.txt index 24f477e..0920f77 100644 --- a/test/ffcvt_test.txt +++ b/test/ffcvt_test.txt @@ -46,6 +46,8 @@ Flags: -p par2create, create par2 files (in work directory) (FFCVT_P) -nc no clobber, do not queue those already been converted (FFCVT_NC) + -bt breath time, interval between conversion to take a breath (FFCVT_BT) + -maxc max conversion done each run (default no limit) (FFCVT_MAXC) -n no exec, dry run (FFCVT_N) -force overwrite any existing none-empty file (FFCVT_FORCE) @@ -83,6 +85,8 @@ Details: no audio, output video only -ato-opus audio encode to opus, using -abr + -bt duration + breath time, interval between conversion to take a breath (default 2m0s) -cfg string cfg file to define your own targets: webm/wx/youtube etc -crf string @@ -108,6 +112,8 @@ Details: Add a karaoke audio track to .mp4 MTV -lang string language selection for audio stream extraction (default "eng") + -maxc int + max conversion done each run (default no limit) -n no exec, dry run -nc no clobber, do not queue those already been converted @@ -289,6 +295,7 @@ Saved: 0% ffcvt: to execute - ffmpeg -i ./StreamSample.mkv -c:v libx265 -x265-params crf=28 -c:a libopus -b:a 64k ./StreamSample_.mkv Time taken so far xxx ms +] Taking a breath for: xxx ms Finishing the remaining 0% in xxx ms Transcoding completed in xxx ms @@ -304,6 +311,7 @@ Saved: 0% ffcvt: to execute - ffmpeg -i ./StreamSample.mkv -c:v libx265 -x265-params crf=28 -c:a libopus -b:a 64k ./StreamSample_.mkv Time taken so far xxx ms +] Taking a breath for: xxx ms Finishing the remaining 0% in xxx ms == Transcoding [2/4] (100%): 'test1.avi' @@ -312,6 +320,7 @@ Finishing the remaining 0% in xxx ms ffcvt: to execute - ffmpeg -i ./test1.avi -c:v libx265 -x265-params crf=28 -c:a libopus -b:a 64k ./test1_.mkv Time taken so far xxx ms +] Taking a breath for: xxx ms Finishing the remaining 0% in xxx ms == Transcoding [3/4] (100%): 'test2.avi' @@ -320,6 +329,7 @@ Finishing the remaining 0% in xxx ms ffcvt: to execute - ffmpeg -i ./test2.avi -c:v libx265 -x265-params crf=28 -c:a libopus -b:a 64k ./test2_.mkv Time taken so far xxx ms +] Taking a breath for: xxx ms Finishing the remaining 0% in xxx ms == Transcoding [4/4] (100%): 'test3.webm' @@ -328,6 +338,7 @@ Finishing the remaining 0% in xxx ms ffcvt: to execute - ffmpeg -i ./test3.webm -c:v libx265 -x265-params crf=28 -c:a libopus -b:a 64k ./test3_.mkv Time taken so far xxx ms +] Taking a breath for: xxx ms Finishing the remaining 0% in xxx ms Transcoding completed in xxx ms @@ -346,6 +357,7 @@ Saved: 0% ffcvt: to execute - ffmpeg -i ./StreamSample.mkv -c:v libvpx-vp9 -b:v 0 -crf 42 -c:a libopus -b:a 64k -c:s copy ./StreamSample_.mkv Time taken so far xxx ms +] Taking a breath for: xxx ms Finishing the remaining 0% in xxx ms Transcoding completed in xxx ms @@ -361,6 +373,7 @@ Saved: 0% ffcvt: to execute - ffmpeg -i ./StreamSample.mkv -c:v libvpx-vp9 -b:v 0 -crf 42 -c:a libopus -b:a 64k -c:s copy ./StreamSample_.mkv Time taken so far xxx ms +] Taking a breath for: xxx ms Finishing the remaining 0% in xxx ms == Transcoding [2/4] (100%): 'test1.avi' @@ -369,6 +382,7 @@ Finishing the remaining 0% in xxx ms ffcvt: to execute - ffmpeg -i ./test1.avi -c:v libvpx-vp9 -b:v 0 -crf 42 -c:a libopus -b:a 64k -c:s copy ./test1_.mkv Time taken so far xxx ms +] Taking a breath for: xxx ms Finishing the remaining 0% in xxx ms == Transcoding [3/4] (100%): 'test2.avi' @@ -377,6 +391,7 @@ Finishing the remaining 0% in xxx ms ffcvt: to execute - ffmpeg -i ./test2.avi -c:v libvpx-vp9 -b:v 0 -crf 42 -c:a libopus -b:a 64k -c:s copy ./test2_.mkv Time taken so far xxx ms +] Taking a breath for: xxx ms Finishing the remaining 0% in xxx ms == Transcoding [4/4] (100%): 'test3.webm' @@ -385,6 +400,7 @@ Finishing the remaining 0% in xxx ms ffcvt: to execute - ffmpeg -i ./test3.webm -c:v libvpx-vp9 -b:v 0 -crf 42 -c:a libopus -b:a 64k -c:s copy ./test3_.mkv Time taken so far xxx ms +] Taking a breath for: xxx ms Finishing the remaining 0% in xxx ms Transcoding completed in xxx ms @@ -401,6 +417,7 @@ Saved: 0% ffcvt: to execute - ffmpeg -i ./StreamSample.mkv -c:v libvpx-vp9 -b:v 0 -crf 42 -c:a libopus -b:a 64k -c:s copy /tmp/test/StreamSample.mkv Time taken so far xxx ms +] Taking a breath for: xxx ms Finishing the remaining 0% in xxx ms == Transcoding [2/4] (100%): 'test1.avi' @@ -409,6 +426,7 @@ Finishing the remaining 0% in xxx ms ffcvt: to execute - ffmpeg -i ./test1.avi -c:v libvpx-vp9 -b:v 0 -crf 42 -c:a libopus -b:a 64k -c:s copy /tmp/test/test1.mkv Time taken so far xxx ms +] Taking a breath for: xxx ms Finishing the remaining 0% in xxx ms == Transcoding [3/4] (100%): 'test2.avi' @@ -417,6 +435,7 @@ Finishing the remaining 0% in xxx ms ffcvt: to execute - ffmpeg -i ./test2.avi -c:v libvpx-vp9 -b:v 0 -crf 42 -c:a libopus -b:a 64k -c:s copy /tmp/test/test2.mkv Time taken so far xxx ms +] Taking a breath for: xxx ms Finishing the remaining 0% in xxx ms == Transcoding [4/4] (100%): 'test3.webm' @@ -425,6 +444,7 @@ Finishing the remaining 0% in xxx ms ffcvt: to execute - ffmpeg -i ./test3.webm -c:v libvpx-vp9 -b:v 0 -crf 42 -c:a libopus -b:a 64k -c:s copy /tmp/test/test3.mkv Time taken so far xxx ms +] Taking a breath for: xxx ms Finishing the remaining 0% in xxx ms Transcoding completed in xxx ms diff --git a/test/test-all.sh b/test/test-all.sh index 9075c15..ad863fc 100755 --- a/test/test-all.sh +++ b/test/test-all.sh @@ -34,13 +34,13 @@ $FFCVT -t x264-mp3 -n -f StreamSample.mkv -w /tmp -tkf 'F#' -tkt Db -vn -abr 72k $FFCVT -t '' -n -f StreamSample.mkv -tkf Gb -tkt 'A#' -vn -abr 72k -aes libmp3lame -ext _.mp3 >> /tmp/ffcvt_test.txt 2>&1 echo '# Test -sym control' | tee -a /tmp/ffcvt_test.txt -$FFCVT -t x265-opus -n -d . >> /tmp/ffcvt_test.txt 2>&1 -$FFCVT -t x265-opus -n -d . -sym >> /tmp/ffcvt_test.txt 2>&1 +$FFCVT -t x265-opus -n -bt 0.1s -d . >> /tmp/ffcvt_test.txt 2>&1 +$FFCVT -t x265-opus -n -bt 0.1s -d . -sym >> /tmp/ffcvt_test.txt 2>&1 -$FFCVT -n -d . >> /tmp/ffcvt_test.txt 2>&1 -$FFCVT -n -d . -sym >> /tmp/ffcvt_test.txt 2>&1 +$FFCVT -n -bt 0.1s -d . >> /tmp/ffcvt_test.txt 2>&1 +$FFCVT -n -bt 0.1s -d . -sym >> /tmp/ffcvt_test.txt 2>&1 -$FFCVT -n -sym -debug 2 -d . -w /tmp >> /tmp/ffcvt_test.txt 2>&1 +$FFCVT -n -sym -debug 2 -bt 0.1s -d . -w /tmp >> /tmp/ffcvt_test.txt 2>&1 echo '# Compare test results, 0 means AOK:' sed -i '/ [0-9.]*[nmµ]*s$/s// xxx ms/' /tmp/ffcvt_test.txt diff --git a/test2/ffcvt_test.txt b/test2/ffcvt_test.txt index fce136a..8e19607 100644 --- a/test2/ffcvt_test.txt +++ b/test2/ffcvt_test.txt @@ -46,6 +46,8 @@ Flags: -p par2create, create par2 files (in work directory) (FFCVT_P) -nc no clobber, do not queue those already been converted (FFCVT_NC) + -bt breath time, interval between conversion to take a breath (FFCVT_BT) + -maxc max conversion done each run (default no limit) (FFCVT_MAXC) -n no exec, dry run (FFCVT_N) -force overwrite any existing none-empty file (FFCVT_FORCE) @@ -83,6 +85,8 @@ Details: no audio, output video only -ato-opus audio encode to opus, using -abr + -bt duration + breath time, interval between conversion to take a breath (default 2m0s) -cfg string cfg file to define your own targets: webm/wx/youtube etc -crf string @@ -108,6 +112,8 @@ Details: Add a karaoke audio track to .mp4 MTV -lang string language selection for audio stream extraction (default "eng") + -maxc int + max conversion done each run (default no limit) -n no exec, dry run -nc no clobber, do not queue those already been converted @@ -297,6 +303,7 @@ Saved: 0% ffcvt: to execute - ffmpeg -i ./subdir/test_s1.avi -c:v libx265 -x265-params crf=28 -c:a libopus -b:a 64k ./subdir/test_s1_.mkv Time taken so far xxx ms +] Taking a breath for: xxx ms Finishing the remaining 64% in xxx ms == Transcoding [2/4] (57%): 'test1.avi' @@ -305,6 +312,7 @@ Finishing the remaining 64% in xxx ms ffcvt: to execute - ffmpeg -i ./test1.avi -c:v libx265 -x265-params crf=28 -c:a libopus -b:a 64k ./test1_.mkv Time taken so far xxx ms +] Taking a breath for: xxx ms Finishing the remaining 43% in xxx ms == Transcoding [3/4] (78%): 'test2.avi' @@ -313,6 +321,7 @@ Finishing the remaining 43% in xxx ms ffcvt: to execute - ffmpeg -i ./test2.avi -c:v libx265 -x265-params crf=28 -c:a libopus -b:a 64k ./test2_.mkv Time taken so far xxx ms +] Taking a breath for: xxx ms Finishing the remaining 22% in xxx ms == Transcoding [4/4] (100%): 'test3.webm' @@ -321,6 +330,7 @@ Finishing the remaining 22% in xxx ms ffcvt: to execute - ffmpeg -i ./test3.webm -c:v libx265 -x265-params crf=28 -c:a libopus -b:a 64k ./test3_.mkv Time taken so far xxx ms +] Taking a breath for: xxx ms Finishing the remaining 0% in xxx ms Transcoding completed in xxx ms @@ -347,6 +357,7 @@ Saved: 0% ffcvt: to execute - ffmpeg -i ./subdir/test_s1.avi -c:v libvpx-vp9 -b:v 0 -crf 42 -c:a libopus -b:a 64k -c:s copy ./subdir/test_s1_.mkv Time taken so far xxx ms +] Taking a breath for: xxx ms Finishing the remaining 64% in xxx ms == Transcoding [2/4] (57%): 'test1.avi' @@ -355,6 +366,7 @@ Finishing the remaining 64% in xxx ms ffcvt: to execute - ffmpeg -i ./test1.avi -c:v libvpx-vp9 -b:v 0 -crf 42 -c:a libopus -b:a 64k -c:s copy ./test1_.mkv Time taken so far xxx ms +] Taking a breath for: xxx ms Finishing the remaining 43% in xxx ms == Transcoding [3/4] (78%): 'test2.avi' @@ -363,6 +375,7 @@ Finishing the remaining 43% in xxx ms ffcvt: to execute - ffmpeg -i ./test2.avi -c:v libvpx-vp9 -b:v 0 -crf 42 -c:a libopus -b:a 64k -c:s copy ./test2_.mkv Time taken so far xxx ms +] Taking a breath for: xxx ms Finishing the remaining 22% in xxx ms == Transcoding [4/4] (100%): 'test3.webm' @@ -371,6 +384,7 @@ Finishing the remaining 22% in xxx ms ffcvt: to execute - ffmpeg -i ./test3.webm -c:v libvpx-vp9 -b:v 0 -crf 42 -c:a libopus -b:a 64k -c:s copy ./test3_.mkv Time taken so far xxx ms +] Taking a breath for: xxx ms Finishing the remaining 0% in xxx ms Transcoding completed in xxx ms @@ -387,6 +401,7 @@ Saved: 0% ffcvt: to execute - ffmpeg -i ./subdir/test_s1.avi -c:v libvpx-vp9 -b:v 0 -crf 42 -c:a libopus -b:a 64k -c:s copy /tmp/test2/subdir/test_s1.mkv Time taken so far xxx ms +] Taking a breath for: xxx ms Finishing the remaining 64% in xxx ms == Transcoding [2/4] (57%): 'test1.avi' @@ -395,6 +410,7 @@ Finishing the remaining 64% in xxx ms ffcvt: to execute - ffmpeg -i ./test1.avi -c:v libvpx-vp9 -b:v 0 -crf 42 -c:a libopus -b:a 64k -c:s copy /tmp/test2/test1.mkv Time taken so far xxx ms +] Taking a breath for: xxx ms Finishing the remaining 43% in xxx ms == Transcoding [3/4] (78%): 'test2.avi' @@ -403,6 +419,7 @@ Finishing the remaining 43% in xxx ms ffcvt: to execute - ffmpeg -i ./test2.avi -c:v libvpx-vp9 -b:v 0 -crf 42 -c:a libopus -b:a 64k -c:s copy /tmp/test2/test2.mkv Time taken so far xxx ms +] Taking a breath for: xxx ms Finishing the remaining 22% in xxx ms == Transcoding [4/4] (100%): 'test3.webm' @@ -411,6 +428,7 @@ Finishing the remaining 22% in xxx ms ffcvt: to execute - ffmpeg -i ./test3.webm -c:v libvpx-vp9 -b:v 0 -crf 42 -c:a libopus -b:a 64k -c:s copy /tmp/test2/test3.mkv Time taken so far xxx ms +] Taking a breath for: xxx ms Finishing the remaining 0% in xxx ms Transcoding completed in xxx ms