There have been multiple accounts created with the sole purpose of posting advertisement posts or replies containing unsolicited advertising.

Accounts which solely post advertisements, or persistently post them may be terminated.

Batch video conversion from command line

Hi fellow sailors,

i have lots of downloaded… ISOs… that i need to converto to save space. I would like to make them all of the same size, let’s say 720p, and same format, let’s say h265.

I am on linux and the… ISOs… are sorted into a neatly named hierarchy of sub-folderds, which i want to preserve too. What is the best tool (CLI) for the scope? I can use ffmpeg with a bash script, but is there anything better suited?

Dark_Dragon ,

For batch converting ISOs to a specific resolution and format while preserving folder hierarchy on Linux, you can indeed use ffmpeg with a bash script. However, you might also consider using HandBrakeCLI, which is a command-line interface for HandBrake, a popular video transcoder.

Here’s how you could use HandBrakeCLI to achieve your goal:

  1. Install HandBrakeCLI if you haven’t already:

<span style="color:#323232;">sudo apt-get install handbrake-cli
</span>
  1. Write a bash script to iterate through your directories, converting ISO files:

<span style="font-style:italic;color:#969896;">#!/bin/bash
</span><span style="color:#323232;">
</span><span style="font-style:italic;color:#969896;"># Set input and output directories
</span><span style="color:#323232;">input_dir</span><span style="font-weight:bold;color:#a71d5d;">=</span><span style="color:#183691;">"/path/to/your/input/directory"
</span><span style="color:#323232;">output_dir</span><span style="font-weight:bold;color:#a71d5d;">=</span><span style="color:#183691;">"/path/to/your/output/directory"
</span><span style="color:#323232;">
</span><span style="font-style:italic;color:#969896;"># Convert ISOs to 720p h.265
</span><span style="color:#323232;">find </span><span style="color:#183691;">"$</span><span style="color:#323232;">input_dir</span><span style="color:#183691;">"</span><span style="color:#323232;"> -name </span><span style="color:#183691;">"*.iso"</span><span style="color:#323232;"> -type f </span><span style="font-weight:bold;color:#a71d5d;">| while </span><span style="color:#62a35c;">read </span><span style="color:#323232;">-r file</span><span style="font-weight:bold;color:#a71d5d;">; do
</span><span style="color:#323232;">    output_file</span><span style="font-weight:bold;color:#a71d5d;">=</span><span style="color:#183691;">"${</span><span style="color:#323232;">file</span><span style="font-weight:bold;color:#a71d5d;">%</span><span style="color:#183691;">.iso}.mp4"
</span><span style="color:#323232;">    handbrakecli --input </span><span style="color:#183691;">"$</span><span style="color:#323232;">file</span><span style="color:#183691;">"</span><span style="color:#323232;"> --output </span><span style="color:#183691;">"$</span><span style="color:#323232;">output_dir</span><span style="color:#183691;">/$</span><span style="color:#323232;">output_file</span><span style="color:#183691;">"</span><span style="color:#323232;"> --preset</span><span style="font-weight:bold;color:#a71d5d;">=</span><span style="color:#183691;">"Super HQ 720p30 Surround"
</span><span style="font-weight:bold;color:#a71d5d;">done
</span>

Adjust the preset according to your needs. You can check available presets with HandBrakeCLI --preset-list.

  1. Make the script executable:

<span style="color:#323232;">chmod +x convert_iso.sh
</span>
  1. Run the script:

<span style="color:#323232;">./convert_iso.sh
</span>

This script will convert all ISO files in the specified input directory to 720p h.265 MP4 files using HandBrakeCLI while preserving the folder hierarchy.

ArcaneSlime ,

You could probably use find and ffmpeg.

alphacyberranger ,
@alphacyberranger@lemmy.world avatar

Use a python script. Use the subprocess function to run the ffmpeg command.

z00s ,

Use chatgpt to create a Python program that runs ffmpeg with your desired settings, and retains the folder structure. Important: use chatgpt 4, not 3

xor ,

lol

Lemmchen ,

I’ve heard that the size difference between 720p and 1080p for HEVC/h.265 is neglectable, so you should probably stick to 1080p for better quality.

But honestly I think what you want to do is neither worth the effort nor is the result very desirable.

ShepherdPie ,

Agreed. Just download the copies you want in 5 minutes rather than spending 45 minutes encoding each video or buy another HDD for more space.

Shimitar OP ,

My internet speed doesn’t allow for this unfortunately. On Usenet I can reach 1mb/sec when lucky. And 6Tb of stuff takes time to find and download again.

ShepherdPie ,

That’s a sticky spot to be in. Is another HDD out of the question? 6TB of encoding is going to take a lot of time too. When I first built my current server, I went ahead and bought a bluray drive with the intent of encoding bluray discs and gave up after about a dozen because of the time requirements.

Shimitar OP ,

OK, I installed tdarr and… Well, not impressed. Quite messy, low quality UI and… Paid features. Meh

Tomorrow will try Unmanic, feels much more refined, I will see.

Nothing against “paid” in tdarr, just doesn’t seems worthwhile given the low quality of the UI.

I am sure I am judging the book by the cover, but hey, even the Unmanic documentation feels better.

tordenflesk ,

You’re not really meant to be using the UI that much, once you’ve set it up.

vojel ,
@vojel@discuss.tchncs.de avatar

I had the same need and didn’t want to read tooo much about ffmpeg and its options. I ended up using fastflix which uses ffmpeg under the hood with built in presets. Supports queues and lots of more stuff.

GravitySpoiled ,

Usually it’s not worth it. Redownload your videos in the desired size. Use radarr et al to manage it. There are People who are specialized on the task.only use raw material to encode. Reencoding makes quality worse. And time and effort isn’t worth it.

It’s much cheaper to buy more drives than to reencode a large library to av1 in order to save space.

AnEilifintChorcra , (edited )

I’ve been using a for loop with ffmpeg to convert to AV1

I start in the series root folder and it iterates through each seasons subfolder


<span style="color:#323232;">for f in ./**/*.mkv; do
</span><span style="color:#323232;">      ffmpeg -i "$f" -c:v libsvtav1 -crf 0 "{f%.*}.av1.mkv"; done
</span>

Since I’m happy with the quality of everything so far, I’ve added this to the start to make it easier to delete the old files


<span style="color:#323232;">for f in ./**/*.mkv; do
</span><span style="color:#323232;">      mv "$f" "${f%.*}.xyz.mkv"; done
</span>

And at the end I’ve added this to delete the old files


<span style="color:#323232;">for f in ./**/*.xyz.mkv; do
</span><span style="color:#323232;">      rm " $f"; done
</span>
Lemmchen ,

Why -crf 0?

AnEilifintChorcra ,

The valid CRF value range is 0-63, with the default being 30. Lower values correspond to higher quality and greater file size.

trac.ffmpeg.org/wiki/Encode/AV1

I compared a bunch of crf values, taking video quality, encode time and file size into account on a few episodes from some of my favorite shows and ended up settling on this.

For the most part, I don’t notice a quality difference compared to my source, but it might just be because of my bad eyes or my monitor lol. But I did notice quality differences around 35 + so they were out.

At crf 0 I’m encoding a 40 min epsisode in about 5 mins which I’m happy with, I probably could have saved time going for a higher value but most of the time I run the script when I’m sleeping so time wasn’t a big issue as long as it wasn’t taking 20+ mins to encode 1 file

Going for 0 meant I’d have as close to the same quality as my source, using the default preset, and I didn’t notice huge file size differences between 0 and 30.

I’ve encoded pretty much all of my TV shows now and I’ve dropped the size of my TV directory to about 1/4 of the original size so going for a higher crf value didn’t seem worth it to me, if I had noticed that my file size at crf 5 was half what it is at crf 0 then I would probably have went with crf 5

I think its pretty subjective some people are happy with 720p and others won’t settle for less than 4k so I don’t think this would be a great solution for everyone to do but I think people should play around with different parameters to see what works best for them.

ShortN0te ,

Basically everything useful uses ffmpeg under the hood. So bash+ffmpeg is just fine. But tdarr exists too

GravitySpoiled ,

I’d prefer Unmanic over tdarr

AlteredEgo ,

Alternatively you could look into av1-svt and av1an (!av1). But there are far more tools for x265

Shimitar OP ,

What’s this? The link you posted seems broken…

Shimitar OP ,

I need to encode in something future-proof that can be streamed to a fire stick pro max (whatever its called) without further transcoding possibly.

Any suggestion in codecs formats and containing formats?

AlteredEgo ,

Not sure why the link doesn’t work: lemmy.ml/c/[email protected] (there is also a second community and a av1 discord server.

Fire stick pro max should support av1 but I have no experience with that.

Av1 is the best compression format but it still requires more work to use it well. The tools for x265 are more mature.

isles ,

I’m pretty certain the two options I can think of are just front-ends for ffmpeg: Handbrake and Tdarr, Tdarr runs as a service and monitors your folder for things that don’t match spec and then converts them, if you plan to continue acquiring ISOs.

Shimitar OP ,

Tdarr looks great, but I don’t love Foss software which have paid plans attached. Can it be used really for free if I have one server and plan to do all transcoding there?

isles ,

Great point about paid plans. I didn’t look closely at the project today - they didn’t have any paid plans when I was first trying it in 2020 (and ultimately decided downloading the preferred source was good enough and abandoned trans-coding).

This is a more script based solution I’ve tried in the past for ongoing ISOs with decent results. Good luck!

UberMentch ,

Yes. I believe the paid version only gives you more possible nodes (where the transcoding is done), and more reports? But yes, you have the entire suite of tools necessary in the free version. It’s worked great for me, I’ve used it for a year and a half now

  • All
  • Subscribed
  • Moderated
  • Favorites
  • [email protected]
  • random
  • lifeLocal
  • goranko
  • All magazines