ó
    ‡Ó}j°f  ã                   ó:  • S SK r S SKrS SKrS SKJr  S SKJrJr  S SKJ	r	  S SK
Jr  S SKrS SKJrJrJr  S SKJrJrJr  S SKJr  S S	KJr  S S
KJr  S SKJr  \ " S S5      5       r " S S5      rS\ \!-  \ RD                  -  \ RF                  -  S\$\\\4   4S jr%g)é    N)ÚSequence)Ú	dataclassÚfield)ÚPath)ÚLiteral)ÚdeviceÚnnÚTensor)Ú_coreÚFrameÚ
FrameBatch)Úcreate_video_decoder)Ú_LG)Ú_get_cuda_backend)ÚDecoderTransformc                   ó–   • \ rS rSr% SrSr\\S'    \" SSS9r	\\S'   \" SSS9r
\\S'   \" SSS9r\\S'   \" S	SS9r\\S
'   S rS rSrg)ÚCpuFallbackStatusé   a”  Information about CPU fallback status.

This class tracks whether the decoder fell back to CPU decoding.
Users should not instantiate this class directly; instead, access it
via the :attr:`VideoDecoder.cpu_fallback` attribute.

Usage:

- Use ``str(cpu_fallback_status)`` or ``print(cpu_fallback_status)`` to see the cpu fallback status
- Use ``if cpu_fallback_status:`` to check if any fallback occurred
FÚstatus_known)ÚdefaultÚinitÚ_nvcuvid_unavailableÚ_video_not_supportedÚ_is_fallbackÚ Ú_backendc                 ó@   • U R                   =(       a    U R                  $ )z"Returns True if fallback occurred.)r   r   ©Úselfs    Ú°C:\Users\johnn\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.13_qbz5n2kfra8p0\LocalCache\local-packages\Python313\site-packages\torchcodec/decoders/_video_decoder.pyÚ__bool__ÚCpuFallbackStatus.__bool__2   s   € à× Ñ ×6 T×%6Ñ%6Ð6ó    c                 óŠ  • U R                   (       d  SU R                   S3$ / nU R                  (       a  UR                  S5        OEU R                  (       a  UR                  S5        O"U R
                  (       a  UR                  S5        U(       a"  SU R                   S3SR                  U5      -   $ SU R                   S3$ )	zJReturns a human-readable string representation of the cpu fallback status.Ú[z] Fallback status: UnknownzNVcuvid unavailablezVideo not supportedz6Unknown reason - try the 'nvdec' backend to know more!z(] Fallback status: Falling back due to: ú, z'] Fallback status: No fallback required)r   r   r   Úappendr   r   Újoin)r   Úreasonss     r    Ú__str__ÚCpuFallbackStatus.__str__6   s¦   € à× × Ø�t—}‘}�oÐ%?Ð@Ð@àˆØ×$×$Ø�N‰NÐ0Õ1Ø×&×&Ø�N‰NÐ0Õ1Ø××Ø�N‰NÐSÔTæà�D—M‘M�?Ð"JÐKØ—)‘)˜GÓ$ñ%ðð �4—=‘=�/Ð!HÐIÐIr#   © N)Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__r   ÚboolÚ__annotations__r   r   r   r   r   Ústrr!   r*   Ú__static_attributes__r,   r#   r    r   r      sk   ‡ ñ
ð €L�$Óð8ñ
 "'¨u¸5Ñ!AÐ˜$ÓAÙ!&¨u¸5Ñ!AÐ˜$ÓAÙ u°5Ñ9€L�$Ó9Ù "¨5Ñ1€HˆcÓ1ò7õJr#   r   c                   óÌ  • \ rS rSrSrSSSSSS\R                  SS.S\\-  \	R                  -  \	R                  -  \-  \-  S	\S-  S
\S   S\S\\-  S-  S\S   S\\\R(                  -     S-  S\R*                  \S   -  S\\-  \	R                  -  \	R                  -  S-  4S jjrS\4S jr\S\4S j5       rS\S\4S jrS\S\4S jrS\R>                  \-  S\4S jr S\!\   4S jr"S\S\#4S jr$S\R                  \!\   -  S\%4S  jr&S.S!\S"\S#\S\%4S$ jjr'S%\(S\#4S& jr)S%\R                  \!\(   -  S\%4S' jr* S/S(\(S)\(S*\(S-  S\%4S+ jjr+S/S*\(S-  S\%4S, jjr,S-r-g)0ÚVideoDecoderéK   aq  A single-stream video decoder.

Args:
    source (str, ``Pathlib.path``, bytes, ``torch.Tensor`` or file-like object): The source of the video:

        - If ``str``: a local path or a URL to a video file.
        - If ``Pathlib.path``: a path to a local video file.
        - If ``bytes`` object or ``torch.Tensor``: the raw encoded video data.
        - If file-like object: we read video data from the object on demand. The object must
          expose the methods `read(self, size: int) -> bytes` and
          `seek(self, offset: int, whence: int) -> int`. Read more in:
          :ref:`sphx_glr_generated_examples_decoding_file_like.py`.
    stream_index (int, optional): Specifies which stream in the video to decode frames from.
        Note that this index is absolute across all media types. If left unspecified, then
        the :term:`best stream` is used.
    dimension_order(str, optional): The dimension order of the decoded frames.
        This can be either "NCHW" (default) or "NHWC", where N is the batch
        size, C is the number of channels, H is the height, and W is the
        width of the frames.

        .. note::

            Frames are natively decoded in NHWC format by the underlying
            FFmpeg implementation. Converting those into NCHW format is a
            cheap no-copy operation that allows these frames to be
            transformed using the `torchvision transforms
            <https://pytorch.org/vision/stable/transforms.html>`_.
    num_ffmpeg_threads (int, optional): The number of threads to use for CPU decoding.
        This has no effect when using GPU decoding.
        Use 1 for single-threaded decoding which may be best if you are running multiple
        instances of ``VideoDecoder`` in parallel. Use a higher number for multi-threaded
        decoding which is best if you are running a single instance of ``VideoDecoder``.
        Passing 0 lets FFmpeg decide on the number of threads.
        Default: 1.
    device (str or torch.device, optional): The device to use for decoding.
        If ``None`` (default), uses the current default device.
        If you pass a CUDA device, decoding uses the ``"nvdec"`` backend by
        default. See :func:`~torchcodec.decoders.set_cuda_backend` to switch
        to the ``"ffmpeg"`` CUDA backend.
    seek_mode (str, optional): Determines if frame access will be "exact" or
        "approximate". Exact guarantees that requesting frame i will always
        return frame i, but doing so requires an initial :term:`scan` of the
        file. Approximate is faster as it avoids scanning the file, but less
        accurate as it uses the file's metadata to calculate where i
        probably is. Default: "exact".
        Read more about this parameter in:
        :ref:`sphx_glr_generated_examples_decoding_approximate_mode.py`
    transforms (sequence of transform objects, optional): Sequence of transforms to be
        applied to the decoded frames by the decoder itself, in order. Accepts both
        :class:`~torchcodec.transforms.DecoderTransform` and
        :class:`~torchvision.transforms.v2.Transform`
        objects. Read more about this parameter in :ref:`sphx_glr_generated_examples_decoding_transforms.py`.
    output_dtype (torch.dtype or ``"auto"``, optional): The dtype of the
        output frames. Supported values are ``torch.uint8`` with values in
        [0, 255] (default), ``torch.float32`` with values in [0, 1], and
        ``"auto"``. When ``"auto"`` is specified, the output dtype is
        determined automatically based on the video content: uint8 for SDR
        content, float32 for HDR content.
        Read more about this parameter in:
        :ref:`sphx_glr_generated_examples_decoding_hdr_decoding.py`

        .. note::
            The features associated with this parameter are in beta stage
            and behavior may change in future versions. Specifically,
            detecting whether a video is SDR or HDR is difficult, so the
            "auto" heuristic is subject to change and improve.

    custom_frame_mappings (str, bytes, or file-like object, optional):
        Mapping of frames to their metadata, typically generated via ffprobe.
        This enables accurate frame seeking without requiring a full video scan.
        Do not set seek_mode when custom_frame_mappings is provided.
        Expected JSON format:

        .. code-block:: json

            {
                "frames": [
                    {
                        "pts": 0,
                        "duration": 1001,
                        "key_frame": 1
                    }
                ]
            }

        Alternative field names "pkt_pts" and "pkt_duration" are also supported.
        Read more about this parameter in:
        :ref:`sphx_glr_generated_examples_decoding_custom_frame_mappings.py`

Attributes:
    metadata (VideoStreamMetadata): Metadata of the video stream.
    stream_index (int): The stream index that this decoder is retrieving frames from. If a
        stream index was provided at initialization, this is the same value. If it was left
        unspecified, this is the :term:`best stream`.
    cpu_fallback (CpuFallbackStatus): Information about whether the decoder fell back to CPU
        decoding. Use ``bool(cpu_fallback)`` to check if fallback occurred, or
        ``str(cpu_fallback)`` to get a human-readable status message. The status is only
        determined after at least one frame has been decoded.
NÚNCHWé   Úexact)Ústream_indexÚdimension_orderÚnum_ffmpeg_threadsr   Ú	seek_modeÚ
transformsÚoutput_dtypeÚcustom_frame_mappingsÚsourcer<   r=   ©r9   ÚNHWCr>   r   r?   ©r;   Úapproximater@   rA   ÚautorB   c                óV  • [         R                  R                  S5        Sn
Xj;  a!  [        SU SSR	                  U
5       S35      eU	b  US:X  a  [        S5      eS nU	b  S	n[        U	5      nS
nX<;  a!  [        SU SSR	                  U5       S35      eUc  [        SU< S35      e[         R                  S[         R                  S0nUS:w  a  X�;  a  [        SU S35      eXØ   n[        5       nUc  [        [         R                  " 5       5      nO [        U[        5      (       a  [        U5      nUR                  S5      (       a  US:X  a  US:w  a  [        SU S35      e[        UUUUUUUUUUS9
u  U l        U l        U l        U R"                  R$                  c   eU R"                  R&                  c   eU R"                  R(                  c   e[*        R,                  " SU R"                   35        U R"                  R$                  U l        U R"                  R&                  U l        U R"                  R(                  U l        [5        5       U l        UR                  S5      (       a*  US:X  a  SU R6                  l        g SU R6                  l        g SU R6                  l        g )Nz torchcodec.decoders.VideoDecoderrF   zInvalid seek mode (z). Supported values are r&   Ú.rG   z­custom_frame_mappings is incompatible with seek_mode='approximate'. Use seek_mode='custom_frame_mappings' or leave it unspecified to automatically use custom frame mappings.rB   rD   zInvalid dimension order (znum_ffmpeg_threads = z should be an int.Úuint8Úfloat32rH   zInvalid output_dtype (z?). Supported values are torch.uint8, torch.float32, and 'auto'.ÚcudaÚffmpegzoutput_dtype=z’ is not supported with the 'ffmpeg' CUDA backend. Only torch.uint8 is supported. Use the default 'nvdec' CUDA backend for non-uint8 output dtypes.)
rC   r?   r<   r=   r>   r   Údevice_variantr@   rB   rA   zVideoDecoder created:
r   ÚCUDAzFFmpeg CUDAÚCPU)ÚtorchÚ_CÚ_log_api_usage_onceÚ
ValueErrorr(   Ú_read_custom_frame_mappingsrK   rL   r   r4   Úget_default_deviceÚ
isinstanceÚtorch_deviceÚ
startswithr   Ú_decoderr<   ÚmetadataÚbegin_stream_secondsÚend_stream_secondsÚ
num_framesr   ÚdebugÚ_begin_stream_secondsÚ_end_stream_secondsÚ_num_framesr   Ú_cpu_fallbackr   )r   rC   r<   r=   r>   r   r?   r@   rA   rB   Úallowed_seek_modesÚcustom_frame_mappings_dataÚallowed_dimension_ordersÚ_DTYPE_TO_STRrO   s                  r    Ú__init__ÚVideoDecoder.__init__°   sÛ  € ô 	�‰×$Ñ$Ð%GÔHØ5ÐØÓ.ÜØ% i [ð 1(Ø(,¯	©	Ð2DÓ(EÐ'FÀaðIóð ð !Ñ,°¸mÓ1KÜð|óð ð &*Ð"Ø Ñ,Ø/ˆIÜ)DØ%ó*Ð&ð $4Ð ØÓ:ÜØ+¨OÐ+<ð =(Ø(,¯	©	Ð2JÓ(KÐ'LÈAðOóð ð
 Ñ%ÜÐ 5Ð 2Ñ6Ð6HÐIÓJÐJäŸ™ g¬u¯}©}¸iÐHˆØ˜6Ó!ØÓ0Ü Ø,¨\¨Nð ;Sð Tóð ð )Ñ6ˆLä*Ó,ˆØ‰>Üœ×1Ò1Ó3Ó4‰FÜ˜¤×-Ñ-Ü˜“[ˆFð ×Ñ˜f×%Ñ%Ø (Ó*Ø Ó'äØ ˜~ð .Dð Eóð ô !ØØØ%Ø+Ø1ØØ)Ø!Ø"<Ø%ñ
ñ		
ØŒMØÔØŒMð �}‰}×1Ñ1Ñ=Ð=Ð=Ø�}‰}×/Ñ/Ñ;Ð;Ð;Ø�}‰}×'Ñ'Ñ3Ð3Ð3ä�	Š	Ð+¨D¯M©M¨?Ð;Ô<à%)§]¡]×%GÑ%GˆÔ"Ø#'§=¡=×#CÑ#CˆÔ ØŸ=™=×3Ñ3ˆÔä.Ó0ˆÔØ×Ñ˜V×$Ñ$Ø Ó*Ø.4�×"Ñ"Õ+à.;�×"Ñ"Õ+à*/ˆD×ÑÕ'r#   Úreturnc                 ó   • U R                   $ ©N)rc   r   s    r    Ú__len__ÚVideoDecoder.__len__  s   € Ø×ÑÐr#   c                 óˆ  • U R                   R                  (       dœ  [        R                  " U R                  5      nSU;  av  SU R                   l        SU;   a_  SU R                   l        U R                   R                  S:X  a4  SU;   a  SU R                   l        U R                   $ SU R                   l        U R                   $ )Nzstatus unknownTzCPU fallbackrP   zNVCUVID not available)	rd   r   ÚcoreÚ_get_backend_detailsr[   r   r   r   r   )r   Úbackend_detailss     r    Úcpu_fallbackÚVideoDecoder.cpu_fallback!  s«   € ð ×!Ñ!×.×.Ü"×7Ò7¸¿¹ÓFˆOà Ó6Ø26�×"Ñ"Ô/à! _Ó4Ø6:�D×&Ñ&Ô3Ø×)Ñ)×2Ñ2°fÓ<ð 3°oÓEØFJ˜D×.Ñ.ÔCð ×!Ñ!Ð!ð GK˜D×.Ñ.ÔCà×!Ñ!Ð!r#   Úkeyc                 ót   • [        U[        5      (       d   e[        R                  " U R                  US9tp#U$ )N©Úframe_index)rX   Úintrq   Úget_frame_at_indexr[   )r   rv   Ú
frame_dataÚ_s       r    Ú_getitem_intÚVideoDecoder._getitem_int<  s3   € Ü˜#œs×#Ñ#Ð#Ð#ä×0Ò0°·±ÈCÑPˆˆ
ØÐr#   c                 ó²   • [        U[        5      (       d   eUR                  [        U 5      5      u  p#n[        R
                  " U R                  UUUS9tpVU$ )N©ÚstartÚstopÚstep)rX   ÚsliceÚindicesÚlenrq   Úget_frames_in_ranger[   )r   rv   r‚   rƒ   r„   r|   r}   s          r    Ú_getitem_sliceÚVideoDecoder._getitem_sliceB  sV   € Ü˜#œu×%Ñ%Ð%Ð%àŸK™K¬¨D«	Ó2Ñˆ�TÜ×1Ò1Ø�M‰MØØØñ	
ˆˆ
ð Ðr#   c                 óð   • [        U[        R                  5      (       a  U R                  [	        U5      5      $ [        U[
        5      (       a  U R                  U5      $ [        S[        U5       S35      e)ai  Return frame or frames as tensors, at the given index or range.

.. note::

    If you need to decode multiple frames, we recommend using the batch
    methods instead, since they are faster:
    :meth:`~torchcodec.decoders.VideoDecoder.get_frames_at`,
    :meth:`~torchcodec.decoders.VideoDecoder.get_frames_in_range`,
    :meth:`~torchcodec.decoders.VideoDecoder.get_frames_played_at`, and
    :meth:`~torchcodec.decoders.VideoDecoder.get_frames_played_in_range`.

Args:
    key(int or slice): The index or range of frame(s) to retrieve.

Returns:
    torch.Tensor: The frame or frames at the given index or range.
zUnsupported key type: z$. Supported types are int and slice.)	rX   ÚnumbersÚIntegralr~   rz   r…   r‰   Ú	TypeErrorÚtype)r   rv   s     r    Ú__getitem__ÚVideoDecoder.__getitem__N  sh   € ô$ �cœ7×+Ñ+×,Ñ,Ø×$Ñ$¤S¨£XÓ.Ð.Ü˜œU×#Ñ#Ø×&Ñ& sÓ+Ð+äØ$¤T¨#£Y KÐ/SÐTó
ð 	
r#   c                 óB   • [         R                  " U R                  5      $ rm   )rq   Ú_get_key_frame_indicesr[   r   s    r    r“   Ú#VideoDecoder._get_key_frame_indicesi  s   € Ü×*Ò*¨4¯=©=Ó9Ð9r#   Úindexc                 ó”   • [         R                  " U R                  US9u  p#n[        UUR	                  5       UR	                  5       S9$ )a'  Return a single frame at the given index.

.. note::

    If you need to decode multiple frames, we recommend using the batch
    methods instead, since they are faster:
    :meth:`~torchcodec.decoders.VideoDecoder.get_frames_at`,
    :meth:`~torchcodec.decoders.VideoDecoder.get_frames_in_range`,
    :meth:`~torchcodec.decoders.VideoDecoder.get_frames_played_at`,
    :meth:`~torchcodec.decoders.VideoDecoder.get_frames_played_in_range`.

Args:
    index (int): The index of the frame to retrieve.

Returns:
    Frame: The frame at the given index.
rx   ©ÚdataÚpts_secondsÚduration_seconds)rq   r{   r[   r   Úitem)r   r•   r˜   r™   rš   s        r    Úget_frame_atÚVideoDecoder.get_frame_atl  sM   € ô$ /3×.EÒ.EØ�M‰M uñ/
Ñ+ˆÐ+ô ØØ#×(Ñ(Ó*Ø-×2Ñ2Ó4ñ
ð 	
r#   r†   c                 ó\   • [         R                  " U R                  US9u  p#n[        UUUS9$ )z¸Return frames at the given indices.

Args:
    indices (torch.Tensor or list of int): The indices of the frames to retrieve.

Returns:
    FrameBatch: The frames at the given indices.
)Úframe_indicesr—   )rq   Úget_frames_at_indicesr[   r   )r   r†   r˜   r™   rš   s        r    Úget_frames_atÚVideoDecoder.get_frames_at‡  s;   € ô /3×.HÒ.HØ�M‰M¨ñ/
Ñ+ˆÐ+ô ØØ#Ø-ñ
ð 	
r#   r‚   rƒ   r„   c                 ó¤   • [        XU5      R                  U R                  5      u  pn[        R                  " U R
                  UUUS9n[        U6 $ )ad  Return multiple frames at the given index range.

Frames are in [start, stop).

Args:
    start (int): Index of the first frame to retrieve.
    stop (int): End of indexing range (exclusive, as per Python
        conventions).
    step (int, optional): Step size between frames. Default: 1.

Returns:
    FrameBatch: The frames within the specified range.
r�   )r…   r†   rc   rq   rˆ   r[   r   )r   r‚   rƒ   r„   Úframess        r    rˆ   Ú VideoDecoder.get_frames_in_range›  sS   € ô " %¨tÓ4×<Ñ<¸T×=MÑ=MÓNÑˆ�TÜ×)Ò)Ø�M‰MØØØñ	
ˆô ˜6Ð"Ð"r#   Úsecondsc           	      ó0  • U R                   Us=::  a  U R                  :  d+  O  [        SU SU R                    SU R                   S35      e[        R                  " U R
                  U5      u  p#n[        UUR                  5       UR                  5       S9$ )a\  Return a single frame played at the given timestamp in seconds.

.. note::

    If you need to decode multiple frames, we recommend using the batch
    methods instead, since they are faster:
    :meth:`~torchcodec.decoders.VideoDecoder.get_frames_at`,
    :meth:`~torchcodec.decoders.VideoDecoder.get_frames_in_range`,
    :meth:`~torchcodec.decoders.VideoDecoder.get_frames_played_at`,
    :meth:`~torchcodec.decoders.VideoDecoder.get_frames_played_in_range`.

Args:
    seconds (float): The time stamp in seconds when the frame is played.

Returns:
    Frame: The frame that is played at ``seconds``.
zInvalid pts in seconds: ú&. It must be greater than or equal to ú and less than rJ   r—   )ra   rb   Ú
IndexErrorrq   Úget_frame_at_ptsr[   r   r›   ©r   r¦   r˜   r™   rš   s        r    Úget_frame_played_atÚ VideoDecoder.get_frame_played_at³  s¦   € ð$ ×)Ñ)¨WÕO°t×7OÑ7OÕOÜØ*¨7¨)ð 47Ø7;×7QÑ7QÐ6Rð S!Ø!%×!9Ñ!9Ð :¸!ð=óð ô
 /3×.CÒ.CØ�M‰M˜7ó/
Ñ+ˆÐ+ô ØØ#×(Ñ(Ó*Ø-×2Ñ2Ó4ñ
ð 	
r#   c                 ó\   • [         R                  " U R                  US9u  p#n[        UUUS9$ )zèReturn frames played at the given timestamps in seconds.

Args:
    seconds (torch.Tensor or list of float): The timestamps in seconds when the frames are played.

Returns:
    FrameBatch: The frames that are played at ``seconds``.
)Ú
timestampsr—   )rq   Úget_frames_by_ptsr[   r   r¬   s        r    Úget_frames_played_atÚ!VideoDecoder.get_frames_played_atÔ  s;   € ô /3×.DÒ.DØ�M‰M gñ/
Ñ+ˆÐ+ô ØØ#Ø-ñ
ð 	
r#   Ústart_secondsÚstop_secondsÚfpsc           	      óp  • X::  d  [        SU SU S35      eU R                  Us=::  a  U R                  :  d+  O  [        SU SU R                   SU R                   S35      eX R                  ::  d  [        SU SU R                   S35      e[        R                  " U R
                  UUUS	9n[        U6 $ )
a—  Returns multiple frames in the given range.

Frames are in the half open range [start_seconds, stop_seconds). Each
returned frame's :term:`pts`, in seconds, is inside of the half open
range.

Args:
    start_seconds (float): Time, in seconds, of the start of the range.
    stop_seconds (float): Time, in seconds, of the end of the range.
        As a half open range, the end is excluded.
    fps (float, optional): If specified, resample output to this frame
        rate by duplicating or dropping frames as necessary. If None
        (default), returns frames at the source video's frame rate.

Returns:
    FrameBatch: The frames within the specified range.
zInvalid start seconds: z1. It must be less than or equal to stop seconds (z).r¨   r©   rJ   zInvalid stop seconds: z#. It must be less than or equal to ©r´   rµ   r¶   )rU   ra   rb   rq   Úget_frames_by_pts_in_ranger[   r   )r   r´   rµ   r¶   r¤   s        r    Úget_frames_played_in_rangeÚ'VideoDecoder.get_frames_played_in_rangeç  sô   € ð( Ó,ÜØ)¨-¨ð 9BØBNÀÈrðSóð ð ×)Ñ)¨]ÕU¸T×=UÑ=UÕUÜØ)¨-¨ð 97Ø7;×7QÑ7QÐ6Rð S!Ø!%×!9Ñ!9Ð :¸!ð=óð ð
 ×7Ñ7Ó7ÜØ(¨¨ð 74Ø48×4LÑ4LÐ3MÈQðPóð ô ×0Ò0Ø�M‰MØ'Ø%Øñ	
ˆô ˜6Ð"Ð"r#   c                 óL   • U R                  U R                  U R                  US9$ )a+  Returns all frames in the video.

Args:
    fps (float, optional): If specified, resample output to this frame
        rate by duplicating or dropping frames as necessary. If None
        (default), returns frames at the source video's frame rate.

Returns:
    FrameBatch: All frames in the video.
r¸   )rº   ra   rb   )r   r¶   s     r    Úget_all_framesÚVideoDecoder.get_all_frames  s1   € ð ×.Ñ.Ø×4Ñ4Ø×1Ñ1Øð /ð 
ð 	
r#   )ra   rd   r[   rb   rc   r\   r<   )r:   rm   ).r-   r.   r/   r0   r1   rR   rK   r4   r   ÚioÚ	RawIOBaseÚBufferedReaderÚbytesr
   rz   r   rY   r   r   r	   ÚModuleÚdtyperi   rn   Úpropertyr   rt   r~   r…   r‰   rŒ   r�   r�   Úlistr“   r   rœ   r   r¡   rˆ   Úfloatr­   r²   rº   r½   r5   r,   r#   r    r7   r7   K   s[  † ñbðP $(Ø39Ø"#Ø,0Ø5<ØDHØ6;·k±kð òl0à�d‘
˜RŸ\™\Ñ)¨B×,=Ñ,=Ñ=ÀÑEÈÑNðl0ð ˜D‘jð	l0ð
 ! Ñ0ðl0ð  ðl0ð �lÑ" TÑ)ðl0ð Ð1Ñ2ðl0ð Ð-°·	±	Ñ9Ñ:¸TÑAðl0ð —k‘k G¨F¡OÑ3ðl0ð �%‰K˜"Ÿ,™,Ñ&¨×):Ñ):Ñ:¸TÑAõl0ð\ ˜ô  ð ð"Ð/ó "ó ð"ð4 ð ¨ô ð
 %ð 
¨Fô 
ð
˜w×/Ñ/°%Ñ7ð 
¸Fô 
ð6:¨¨S©	ô :ð
 #ð 
¨%ô 
ð6
 U§\¡\°D¸±IÑ%=ð 
À*ô 
ñ(#¨ð #°Cð #¸sð #È:õ #ð0
¨5ð 
°Uô 
ðB
¨E¯L©L¸4À¹;Ñ,Fð 
È:ô 
ð( NRñ*#Ø"ð*#Ø27ð*#Ø>CÀd¹lð*#à	õ*#ñX
 %¨$¡,ð 
¸*÷ 
ð 
r#   r7   rB   rk   c           	      óØ  ^
•  [        U S5      (       a  [        R                  " U 5      O[        R                  " U 5      nU(       a  SU;  a  [        S5      eUS   S   m
[        U
4S jS	 5       S5      n[        U
4S
 jS 5       S5      nST
;   nU(       a  U(       a  U(       d  [        S5      e[        R                  " US    Vs/ s H  n[        Xc   5      PM     sn[        R                  S9n[        R                  " US    Vs/ s H  n[        US   5      PM     sn[        R                  S9n[        R                  " US    Vs/ s H  n[        Xd   5      PM     sn[        R                  S9n	[        U5      [        U5      s=:X  a  [        U	5      :X  d  O  [        S5      eXxU	4$ ! [        R                   a  n[        SU S35      UeSnAff = fs  snf s  snf s  snf )aå  Parse custom frame mappings from JSON data and extract frame metadata.

Args:
    custom_frame_mappings: JSON data containing frame metadata, provided as:
        - A JSON string (str, bytes)
        - A file-like object with a read() method

Returns:
    A tuple of three tensors:
    - all_frames (Tensor): Presentation timestamps (PTS) for each frame
    - is_key_frame (Tensor): Boolean tensor indicating which frames are key frames
    - duration (Tensor): Duration of each frame
ÚreadzInvalid custom frame mappings: z9. It should be a valid JSON string or a file-like object.Nr¤   zWInvalid custom frame mappings. The input is empty or missing the required 'frames' key.r   c              3   ó6   >#   • U  H  oT;   d  M
  Uv •  M     g 7frm   r,   ©Ú.0rv   Úfirst_frames     €r    Ú	<genexpr>Ú._read_custom_frame_mappings.<locals>.<genexpr>F  s   øé € ÐLÒ#5˜CÀÑ9K—C‘CÒ#5ùó   ƒ	�	)ÚptsÚpkt_ptsc              3   ó6   >#   • U  H  oT;   d  M
  Uv •  M     g 7frm   r,   rË   s     €r    rÎ   rÏ   H  s   øé € ÐKÒ4�¸{Ñ8J�‰Ò4ùrÐ   )ÚdurationÚpkt_durationÚ	key_framez‡Invalid custom frame mappings. The 'pts'/'pkt_pts', 'duration'/'pkt_duration', and 'key_frame' keys are required in the frame metadata.)rÄ   z&Mismatched lengths in frame index data)ÚhasattrÚjsonÚloadÚloadsÚJSONDecodeErrorrU   ÚnextrR   Útensorrz   Úint64r2   r‡   )rB   Ú
input_dataÚeÚpts_keyÚduration_keyÚkey_frame_presentÚframeÚ
all_framesÚis_key_framerÔ   rÍ   s             @r    rV   rV   %  sÖ  ø€ ð 	ô Ð,¨f×5Ñ5ô �IŠIÐ+Ô,ä—’Ð1Ó2ð 	ö ˜¨Ó3ÜØeó
ð 	
ð ˜XÑ& qÑ)€KÜÔLÑ#5ÓLÈdÓS€GÜÜKÑ4ÓKÈTó€Lð $ {Ñ2Ðæž,Ö.?Üð Vó
ð 	
ô —’Ø*4°XÒ*>Ó?Ò*> ŒˆU‰^Ö	Ñ*>Ñ?ÄuÇ{Á{ñ€Jô —<’<Ø.8¸Ò.BÓCÒ.B UŒˆU�;ÑÖ	 Ñ.BÑCÌ5Ï:É:ñ€Lô �|Š|Ø/9¸(Ò/CÓDÒ/C eŒˆUÑ Ö	!Ñ/CÑDÌEÏKÉKñ€Hô �
‹Oœs <Ó0ÕA´C¸³MÕAÜÐAÓBÐBØ XÐ-Ð-øôC ×Ñó ÜØ-¨a¨SÐ0iÐjó
àð	ûðüò. 	@ùò 	Dùò 	Es)   ƒ=F1 ÃGÄ
G"ÅG'Æ1GÇGÇG)&r¿   rØ   rŒ   Úcollections.abcr   Údataclassesr   r   Úpathlibr   Útypingr   rR   r   rY   r	   r
   Ú
torchcodecr   rq   r   r   Útorchcodec._core._decoder_utilsr   Útorchcodec._loggingr   Ú"torchcodec.decoders._decoder_utilsr   Útorchcodec.transformsr   r   r7   r4   rÂ   rÀ   rÁ   ÚtuplerV   r,   r#   r    Ú<module>rñ      sš   ðó 
Û Û Ý $ß (Ý Ý ã ß 4Ñ 4ß 7Ñ 7Ý @Ý #Ý @Ý 2ð ÷.Jð .Jó ð.J÷bW
ñ W
ðt7.Ø ™;¨¯©Ñ5¸×8IÑ8IÑIð7.à
ˆ6�6˜6Ð!Ñ"õ7.r#   