Repository: ManimCommunity/manim

Issue:
Implement `-q[l|m|h|p|k]` to specify render quality
Forked from #65.

Instead of `-l` being the abbreviation of `--low_quality`, we should have `-ql`, and similarly so for medium/high/production/4k quality. Also, we should have a `--production_quality` flag.



Discussion:
This is a fairly easy PR now that #98 has been merged. Any takers?
I can take a look at this, I assume that `production_quality` is higher quality than `fourk_quality`?
Thanks @jvdoorn for volunteering! You can see what each quality means in `https://github.com/ManimCommunity/manim/blob/master/manim/config/default.cfg`. The "production" quality is defined under the [CLI] section, as frame_rate = 60 pixel_height = 1080, pixel_width = 1920. The other four have their own sections [low_quality], etc.
Is this fixed?
Yes except for the `-qp` flag, however since that is default behavior I personally don't see a use for it. It could however be implemented very easily if you want. Otherwise this issue is done and dusted. 
It is useful, beccause you can't predict if the default behavior may change in the future. If you make yourself a script that auto-renders or anything, you may want to "force" production resolution
It would actually be good to have a `-qp` flag, if only to say that it's the default in the help menu (currently it's not clear that high quality isn't the default).
Got it, will create a PR for that probably later today.

Also, slightly unrelated, but shouldn't production quality be the highest possible quality? Since "production quality" often refers to the quality for the end-user which should be the highest right? But I don't know how you guys interpret production quality.
I agree, i would suggest more explicit names, like -qHD -qFHD -q2K -q4K. We can take the names from the wikipedia page : https://en.wikipedia.org/wiki/List_of_common_resolutions?wprov=sfla1
To every referenced resolution is associated a name. We could even create a file containing a association map with Name->resolutionData. And then allow the user to create his own "resolutiondata" and use -qMyRes freely. What do you think ?

I think that'd be overcomplicating it a bit, especially since these can already be set from the config file.

Resolving patch:
diff --git a/manim/config/config.py b/manim/config/config.py
--- a/manim/config/config.py
+++ b/manim/config/config.py
@@ -86,7 +86,7 @@ def _parse_config(config_parser, args):
     # and are stored in 'camera_config'.  Note the highest resolution
     # passed as argument will be used.
     quality = _determine_quality(args)
-    section = config_parser[quality if quality != "production" else "CLI"]
+    section = config_parser[quality if quality != constants.DEFAULT_QUALITY else "CLI"]
 
     # Loop over low quality for the keys, could be any quality really
     config = {opt: section.getint(opt) for opt in config_parser["low_quality"]}
diff --git a/manim/config/config_utils.py b/manim/config/config_utils.py
--- a/manim/config/config_utils.py
+++ b/manim/config/config_utils.py
@@ -343,6 +343,7 @@ def _parse_cli(arg_list, input=True):
         "-q",
         "--quality",
         choices=constants.QUALITIES.values(),
+        default=constants.DEFAULT_QUALITY_SHORT,
         help="Render at specific quality, short form of the --*_quality flags",
     )
     parser.add_argument(
@@ -360,6 +361,11 @@ def _parse_cli(arg_list, input=True):
         action="store_true",
         help="Render at high quality",
     )
+    parser.add_argument(
+        "--production_quality",
+        action="store_true",
+        help="Render at default production quality",
+    )
     parser.add_argument(
         "--fourk_quality",
         action="store_true",
@@ -650,7 +656,10 @@ def _determine_quality(args):
     }
 
     for quality in constants.QUALITIES.keys():
-        if getattr(args, quality) or (
+        if quality == constants.DEFAULT_QUALITY:
+            # Skip so we prioritize anything that overwrites the default quality.
+            pass
+        elif getattr(args, quality) or (
             hasattr(args, "quality") and args.quality == constants.QUALITIES[quality]
         ):
             return quality
@@ -662,4 +671,4 @@ def _determine_quality(args):
             )
             return old_qualities[quality]
 
-    return "production"
+    return constants.DEFAULT_QUALITY
diff --git a/manim/constants.py b/manim/constants.py
--- a/manim/constants.py
+++ b/manim/constants.py
@@ -130,7 +130,11 @@ class MyText(Text):
 # Video qualities
 QUALITIES = {
     "fourk_quality": "k",
+    "production_quality": "p",
     "high_quality": "h",
     "medium_quality": "m",
     "low_quality": "l",
 }
+
+DEFAULT_QUALITY = "production_quality"
+DEFAULT_QUALITY_SHORT = QUALITIES[DEFAULT_QUALITY]


Test patch:
diff --git a/tests/test_cli_flags.py b/tests/test_cli_flags.py
--- a/tests/test_cli_flags.py
+++ b/tests/test_cli_flags.py
@@ -3,10 +3,11 @@
 
 
 def test_quality_flags():
-    # Assert that quality is None when not specifying it
+    # Assert that quality is the default when not specifying it
     parsed = _parse_cli([], False)
 
-    assert not parsed.quality
+    assert parsed.quality == constants.DEFAULT_QUALITY_SHORT
+    assert _determine_quality(parsed) == constants.DEFAULT_QUALITY
 
     for quality in constants.QUALITIES.keys():
         # Assert that quality is properly set when using -q*
@@ -41,4 +42,4 @@ def test_quality_flags():
         parsed = _parse_cli([], False)
 
         assert not getattr(parsed, quality)
-        assert "production" == _determine_quality(parsed)
+        assert _determine_quality(parsed) == constants.DEFAULT_QUALITY