Jump to content
  • Sign Up
TheOneWhoSees

[Help] Best way to convert to x265 with ffmpeg?

Recommended Posts

TheOneWhoSees

I am trying to convert my Blu-Ray rips to x265 with ffmpeg.

However, every command I have tried has made the video the same size as the original.

 

I want to convert them to x265 and make the files smaller, but still high quality (like [psuedo]'s or [bonkai77]'s releases).

 

What is the best ffmpeg command to do this?

Should I use a different program to do it?

 

Any help will be appreciated :)

-TheOneWhoSees

 

I'm not sure if this is the correct section to post this...

Share this post


Link to post
Share on other sites
46620

The ffmpeg command I use for my own files is:

ffmpeg -i [input file] -map 0 -c:v libx265 -c:a copy [output file]

 

  • Thanks 1

Share this post


Link to post
Share on other sites
blubbso

Well, you can, and probably should, use a lot more options than the command  @46620 posted to get the most out of H265. I'm by no means an expert in video encoding, but I'll try to explain my process. You should definitely read the ffmpeg wiki pages for H264 and H265, they are very accessible, even to a beginner.

 

A more comprehensive command

Here is what I use most of the time, and a breakdown of the non-obvious components:

ffmpeg -i [input file] -map 0 -c copy -c:v libx265 -crf [crf] -preset [preset] -tune animation -c:a libopus -b:a [audio bitrate] [output file]

-map 0 means all the "input streams" (video, different audio streams, different subtitles) will be included in the output. By default, ffmpeg selects one from each category and discards the others.

-c copy means "do not re-encode anything unless I tell you to". By default, ffmpeg makes guesses for codecs, which may not be what you want.

- c:v libx265 chooses the x265 encoder for video streams

- crf [crf] sets the constant rate factor. Refer to the wiki links above for a short explanation and sane starting values. You will need to try out a few values.

-preset [preset] sets the preset. Refer to the wiki links above for a short explanation. I usually start with "slow" and am satisfied, but sometimes you may want to try out different values.

-tune animation sets the tune. Refer to the wiki links above for a short explanation. If you are encoding old shows captured on film, then -tune grain will produce much more accurate results. But encoding grain is hard, so your file will be larger.

-c:a libopus converts audio streams to Opus, which is highly efficient, but may not be compatible with all devices (I don't care, I have a computer hooked up to my TV). First, check if the size of the audio stream is already satisfactory. If so, omit this option.

-b:a [audio bitrate] set the bitrate. Note that this depends on the number of audio channels. 5.1 sound needs more bitrate than stereo. I usually use [48*channels]k, but you may need to adjust this. Again, the ffmpeg wiki provides an accessible introduction.

 

Working efficiently

As you may already guess, encoding is a trial-and-error process. You pick some values that served you well in the past and see if the result is satisfactory. If it isn't, you tweak the paramers one-by-one. This can be time consuming, so here is a shortcut: Initially, only encode "difficult" scenes, and once you find parameters that work well for those, encode the whole video.  "difficult" scenes would be those with lots of movement, lots of grain (if your video has grain), and dark scenes. If you are comparing them frame by frame, try not to use frames at the start of scene cuts, as those are likely to be I-Frames (too lazy to explain, google that one if you want to know).

But how do you only encode those scenes? The option -ss MM:SS tells ffmpeg the point in time where it should start encoding, and -t SS tells it for how long it should keep going. These options come immediatly after ffmpeg. So, ffmpeg -ss 17:30 -t 40 ... will encode the portion from 17:30 to 18:10.

 

A caveat

Note that, if your ffmpeg isn't built with Version 3.0 of the x265 encoder, then -tune animation will not be available. In this case, replace it with this:

-x265-params "psy-rd=0.4:aq-strength=0.4:deblock=1:1:bframes=[bframes]"

The -tune animation is basically a shortcut for this. The value of [bframes] depends on the [preset] you use, as described in the x265 documentation. Basically, find the value in the bframe row of the table and add 2. That is your [bframes]. In fact, all -preset and -tune options are just shortcuts for a myriad of options that ffmpeg / x265 offer, and if you know more about those you can make more fine-scale adjustments. But that is out of my league, maybe someone with more in-depth knowledge could expand on this? I would love to learn more, but while you can find bits and pieces for specific problems, a general process one can follow seems to be hard to find. Anyway, I hope this helped a bit.

Edited by blubbso
  • Like 1
  • Thanks 1

Share this post


Link to post
Share on other sites
Spoony

I question why ffmpeg is even being used in the first place.

 

Just grab x265.exe and write a .bat file for the encode process. If you're wanting to filter things for banding and such grab vapoursynth , vsedit, and whatever filters you want to utilize.

 

Also, for the record all tune presets are pretty terrible, but tune:animation is probably one of the worst offenders of causing detail loss, despite it's name it's not the best solution for animation out of the preset tune options for sure. tune:grain tends to preserve things better and is probably the closest preset to settings that encoders tend to recommend, but again presets are pretty terrible and results will pretty much always be better by customizing things rather than using a tune preset.

Edited by SpoonyBard
  • Thanks 1

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...