Repository: just-work/fffw

Issue:
Interface for accessing meta of output files
Now, to get meta info about outputs (ex. total_frames) we have to use getattr and cast. A more comfortable way is required.

Please contact if need more details.



Discussion:

Patch:
diff --git a/fffw/encoding/ffmpeg.py b/fffw/encoding/ffmpeg.py
index 248f3ef..23a5790 100644
--- a/fffw/encoding/ffmpeg.py
+++ b/fffw/encoding/ffmpeg.py
@@ -1,9 +1,8 @@
 from dataclasses import dataclass
-from typing import List, Optional, Union
+from typing import List, Optional, Union, Tuple
 
-from fffw.encoding import inputs
 from fffw.encoding.complex import FilterComplex
-from fffw.encoding.inputs import InputList, Input
+from fffw.encoding.inputs import InputList, Input, Stream
 from fffw.encoding.outputs import OutputList, Output, Codec
 from fffw.graph import base, meta
 from fffw.graph.meta import AUDIO, VIDEO, StreamType
@@ -97,6 +96,20 @@ class FFMPEG(BaseWrapper):
             return NotImplemented
         return self.add_output(other)
 
+    @property
+    def inputs(self) -> Tuple[Input, ...]:
+        """
+        :return: a copy of ffmpeg input list.
+        """
+        return tuple(self.__inputs)
+
+    @property
+    def outputs(self) -> Tuple[Output, ...]:
+        """
+        :return: a copy of ffmpeg output list.
+        """
+        return tuple(self.__outputs)
+
     @property
     def filter_device(self) -> meta.Device:
         """ Returns filter hardware device metadata."""
@@ -107,7 +120,7 @@ class FFMPEG(BaseWrapper):
         return meta.Device(hardware, name)
 
     @property
-    def video(self) -> inputs.Stream:
+    def video(self) -> Stream:
         """
         :returns: first video stream not yet connected to filter graph or codec.
 
@@ -120,7 +133,7 @@ class FFMPEG(BaseWrapper):
         return self._get_free_source(VIDEO)
 
     @property
-    def audio(self) -> inputs.Stream:
+    def audio(self) -> Stream:
         """
 
         :returns: first audio stream not yet connected to filter graph or codec.
@@ -134,7 +147,7 @@ class FFMPEG(BaseWrapper):
         """
         return self._get_free_source(AUDIO)
 
-    def _get_free_source(self, kind: StreamType) -> inputs.Stream:
+    def _get_free_source(self, kind: StreamType) -> Stream:
         """
         :param kind: stream type
         :return: first stream of this kind not connected to destination


Test patch:
diff --git a/tests/test_ffmpeg.py b/tests/test_ffmpeg.py
index d9ac3c4..de0195a 100644
--- a/tests/test_ffmpeg.py
+++ b/tests/test_ffmpeg.py
@@ -119,6 +119,23 @@ class FFMPEGTestCase(BaseTestCase):
             '/tmp/out.mp3'
         )
 
+    def test_inputs_property(self):
+        """
+        ffmpeg private input list could be accessed via property
+        """
+        self.ffmpeg < self.source
+
+        self.assertTupleEqual(self.ffmpeg.inputs, (self.source,))
+
+    def test_outputs_property(self):
+        """
+        ffmpeg private output list could be accessed via property
+        """
+        self.ffmpeg < self.source
+        self.ffmpeg > self.output
+
+        self.assertTupleEqual(self.ffmpeg.outputs, (self.output,))
+
     def test_filter_device_helper(self):
         """
         filter_device correcly parses init_hardware and filter_hardware flags.