I am trying to recompact the MKV files produced by MakeMKV

MKV playback, recompression, remuxing, codec packs, players, howtos, etc.
Post Reply
MarcNBarrett
Posts: 8
Joined: Mon Oct 26, 2020 5:30 am

I am trying to recompact the MKV files produced by MakeMKV

Post by MarcNBarrett »

I have been ripping my large library of DVDs and BluRays to a Plex media library, with MakeMKV. MakeMKV works wonderfully, except that the files are rather large. A Blu-Ray file can typically be about 40-50GB, and a DVD file about 6GB. That is much too big. I have been trying to use ffmpeg to recompact the MakeMKV MKV files, and I was wondering if someone could help me with this.

I have been using the following command to recompact the Blu-Ray MKV files:

Code: Select all

ffmpeg -y -hwaccel cuvid -c:v h264_cuvid -vsync 0 -i in.mkv -map 0 -codec:v h264_nvenc -codec:a copy -codec:s copy -max_muxing_queue_size 4096 out.mkv
That command does two things for me. Since I have a halfway decent graphics card (Nvidia geforce RTX 2060), it gives me the hardware acceleration I desire. It also retains all subtitles when recompacting the files.

That command works very well for Blu-Rays. It can reduce a 40-50GB MKV file to about 7GB. The problem is, that only works on files produced by ripping Blu-Rays. If I try it on DVD files, I get errors.

Code: Select all

[h264 @ 0x555573579a80] Invalid NAL unit 0, skipping.
    Last message repeated 5 times
[h264 @ 0x555573579a80] non-existing PPS 2 referenced
[h264 @ 0x555573579a80] Invalid NAL unit 0, skipping.
    Last message repeated 4 times
[h264 @ 0x555573579a80] non-existing PPS 2 referenced
[h264 @ 0x555573579a80] decode_slice_header error
[h264 @ 0x555573579a80] data partitioning is not implemented. Update your FFmpeg version to the newest one from Git. If the problem still occurs, it means that your file has a feature which has not been implemented.
[h264 @ 0x555573579a80] If you want to help, upload a sample of this file to ftp://upload.ffmpeg.org/incoming/ and contact the ffmpeg-devel mailing list. (ffmpeg-devel@ffmpeg.org)
[h264 @ 0x555573579a80] data partitioning is not implemented. Update your FFmpeg version to the newest one from Git. If the problem still occurs, it means that your file has a feature which has not been implemented.
[h264 @ 0x555573579a80] If you want to help, upload a sample of this file to ftp://upload.ffmpeg.org/incoming/ and contact the ffmpeg-devel mailing list. (ffmpeg-devel@ffmpeg.org)
[h264 @ 0x555573579a80] data partitioning is not implemented. Update your FFmpeg version to the newest one from Git. If the problem still occurs, it means that your file has a feature which has not been implemented.
[h264 @ 0x555573579a80] If you want to help, upload a sample of this file to ftp://upload.ffmpeg.org/incoming/ and contact the ffmpeg-devel mailing list. (ffmpeg-devel@ffmpeg.org)
[h264 @ 0x555573579a80] A non-intra slice in an IDR NAL unit.
[h264 @ 0x555573579a80] decode_slice_header error
[h264 @ 0x555573579a80] SEI type 70 size 1120 truncated at 932
[h264 @ 0x555573579a80] crop values invalid 1 5 11 5 / 48 64
    Last message repeated 2 times
[h264 @ 0x555573579a80] sps_id 0 out of range
[h264 @ 0x555573579a80] no frame!
[h264 @ 0x555573579a80] non-existing PPS 0 referenced
[h264 @ 0x555573579a80] Invalid NAL unit 1, skipping.
[h264 @ 0x555573579a80] non-existing PPS 0 reference
I am using ffmpeg version n4.1.4 on a Ubuntu Mate 20.04 system, Intel X64 PC. Everything is up-to-date (I run apt update/upgrade regularly).

The following command works on the DVD files produced by MakeMKV, except I get no hardware acceleration:

Code: Select all

ffmpeg -i in.mkv -map 0 -codec:a copy -codec:s copy -max_muxing_queue_size 4096 out.mkv
If someone could help me with this, I would really appreciate it.
Woodstock
Posts: 10312
Joined: Sun Jul 24, 2011 11:21 pm

Re: I am trying to recompact the MKV files produced by MakeMKV

Post by Woodstock »

Did you get the ffmpeg from the Ubuntu repository, or build if from source, obtained from the ffmpeg site?

If the experience of Ubuntu users of handbrake is any indication, using much of anything from the Ubuntu repositories is hit and miss. Ubuntu packagers have a habit of "forgetting" that some packages use customized libraries, and link in unmodified ones, with bad results.

Also, your ffmpeg command line isn't going to do anything about the interlaced nature of DVD, or incorporate any subtitles.
xr200
Posts: 56
Joined: Tue Nov 10, 2015 3:11 am

Re: I am trying to recompact the MKV files produced by MakeMKV

Post by xr200 »

I recommend you use HandBrake instead of ffmpeg.

If you (like me) prefer the command line to a GUI interface, here's an
excellent place to start:

https://github.com/donmelton/video_transcoding
MarcNBarrett
Posts: 8
Joined: Mon Oct 26, 2020 5:30 am

Re: I am trying to recompact the MKV files produced by MakeMKV

Post by MarcNBarrett »

I appreciate the responses, but a kind person on the ffmpeg mailing list helped me out. I did not realize that MakeMKV is producing mpeg2 streams in a MKV container. I simply replaced "h264_cuvid" with "mpeg2_cuvid". Like this:

Code: Select all

ffmpeg -y -hwaccel cuvid -c:v mpeg2_cuvid -vsync 0 -i in.mkv -map 0 -codec:v h264_nvenc -codec:a copy -codec:s copy -max_muxing_queue_size 4096 out.mkv
That works very well.
Woodstock
Posts: 10312
Joined: Sun Jul 24, 2011 11:21 pm

Re: I am trying to recompact the MKV files produced by MakeMKV

Post by Woodstock »

MakeMKV copies whatever is on the source disk to the MKV file. On DVDs, that would be MPEG2, but BD sources could be h264, VC-1, VC-1 Interlaced, and a few others. UHD adds h265 to the mix.
Post Reply