It seems that you're using an outdated browser. Some things may not work as they should (or don't work at all).
We suggest you upgrade newer and better browser like: Chrome, Firefox, Internet Explorer or Opera

×
I believe VP9 is used on youtube for resolutions above 720p by default.
And yeah, hardware acceleration on VP9 codec is not good on older computer hardware. Low end devices, including the raspberry usually perform better by forcing the AVC1 codec instead (h264ify is a well know extension). Mobile may have better support generally.
K new fun interesting things to share.

Been playing with FFMpeg and encoding of course, but i was wondering if i could do Hardware encoding. So i looked at the details of my video card, it is suppose to support it, but i can't get it to work. Alright we'll come back to that....

Then i look and saw my NAS does Transcoding, which is supported in some media servers, where if your system may not support say RealMedia (.rm, used a bit 1998-2005 probably more than anything due to low bitrates) then the media server will decode, re-encode, and send the encoded compatible format to the requesting service.

So... it's hardware, and looking at supported hardware on my NAS it clearly says it supports hardware accelerated encoding. Curiously the method is VAAPI, which i don't quite understand.

Regardless, h264, hevc, and vp8 are supported types.

I had an issue where i encode something and check it, and i couldn't render it.... seems it needed to sync with the drive first, then it started working. May be related to it probably re-writing the header to make something playable, vs getting an incomplete mp4 files online that you can start playing without the file being downloaded. (Also replacing a file it won't work til you refresh either).

So, lots of fighting with documentation, settings, trying various things. finally got to a combination that seems to more or less work.

ffmpeg -hwaccel vaapi -i input_file -vcodec hevc_vaapi -vf 'format=nv12,hwupload' output_file

Curiously this also requires root access or accessing VAAPI won't work as it needs direct access to /dev/dri/renderD128 in order to encode. meaning sudo or other runs to get it going. But having it going 20-30fps vs 1-3fps makes it a interesting balancing issue.

Hardware encoding also doesn't like/have CRF, and the settings i see only uses -qp, which seems to be Constant rate. Some documentation says there's -qmin -qmax -q and -qp, but in my case only -qp was there.
avatar
rtcvb32: ...
Hello rtcvg32, thanks for sharing your knowledge.
I want to make a question that may be or not offtopic but it's based on your knowledge of encoding.

Where I can find good documentation for ffmpeg on how to convert simple mp4 videos into lesser quality?
Im used to using Windows only converters (specially a really old one that never failed me FormatFactory, which I use for 10 years now. Problem is the new version which is full of ads, but I use a version before they added ads to the software.)

What I want is to learn how to reduced file sizes on huge videos (1+ hour lectures, for example) with acceptable quality loss without compromising content on Linux. The GUI softwares I tried looked way too complicated for me and I'd rather learn the CLI options, if possible.

What you'd recommend? Thank you!
avatar
.Keys: What you'd recommend? Thank you!
This will encode the video with AV1 and a CRF of 30. The audio and subtitle streams will be copied as is.

ffmpeg -y -i input.mp4 -c:v libsvtav1 -crf 30 -c:a copy -c:s copy -pix_fmt yuv420p10le out.mp4

A larger CRF # will use more compression a lower # will use less. That's usually all you need.
Post edited January 10, 2023 by EverNightX
avatar
.Keys: Hello rtcvb32, thanks for sharing your knowledge.
I want to make a question that may be or not offtopic but it's based on your knowledge of encoding.
I'm still new to this, but the 'swiss-army-knives' of tools are all a bit crazy and often i end up at superload or stackframe or elsewhere with a question and i get generally the right answer.

Otherwise ffmpeg -h will give you a minimum output of basic variables, enough to get you through.

avatar
.Keys: What I want is to learn how to reduced file sizes on huge videos (1+ hour lectures, for example) with acceptable quality loss without compromising content on Linux
avatar
EverNightX: This will encode the video with AV1 and a CRF of 30. The audio and subtitle streams will be copied as is.

ffmpeg -y -i input.mp4 -c:v libsvtav1 -crf 30 -c:a copy -c:s copy -pix_fmt yuv420p10le out.mp4
I haven't used libsvtav before, and unless there's reason i'd just assume use h264 or x265. Also i don't know if 10bit will help much here.

The basic format for encoding is ffmpeg -i filename [options] outputfile.

So do you need the files at a smaller resolution or not? For a long time i had 320x240 resolution lectures, and what they write on the boards was still legible. Otherwise 480 would probably be the lowest resolution you want. -s you specify dimensions and it will resize to that.

Specify the codec, if you don't mind WebM then VP8 or VP9, otherwise x265 or if you have anemic older hardware x264. And in the event you REALLY want to use old hardware, Mpeg2.

Also audio quality, does it have to be CD or would say Tape (22k) be okay? -ar will change the audio rate, and -r will change the framerate.

So let's assume you are okay with Tape quality, same resolution, x265 and say 15fps. And a 'decent' quality where you aren't losing much 30 suggested should be readable even if some of people's faces or edges might get ugly with motion. Lastly lectures don't really need stereo, so mono channel and 40kbit should suffice. (128k is considered okay for CD, cut in a quarter you get 32k, a hair higher should ensure it doesn't sound too grainy)

[code]
#!/bin/bash
for X;
do
ffmpeg -i "$X" -vcodec libx265 -crf 30 -ar 22050 -r 15 -acodec aac -ac 1 -b:a 40k -t 120 "$X_new.mp4"
done
[/code]

lecture.mp4 should become lecture.mp4_new.mp4, using rename will fix that if you really want as a single line of code (assuming rename is installed, otherwise sed will do it too. Come back when that time comes and i'll help).

NOTE: the -t 120. That will just encode 2 minutes. Check your file and see if it looks good. If it does, remove the -t 120 and replace with -preset slow. The slow preset will let it find better matches and increase the quality vs bitrate. If you don't have the time just remove -t 120 and it will encode fairly decently regardless.
libsvtav1 is better, faster, and doesn't require royalties. And 10bit is more efficient. Pretty good reasons I'd say.
Post edited January 10, 2023 by EverNightX
avatar
EverNightX: libsvtav1 is better, faster, and doesn't require royalties. And 10bit is more efficient. Pretty good reasons I'd say.
Interesting. I'll give it a go on some files i'm working on and see how they do.

edit: a problem, half the ffmpeg's i look over don't have that codec as an option. 264 and 265 are two that always seem to be there.
Post edited January 10, 2023 by rtcvb32
avatar
EverNightX:
avatar
rtcvb32: ...
Thanks, really!
avatar
EverNightX: libsvtav1 is better, faster, and doesn't require royalties. And 10bit is more efficient. Pretty good reasons I'd say.
avatar
rtcvb32: Interesting. I'll give it a go on some files i'm working on and see how they do.

edit: a problem, half the ffmpeg's i look over don't have that codec as an option. 264 and 265 are two that always seem to be there.
So...like download a build that doesn't suck. Takes 10 seconds.
Post edited January 10, 2023 by EverNightX
This thread goes to my bookmarks.

I've dabbled with ffmpeg before, and I have to check VirtualDub2 as well.

My main "project" is that I have some very old TV recordings (mostly rare movies I haven't seen elsewhere) which are in .rec files that the "digital TV recorder" box" used. I think they contain MPEG-2 files. The digital TV recorder box was "Topfield" which used to be very common and popular here back in the day, somewhat like this except I didn't have a HDMI version, but only with SCART port:

https://www.tori.fi/kanta-hame/Digiboksi_Topfield_107382794.htm

All those files play fine with e.g. VLC, but they have lots of excessive baggage like TV commercials in between, stuff before and after the TV program (because the recording didn't start and end at exact moments) etc. So need to tidy them up.

Also, considering they are just SD low quality recordings (not HD or even 720p), they take far too much space for their quality, like one movie can take 3-4 gigabytes or so.

I dabbled before trying to achieve these:
1. Extract the video, audio (and subtitles, if they are not burned in to video) tracks from those .rec files. I guess the .rec is just the "container" that Topfield digital box used, and the files inside are e.g. common MPEG-2 video files and whatever audio format was used, and possibly separate subtitle track(s) as well if the subtitles were not burned into the video.
2. Edit the tracks to remove ads etc.
3. If possible, convert the separate subtitle track into a more common format like .srt or .sub or whatever (this proved to be quite tricky, depending what that subtitle track was, e.g. teletext based).
4. Then re-encode the edited video/audio files into a smaller video file, hopefully not losing much of any of the original "quality", but at least a considerably smaller size.

I used to use some old java based video editor for at least steps 1 and 2 (the name of that editor escapes me, and i don't think it has been supported for over 10 years or so; it might still work though at least in Linux, as it is java based, I did recall using it a couple of years ago in Linux), and step 4 with ffmpeg. EDIT: I think that old video demultiplexing/editor was ProjectX:

https://www.videohelp.com/software/ProjectX (latest version from 2011).

Should VirtualDub2 be able to achieve at least steps 1 and 2?

Is there any benefit (in size vs. quality) in using those more advanced formats like AV1 etc. for lower resolution/quality MPEG-2 files?

EDIT: I googled for "Convert Topfield rec" and it seems I am not the only person still trying to achieve that:

https://www.videoconverterfactory.com/tips/convert-rec-to-mp4.html

https://forum.videohelp.com/threads/394280-Any-free-software-to-convert-rec-files-%28from-the-Topfield-PVR%29-into-MP4

https://en.freedownloadmanager.org/tutorials/how-to-convert-rec-to-mp4-with-vlc-media-player.html

Not sure if any of those can do anything about the separate subtitle tracks though... I guess I just have to test them. One problem may be that I'd like to edit the video/audio files (remove the ads etc.) before re-encoding them to some other format, otherwise I think I will end up re-encoding them twice, which loses quality even more. Or can you edit e.g. a MP4 file without having to re-encode it?
Post edited January 10, 2023 by timppu
avatar
phaolo: ...... but I'm using Avidemux instead of it. It's good for simple lossless cutting.
I used a couple of different versions of Avidemux for a few years, but have pretty much just stuck to ffmpeg in recent years, learning its tricks ... rotating, mirror image, etc.

Mostly these days I just convert or repackage videos as MKV, if they aren't, which I have found has the better error correction ability. I also add in chapters every three minutes, another benefit of MKV. I've also created a script to create a preview file, sampling 10 equally spaced segments of a video file, for 4 seconds each, resulting in a 40 second video, that I use as a quick check of the full video as some kind of passable issue detector ... less than perfect of course, but saves a lot of time, and on average works well enough.

I don't really bother to compress much in this age of cheap large hard drives, especially with ever larger 4K and beyond TVs. Many videos created 10 years ago for instance, look crap on a modern widescreen TV these days.

EDIT
But then I don't watch much video on handheld devices like a phone for instance. Just the usual home made videos and rare youTube clip. I don't mind watching TV Sitcoms on my 10" Samsung Tablet, but never a movie really or a doco. Hell I don't even watch movies on my PC or laptop, unless connected to a TV. So video file size is not really an issue for me.
Post edited January 10, 2023 by Timboli
avatar
timppu: Should VirtualDub2 be able to achieve at least steps 1 and 2?

Is there any benefit (in size vs. quality) in using those more advanced formats like AV1 etc. for lower resolution/quality MPEG-2 files?
Probably. Mind you also make sure you do copy-only during those steps (no processing) which will leave the quality of the videos/audio intact and be lightning fast. Though the limitation comes down that it don't be able to start on any slice except on key frames. Though you can stop it anywhere.

Considering Mpeg2 is also used on DVD's, it's low decoding requirement combined with high bitrate... Well it's well used.

As for size, I'd wager you could get them 1:8th the size... Every little bit can help. though if they are low quality Mpeg2 files, then it might not be worth it.

avatar
timppu: Also, considering they are just SD low quality recordings (not HD or even 720p), they take far too much space for their quality, like one movie can take 3-4 gigabytes or so.
Mhmm, which is why when MPEG-4 partial codecs were coming out (DivX, Project Mayo, 3ivx, H.263, etc) were available, it actually was starting to become feasible to use internet to pass video around. Same with MP3 used for music.

Actually a bit disappointing, looking at some of my older stuff and i got a lot of weird lower resolutions on stuff. Like 640x348 or something.
Post edited January 10, 2023 by rtcvb32
avatar
EverNightX: So...like download a build that doesn't suck. Takes 10 seconds.
Depends, on the hardware you're using. The NAS with hardware accelerated encoding doesn't include it, but other builds do include it. For transcoding using hardware fast speed is a higher priority (even at a slightly higher rate) than AV1.

Still, tried encoding a video. Then i couldn't open it. Go figure, finding a codec is annoying. Though ffplay did let me view the output and see how it looks, which.... looks pretty good all things considered.

I'm sure as adoption is increased it will be accepted more and become the standard (while h264 or mpeg2 will be the fallback for lower end devices).

So, do i go with a known playback format my TV likes; Or do i fight with it and have to find codecs and possibly not have it play at full speed... choices choices.
avatar
EverNightX: So...like download a build that doesn't suck. Takes 10 seconds.
avatar
rtcvb32: Depends, on the hardware you're using. The NAS with hardware accelerated encoding doesn't include it, but other builds do include it. For transcoding using hardware fast speed is a higher priority (even at a slightly higher rate) than AV1.

Still, tried encoding a video. Then i couldn't open it. Go figure, finding a codec is annoying. Though ffplay did let me view the output and see how it looks, which.... looks pretty good all things considered.

I'm sure as adoption is increased it will be accepted more and become the standard (while h264 or mpeg2 will be the fallback for lower end devices).

So, do i go with a known playback format my TV likes; Or do i fight with it and have to find codecs and possibly not have it play at full speed... choices choices.
I use Linux and MPV. The playback is accelerated on an RTX30XX or newer I believe. On Windows 10 I think you should be able to download a free AV1 video extension from their store. Chrome, FireFox, and Edge browsers should also be able to play it. I can't speak for your TV. I mean use whatever works for your current setup. But I expect a major switch over to AV1 (at least online) because companies won't have to deal with the royalties. That's a big deal if you have a billion videos like youtube, netflix, etc.
Post edited January 12, 2023 by EverNightX
avatar
EverNightX: I use Linux and MPV. The playback is accelerated on an RTX30XX or newer I believe. On Windows 10 I think you should be able to download a free AV1 video extension from their store.
Yes, some funky appx installer. Not sure how that helps me on this Win7 machine...

avatar
EverNightX: Chrome, FireFox, and Edge browsers should also be able to play it. I can't speak for your TV.
Got VLC installed on the TV, so if it supports it, i'll find out...

edit: Yes it does, however it's likely software decoding, as it stuttered to a halt 30 seconds in during the difficult part.

Firefox does indeed open it (reminds me of opening flash content in Firefox because the standalone player was not only a separate harder-to-find product, but also shoved unwanted ads every 2-3 flashes you tried to open, or be forced to stare 20 seconds at nothing). So there's that i guess. Though that's probably more for being forced to update FF multiple times which i am not happy about in the last 7 years.

avatar
EverNightX: I mean use whatever works for your current setup. But I expect a major switch over to AV1 (at least online) because companies won't have to deal with the royalties. That's a big deal if you have a billion videos like youtube, netflix, etc.
Mhmm. Personally i don't care, but if the compression is better i'd use it. Better if it's free then hardware decoders will be accepted more in hardware (probably also in upcoming pi within a few years)

edit: alright tried a minute from Blade, (5 minutes in, bloodbath). 25 looked identical, 30 looked good, 40 i can see issues but nowhere near what the hardware x265 was giving; But 40 it would be more than sufficient for lectures, maybe even higher.

edit: Okay did a bunch of tests of different complexity. Note audio stripped and removed so it's not a factor

sourced ~32Mb 1080 Blade movie
CRF w/ SVT AV1
25 - 32Mb (so same data amount as input)
30 - 23Mb (probably on par with the original encoding)
35 - 16.2Mb (Looks like DVD, some detectable errors but easily ignorable)
40 - 12Mb (Could almost fit an hour 1080 movie on a CD! High motion lots of errors, but not as much not noticable so much)
45 - 8.2Mb (shadows and low color become blocky, while foreground stuff still gets definition, but high motion it looks like garbage. Though this would still be fine for low quality screens, Tablets phones and other if you are watching a movie, or lectures)
50+ - don't bother for entertainment, unless you want 2005 youtube low resolution and terrible blockiness and ugliness

480x360 Stanford lecture 4.4Mb source 1 minute. Projector and chalkboard diagrams.
25 - 4.34Mb (Looks as expected, being the same data amount)
30 - 3.19Mb (Looks fine, readable)
35 - 2.3Mb (Looks fine, readable, looks like some lower shadows/shading are updated less often under the projector area)
40 - 1.66Mb (A lot of artifacting/blurr/distortion around edges but boards still readable)
45 - 1.21Mb (About 5-8 pixels around the teacher are hazy, lesser shadows are updated less often, but board/screen are still readable)
50 - 925k (same as above, but the teacher has more errors on his face/body than before.)
55 - 686k (While the board and projection are readable still, area around the teacher are heavily blurred, it's hard to even see his face or what he's wearing he's heavily pixelated. Probably be fine quality for screen capture presentations at this point, probably not as bad if this was a larger resolution)
60 - 463k (20-30 pixels around the teacher are affected, probably not as bad on higher resolution vs what i have here, though on key frames blurry whole screen changes are fixed and boards are still readable, but the teacher would be better not being there at that point)

Screencap lecture 1152x720 5 minutes, 9.07Mb (lots of static imagery with corner of talking professor on webcam)
35 - 7.68Mb (Crisp and sharp on the powerpoint, pretty much the same all the way down)
40 - 6.06Mb
45 - 5MbMb
50 - 4.21Mb (some errors around the professor, but that's unimportant)
55 - 3.5Mb
60 - 2.64Mb (a lot more noticeable on the webcam, however the Powerpoint is clear and sharp)



Conclusion: 20 can probably be used for saving original source videos, 25 i don't see any real differences, depends on how lossy you accept as the 'originals'.

30-35 is usable overall without any huge noticeable degradation, 40-45 errors appear but can be ignored unless it's high action/activity. 50+ don't use for entertainment (though 50 MAY end up working for say podcasts where 30-40% of the screen doesn't really change)

As for Lectures, 40-55 is acceptable with higher resolutions, and Powerpoint/static imagery 60 is easily usable.
Post edited January 13, 2023 by rtcvb32