Newest 'ffmpeg' Questions - Stack Overflow
Les articles publiés sur le site
-
FFMPEG copy audio from input to output
21 décembre 2017, par Ewan SouI'm using the below ffmpeg code to embed a video over a background image
ffmpeg -loop 1 -i -i - filter_complex "[1]scale=515:386 [vid]; [0][vid]overlay=43:46:shortest=1[out]" -map "[out]" -y
This will put my input video file on top of my input background image and create a final output video file. However, I need the audio from the input video file to be copied over to the output video file as well. How do I achieve that?
Thank you!
-
combine different encoding movie into one [duplicate]
21 décembre 2017, par HunneThis question already has an answer here:
We are trying to combine/concat different movie episodes into one but when sometimes the video is with different encoding at that time FFMPEG command throws an error so I would like you please help me in this that if we modify the FFMPEG command and it combine different encoding movie into one
> /bin/ffmpeg \ -f lavfi -i color=c=black \ -ss 0.000 -t 16.545 \ -i "/var/customers/webs/dilip/motions4/upload/public/userfiles/input/fb10209949081578900/1509686278_59fbfc06d394b.mp4" \ -ss 0.000 -t 32.038 \ -i "/var/customers/webs/dilip/motions4/upload/public/userfiles/tmp/fb881023855388222/1509704918_59fc44d6ac51b.mp4" \ -ss 16.545 -t 20.386 \ -i "/var/customers/webs/dilip/motions4/upload/public/userfiles/input/fb10209949081578900/1509686278_59fbfc06d394b.mp4" \ -i "/var/customers/webs/dilip/motions4/upload/public/userfiles/input/fb10209949081578900/1509685957_59fbfac5113ff.png" \ -i "/var/customers/webs/dilip/motions4/upload/public/userfiles/public/1509691135_59fc0effd94c8.mp3" \ -f lavfi -i color=c=black:s=854x480:r=25:d=3 \ -f lavfi -i color=c=black:s=854x480:r=25:d=3 \ -filter_complex " \ [1:v]fps=fps=25[1_fps]; \ [1_fps]scale=853:480:force_original_aspect_ratio=increase[1_fps_tmpsize]; \ [1_fps_tmpsize]pad=854:480:x=0.5:y=0:color=black[1_scaled]; \ [2:v]fps=fps=25[2_fps]; \ [2_fps]scale=640:480:force_original_aspect_ratio=increase[2_fps_tmpsize]; \ [2_fps_tmpsize]pad=854:480:x=107:y=0:color=black[2_scaled]; \ [3:v]fps=fps=25[3_fps]; \ [3_fps]scale=853:480:force_original_aspect_ratio=increase[3_fps_tmpsize]; \ [3_fps_tmpsize]pad=854:480:x=0.5:y=0:color=black[3_scaled]; \ [2_scaled][1_scaled]scale2ref[scaled_2_scaled][1_scaled]; \ [3_scaled][1_scaled]scale2ref[scaled_3_scaled][1_scaled]; \ [1_scaled][scaled_2_scaled][scaled_3_scaled]concat=n=3:v=1:a=0[video_out]; \ [video_out]drawtext=fontfile='/var/customers/webs/dilip/motions4/upload/public/assets/fonts/libel-suit-rg.ttf' \ :x=w-tw-25:y=25:fontsize=32:text='www.omegaitech.com':fontcolor=white[video_out_watermarked]; \ [4:v]scale=100:100[scalled_logo]; [video_out_watermarked][scalled_logo]overlay=10:10 [video_out_watermarked]; \ [5:a]adelay=300|300|300|300|300|300|300|300[audio_out]; \ [6]setsar=1[a]; \ [a]drawtext=fontfile='/var/customers/webs/dilip/motions4/upload/public/assets/fonts/libel-suit-rg.ttf' \ :x=(w-text_w)/2:y=(h-text_h-line_h)/2:fontsize=32:text='Intro text':fontcolor=white[a]; \ [7]setsar=1[c]; \ [c]drawtext=fontfile='/var/customers/webs/dilip/motions4/upload/public/assets/fonts/libel-suit-rg.ttf':x=(w-text_w)/2:y=(h)/2-(line_h*2):fontsize=32:text='Created By':fontcolor=white,drawtext=fontfile='/var/customers/webs/dilip/motions4/upload/public/assets/fonts/libel-suit-rg.ttf':x=(w-text_w)/2:y=(h)/2-(line_h)+10:fontsize=32:text='Dilip Gorasia (omegaitech@yahoo.com)':fontcolor=white,drawtext=fontfile='/var/customers/webs/dilip/motions4/upload/public/assets/fonts/libel-suit-rg.ttf':x=(w-text_w)/2:y=(h)/2+20:fontsize=32:text='Modified By':fontcolor=white,drawtext=fontfile='/var/customers/webs/dilip/motions4/upload/public/assets/fonts/libel-suit-rg.ttf':x=(w-text_w)/2:y=(h)/2+(line_h)+20:fontsize=32:text='Raj Patel (rinpate@gmail.com)':fontcolor=white[c]; \ [video_out_watermarked]setsar=1[b]; \ [a][b][c]concat=n=3:v=1:a=0[video_out_watermarked]; \ [video_out_watermarked]drawtext=fontfile='/var/customers/webs/dilip/motions4/upload/public/assets/fonts/arial.ttf' \ :x=100:y=100:fontsize=32:text='Raj Patel':fontcolor=white:enable='between(t,0,13.37)'[video_out_watermarked]; \ [video_out_watermarked]drawtext=fontfile='/var/customers/webs/dilip/motions4/upload/public/assets/fonts/arial.ttf' \ :x=200:y=200:fontsize=32:text='Raj Patel':fontcolor=white:enable='between(t,13.37,38.78)'[video_out_watermarked] \ " \ -map "[video_out_watermarked]" -map "[audio_out]" \ -s 854x480 \ -aspect 1.779167 \ -r 25 \ -c:v libx264 -b:v 800k -bufsize 64k -crf 24 -movflags faststart -q:v 0 -q:a 0 -c:a aac -strict experimental -b:a 128k -f mp4 -threads 2 -shortest \ -t 74.969 -async 1 \ -y "/var/customers/webs/dilip/motions4/upload/public/userfiles/output/fb881023855388222/1509704929_59fc44e122d41.mp4" ffmpeg version N-87770-g1954e62 Copyright (c) 2000-2017 the FFmpeg developers built with gcc 4.9.2 (Debian 4.9.2-10) configuration: --prefix=/root/ffmpeg_build --pkg-config-flags=--static --extra-cflags=-I/root/ffmpeg_build/include --extra-ldflags=-L/root/ffmpeg_build/lib --bindir=/root/bin --enable-gpl --enable-libass --enable-libfdk-aac --enable-libfreetype --enable-libmp3lame --enable-libopus --enable-libtheora --enable-libvorbis --enable-libvpx --enable-libx264 --enable-libx265 --enable-nonfree libavutil 55. 77.101 / 55. 77.101 libavcodec 57.106.104 / 57.106.104 libavformat 57. 82.104 / 57. 82.104 libavdevice 57. 9.102 / 57. 9.102 libavfilter 6.106.101 / 6.106.101 libswscale 4. 7.103 / 4. 7.103 libswresample 2. 8.100 / 2. 8.100 libpostproc 54. 6.100 / 54. 6.100 Input #0, lavfi, from 'color=c=black': Duration: N/A, start: 0.000000, bitrate: N/A Stream #0:0: Video: rawvideo (I420 / 0x30323449), yuv420p, 320x240 [SAR 1:1 DAR 4:3], 25 tbr, 25 tbn, 25 tbc Input #1, mov,mp4,m4a,3gp,3g2,mj2, from '/var/customers/webs/dilip/motions4/upload/public/userfiles/input/fb10209949081578900/1509686278_59fbfc06d394b.mp4': Metadata: major_brand : mp42 minor_version : 0 compatible_brands: isommp42 creation_time : 2016-09-07T03:10:56.000000Z Duration: 00:04:06.76, start: 0.000000, bitrate: 2324 kb/s Stream #1:0(und): Video: h264 (Main) (avc1 / 0x31637661), yuv420p, 1280x720 [SAR 1:1 DAR 16:9], 2194 kb/s, 29.97 fps, 29.97 tbr, 90k tbn, 59.94 tbc (default) Metadata: creation_time : 2016-09-07T03:10:56.000000Z handler_name : ISO Media file produced by Google Inc. Stream #1:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 125 kb/s (default) Metadata: creation_time : 2016-09-07T03:10:56.000000Z handler_name : ISO Media file produced by Google Inc. Input #2, mov,mp4,m4a,3gp,3g2,mj2, from '/var/customers/webs/dilip/motions4/upload/public/userfiles/tmp/fb881023855388222/1509704918_59fc44d6ac51b.mp4': Metadata: major_brand : isom minor_version : 512 compatible_brands: isomiso2avc1mp41 encoder : Lavf57.36.100 comment : 1361809051215868 Duration: 00:00:32.38, start: 0.000000, bitrate: 310 kb/s Stream #2:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 320x240 [SAR 1:1 DAR 4:3], 182 kb/s, 24 fps, 24 tbr, 12288 tbn, 48 tbc (default) Metadata: handler_name : VideoHandler Stream #2:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 122 kb/s (default) Metadata: handler_name : SoundHandler Input #3, mov,mp4,m4a,3gp,3g2,mj2, from '/var/customers/webs/dilip/motions4/upload/public/userfiles/input/fb10209949081578900/1509686278_59fbfc06d394b.mp4': Metadata: major_brand : mp42 minor_version : 0 compatible_brands: isommp42 creation_time : 2016-09-07T03:10:56.000000Z Duration: 00:04:06.76, start: 0.000000, bitrate: 2324 kb/s Stream #3:0(und): Video: h264 (Main) (avc1 / 0x31637661), yuv420p, 1280x720 [SAR 1:1 DAR 16:9], 2194 kb/s, 29.97 fps, 29.97 tbr, 90k tbn, 59.94 tbc (default) Metadata: creation_time : 2016-09-07T03:10:56.000000Z handler_name : ISO Media file produced by Google Inc. Stream #3:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 125 kb/s (default) Metadata: creation_time : 2016-09-07T03:10:56.000000Z handler_name : ISO Media file produced by Google Inc. Input #4, png_pipe, from '/var/customers/webs/dilip/motions4/upload/public/userfiles/input/fb10209949081578900/1509685957_59fbfac5113ff.png': Duration: N/A, bitrate: N/A Stream #4:0: Video: png, rgba(pc), 128x128, 25 tbr, 25 tbn, 25 tbc Input #5, mp3, from '/var/customers/webs/dilip/motions4/upload/public/userfiles/public/1509691135_59fc0effd94c8.mp3': Metadata: TOAL : www.Songs.PK TRSN : www.Songs.PK TPE4 : www.Songs.PK encoded_by : Eac * Lame EpisodeID : www.Songs.PK comment : www.Songs.PK lyrics-eng : www.Songs.PK title : Zor Ka Jhatka - www.Songs.PK track : 1 TGID : www.Songs.PK TIT1 : www.Songs.PK TIT3 : www.Songs.PK copyright : www.Songs.PK performer : www.Songs.PK publisher : www.Songs.PK genre : Bollywood Music album : Action Replayy album_artist : www.Songs.PK composer : www.Songs.PK TEXT : www.Songs.PK TOLY : www.Songs.PK TOPE : Music: Pritam | Lyrics: Irshad Kamil artist : Daler Mehndi, Richa Sharma TDES : www.Songs.PK TCAT : www.Songs.PK date : 2010 Duration: 00:04:10.17, start: 0.025056, bitrate: 164 kb/s Stream #5:0: Audio: mp3, 44100 Hz, stereo, s16p, 158 kb/s Metadata: encoder : LAME3.98r Stream #5:1: Video: mjpeg, yuvj420p(pc, bt470bg/unknown/unknown), 900x803 [SAR 300:300 DAR 900:803], 90k tbr, 90k tbn, 90k tbc Metadata: comment : Cover (front) Input #6, lavfi, from 'color=c=black:s=854x480:r=25:d=3': Duration: N/A, start: 0.000000, bitrate: N/A Stream #6:0: Video: rawvideo (I420 / 0x30323449), yuv420p, 854x480 [SAR 1:1 DAR 427:240], 25 tbr, 25 tbn, 25 tbc Input #7, lavfi, from 'color=c=black:s=854x480:r=25:d=3': Duration: N/A, start: 0.000000, bitrate: N/A Stream #7:0: Video: rawvideo (I420 / 0x30323449), yuv420p, 854x480 [SAR 1:1 DAR 427:240], 25 tbr, 25 tbn, 25 tbc Stream mapping: Stream #1:0 (h264) -fps Stream #2:0 (h264) -fps Stream #3:0 (h264) -fps Stream #4:0 (png) -scale Stream #5:0 (mp3) -adelay Stream #6:0 (rawvideo) -setsar Stream #7:0 (rawvideo) -setsar drawtext -Stream #0:0 (libx264) adelay -Stream #0:1 (aac) Press [q] to stop, [?] for help -async is forwarded to lavfi similarly to -af aresample=async=1:min_hard_comp=0.100000:first_pts=0. [Parsed_concat_11 @ 0x340f840] Input link in1:v0 parameters (size 854x480, SAR 1:1) do not match the corresponding output link in0:v0 parameters (854x480, SAR 2560:2559) [Parsed_concat_11 @ 0x340f840] Failed to configure output pad on Parsed_concat_11 Error reinitializing filters! Failed to inject frame into filter network: Invalid argument Error while processing the decoded data for stream #7:0 Conversion failed!`enter code here`
Thx for your help
-
Concatenating video using FFMPEG wrapper class [duplicate]
21 décembre 2017, par alan samuelThis question already has an answer here:
I am trying to concatenate video using NReco.VideoConverter wrapper class made for FFMPEG.
I have three video files with the same frame rate and same frame size.
Here is what I have done.
string toconcatfile = @"C:\Users\Alan\Desktop\Black.mp4"; string output1 = @"C:\Users\Alan\Desktop\output1.mp4"; string output2 = @"C:\Users\Alan\Desktop\output2.mp4"; string finaloutput = @"C:\Users\Alan\Desktop\finaloutput.mp4";
All the three videos have a frame rate of 25 and Video frame size yet it fails when I add in toconcatfile to the final conversion method.
It works when its just output1 and output2 meaning there must be a different setting in toconcatfile.
Here is what I have tried.
FFMpegConverter fFMpeg = new FFMpegConverter(); //Slices first video ConvertSettings settings = new ConvertSettings { VideoFrameRate = 25, VideoFrameSize = FrameSize.hd480, MaxDuration = startcut, AudioSampleRate = 44100 }; //Slices second video ConvertSettings settings2 = new ConvertSettings { VideoFrameRate = 25, VideoFrameSize = FrameSize.hd480, Seek = endcut, AudioSampleRate = 44100 }; //Copies framerate and size from the previous video to the concatenation video ConvertSettings settings3 = new ConvertSettings { VideoFrameRate = 25, VideoFrameSize = FrameSize.hd480, MaxDuration = 4, AppendSilentAudioStream = true, AudioSampleRate = 44100 }; string newblack = @"C:\Users\Alan\Desktop\newblack.mp4"; //Slice method called fFMpeg.ConvertMedia(pathtofile, Format.mp4, output1, Format.mp4, settings); fFMpeg.ConvertMedia(pathtofile, Format.mp4, output2, Format.mp4, settings2); fFMpeg.ConvertMedia(toconcatfile, Format.mp4, newblack, Format.mp4, settings3); String[] inputfiles = new String[2]; inputfiles[0] = output1; inputfiles[1] = newblack; //inputfiles[1] = output2; ConcatSettings concatSettings = new ConcatSettings { //CustomOutputArgs = output1+" "+ toconcatfile+ " "+output2+ " -filter_complex \"[0:v:0][0:a:0][1:v:0][1:a:0][2:v:0][2:a:0]concat=n=3:v=1:a=1[outv][outa]\" -map \"[outv]\" - map \"[outa]\"" }; fFMpeg.ConcatMedia(inputfiles, finaloutput, Format.mp4, concatSettings);
Can anyone help ?
Edit : I get the exception message - "Invalid argument (exit code: 1)",
Here is the output log of FFMPEG
FFMPEG LOG ITEM - ffmpeg version 3.2.2 Copyright (c) 2000-2016 the FFmpeg developers FFMPEG LOG ITEM - built with gcc 5.4.0 (GCC) FFMPEG LOG ITEM - configuration: --enable-gpl --enable-version3 --enable- dxva2 --enable-libmfx --enable-nvenc --enable-avisynth --enable-bzlib --enable-fontconfig --enable-frei0r --enable-gnutls --enable-iconv --enable-libass -- enable-libbluray --enable-libbs2b --enable-libcaca --enable-libfreetype --enable-libgme --enable-libgsm --enable-libilbc --enable-libmodplug --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenh264 --enable-libopenjpeg --enable-libopus --enable-librtmp --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libtheora --enable-libtwolame --enable-libvidstab --enable-libvo-amrwbenc --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxavs --enable-libxvid --enable-libzimg --enable-lzma --enable-decklink --enable-zlib FFMPEG LOG ITEM - libavutil 55. 34.100 / 55. 34.100 FFMPEG LOG ITEM - libavcodec 57. 64.101 / 57. 64.101 FFMPEG LOG ITEM - libavformat 57. 56.100 / 57. 56.100 FFMPEG LOG ITEM - libavdevice 57. 1.100 / 57. 1.100 FFMPEG LOG ITEM - libavfilter 6. 65.100 / 6. 65.100 FFMPEG LOG ITEM - libswscale 4. 2.100 / 4. 2.100 FFMPEG LOG ITEM - libswresample 2. 3.100 / 2. 3.100 FFMPEG LOG ITEM - libpostproc 54. 1.100 / 54. 1.100 FFMPEG LOG ITEM - Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'C:\Users\Alan\Desktop\output1.mp4': FFMPEG LOG ITEM - Metadata: FFMPEG LOG ITEM - major_brand : isom FFMPEG LOG ITEM - minor_version : 512 FFMPEG LOG ITEM - compatible_brands: isomiso2avc1mp41 FFMPEG LOG ITEM - encoder : Lavf57.56.100 FFMPEG LOG ITEM - Duration: 00:00:30.02, start: 0.000000, bitrate: 543 kb/s FFMPEG LOG ITEM - Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 852x480 [SAR 3893:2872 DAR 276403:114880], 407 kb/s, SAR 12800:9443 DAR 320:133, 25 fps, 25 tbr, 12800 tbn, 50 tbc (default) FFMPEG LOG ITEM - Metadata: FFMPEG LOG ITEM - handler_name : VideoHandler FFMPEG LOG ITEM - Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 129 kb/s (default) FFMPEG LOG ITEM - Metadata: FFMPEG LOG ITEM - handler_name : SoundHandler FFMPEG LOG ITEM - Input #1, mov,mp4,m4a,3gp,3g2,mj2, from 'C:\Users\Alan\Desktop\newblack.mp4': FFMPEG LOG ITEM - Metadata: FFMPEG LOG ITEM - major_brand : isom FFMPEG LOG ITEM - minor_version : 512 FFMPEG LOG ITEM - compatible_brands: isomiso2avc1mp41 FFMPEG LOG ITEM - encoder : Lavf57.56.100 FFMPEG LOG ITEM - Duration: 00:00:04.02, start: 0.000000, bitrate: 19 kb/s FFMPEG LOG ITEM - Stream #1:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 852x480 [SAR 160:213 DAR 4:3], 7 kb/s, 25 fps, 25 tbr, 12800 tbn, 50 tbc (default) FFMPEG LOG ITEM - Metadata: FFMPEG LOG ITEM - handler_name : VideoHandler FFMPEG LOG ITEM - Stream #1:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 2 kb/s (default) FFMPEG LOG ITEM - Metadata: FFMPEG LOG ITEM - handler_name : SoundHandler FFMPEG LOG ITEM - Input #2, mov,mp4,m4a,3gp,3g2,mj2, from 'C:\Users\Alan\Desktop\output2.mp4': FFMPEG LOG ITEM - Metadata: FFMPEG LOG ITEM - major_brand : isom FFMPEG LOG ITEM - minor_version : 512 FFMPEG LOG ITEM - compatible_brands: isomiso2avc1mp41 FFMPEG LOG ITEM - encoder : Lavf57.56.100 FFMPEG LOG ITEM - Duration: 00:01:34.22, start: 0.000000, bitrate: 1058 kb/s FFMPEG LOG ITEM - Stream #2:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 852x480 [SAR 3893:2872 DAR 276403:114880], 923 kb/s, SAR 12800:9443 DAR 320:133, 25 fps, 25 tbr, 12800 tbn, 50 tbc (default) FFMPEG LOG ITEM - Metadata: Exception thrown: 'NReco.VideoConverter.FFMpegException' in NReco.VideoConverter.dll FFMPEG LOG ITEM - handler_name : VideoHandler FFMPEG LOG ITEM - Stream #2:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 128 kb/s (default) FFMPEG LOG ITEM - Metadata: FFMPEG LOG ITEM - handler_name : SoundHandler FFMPEG LOG ITEM - [Parsed_concat_0 @ 04ded5e0] Input link in1:v0 parameters (size 852x480, SAR 160:213) do not match the corresponding output link in0:v0 parameters (852x480, SAR 12800:9443) FFMPEG LOG ITEM - [Parsed_concat_0 @ 04ded5e0] Failed to configure output pad on Parsed_concat_0 FFMPEG LOG ITEM - Error configuring complex filters. FFMPEG LOG ITEM - Invalid argument
-
How to speed up audio and video in FFmpeg
21 décembre 2017, par alan samuelI am trying to speed up audio and video to 4 times using a C# wrapper class for ffmpeg.
Here is how it looks.
var ffMpeg = new NReco.VideoConverter.FFMpegConverter(); ConvertSettings convertSettings = new ConvertSettings { CustomOutputArgs = "-filter_complex \"[0:v]setpts = 0.25 * PTS[v];[0:a] atempo=2.0[a],atempo=2.0[a] \" -map \"[v]\" -map \"[a]\"" }; string inputpath = tempvideolocation + "/tempvideo.mp4"; string outputpath = tempvideolocation + "/convertedvideo.mp4"; ffMpeg.ConvertMedia(inputpath, Format.mp4, outputpath, Format.mp4, convertSettings);
But i get "Error - Cannot find a matching stream for unlabeled input pad 0 on filter Parsed_atempo_2 (exit code: 1)"
-
FFMPEG command from Python 3.5 does not actually create audio file
20 décembre 2017, par Nathan BlaineI have a Django web application that accepts user uploaded videos/audio and saves them into a folder '../WebAppDirectory/media/recordings'.
I am then using a speech to text API to get a rough transcription of the audio. This is working fine for .wav and .mp4 files, but the web app also accepts videos (.MOV) that I would like to first convert to .wav, then pass off to the API.
Using ffmpeg from my command line like this
ffmpeg -i C:\Users\Nathan\Desktop\MeetingRecorderWebAPP\media\recordings\upload_sample.MOV -ab 160k -ac 2 -ar 44100 -vn upload_sample.wav
Correctly creates the .wav file from the original .MOV.
However, when I run this from python with
subprocess.check_call(command, shell=True)
ffmpeg responds with
File 'upload_sample.wav' already exists. Overwrite ? [y/N]
While Python tells me
FileNotFoundError: [Errno 2] No such file or directory: 'C:\Users\Nathan\Desktop\MeetingRecorderWebAPP\media\recordings\upload_sample.wav'
It is also worth noting that I do not see a 'upload_sample.wav' file in the media/recordings/ directory.
This leads me to believe that maybe Python and ffmpeg are looking in different folders, but I am not sure where I am going wrong. When I print the command from the subprocess.check_call and copy/paste it into cmd, the file is created as expected.
Hoping someone with some experience with ffmpeg/Python subprocess can help shed some light! Here are the files I am working with:
Folder Structure
DjangoWebApp |---media |---|---imgs |---|---recordings |---|---|---upload_sample.MOV |---uploaded_audio_to_text.py
uploaded_audio_to_text.py
import speech_recognition as sr from os import path import os import subprocess def speech_to_text(file_name): AUDIO_FILE = path.join(path.dirname(path.realpath(__file__)), 'media','recordings', file_name) print("Looking at path: ",AUDIO_FILE) # get extension AUDIO_FILE_EXT = os.path.splitext(AUDIO_FILE)[1] if(AUDIO_FILE_EXT == '.MOV'): print("File is not .wav: ", AUDIO_FILE_EXT, "found. Converting...") # We will use subprocess and ffmpeg to convert this .MOV file to .wav, so we can send to API temp_wav = os.path.splitext(file_name)[0] + '.wav' print("New audio file will be: ", temp_wav) # build CMD ffmpeg command command = "ffmpeg -i " command += AUDIO_FILE command += " -ab 160k -ac 2 -ar 44100 -vn " command += temp_wav print("Attempting to run this command: \n",command) print(subprocess.check_call(command, shell=True)) print("Past Subprocess.call") AUDIO_FILE = path.join(path.dirname(path.realpath(__file__)), 'media','recordings', temp_wav) print("AUDIO_FILE now set to: ", AUDIO_FILE) else: # continue with what we are doing pass r = sr.Recognizer() with sr.AudioFile(AUDIO_FILE) as source: audio = r.record(source) # read the entire audio file text_transcription = "Sentinel" # recognize speech using Microsoft Bing Voice Recognition BING_KEY = "MY_KEY_:)" try: text_transcription = r.recognize_bing(audio, key=BING_KEY) except sr.UnknownValueError: print("Microsoft Bing Voice Recognition could not understand audio") except sr.RequestError as e: print("Could not request results from Microsoft Bing Voice Recognition service; {0}".format(e)) return text_transcription #my tests my_relative_file_path = "upload_sample.MOV" print(speech_to_text(my_relative_file_path))
Console output (traceback and my print()'s)
Looking at path: C:\Users\Nathan\Desktop\MeetingRecorderWebAPP\media\recordings\upload_sample.MOV File is not .wav: .MOV found. Converting... New audio file will be: upload_sample.wav Attempting to run this command: ffmpeg -i C:\Users\Nathan\Desktop\MeetingRecorderWebAPP\media\recordings\upload_sample.MOV -ab 160k -ac 2 -ar 44100 -vn upload_sample.wav ffmpeg version git-2017-12-18-74f408c Copyright (c) 2000-2017 the FFmpeg developers built with gcc 7.2.0 (GCC) ----REMOVED SOME FFMPEG OUTPUT FOR BREVITY---- File 'upload_sample.wav' already exists. Overwrite ? [y/N] y Stream mapping: Stream #0:1 -> #0:0 (aac (native) -> pcm_s16le (native)) Press [q] to stop, [?] for help Output #0, wav, to 'upload_sample.wav': Metadata: major_brand : qt minor_version : 0 compatible_brands: qt com.apple.quicktime.creationdate: 2017-12-19T16:06:10-0500 com.apple.quicktime.make: Apple com.apple.quicktime.model: iPhone 6 com.apple.quicktime.software: 10.3.3 ISFT : Lavf58.3.100 Stream #0:0(und): Audio: pcm_s16le ([1][0][0][0] / 0x0001), 44100 Hz, stereo, s16, 1411 kb/s (default) Metadata: creation_time : 2017-12-19T21:06:11.000000Z handler_name : Core Media Data Handler encoder : Lavc58.8.100 pcm_s16le size= 1036kB time=00:00:06.01 bitrate=1411.3kbits/s speed=N/A video:0kB audio:1036kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.007352% 0 Traceback (most recent call last): Past Subprocess.call File "C:\Users\Nathan\Desktop\MeetingRecorderWebAPP\uploaded_audio_to_text.py", line 53, in
AUDIO_FILE now set to: C:\Users\Nathan\Desktop\MeetingRecorderWebAPP\media\recordings\upload_sample.wav print(speech_to_text(my_relative_file_path)) File "C:\Users\Nathan\Desktop\MeetingRecorderWebAPP\uploaded_audio_to_text.py", line 36, in speech_to_text with sr.AudioFile(AUDIO_FILE) as source: File "C:\Users\Nathan\AppData\Local\Programs\Python\Python36-32\lib\site-packages\speech_recognition\__init__.py", line 203, in __enter__ self.audio_reader = wave.open(self.filename_or_fileobject, "rb") File "C:\Users\Nathan\AppData\Local\Programs\Python\Python36-32\lib\wave.py", line 499, in open return Wave_read(f) File "C:\Users\Nathan\AppData\Local\Programs\Python\Python36-32\lib\wave.py", line 159, in __init__ f = builtins.open(f, 'rb') FileNotFoundError: [Errno 2] No such file or directory: 'C:\\Users\\Nathan\\Desktop\\MeetingRecorderWebAPP\\media\\recordings\\upload_sample.wav' Process finished with exit code 1