Easy ubuntu cli / cron job to batch convert recursively

Discussion of the HandBrake command line interface (CLI)
Forum rules
An Activity Log is required for support requests. Please read How-to get an activity log? for details on how and why this should be provided.
Post Reply
wildebeest
Posts: 6
Joined: Tue Apr 21, 2020 4:25 am

Easy ubuntu cli / cron job to batch convert recursively

Post by wildebeest »

Hi there, I've been using handbrake on Windows. Recently however, I built myself an Ubuntu Server 18.04 LTS NAS with a decent GPU and thought I'd use that to batch convert tons of drone footage b-roll quality to save some hard disk space. I saw the below which looks exciting, however, I'm running a headless server and don't want to start a docker container with GUI etc, because then it gets nasty with GPU utilization and I'm not a docker expert (yet).

https://www.reddit.com/r/PleX/comments/ ... recursive/

Ideally, I'd like to do this in a more simple way, over command line or bash script. Does anybody use anything similar as I'm sure it's a common query, I just couldn't find anything that does exactly what I needed:

  • script that allows specifying input and output directories
  • input and output directory can be the same or different. If different, the output directory however needs to replicate the (sub-)folder structure of the original path.
  • if folders are the same, filename extension ....-converted.mp4 would be needed
  • settings can be fixed at 1920x1080 x 30p for all, unless original is already lower-res (see below "bonus" query about preserving original resolution
  • should recursively scan all folders and place the converted video
  • needs to use NVIDIA GPU
  • "bonus" query: it would of course be great if handbrake could maintain the original resolution and frame rate and just re-compress the video itself. This way, I could throw HD and 4K content at the script without having to worry about losing detail in the footage beyond the compression impact of course.
Question: I like the compression results of H.265 over H.264 but am not 100% sure whether H.265 is ready yet for every media player. I use Plex to view stuff on my TV so I think I'm o.k. there. Any other reasons why you would / would not use H.265 as a codec?

Who can help me with this script or point me to a good resource? Ideally so that I can run it as a cron-job, maybe once a week?

Thanks folks, really appreciate the support. I love handbrake, so would prefer to stick with it.
Woodstock
Veteran User
Posts: 3759
Joined: Tue Aug 27, 2013 6:39 am

Re: Easy ubuntu cli / cron job to batch convert recursively

Post by Woodstock »

If you're dealing with a maximum resolution of 1080p, don't bother with x265. The advantages are marginal, while the disadvantages (compatibility with older players) can be great.

Also, hardware encoder support on Linux is rather limited, other than QSV, and that's only if you use the flatpack distribution, OR compile it yourself.
User avatar
JohnAStebbins
HandBrake Team
Posts: 5583
Joined: Sat Feb 09, 2008 7:21 pm

Re: Easy ubuntu cli / cron job to batch convert recursively

Post by JohnAStebbins »

One person reported success building the linux version with AMD VCE.
viewtopic.php?p=189557#p189557

I don't recall anyone reporting success or failure with NVidia NVENC.

In either case, it's required to install proprietary drivers along with other libraries and to build HandBrake yourself with the relevant hardware encoder option enabled.

But if you have a recent Intel CPU with QSV support, that would be better than either VCE or NVENC both in terms of the quality of the output and the level of support in HandBrake. I've bundled everything that is needed for QSV in a flatpak plugin that works with the flatpak release of HandBrake. The flatpak package and plugin can be found on our downloads page or nightly builds page.

The flatpak package contains both the GUI and CLI. The CLI can be run with the following command:

Code: Select all

flatpak run --command=HandBrakeCLI fr.handbrake.ghb --help
Also, flatpaks can be installed as a regular user. It is not necessary to have admin privileges. I.e. "flatpak --user install blah.flatpak" will install to your user account without need of admin privileges and without disturbing the rest of the system.
wildebeest
Posts: 6
Joined: Tue Apr 21, 2020 4:25 am

Re: Easy ubuntu cli / cron job to batch convert recursively

Post by wildebeest »

great, thank you both for the reply. I'll try the flatpak, appreciate the advice on H.264/5.
Question though (my actual questions): how do I recursively convert the videos per the above requirements in the bullets? I.e. is there any simple, readily available script I could tweak? I'm not great with IF END NEXT THEN stuff... :-)

Cheers!
mduell
Veteran User
Posts: 7194
Joined: Sat Apr 21, 2007 8:54 pm

Re: Easy ubuntu cli / cron job to batch convert recursively

Post by mduell »

Take a look at HBBatchBeast, it's more along the lines of what you're looking for.
wildebeest
Posts: 6
Joined: Tue Apr 21, 2020 4:25 am

Re: Easy ubuntu cli / cron job to batch convert recursively

Post by wildebeest »

yeah, I saw that, just wasn't quite sure it works on Linux, saw all these Windows screenshots.. will take another look...
wildebeest
Posts: 6
Joined: Tue Apr 21, 2020 4:25 am

Re: Easy ubuntu cli / cron job to batch convert recursively

Post by wildebeest »

... and 100% command line as my server is headless...
mduell
Veteran User
Posts: 7194
Joined: Sat Apr 21, 2007 8:54 pm

Re: Easy ubuntu cli / cron job to batch convert recursively

Post by mduell »

It's available as a docker container https://github.com/HaveAGitGat/HBBatchBeast
wildebeest
Posts: 6
Joined: Tue Apr 21, 2020 4:25 am

Re: Easy ubuntu cli / cron job to batch convert recursively

Post by wildebeest »

Per my initial post, I want to avoid docker:

...saw the below which looks exciting, however, I'm running a headless server and don't want to start a docker container with GUI etc, because then it gets nasty with GPU utilization and I'm not a docker expert (yet).
mduell
Veteran User
Posts: 7194
Joined: Sat Apr 21, 2007 8:54 pm

Re: Easy ubuntu cli / cron job to batch convert recursively

Post by mduell »

Then I guess you'll have to write or crib all the logic in your own CLI app.
wildebeest
Posts: 6
Joined: Tue Apr 21, 2020 4:25 am

Re: Easy ubuntu cli / cron job to batch convert recursively

Post by wildebeest »

Yep, and that was exactly what I was for help with, particularly with the syntax of the script... parameters I can figure out.. thx. No point in using docket when I can’t include the gpu and don’t want to spend two weeks learning how to do it ;-)
roddersg
New User
Posts: 1
Joined: Wed May 20, 2020 12:29 pm

Re: Easy ubuntu cli / cron job to batch convert recursively

Post by roddersg »

Instead of using cron, I use task-spooler in which i enter each conversion from the cli and it puts it in a batch queue.
Here's the link: https://vicerveza.homeunix.net/~viric/soft/ts/

I then write a shell program e.g. hbmake and then if I need to convert anything, I just enter hbmake <filename> , and the task-spooler puts each of them into the queue
Post Reply