> ## Documentation Index
> Fetch the complete documentation index at: https://docs.encord.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Re-encoding Videos (SDK)

You can use Encord's Python SDK to re-encode videos. See our [detailed documentation on re-encoding](/platform-documentation/General/general-supported-data#re-encode-videos) for more information.

<Note>If you data is hosted on a private cloud, Encord requires 'write' permissions to your cloud to re-encode videos.</Note>

Use the [dataset.re\_encode\_data()](/sdk-documentation/sdk-references/dataset#re-encode-data) method to re-encode a list of videos, replacing \<video1\_data\_hash> and \<video2\_data\_hash> below with the hashes of the videos to be re-encoded.

<CodeGroup>
  ```python Sample Code theme={"dark"}
  # Import dependencies
  from encord import EncordUserClient

  # Authenticate with Encord using the path to your private key
  user_client = EncordUserClient.create_with_ssh_private_key(ssh_private_key_path="<private_key_path>")

  # Specify the dataset you want to re-encord data from by using its dataset hash
  dataset = user_client.get_dataset("<dataset_hash>")

  # Specify the data hashes of the files to be re-encoded
  task_id = dataset.re_encode_data(
      [
          "<video1_data_hash\>",
          "<video2_data_hash>",
      ]
  )

  # Print the task ID for the re-encoding job
  print(task_id)
  ```

  ```python Example output theme={"dark"}
  1337 
  ```
</CodeGroup>

The output is a list of task ID's of each re-encoding job. The `task_id` can be used to [monitor the progress](#check-the-status-of-a-re-encoding-task) of the task.

<Note>Ensure that the list contains videos from the same Dataset that was used to initialize the `EncordClient`. Any videos that do not belong to the Dataset used for initialization are ignored.</Note>

***

### Check the status of a re-encoding task

Use the [dataset.re\_encode\_data\_status()](/sdk-documentation/sdk-references/dataset#re-encode-data-status) method to get the status of an existing re-encoding task. Replace `task_id` in the sample below with the task ID of the re-encoding task you'd like to check the status of.

```python Sample Code theme={"dark"}
# Import dependencies
from encord import EncordUserClient

# Authenticate with Encord using the path to your private key
user_client = EncordUserClient.create_with_ssh_private_key(ssh_private_key_path="<private_key_path>")

# Specify the dataset you want to re-encord data from by using its dataset hash
dataset = user_client.get_dataset("<dataset_hash>")

# Define and print the status of the re-encoding task by inserting the re-encoding task's ID
task = (
    dataset.re_encode_data_status("<task_id>")
)
print(task)
```

```python Example output theme={"dark"}
ReEncodeVideoTask(
    status="DONE",
    result=[
        ReEncodeVideoTaskResult(
            data_hash="<data_hash>",
            signed_url="<signed_url>",
            bucket_path="<bucket_path>",
        ),
        ...
    ]
) 
```

The ReEncodeVideoTask object contains a status field, which can take the following values:

* "SUBMITTED": the task is currently in progress and the status should be checked back again later.

* "DONE": the task has been completed successfully and the field ‘result’ would contain metadata about the re-encoded video.

* "ERROR": the task has failed and could not complete the re-encoding.

#### Re-encode locally

Some cases, such as corrupted metadata, might require you to re-encode your data locally before uploading them to the Encord platform.

Use the following `ffmpeg` command, replacing `video.mp4` with the name of the file you want to re-encode, and `re-encoded-video.mp4` with the name you want the re-encoded file to have:

```bash theme={"dark"}
ffmpeg -err_detect aggressive -fflags discardcorrupt -i video.mp4 -r 30 -c:v libx264 -movflags faststart -an -tune zerolatency re-encoded-video.mp4
```

<Warning>
  Since browsers require a constant frame rate, we apply the -r 30 flag (30 fps). Verify your video’s frame rate and adjust the value accordingly.
  We recommend using the average frame rate of your video to set the constant rate (rounded to the nearest whole number).

  You can figure out the average frame rate of your video with this command:

  ```bash theme={"dark"}
  ffprobe -v 0 -select_streams v:0 -show_entries stream=r_frame_rate -of default=noprint_wrappers=1:nokey=1 video.mp4 | bc -l
  ```

  You may need to install `ffprobe` & `bc`
</Warning>

<Note>
  Here is a summary of the various flags:

  * `-err_detect aggressive`: Improves error detection during decoding.
  * `-fflags discardcorrupt`: Discards corrupted packets to maintain integrity.
  * `-r 30`: This sets the frame rate to a constant 30 frames per second (FPS). Feel free to adjust `30` to your desired frame rate.
  * `-c:v libx264`: Specifies the `H.264` codec for video re-encoding.
  * `-movflags faststart`: Optimizes for web playback by moving video metadata to the beginning of the file.
  * -an: This ensures the audio is removed from the re-encoded video.
  * `-tune zerolatency`: Configures for low-latency encoding scenarios.
</Note>
