How to save WAV file with script in praat? - praat

I try to save a praat sound object to wav file. There is no problem when I do it in GUI. But it complains "Sounds not concatenated and not saved" in script. Does anyone know why?
Here is the command line output:
~/Downloads$ /Applications/Praat.app/Contents/MacOS/Praat --run aa1.praat
Error: Cannot create file “/Users/hgneng/Downloads/"/Users/hgneng/Downloads/aa2.wav"”.
Sounds not concatenated and not saved to “/Users/hgneng/Downloads/"/Users/hgneng/Downloads/aa2.wav"”.
Script line 15 not performed or completed:
« Save as WAV file... "/Users/hgneng/Downloads/aa2.wav" »
Script “/Users/hgneng/Downloads/aa1.praat” not completed.
Praat: script command <<aa1.praat>> not completed.
Here is the content of praat script:
sound = Read from file: "/Users/hgneng/e-guidedog/jyutping-wong/aa1.wav"
endtime = Get end time
To Manipulation... 0.01 75 600
selectObject: sound
Create DurationTier: "aa1", 0, endtime
Add point: 0, 3
selectObject: "Manipulation aa1"
plusObject: "DurationTier aa1"
Replace duration tier
minusObject: "DurationTier aa1"
Get resynthesis (overlap-add)
removeObject: sound
removeObject: "Manipulation aa1"
removeObject: "DurationTier aa1"
Save as WAV file... "/Users/hgneng/Downloads/aa2.wav"

Change
Save as WAV file... "/Users/hgneng/Downloads/aa2.wav"
to
Save as WAV file: "/Users/hgneng/Downloads/aa2.wav"
will fix the issue.

Related

Play custom bundled sound in apple script

So im trying to use shellscript "afplay " in applescript to play an .m4a file I bundled into the app resource. Not entirely sure how it works.
Got this after a bit of searching around,
set soundPath to POSIX path of (path to resource "Sound File.aiff")
do shell script "afplay " & quoted form of soundPath
This isnt really what I want.
playAudio() -- place this Line To call the handler to Play An Audio File.
on playAudio()
set audioFile to path to resource "Sound File.aiff"
set theFile to POSIX path of audioFile
do shell script "afplay -q 1 -t 25 " & " " & quoted form of theFile
end playAudio
-- Command Line OPTIONS For Playing Audio Files
(*
afplay [option...] audio_file
Options: (may appear before or after arguments)
{-v | --volume} VOLUME
set the volume for playback of the file
{-h | --help}
print help
{ --leaks}
run leaks analysis
{-t | --time} TIME
play for TIME seconds
{-r | --rate} RATE
play at playback rate
{-q | --rQuality} QUALITY
set the quality used for rate-scaled playback (default is 0 - low quality, 1 - high quality)
{-d | --debug}
debug print output
*)

connection timeout between client and ffserver

I have a directory which contain some files,I loop around this files and stream them using ffmpeg to ffserver,the problem is when song is over,the client stop receiving the stream.VLC and jwplayer have this problem-which I tested-(although I can fix this problem in jwplayer by adding repeat: true option but I don't think it's such a good idea).
what I need is an option or some trick in ffserver which keep connection alive(at least for a while) so that if a song is over,the next song start automatically(it take 1 second to switch songs),maybe ffserver have a timeout option ?
I ended up using concat for streaming files without breaking connection
the easiest way would be to create a file,name it file_paths.txt and add paths to file like this :
file '/path/to/file1'
file '/path/to/file2'
file '/path/to/file3'
and then in your ffmpeg command do something like this :
ffmpeg -re -f concat -i file_paths.txt http:/ip:8090/feed1.ffm
this works really well,although all files must have the same codec and format
for more information and see how to use concat for different formats see this

SNAP: Simulation and Neuroscience Application Platform

Is there any documentation/help manual on how to use SNAP (Simulation and Neuroscience Application Platform)1.
I wanted to run the Motor Imagery sample scenario with a .avi file for the stimulus instead of the image. How can that be done?
The following error is obtained when using the AlphaCalibration scenario which gives code to play an avi file.Any help appreciated
:movies:ffmpeg(warning): parser not found for codec indeo4, packets or times may be invalid.
:movies:ffmpeg(warning): max_analyze_duration 5000000 reached at 5000000
:movies(error): Could not open /e/BCI_Feb2014/SNAP-master/src/studies/SampleStudy/bird.avi
:audio(error): Cannot open file: /e/BCI_Feb2014/SNAP-master/src/studies/SampleStudy/bird.avi
:audio(error): Could not open audio /e/BCI_Feb2014/SNAP-master/src/studies/SampleStudy/bird.avi
:movies:ffmpeg(warning): parser not found for codec indeo4, packets or times may be invalid.
:movies:ffmpeg(warning): max_analyze_duration 5000000 reached at 5000000
:movies(error): Could not open /e/BCI_Feb2014/SNAP-master/src/studies/SampleStudy/bird.avi
:gobj(error): Texture "/e/BCI_Feb2014/SNAP-master/src/studies/SampleStudy/bird.avi" exists but cannot be read.
Traceback (most recent call last):
File "E:\BCI_Feb2014\SNAP-master\src\framework\latentmodule.py", line 458, in _run_wrap
self.run()
File "modules\BCI\AlphaCalibration.py", line 30, in run
Exception during run():
m = self.movie(self.moviefile, block=False, scale=[0.7,0.4],aspect=1.125,contentoffset=[0,0],volume=0.3,timeoffset=self.begintime+t*self.awake_duration,looping=True)
Could not load texture: bird.avi
File "E:\BCI_Feb2014\SNAP-master\src\framework\basicstimuli.py", line 348, in movie
tex = self._engine.base.loader.loadTexture(filename)
File "E:\BCI_Feb2014\Panda3D-1.8.0\direct\showbase\Loader.py", line 554, in loadTexture
raise IOError, message
IOError: Could not load texture: bird.avi
The video files are not included in the github repository due to the file size. However, your use case should work if you use any other video file that you put on the search path (e.g., next to the other media files - see also Panda3d's notion of content search paths).
There is a SNAP release including media files at: ftp://sccn.ucsd.edu/pub/software/LSE-SDK/ which might include the files you're looking for.

How to tell if ffmpeg errored or not?

The Situation:
I'm using ffmpeg (via .net) to save video files. I can get the output from ffmpeg but I dont know how can I customize the output to have better result.
My Problem:
My problem is, there is no certain difference between successful and failed operation.
last line of success:
video:1006kB audio:134kB subtitle:0 global headers:0kB muxing overhead 0.943510%
last lines from fails
c:\x\test-9-8/30/2012-9:29:56-AM.mp4: Invalid argument
rtmp://cdn.tv/cdn-live39/definst/stream01: Unknown error occurred
My Question:
Is there an option (or command line parameter) to add some sort of return code (200: success, 500: error, etc)
Thanks!
PS: I saw this topic How to tell if ffmpeg errored? but there is no number before/after last line. I think the last version doesnt have number anymore.
I know this is very old but as i came across and found no other reliable answer and after some more testing:
The suggestion with checking for return of 0 is in general a good advice - but does not help in all cases. The other idea with checking if the file exists is also good - but again - does not help in all cases.
For example when the input file is a mp3 file that has an embedded cover - then ffmpeg does (in my tests) use this image and extracts that one as an (unusable) video file.
What i do now is to have debug level output and parse it for the number of muxed packets.
ffmpeg -i "wildlife.mp4" -c:v copy -an -sn "out.mp4" -y -loglevel debug 2> wildlife.txt
With a regex i search for this text:
Output stream .+ (video): [0-9][0-9]+ packets muxed \([0-9][0-9]+ bytes\)
(this assumes that every video has more than 9 packets - could of course be optimized for really short videos).
Of course for RTMP or other settings the output may differ but i think to parse the full output stream is the only option.
You could just check the exit code returned by ffmpeg. It should return 0 on success, anything else means it failed.
You can run ffmpeg in -v error mode and have it return errors into a text file, see here: https://superuser.com/questions/100288/how-can-i-check-the-integrity-of-a-video-file-avi-mpeg-mp4 You can combine this with encoding without the null output but you will only be able to read the results from the text file.
Or you can have an additional script that will follow-up on the errors. Here is a Python example, which checks for file integrity, notice the if stdout clause. This will basically re-check encoded file if you need to see normal output first.
Solution 1:
import subprocess
import os
import sys
import re
def check_video(files):
if type(files) == str:
files = [files]
for file in files:
print(f"Checking {file}...")
command_line = f'ffmpeg -v error -i "{file}" -map 0:v -map 0:a? -vcodec copy -acodec copy -f null -'
base_name = os.path.splitext(file)[0]
extension = os.path.splitext(file)[1]
process = subprocess.Popen(command_line, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
stdout, stderr = process.communicate()
return_code = process.returncode
pid = process.pid
print(f"Base: {base_name}")
print(f"Extension: {extension}")
print(f"RC: {return_code}")
if stdout:
allowed_errs = ["invalid as first byte of an EBML number"]
stdout_detect = stdout.decode().split("\n")
for error in allowed_errs:
if error not in stdout_detect[0] or len(stdout_detect) > 2:
print(f"Errors!")
print(os.path.splitext(file)[1])
os.rename(file, f"{file}.error")
with open(f"{file}.error.log", "w") as errfile:
if stdout:
errfile.write(stdout.decode())
if stderr:
errfile.write(stderr.decode())
else:
print("Minor problems detected.")
else:
print("File OK.")
process.wait()
if __name__ == "__main__":
files = sys.argv[1:]
# files = ["a.mkv"]
check_video(files)
Solution 2:
with subprocess.Popen(command_line,
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
universal_newlines=True) as self.process:
for line in self.process.stdout:
print(line, end='')
return_code = self.process.wait()
From here, you can do whatever you like with each line, like checking for error keywords in them. I think ffmpeg has some standard of error reporting (https://ffmpeg.org/doxygen/trunk/group__lavu__error.html). With this solution, output will be displayed to you same as with directly running ffmpeg. Source: https://stackoverflow.com/a/4417735/1793606. Tested with Python 3.10
Solution 3:
Also, you can set err_detect for ffmpeg itself, that should reflect in the return code

ffmpeg - automatically chopped?

I have an ISO file that I would like to encode it out to mp4 in parts so it's easier to upload to youtube. I am not sure how it handles with chapters etc in this iso file. I have tried
ffmpeg -i file.iso newfile.mp4
which works great however it's one large file.
I have google and read some where that says if you put a % within the output file, it should automatically give you parts of the video based on the -t you set, so I went ahead and did this
ffmpeg -i file.iso -t 30 newfile%.mp4
however, the above does not work as it only give me 30 seconds with the file name: newfile%.mp4
Thanks for your time and hoping I can get some help with this. Thank you in advance!
You can use -t and -ss in conjunction to do this with a script.
Here is one: http://grapsus.net/blog/post/A-script-for-splitting-videos-using-ffmpeg

Resources