File: flv_extractor.py

package info (click to toggle)
hachoir 3.1.0%2Bdfsg-5
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 3,364 kB
  • sloc: python: 50,349; makefile: 129; sh: 26
file content (37 lines) | stat: -rwxr-xr-x 1,038 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#!/usr/bin/env python3
"""
Extract audio from a FLV movie

Author: Victor Stinner
Creation date: 2006-11-06
"""
from hachoir.parser import createParser
from hachoir.stream import FileOutputStream
from hachoir.parser.video.flv import AUDIO_CODEC_MP3
from sys import stderr, exit, argv


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

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

    # 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.parent.stream, data.absolute_address, data.size, data.parent.endian)
    print("Write audio into: %s" % outputname)


main()