[PYTHON] For the time being, I want to convert files with ffmpeg !!

I want to use a radio sound source as deep learning data

――What is important in deeolearning? -"It's data!" (Old !!) ――Therefore, I thought about using the super A & G radio data as data by pulling it out. --Caution There are various copyrights, so use is at your own risk. ――It can be used for conversion of various data, so make it public and show

Program procedure

  1. There is a directory containing the data you want to convert
  2. Specify input and out directories on the command line
  3. After that, bite the subprocess and convert with ffmpeg

point

--About ffmpeg commands --In this program, flv file is converted to wav file and converted to 16000HZ at the same time. --A brief summary of ffmpeg is as follows

python


#First of all, extension conversion
$ffmpeg input.hoge output.hoge #hoge is an extension

#Sampling rate conversion
$ffmpeg input.hoge -ar 16000 output.hoge #-ar newsamplingrate

aandg.py


# -*- coding: utf-8 -*-
import sys
import glob
import os
import subprocess

#Directory specification
if len(sys.argv) != 3:
    print("python3 aandg.py [inputfile_dir] [outputfile_dir]")
    sys.exit()

else:
    print(sys.argv[1])
    inputpath=path = os.path.abspath(sys.argv[1])
    #This time in the entered directory.List only flv
    file_list=glob.glob(inputpath+"/*.flv")
    #Create if there is no output directory
    if not os.path.exists(sys.argv[2]):
        os.mkdir(sys.argv[2])
        print("make dir",sys.argv[2])
    
    output_path = os.path.abspath(sys.argv[2])
    
    for item in file_list:
        #Get the file name without conversion extension with subprocess
        basename_without_ext = os.path.splitext(os.path.basename(item))[0]
        #This time flv 16,Convert to 000HZ wav
        cmd = "ffmpeg -i "+item+" -ar 16000 "+output_path+"/"+basename_without_ext+".wav"
        runcmd = subprocess.call(cmd.split())

--Sample code will be posted on github. The rest is nice

Recommended Posts

For the time being, I want to convert files with ffmpeg !!
I want to move selenium for the time being [for mac]
I want to create a Dockerfile for the time being.
I want to use the Ubuntu desktop environment on Android for the time being (Termux version)
I want to use Ubuntu's desktop environment on Android for the time being (UserLAnd version)
Use logger with Python for the time being
I want to convert an image to WebP with lollipop
Flow memo to move LOCUST for the time being
Run with CentOS7 + Apache2.4 + Python3.6 for the time being
Molecular dynamics simulation to try for the time being
I want to inherit to the back with python dataclass
[Hi Py (Part 1)] I want to make something for the time being, so first set a goal.
I will install Arch Linux for the time being.
Next to Excel, for the time being, jupyter notebook
I want to use Ubuntu's desktop environment on Android for the time being (Termux version-Japanese input in desktop environment)
For the time being using FastAPI, I want to display how to use API like that on swagger
I will try to summarize the links that seem to be useful for the time being
I want to create a lunch database [EP1] Django study for the first time
I want to create a lunch database [EP1-4] Django study for the first time
[TensorFlow] I want to master the indexing for Ragged Tensor
I tried running PIFuHD on Windows for the time being
[NetworkX] I want to search for nodes with specific attributes
I want to change the Japanese flag to the Palau flag with Numpy
[Python] I want to use the -h option with argparse
I want to convert an ISO-8601 character string to Japan time
[Introduction to Reinforcement Learning] Reinforcement learning to try moving for the time being
I want to do ○○ with Pandas
I want to debug with Python
I want to get the name of the function / method being executed
I want to record the execution time and keep a log.
I tried to describe the traffic in real time with WebSocket
I want to know the weather with LINE bot feat.Heroku + Python
Java programmer tried to touch Go language (for the time being)
I want to check the position of my face with OpenCV!
"Stop committing Japanese files to git on Mac> <" For the time being, I wrote a script to search for incompatible Japanese files on Mac and Linux.
I want to pin Spyder to the taskbar
I want to detect objects with OpenCV
I want to output to the console coolly
I want to handle the rhyme part1
Search for files with the specified extension
I want to blog with Jupyter Notebook
Python Master RTA for the time being
I want to handle the rhyme part3
I want to pip install with PythonAnywhere
I tried to create serverless batch processing for the first time with DynamoDB and Step Functions
I want to analyze logs with Python
I want to play with aws with python
Convert PDF files to PNG files with GIMP
I made a function to check if the webhook is received in Lambda for the time being
I want to display the progress bar
Convert HEIC files to PNG files with Python
I want to handle the rhyme part2
I want to handle the rhyme part5
I want to handle the rhyme part4
I tried to refer to the fun rock-paper-scissors poi for beginners with Python
Challenge image classification with TensorFlow2 + Keras CNN 1 ~ Move for the time being ~
For the first time in Numpy, I will update it from time to time
I want to stop the automatic deletion of the tmp area with RHEL7
Python: I want to measure the processing time of a function neatly
I tried using scrapy for the first time
How to use MkDocs for the first time