Skip to content

Commit

Permalink
Merge pull request #1 from chrootLogin/develop
Browse files Browse the repository at this point in the history
Remove more waste from material
  • Loading branch information
chrootlogin committed Oct 12, 2017
2 parents 89215a9 + b10846c commit 4556f75
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 4 deletions.
4 changes: 3 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ MAINTAINER Simon Erhardt <me+docker@rootlogin.ch>
ARG VCS_REF
ARG BUILD_DATE

LABEL org.label-schema.vcs-ref=$VCS_REF \
LABEL org.label-schema.name="FFProcess" \
org.label-schema.description="A small docker container including ffmpeg to batch convert your media library to a defined h264/aac profile." \
org.label-schema.vcs-ref=$VCS_REF \
org.label-schema.build-date=$BUILD_DATE \
org.label-schema.vcs-url="https://github.com/chrootLogin/ffprocess"

Expand Down
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,15 @@
A small docker container including ffmpeg to batch convert your media library to a defined h264/aac profile.

-> [DockerHub](https://hub.docker.com/r/rootlogin/ffprocess/)
-> [Quay.io](https://quay.io/repository/rootlogin/ffprocess)

## Features

* Made for Docker.
* Converts files only if needed.
* You can set a maximum framerate and resolution.
* Truncates all streams that are not video, audio or subtitles.
* Removes not needed additional video streams like embedded images.

## Dependencies when used standalone

Expand Down Expand Up @@ -61,6 +64,12 @@ optional arguments:
--rate RATE maximum framerate (default: 25)
```

## Development

I'm very happy about every filed issue or pull-request.

If you create a pull-request, please compare it against the "develop" branch.

## Warranty

This software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. It could even start a nuclear war or kill your kittens. ;)
Expand Down
33 changes: 30 additions & 3 deletions ffprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def run_command(command):
return process.wait()

parser = argparse.ArgumentParser(description='Batch convert your media library to H264 and AAC.')
parser.add_argument('--quality', required=False, type=int, default=23, help='crf quality of libx264 (default: 23)')
parser.add_argument('--quality', required=False, type=int, default=20, help='crf quality of libx264 (default: 20)')
parser.add_argument('--preset', required=False, type=str, default='veryslow', help='encoding preset for libx264 (default: veryslow)')
parser.add_argument('--resolution', required=False, type=int, default=1080, help='maximum resolution in height (default: 1080)')
parser.add_argument('--rate', required=False, type=int, default=25, help='maximum framerate (default: 25)')
Expand Down Expand Up @@ -65,7 +65,7 @@ def run_command(command):

cmd = ['ffprobe', '-show_format', '-show_streams', '-loglevel', 'quiet', '-print_format', 'json', filepath]

ffmpegCmd = ['ffmpeg','-y','-i',filepath, '-map', '0']
ffmpegCmd = ['ffmpeg', '-y', '-i', filepath]
convertCmd = []
reconvert = False

Expand All @@ -78,10 +78,15 @@ def run_command(command):

i = 0
audioStream = 0
videoStream = 0
subtitleStream = 0
for stream in data['streams']:
logging.debug("Found stream of type %s" % stream['codec_type'])

if stream['codec_type'] == 'video':
if stream['codec_type'] == 'video' and not videoStream > 0:
ffmpegCmd.append("-map")
ffmpegCmd.append("0:%d" % i)

convertVideo = False
videoConvertCmd = []

Expand Down Expand Up @@ -139,7 +144,16 @@ def run_command(command):
convertCmd.append("-c:v")
convertCmd.append("copy")

videoStream += 1

elif stream['codec_type'] == 'video' and videoStream > 0:
logging.info("Found more than one video stream, reconverting...")
reconvert = True

elif stream['codec_type'] == 'audio':
ffmpegCmd.append("-map")
ffmpegCmd.append("0:%d" % i)

if stream['channel_layout'] == 'stereo' and not stream['codec_name'] == 'aac':
logging.info("Audio codec is not aac, reconverting...")

Expand All @@ -156,6 +170,19 @@ def run_command(command):

audioStream += 1

elif stream['codec_type'] == 'subtitle':
ffmpegCmd.append("-map")
ffmpegCmd.append("0:%d" % i)

convertCmd.append("-c:s:"+str(audioStream))
convertCmd.append("copy")

subtitleStream += 1

else:
logging.info("Found data waste of type '%s', reconverting..." % stream['codec_type'])
reconvert = True

i += 1

if reconvert is True:
Expand Down

0 comments on commit 4556f75

Please sign in to comment.