This forum has been archived. All content is frozen. Please use KDE Discuss instead.

How to convert divx without losing quality?

Tags: None
(comma "," separated)
jony127
Registered Member
Posts
31
Karma
0
OS
Hi.

I'm trying to convert a video to mpeg4-asp/mp3 format (divx compatible) and the video loses a lot of quality. How can I perform the transformation while preserving the same quality as the original?

Thank you.
Inapickle
Registered Member
Posts
157
Karma
3
You can't get truly lossless conversion to mpeg4-asp (mpeg4 Part 2).

The highest quality that can be achieved is at a Constant Quantizer (CQ) value of 1 (i.e. maximum saturation) and with B-frames (B-VOP's) disabled. But the file sizes will be very large. There is in fact an MLT preset for mpeg4 'intra-frame only' at maximum quality, but it is (was) primarily intended for use as an intermediate/interchange format.

https://github.com/mltframework/mlt/blo ... ate/MPEG-4

Actually with qscale=2 you would be hard pressed to perceive any difference in quality compared to qscale=1, but the file sizes would be a lot smaller.

FWIW, adding vtag=xvid will force xvid as the video FourCC identifier.

As for the 'standard' MPEG-4-ASP/MP3 (DivX Compatible) KDenLive render profile (under 'Old TV Definition' i.e. standard definition) - which I assume is what you are referring to; what video 'quality' level do you have it set at ? And what is your target playback platform? If for playback on "DivX Certified" device, which profile ?

http://www.divx.com/files/DivX-Profiles_Tech-Specs.pdf
jony127
Registered Member
Posts
31
Karma
0
OS
Hi.

The video I'm going to play on a TV but I do not know what divx profile it uses.

The divdx profile of kdenlive by default for the video:

Qualities: 5.15
Default quality: 0

I do not understand how to adjust these parameters so that the video does not lose quality.
Inapickle
Registered Member
Posts
157
Karma
3
jony127 wrote:Hi.
The video I'm going to play on a TV but I do not know what divx profile it uses.


That's important to know, but let's look at it another way - what is the format of your source video and what resolution/frame-rate settings are you using for your project ?
jony127
Registered Member
Posts
31
Karma
0
OS
Hi. These are the original features of the video I want to convert to divx:

Code: Select all
ffmpeg -i video.mp4
ffmpeg version 3.0.7-0ubuntu0.16.10.1 Copyright (c) 2000-2017 the FFmpeg developers
  built with gcc 6.2.0 (Ubuntu 6.2.0-5ubuntu12) 20161005
  configuration: --prefix=/usr --extra-version=0ubuntu0.16.10.1 --toolchain=hardened --libdir=/usr/lib/x86_64-linux-gnu --incdir=/usr/include/x86_64-linux-gnu --cc=cc --cxx=g++ --enable-gpl --enable-shared --disable-stripping --disable-decoder=libopenjpeg --disable-decoder=libschroedinger --enable-avresample --enable-avisynth --enable-gnutls --enable-ladspa --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libflite --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libgme --enable-libgsm --enable-libmodplug --enable-libmp3lame --enable-libopenjpeg --enable-libopus --enable-libpulse --enable-librubberband --enable-librtmp --enable-libschroedinger --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libssh --enable-libtheora --enable-libtwolame --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx265 --enable-libxvid --enable-libzvbi --enable-openal --enable-opengl --enable-x11grab --enable-libdc1394 --enable-libiec61883 --enable-libzmq --enable-frei0r --enable-chromaprint --enable-libx264
  libavutil      55. 17.103 / 55. 17.103
  libavcodec     57. 24.102 / 57. 24.102
  libavformat    57. 25.100 / 57. 25.100
  libavdevice    57.  0.101 / 57.  0.101
  libavfilter     6. 31.100 /  6. 31.100
  libavresample   3.  0.  0 /  3.  0.  0
  libswscale      4.  0.100 /  4.  0.100
  libswresample   2.  0.101 /  2.  0.101
  libpostproc    54.  0.100 / 54.  0.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'video.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 1
    compatible_brands: isomavc1
    creation_time   : 2013-09-04 11:27:02
  Duration: 00:50:38.60, start: 0.000000, bitrate: 985 kb/s
    Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p(tv, bt709/unknown/unknown), 720x404, 848 kb/s, 25 fps, 25 tbr, 25k tbn, 50 tbc (default)
    Metadata:
      creation_time   : 2013-09-04 11:27:02
      handler_name    : FCC 4ever
    Stream #0:1(spa): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 132 kb/s (default)
    Metadata:
      creation_time   : 2013-09-04 11:27:05
      handler_name    : FCC 4ever


In windows I have an application that uses ffpmeg to perform the conversion and has a predefined format to convert to divx to be able to play it on most devices.

This application performs the conversion and the video is viewed as the original, I do not notice loss of quality. This is what I want to do with kdenlive.
capslock
Registered Member
Posts
699
Karma
4
OS
With kdenlive you always will rerender and lose some quality. Searching the web for ffmpeg to divx conversion gives a lot of hints that may come closer to the results of the windows tool you mentioned. There are some ffmpeg command lines or even the hint that VLC can convert videos. kdenlive as a video editor is developed for something different and may be suboptimal for your needs.
jony127
Registered Member
Posts
31
Karma
0
OS
You may lose some quality but not as much as you do kdenlive with the divx profile you have by default where the converted video takes up half that of the original.

The windows tool that commented makes use of ffmpeg so with kdenlive should get about the same result, the problem is only the poor quality of the converted video. I understand that modifying some parameter of the divx profile of kdenlive can obtain a quality similar to the original video but I do not know how.

I will try the conversion with vlc.
capslock
Registered Member
Posts
699
Karma
4
OS
kdenlive does not use ffmpeg to render, but mlt.
jony127
Registered Member
Posts
31
Karma
0
OS
OK thanks. I'm waiting to try converting with vlc.

The default format that brings kdenlive to convert to divx allows modification, I have seen that there are two options to modify the quality of the video, by default they have the values:

Qualities: 5.15
Default quality: 0

Can these parameters be modified to adjust the video quality to be similar to the original?
vpinon
KDE Developer
Posts
708
Karma
6
OS
Kdenlive renders through MLT, which itself uses libavcodec to encode result (from FFmpeg, also used by VLC)...

In Kdenlive you have a transcode menu in the bin list, which converts files directly through FFmpeg, using transcode setting (defined for intemediate work) that are not the same as export settings (defined for final delivery). You could define a Lossless DivX transcode setting with given ffmpeg parameters...

Regarding your encoding parameter question, these have evolved a bit in recent versions, what Kdenlive version do you use?
It normally gives the best/worst crf or qscale values to be used in the Quality cursor of the UI. Default might be an index value, so 0 is best (5).
If you change Qualities to 2,15 you would get the quality you're asking for...
Inapickle
Registered Member
Posts
157
Karma
3
jony127 wrote:In windows I have an application that uses ffpmeg to perform the conversion and has a predefined format to convert to divx to be able to play it on most devices.
This application performs the conversion and the video is viewed as the original, I do not notice loss of quality. This is what I want to do with kdenlive.


I must say that until your last post I had the impression that you were actually using KDenLive for editing your video (maybe cut editing/trimming) and that you simply wanted to render out to "DivX compatible" MPEG-4 at the highest quality possible ; otherwise why would you not be using your Windows application if it produces the desired results ? If it is the case that you are merely looking at KDenLive as a linux-alternative to convert your video, I would tend to agree with Capslock.

I haven't done any DivX encoding for a long time now and when I did it was using the proprietary DivX VFW codec or open-source XviD equivalent. If I were in your shoes, my inclination would be to find out what ffmpeg encoding parameters it uses (I assume this is some preset profile) and replicate that with an ffmpeg command line. Or, like Capslock suggests, search the web for ffmpeg commands that meet your requirements. Doing so would likely turn-up some commands that use the libxvid encoder and others that use the native mpeg4 encoder. This ffmpeg reference doc explains the pros and cons of each:

https://trac.ffmpeg.org/wiki/Encode/MPEG-4

KDenLive uses an "MLT implementation" of the native ffmpeg mpeg4 encoder. Do you know which one your Windows application uses ? You haven't said what the application is.

I don't have experience using VLC player for converting video. If that doesn't work for you, there are a couple of other cross-platform converters you could look at. Handbrake and WinFF come to mind. I used Handbrake only briefly in Windows when it first came into vogue and I recall that there were then device-specific presets for DivX. It uses Mencoder. Checking the current version (available for Kubuntu) I see that it does still offer configurable mpeg4 (part 2) encoding, but the device-specific presets (logically) are all now for AVC. Whether you can still find the old DivX presets and whether they would work with the current versions of Handbrake, I'm not sure. Alternatively you could look at using the Mencoder CLI. Again, you'd have to search for suitable command lines. I haven't used WinFF myself, but this presets pack includes some profiles for XviD:

https://github.com/ryanpcmcquen/winff/b ... resets.xml

This Doom9 forum thread cites an ffmpeg command taken from WinFF as well as one for Mencoder:

http://forum.doom9.org/showthread.php?t=166732

As regards your comment:

jony127 wrote:You may lose some quality but not as much as you do kdenlive with the divx profile you have by default where the converted video takes up half that of the original.

Actually, if you look at the intrinsic quality efficiency of KDenLive using lossless formats and quality metrics there is negligible quality loss on "pass-through", as discussed here:

viewtopic.php?f=272&t=131333&p=352945&hilit=kdenlive+best+quality+render+lossless#p352846

But you do have a point about the 'MPEG-4-ASP/MP3 (DivX Compatible)' render profile, and in regards to your last post:

jony127 wrote:OK thanks. I'm waiting to try converting with vlc.

The default format that brings kdenlive to convert to divx allows modification, I have seen that there are two options to modify the quality of the video, by default they have the values:

Qualities: 5.15
Default quality: 0

Can these parameters be modified to adjust the video quality to be similar to the original?


I don't normally use any of the standard KDenLive render profiles; for my workflow I prefer to use custom created profiles for lossless output. But having run a few quick tests with the 'MPEG-4-ASP/MP3 (DivX Compatible)' profile using a standard definition source clip, several things strike me. One is that when rendered at the default settings the visual quality of the rendered video was not that great, with a fair degree of 'blockiness' - which perhaps is not surprising given that the rendered video stream bitrate was just 704 kbps

Image

What's more, adjusting the Video and/or Audio 'Default Quality' values doesn't appear to do anything; it still encodes at the 'original' default values. And neither could I select any of the Speed options. So something is not right there. This is with KdenLive 16.12.3 (from the testing ppa) on Kubuntu 16.10 (AMD 64).

But what you could do as a workaround is manually enter the desired qscale and aq values in place of the (non functioning) qscale=%quality and aq=%audioquality parameters in the Parameters pane and save that as a custom profile.

So, here's the default profile:

Image

And here's one with the qscale and aq values set to 5 and 3.

Image

So in that way you could test at higher quality settings (i.e. lower qscale and/or aq values) to see if that better meets your requirements. And likewise if you want to experiment with the different 'Speed' options:

subq=5 cmp=2 subcmp=2 trellis=1 bf=2
subq=3 cmp=1 subcmp=1 trellis=1 bf=2
subq=1

'Speed' in this context referring to encoding rate, the rationale being that encoding at a slower settings brings about some improvement in compression efficiency - i.e. the same quality at a lower bitrate. In this case, subq=5 cmp=2 subcmp=2 trellis=1 bf=2 is the slowest. There again, it's just a matter of copy pasting the respective parameter string into the profile Parameter pane.

If you are not familiar with creating custom profiles, what you need to do is highlight the default MPEG-4-ASP/MP3 (DivX Compatible) preset on the menu and click on the 'Create New Profile' icon (document symbol) to open up the profile.

Image

Then make your changes, give the profile new title and OK to save it.

By way of example, here are the bitrates of the renders produced with that same standard definition clip with the qscale value set at 5 (and aq at 3):

Image

And then with qscale=3.

Image

Unless you are intending to do some editing with KdenLive I still think you would be better off using an external encoder, but if this works for you all well and good.

Edit: In those tests with the PAL 720x576 (16:9) source I probably should have rescaled to square pixels (mod16) - but never mind, it was more to illustrate the impact of lowered qscale value on the resulting bitrate.

Edit: Of course, if you settle on a render profile that produces the desired results you could also use the same parameters to create a custom transcode profile. There again, is it worth it if this is a one-off conversion.
Inapickle
Registered Member
Posts
157
Karma
3
vpinon wrote:Regarding your encoding parameter question, these have evolved a bit in recent versions, what Kdenlive version do you use?
It normally gives the best/worst crf or qscale values to be used in the Quality cursor of the UI. Default might be an index value, so 0 is best (5).
If you change Qualities to 2,15 you would get the quality you're asking for...


So that's how it works. I didn't realize the two 'Qualities' values actually constitute a setting. I had the impression they represented a range of 'recommended' qscale values from which to choose, and that the 'Default Quality' box is where you are supposed enter the desired qscale value...except that changing it made no difference, which made me think there was a bug. I'm still not clear though how one is supposed to change the 'Speed' option short of copy pasting the respective parameter string into the Parameters pane.

Edit: FWIW, here are the video bitrates of renders produced with that SD source clip at different 'qualities' settings:

5,15 (default) - 704 kbps
4,15 - 788 kbps
3,15 - 933 kbps
2,15 - 933 kbps

The reason why replacing the qscale=%quality parameter with a discrete qscale value produced higher bitrates is because it forced uniform constraint to that quantization level, tantamount to constant quality:

Inapickle wrote:
jony127 wrote:By way of example, here are the bitrates of the renders produced with that same standard definition clip with the qscale value set at 5 (and aq at 3):

Image

And then with qscale=3.

Image


Setting the two video 'Qualities' values to the same value achieves the same result. And personally that's what I would recommend doing as it achieves constant quality, which is what you want. In addition, the bitrate of your source AVC video is just 985 kbps, so converting to MPEG-4 you would certainly want a higher bitrate than that if you want to preserve quality as much as possible.

I'd suggest 3,3 as a starting point:

[url]Image[/url]

If the bitrate proves too high for your playback platform, try dropping down to 4,4
Inapickle
Registered Member
Posts
157
Karma
3
So did you achieve the desired result jony127 ?


Bookmarks



Who is online

Registered users: Bing [Bot], Google [Bot], lockheed, Sogou [Bot]