hachoir / hachoir-tools /

Extract audio from a FLV movie

Author: Victor Stinner
Creation date: 2006-11-06
from hachoir_parser import createParser
from import FileOutputStream
from hachoir_core.i18n import getTerminalCharset
from import AUDIO_CODEC_MP3
from sys import stderr, exit, argv

def main():
    if len(argv) != 2:
        print >>stderr, "usage: %s video.flv" % argv[0]

    # Open input video
    inputname = unicode(argv[1], getTerminalCharset())
    parser = createParser(inputname)
    if parser["audio[0]/codec"].value != AUDIO_CODEC_MP3:
        print >>stderr, "Unknown audio codec: %s" % parser["audio[0]/codec"].display

    # Extract audio
    print "Extractor audio from: %s" % inputname
    outputname = inputname + ".mp3"
    output = FileOutputStream(outputname)
    for chunk in parser.array("audio"):
        data = chunk["music_data"]
        output.copyBitsFrom(, data.absolute_address, data.size, data.parent.endian)
    print "Write audio into: %s" % outputname

Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.