this post was submitted on 22 Feb 2026
198 points (98.5% liked)

Linux

63197 readers
645 users here now

From Wikipedia, the free encyclopedia

Linux is a family of open source Unix-like operating systems based on the Linux kernel, an operating system kernel first released on September 17, 1991 by Linus Torvalds. Linux is typically packaged in a Linux distribution (or distro for short).

Distributions include the Linux kernel and supporting system software and libraries, many of which are provided by the GNU Project. Many Linux distributions use the word "Linux" in their name, but the Free Software Foundation uses the name GNU/Linux to emphasize the importance of GNU software, causing some controversy.

Rules

Related Communities

Community icon by Alpár-Etele Méder, licensed under CC BY 3.0

founded 6 years ago
MODERATORS
 

made it so i just click file and paste YouTube url

Linux is amazing

#! /usr/bin/bash
echo "Enter a url"
read a

yt-dlp -x $a
you are viewing a single comment's thread
view the rest of the comments
[–] db2@lemmy.world 1 points 1 day ago (1 children)

I wonder if we have the same resize.sh

[–] 0t79JeIfK01RHyzo@lemmy.ml 1 points 1 day ago (1 children)

The version I have was copied from stackoverflow. It doesn't work very well, it makes a rough estimate to get the video file size under the set value. As an example

resize video.mp4 10

Which then resizes the video to 10 megabytes if possible.

resize.sh code

file=$1
target_size_mb=$2  # target size in MB
target_size=$(( $target_size_mb * 1000 * 1000 * 8 )) # target size in bits
length=`ffprobe -v error -show_entries format=duration -of default=noprint_wrappers=1:nokey=1 "$file"`
length_round_up=$(( ${length%.*} + 1 ))
total_bitrate=$(( $target_size / $length_round_up ))
audio_bitrate=$(( 128 * 1000 )) # 128k bit rate
video_bitrate=$(( $total_bitrate - $audio_bitrate ))
ffmpeg -i "$file" -b:v $video_bitrate -maxrate:v $video_bitrate -bufsize:v $(( $target_size / 20 )) -b:a $audio_bitrate "${file}-${target_size_mb}mb.mp4"

I'll probably replace it eventually.

[–] db2@lemmy.world 2 points 1 day ago* (last edited 1 day ago) (1 children)

Definitely not the same lol

Mine uses ffmpeg to change the resolution, it doesn't so much care about file sizes.

It could be a one-liner if you only ever feed it a single file to manipulate..

[–] 0t79JeIfK01RHyzo@lemmy.ml 2 points 1 day ago

I might add one for scaling. I just don't use it as frequently as trying to meet a file size limit. The scaling is also much easier to remember

ffmpeg -i  in.mp4 -vf "scale=600:-1" -an out.mp4

It does get complicated though, when scaling many videos and images, I've used something like the following in the past

find .  -exec ffmpeg -i {} -vf "scale=1920:1080:force_original_aspect_ratio=decrease,pad=1920:1080:-1:-1:color=black" {}.mp4 \;

Those were the only two that showed up when I typed history | grep scale.

after commenting, I also added a new video file resizer.

It works significantly better than the one I previously posted. It's also copied from stackoverflow.

bitrate="$(awk "BEGIN {print int($2 * 1024 * 1024 * 8 / $(ffprobe \
    -v error \
    -show_entries format=duration \
    -of default=noprint_wrappers=1:nokey=1 \
    "$1" \
) / 1000)}")k"
ffmpeg \
    -y \
    -i "$1" \
    -c:v libx264 \
    -preset medium \
    -b:v $bitrate \
    -pass 1 \
    -an \
    -f mp4 \
    /dev/null \
&& \
ffmpeg \
    -i "$1" \
    -c:v libx264 \
    -preset medium \
    -b:v $bitrate \
    -pass 2 \
    -an \
    "${1%.*}-$2mB.mp4"