It's possibly a container problem, copying it to a new container format with
avconv -i input.ts -c copy output.mp4
may well fix your problem. This will be 100% lossless. If that doesn't work, a crf of 18 is normally considered 'visually lossless'; you can set this is HandBrake (under the 'video' tab), or with avconv:
avconv -i input.ts -c:a copy -c:v libx264 -crf 18 -preset veryfast output.mp4
The presets are: ultrafast, superfast, veryfast, faster, fast, medium, slower, slow, veryslow. The slower the preset, the smaller the file (but with an increase in encode time). In my personal experimentation, I've found the biggest dropoff in terms of filesize is between superfast and veryfast, after that it seems to be much more incremental.
NOTE: If you want, ffmpeg can do everything avconv can do, with identical syntax (simply replace all instances of avconv with ffmpeg).
FOOTNOTE: You may find this ffmpeg x264 encoding guide useful for more information.
First of all, install a more recent version of FFmpeg – grab a static build from the download page.
The use of vpre
presets (which is a way to set default values for ffmpeg settings, not encoder settings) is not really necessary; you usually want to use the -preset
options defined by the encoders.
The reasons you get low output quality are the following, for your two cases respectively:
In the first case you use crf 25
, a Constant Rate Factor that's going to give you worse quality than the default for the x264 encoder (which is 23). The CRF controls the quality. Try setting a lower CRF, maybe 20, 18, etc. Here, lower means better quality, but it'll increase the file size. A change of 6 in the CRF gives you twice/half the original average bitrate, roughly speaking.
You'll have to set a lower CRF because of the generation loss. You're encoding something that was already encoded, so you're again throwing away visual information. That's never good, but if you have to, you're going to have to set a higher quality so as not to remove too much information from the input video.
In the second case you're trying to set a constant bit rate of 2 MBit/s. Your input video roughly has the same bit rate. Now, x264 delivers much better visual quality than an MPEG-4 Visual encoder for the same bitrate, but due to the generation loss, again, you might want to use an even higher bitrate than the original – otherwise you'll end up compressing away too much information.
Furthermore, constant bitrate encoding might result in some passages looking good, but other parts of the video looking worse. If you don't let the encoder freely choose the amount of bits it wants to spend on something, you're going to sacrifice quality at the expense of knowing the target file size.
x264 does have a constant bit rate mode, but it's considered inferior to the other encoding methods. Actually, two-pass encoding isn't meant to target optimal quality, so scratch that.
That all being said, try something along the following:
ffmpeg -i input.avi -c:v libx264 -crf 19 -preset slow -c:a libfdk_aac -b:a 192k -ac 2 out.mp4
If libfdk_aac
is not available, use this instead:
ffmpeg -i input.avi -c:v libx264 -crf 19 -preset slow -c:a aac -b:a 192k -ac 2 out.mp4
The main quality control knob will be your CRF setting. Experiment with that and use a lower value if you need better quality.
You can also choose the veryslow
preset, which will give you better compression, but the encoding will obviously take longer.
If you can't manage to get a decent quality file at a reasonable file size, then you're out of luck. Better keep the original file as-is, without re-encoding. There's no magic "keeping the same quality" tool when you're compressing something that's already compressed.
Best Answer
Convert 10-bit H.265 to 10-bit H.264:
libx264 will automatically to to match the pixel format of the input, so no extra parameters are needed.
The example uses
-crf 18
which will likely appear visually lossless. If you want true lossless mode then then use-crf 0
, but note this can create large files. See FFmpeg Wiki: H.264.Convert 10-bit H.265 to 8-bit H.265:
Uses the format filter to choose the
yuv420p
pixel format to create 8-bit output.Adjust the
-crf
value to provide the desired level of quality. Default is-crf 28
. See FFmpeg Wiki: H.265.If you want lossless mode then then replace
-crf
with-x265-params lossless=1
, but note this can create large files.Convert 10-bit H.265 to 8-bit H.264:
Uses the format filter to choose the
yuv420p
pixel format to create 8-bit output.The example uses
-crf 18
which will likely appear visually lossless. If you want true lossless mode then then use-crf 0
, but note this can create large files. See FFmpeg Wiki: H.264.