Skip to content

Commit

Permalink
Merge pull request #1 from Reza-Rezvan/master
Browse files Browse the repository at this point in the history
Python 3 Compatibility Update for video-transcoder-py3.py
  • Loading branch information
godsgood33 authored Nov 21, 2024
2 parents 4326b27 + a102a9b commit bd43a92
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
11 changes: 8 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,14 @@ This file converts a Plex DVR recorded TS file to an MP4 container file. In my
## Usage
To use the script copy it to whatever directory you want to run the folllowing command

`python video-transcode.py /path/to/ts/files`
`python video-transcode-py3.py /path/to/ts/files`

The script will find all the `.ts` files in that directory (NO SUBFOLDERS), then, using the `ffmpy` module in python, run `ffmpeg` on all the files to convert them to `mp4` files. It will put the transcoded file in the same directory as the original file. The script does NOT remove the original file. If you want to delete the original file, you can add the `--deleteOriginal` parameter to the command and if the transcoded file is between 0.25 and 1.2 times the size of the original it will delete the original.

## Tested
I've test this on Python 2.7.5 as that is what I have on my server. Feel free to post any bugs AND SOLUTIONS if there are problems with other versions.
## Updates

### Python 3 Compatibility Update
- Updated the `video-transcoder-py3.py` script to be compatible with Python 3.
- Fixed syntax issues, primarily by modifying `print` statements to use parentheses.
- This update ensures compatibility with modern Python versions while maintaining the existing functionality.

14 changes: 7 additions & 7 deletions video-transcoder.py → video-transcoder-py3.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import ffmpy

def create_arg_parser():
""""Creates and returns the ArgumentParser object."""
"""Creates and returns the ArgumentParser object."""

parser = argparse.ArgumentParser(description='This script allows you to find all .ts files in the inputDirectory and convert them to mp4 files using ffmpeg')
parser.add_argument('inputDirectory',
Expand All @@ -25,7 +25,7 @@ def transcode_file(inputFile):
inputs={inputFile: None},
outputs={outputFile: '-c:v libx264 -strict -2'},
)
print ff.cmd
print(ff.cmd) # Updated to use parentheses
ff.run()

def check_file(inputFile, deleteOriginal):
Expand All @@ -38,13 +38,13 @@ def check_file(inputFile, deleteOriginal):
size_max = ofs * 1.2

if (tfs < size_min) or (tfs > size_max):
print "Transcoded file not within reasonable size limits"
print "Transcoded file size: " + tfs + " bytes"
print "Limits:\nMin: " + size_min + "\nMax: " + size_max
print "Original file size: " + ofs + " bytes"
print("Transcoded file not within reasonable size limits")
print("Transcoded file size: " + str(tfs) + " bytes")
print("Limits:\nMin: " + str(size_min) + "\nMax: " + str(size_max))
print("Original file size: " + str(ofs) + " bytes")
os._exit(1)
elif tfs >= size_min and tfs <= size_max:
print "Transcoded file within reasonable size limits"
print("Transcoded file within reasonable size limits")
if deleteOriginal:
os.remove(inputFile)

Expand Down

0 comments on commit bd43a92

Please sign in to comment.