Skip to content

Instantly share code, notes, and snippets.

@davetromp
Created December 15, 2015 22:25
Show Gist options
  • Save davetromp/8fbb63e7dfc714668892 to your computer and use it in GitHub Desktop.
Save davetromp/8fbb63e7dfc714668892 to your computer and use it in GitHub Desktop.
# the code is explained here: https://youtu.be/Eex4zBc9r7Y
import os
def main():
files = os.listdir("./")
for f in files:
if f.lower()[-3:] == "mp4":
print "processing", f
process(f)
def process(f):
inFile = f
outFile = f[:-3] + "mp3"
cmd = "ffmpeg -i {} -vn -ac 2 -ar 44100 -ab 320k -f mp3 {}".format(inFile, outFile)
os.popen(cmd)
main()
Copy link

ghost commented Jun 26, 2017

code doesnt seem to work if the video file name have spaces in between. for eg. sample video.mp4
is there a solution for that?

@jigassa
Copy link

jigassa commented Sep 15, 2017

Hi, i´m trying export it on other directory, can u help me ?

i´m doing this:

import os

def main():
files = os.listdir("/media/HotStorage/PCTV/UHHD")
for f in files:
if f.lower()[-3:] == "mov":
print "processing", f
process(f)

def process(f):
inFile = f
outFile = f[:-3] + "mov"
cmd = "ffmbc -i {} -tff -target xdcamhd422 -vtag xd5b -threads 4 -s 1920x1080 -timecode 00:00:00:00 "/media/PCTV/PCTVRenders/{}"".format(inFile, outFile)
os.popen(cmd)

main()

But, de cmd tell me

Copyright (c) 2008-2016 Baptiste Coudurier and the FFmpeg developers
NAME.mov: No such file or directory

@Rahul-Kaura
Copy link

If you guys find a solution. Please don't hesitate to write the code in a comment.
I'm using a Mac so it would helpful if you extracted audio from a video file without using ffmpeg.

@davetromp
Copy link
Author

code doesnt seem to work if the video file name have spaces in between. for eg. sample video.mp4
is there a solution for that?

De python code executes some command-line script. If a file name has spaces, it should be called within quotes. So try to replace:
cmd = "ffmpeg -i {} -vn -ac 2 -ar 44100 -ab 320k -f mp3 {}".format(inFile, outFile)
with:
cmd = '''ffmpeg -i "{}" -vn -ac 2 -ar 44100 -ab 320k -f mp3 "{}"'''.format(inFile, outFile)

@TheGR8CornJulio
Copy link

Works In Windows 10 1909 Build 18363.535 And Python 3.8.1 With Cmd Change
cmd = '''ffmpeg -i "{}" -vn -ac 2 -ar 44100 -ab 320k -f mp3 "{}"'''.format(inFile, outFile)
Many Thanks For The Script

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment