mackworth / cTiVo

TiVo Show Downloads for MacOS
220 stars 36 forks source link

HandBrake Encode times slower on M1 Max and Pro computers than in HandBrake. #481

Closed ghost closed 1 year ago

ghost commented 2 years ago

Let me start by saying how much I appreciate your work here. That being said, this issue is more than a question mark than a mission critical issue. I use a handbrake profile using the Video-Tool-Box to leverage the gpu resources for encoding. Because of this strategy I am only using <40% of CPU resources for 2 concurrent encodes through handbrake. With this new build I am seeing an increased encode times for both 2 encoders and 1 encoders. I was seeing a 14 minute encode for 1 hour of content. Now I am seeing 30+minute encode times for the same 1 hour.

Just an FYI Thank you again.

ghost commented 2 years ago

Did a decrypt download and ran it through handbrake directly. 6 minute encode using the handbrake profile I use for cTiVo. Same show encode using cTiVo and handbrake profile 30 minutes.

Mac Studio 2022 Apple M1 Ultra 20 Core CPU 48 Core GPU 64 GB RAM

mackworth commented 2 years ago

First, nice system!

So, that's certainly interesting; when do you think this started?

First annoying suggestion: 2x is about the size of the Rosetta penalty. Can you check in Activity Monitor during an encode to ensure that Handbrake is not running in Intel mode (Kind: Apple)?

Next question: is this specific to your GPU Format, or is the same ratio true for the built-in HandBrake Formats?

Final step would be to isolate whether it's the HandbrakeCLI that's the problem, the parameters to it, or running inside cTiVo itself (e.g. cTiVo chooses to run in background mode which shouldn't affect performance when nothing's going on in the background).

  1. In Adv Prefs, set TaskChain to Verbose and temporarily turn on Don't Delete temp FIles.
  2. Run a download w/ your Format.
  3. Open the log file.
  4. Search for LaunchPath, making sure it's the HandbrakeCLI one.
  5. Copy everything from the / to end of the line.
  6. Open Terminal.
  7. Type date and return
  8. Paste the line and return.
  9. While it's executing, you can type dateand return again; as soon as encode finishes, that'll show you exactly how long it took.
  10. Be sure to put the Adv Prefs back to Major (my preferred mode) and turn off Don't Delete temp Files
  11. You could go to your tmp directory to delete the temp files, but just quitting and restarting cTivo will do the same thing.
ghost commented 2 years ago

Screen Shot 2022-05-13 at 10 11 11 Screen Shot 2022-05-13 at 10 11 31

ghost commented 2 years ago

I ran the same format inside and outside cTiVo with inside >30 min, and outside 6 Min.

mackworth commented 2 years ago

Interesting. To confirm, that’s following the detailed steps was 6 minutes, but cTiVo regular mode takes 30?

And on the other questions?

ghost commented 2 years ago

no that was a previous test. I am still running the inside encode to get log file specs

ghost commented 2 years ago

Hum, that is interesting. I updated the settings you outlined and now it is detecting ads. It has not done that before.

ghost commented 2 years ago

it is running now with a stated finish time of 31m. I will check when it finishes to confirm. 50 fps as opposed to inside handbrake at 277 fps. Big difference.

ghost commented 2 years ago

Job Info:

[11:06:31] Starting Task: Encoding Pass [11:06:31] Skipping crop/scale filter [11:06:31] job configuration: [11:06:31] source [11:06:31] + /var/folders/_2/3bvxqx2n56s9s__lbm0dqls40000gn/T/ctivo/bufferBeyond the Edge - Ask a Monkey for Help.mpg [11:06:31] + title 1, chapter(s) 1 to 1 [11:06:31] destination [11:06:31] + /Volumes/Samsung_T4/TiVo Recordings/Beyond the Edge/Beyond the Edge - Ask a Monkey for Help.mp4 [11:06:31] + container: MPEG-4 (libavformat) [11:06:31] + align initial A/V stream timestamps [11:06:31] video track [11:06:31] + decoder: mpeg2video 8-bit (yuv420p) [11:06:31] + bitrate 200 kbps [11:06:31] + filter [11:06:31] + Framerate Shaper (mode=1:rate=27000000/900900) [11:06:31] + frame rate: 29.970 fps -> constant 29.970 fps [11:06:31] + Output geometry [11:06:31] + storage dimensions: 1920 x 1080 [11:06:31] + pixel aspect ratio: 1 : 1 [11:06:31] + display dimensions: 1920 x 1080 [11:06:31] + encoder: H.264 (libavcodec) [11:06:31] + preset: quality [11:06:31] + profile: auto [11:06:31] + level: auto [11:06:31] + bitrate: 6800 kbps, pass: 0 [11:06:31] + color profile: 1-1-1 [11:06:31] audio track 1 [11:06:31] + decoder: Unknown (AC3) (5.1 ch) (384 kbps) (track 1, id 0x8000bd) [11:06:31] + bitrate: 384 kbps, samplerate: 48000 Hz [11:06:31] + mixdown: Stereo [11:06:31] + encoder: AAC (Apple AudioToolbox) [11:06:31] + bitrate: 320 kbps, samplerate: 48000 Hz

ghost commented 2 years ago

[11:39:47] libhb: work result = 0

37 minutes

ghost commented 2 years ago

script: Screen Shot 2022-05-13 at 11 15 55

Handbrake: Screen Shot 2022-05-13 at 11 41 39

ghost commented 2 years ago

The only thing I notice is the 56.7 fps vs 277.63 fps

mackworth commented 2 years ago

Not quite following here; when you say "inside and outside", do you mean cTiVo v HandSpring, or cTiVo v Terminal?

Some other open questions:

I tried on my M1 MacBook with a 1.1GB file using HB Default Format (aka Apple 720p30 in HB), and got pretty comparable results In Terminal and Handbrake. cTiVo: 10:05 to encode; 700% CPU 1.8Mbps Terminal: 8:17 to encode; 251.30 fps; 700% CPU; 1.6 MBps Handbrake: 9:31 to encode 246fps

ghost commented 2 years ago

Inside = cTiVo; Outside = cTiVo. I included screens shots above of the programs and both are universal. Looks like the inside cTiVo is running at a slower fps than in the handbrake interface. 59 vs. 270fps. For the same profile absolutely. Others in my social network are seeing similar results. I should probably go back to a pervious version to see if it is hardware or software. cTiVo and terminal yielded the same 59fps results. However if I take the decrypted mpg into handbrake I get 270 fps. Odd really. I might have to use the manual approach soon to minimize the machine time for encodes. I am off site currently but will export the profile this evening. Basically it is production proxy 1080 with alight av before start, 29.97 constant frame rate, 6800 constant bit rate, using h.264 video toolbox.

mackworth commented 2 years ago

I'm still not understanding this:

Inside = cTiVo; Outside = cTiVo.

and what's alight av mean?

So, checking the binary for Universal isn't good enough; you need to confirm during runtime in Activity Monitor to see whether it is running Rosetta emulation (Kind: Intel) or not (Kind: Apple). It's possible although unlikely that cTiVo and/or its sub-programs such as Handbrake are running in emulation mode even through they have the AppleSilicon code available. The fact that Terminal gives the same results suggests not, but your Terminal might be set for Rosetta.

I note an interesting discussion of similar issues here: https://github.com/HandBrake/HandBrake/discussions/3932#discussioncomment-1592973

They suggest also checking in Activity Monitor > Window -> CPU History to see if HB is using efficiency or performance cores.

Ah, another possibility: I haven't updated the HandbrakeCLI recently, so this may simply be a 1.4.2 v 1.5.1 issue . Try downloading the HBCli here, and do the same command line in Terminal but calling that version of the CLI instead. (if you're not used to terminal, just drag the CLI onto an open Terminal window to type it on a command line. You can then cut/paste the parameters from a previous line.) I didn't see any change in my system, but I'm not seeing the same discrepancy you are.

Ultimately the CLI and Handbrake should give roughly the same results, given the same environment/code/parameters, so we should be able to get there.

ghost commented 2 years ago

H.264 TiVo PP-VTB.json.zip

ghost commented 2 years ago

Ctivo is running in apple mode, align a/v before start. Sorry for the typo

https://user-images.githubusercontent.com/22117759/168452502-03fe761d-b8a2-43a8-b4c6-6b01feb8c605.mov

ghost commented 2 years ago

it is ok. I didn't mean to give you a headache. I just was giving you a heads up on the slow down doing the custom handbrake CLI from the cTiVo app. I will cut over to downloading as decrypted and using the handbrake GUI again. No worries.

ghost commented 2 years ago

Someone was testing a m1 vs m1 max and I have been using a ultra max. As you stated m1 testing yielded a good result. However, the max and the ultra are not function as expected. Again this is just information it is not a complaint. I just wanted to share some beta testing findings we have discovered. For me I will bring the show down as decrypted TiVo and manually encode using handbrake app to get the 6 minute results per one hour episode.

Warm regards

mackworth commented 2 years ago

No reason to give up quite yet 😀.

I spent some more time on the handbrake forum. It's pretty clearly a version issue on Handbrake.

Can you try the newest CLI as described above? If that works, you can just point to that executable in your Format, and cTiVo should then run it at full speed. (And I'll update the CLI anyways)

ghost commented 2 years ago

Will do but it might take some time. When I am work I work many hours and I will not have time to give it justice until Wednesday. Thank you for all of your help. I am not very good with terminal can you tell me how to substitute that CLI?

ghost commented 2 years ago

Here are the results of this amazing test. Zowie... 924 fps with the new CLI.... Screen Shot 2022-05-15 at 17 40 51 I have a video I will try to shrink it to 10 mb

mackworth commented 2 years ago

Ok then. Good to know they fixed it, and that I don't have to do anything (except apparently buy a new computer).

Until I prepare the next version, you can do one of two work arounds:

ghost commented 2 years ago

Ran my modified version and got a 1 hour show encoded in less than four minutes. Thank you for your help....

ghost commented 2 years ago

We added the new CLI to a m1 and the results were a 6 minute encode for a 3 hour movie 720 x 320 on a MacBook Air. So no need to buy another computer. Just update your CLI.

mackworth commented 1 year ago

And finally...a beta release of 3.6 with Handbrake 1.6.1 embedded.

ghost commented 1 year ago

Lol. Works great though. On Mar 10, 2023, at 13:02, Hugh Mackworth @.***> wrote: And finally...a beta release of 3.6 with Handbrake 1.6.1 embedded.

—Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you authored the thread.Message ID: @.***>