Skip to content

Instantly share code, notes, and snippets.

@shvechikov
Created December 17, 2013 21:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shvechikov/8012638 to your computer and use it in GitHub Desktop.
Save shvechikov/8012638 to your computer and use it in GitHub Desktop.
Mux Youtube DASH audio and video
from __future__ import unicode_literals
import sys
from sh import ffmpeg
from unipath import Path
_, src_dir, dest_dir = sys.argv
src_dir = Path(src_dir)
dest_dir = Path(dest_dir)
if not dest_dir.exists():
dest_dir.mkdir()
m4a = set(f.stem for f in src_dir.listdir('*.m4a'))
mp4 = set(f.stem for f in src_dir.listdir('*.mp4'))
both = sorted(m4a & mp4)
for basename in both:
source_video = src_dir + basename + '.mp4'
source_audio = src_dir + basename + '.m4a'
destination = dest_dir + basename + '.480.mp4'
if source_audio.exists() and source_video.exists():
if destination.exists():
print destination, 'already muxed!'
else:
print destination, 'running ffmpeg...'
ffmpeg(
'-i', source_video,
'-i', source_audio,
'-vcodec', 'copy',
'-acodec', 'copy',
destination,
)
print 'OK'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment