I have a script that is currently using wget to grab an image from a url then passing that image to ffprobe. I'd like to remove the wget dependancy. What is the best way to download this image from the URL into STDIN so that ffprobe can read it.
Current logic is:
wget_command = "wget --header=\"ApiKey: #{#config.api_key}\" -O- #{file} | "
ffprobe_command = "ffprobe -v error -select_streams v:0 -show_entries stream=width,height -of csv=s=x:p=0 -i"
Open3.capture3("#{wget_command} #{ffprobe_command} -")
Other places in the script use Faraday for http requests so that is ideally what I would like to use to pull the image.
What is the best way to download this image from the URL into STDIN so
that ffprobe can read it.
ffprobe itself can get network resource, from ffprobe docs, your case is somewhat more complicated, but it should be possible if ffprobe does act in this are same way as ffmpeg which allows you to pass http headers, I suggest starting with following command
ffprobe -headers $'ApiKey: YOURAPIKEY' -i URLTOIMAGE -v trace
I'm currently running the following command and it's giving me mostly what I need, but I would like to also have it include the file name.
for %%A IN (%VAR0%\*.wav) DO "C:\program files (x86)\ffmpeg\bin\ffprobe" -i "%%A" -show_entries format=duration -v quiet -of csv="p=0" >>output.txt
The above produces this:
110.994375
This is great, but what I would really want is something like this as I need to import this data into a db for further processing. I need to know which file the 110.9943765 came from.
recording1.wav, 110.994375
Thanks,
Steven
All you need is to add the filename key as well.
ffprobe -i "%%A" -show_entries format=filename,duration -v quiet -of csv="p=0" >>output.txt
I am using ffprobe on Windows to identify files. The command/parameters I use are:
ffprobe -show_entries format=format_name -v quiet filename
I noticed with certain image files ffprobe reports a different format if the file name has (or does not have) and extension. For example, for a BMP image file named XXX
ffprobe -show_entries format=format_name -v quiet XXX
reports
[FORMAT]
format_name=mp3
[/FORMAT]
But, if I rename the file to XXX.BMP and rerun the command
ffprobe -show_entries format=format_name -v quiet XXX.BMP
reports
[FORMAT]
format_name=image2
[/FORMAT]
Is this behavior expected? Has anyone else encountered this issue? I am using the most recent version of ffmpeg.
How can I load the output of below command into a text file?
ffmpeg -i units.wav -af silencedetect=noise=-20dB:d=0.2 -f null -
This command simply detects the silences from a video and I need to store this output in a text file.
I have also found this link but as I am newbie in ffmpeg I am not able to use it in my command.
Thanks..
Wanted to post this update for other people who've had this problem. I had the same problem with the > pipe command and found you can use 2> instead. Possible FFMpeg bug? Not sure.
ffmpeg -i units.wav -af silencedetect=noise=-20dB:d=0.2 -f null - 2> output.txt
You can pipe its output to a file like this:
ffmpeg -i units.wav -af silencedetect=noise=-20dB:d=0.2 -f null - > output.txt
I'm using FFMPEG to measure the duration of videos stored in an Amazon S3 Bucket.
I've read the FFMPEG docs, and they explicitly state that all whitespace and special characters need to be escaped, in order for FFMPEG to handle them properly:
See docs 2.1 and 2.1.1: https://ffmpeg.org/ffmpeg-utils.html
However, when dealing with files whose filenames contain whitespace, ffmpeg fails to render a result.
I've tried the following, with no success
ffmpeg -i "http://s3.mybucketname.com/videos/my\ video\ file.mov" 2>&1 | grep Duration | awk '{print $2}' | tr -d
ffmpeg -i "http://s3.mybucketname.com/videos/my video file.mov" 2>&1 | grep Duration | awk '{print $2}' | tr -d
ffmpeg -i "http://s3.mybucketname.com/videos/my'\' video'\' file.mov" 2>&1 | grep Duration | awk '{print $2}' | tr -d
ffmpeg -i "http://s3.mybucketname.com/videos/my\ video\ file.mov" 2>&1 | grep Duration | awk '{print $2}' | tr -d
However, if I strip out the whitespace in the filename – all is well, and the duration of the video is returned.
If you happen to have spaces in your file name, just quote them:
ffmpeg -i "my video file.mov"
In a URL, a space cannot be there. Most probably you have to replace every single space with a %20, so that you get:
ffmpeg -i http://myurl.com/my%20video%20file.mov
^^^ ^^^
ffmpeg uses % to define a pattern and handle multiple files. For instance if your filename is URI encoded you must use "-pattern_type none" to avoid misinterpretation from ffmpeg:
ffmpeg -pattern_type none -i file%20name.mp4
To make ffmeg works with filename/path that have whitespaces, you should:
1) set the working directory with Pushd
2) put your filename inside quote ""
here is a working example:
cls
REM ++++++++++++++++++++++++++
REM Cut an audio file by right-cliking it (works also on multiple selected audio)
REM 1) save this file
REM 2) open registry, browse to Computer\HKEY_LOCAL_MACHINE\SOFTWARE\Classes\SystemFileAssociations\audio\shell. On the left panel, right-click on "shell" and select "New", then "Key". Type "Cut audio 5min". Right click on the newly created folder "Cut audio 5min" and select again "New" and then "Key". Type “command”. On the right pane, double-click the "(default)" value name and type the following: "C:\Users\Me\Cut audio.cmd" "%1"
REM optional: if you want an Icon : in the left pane, right click "Cut audio 5min", and select String value, then in the right pane, rename the new value to Icon, then double click on it and past this "%SystemRoot%\\System32\\shell32.dll,186" (; list icon: https://diymediahome.org/windows-icons-reference-list-with-details-locations-images/ )
REM 3) right click an audio file and select "Cut audio 5min": the chunks will be created in the same folder.
REM because ffmpeg has trouble with path/filename with space, we set the working directory to the folder of the audio file and the we run the command not on a full path but just on the filename, with "" around it
REM get https://stackoverflow.com/a/15568171/3154274
REM fullpath of rightclicked file %1
REM full path (letter drive + path ithout letter drive) %~d1%~p1
REM filename (filename + extension) %~n1%~x1
REM https://windowsloop.com/split-mp3-files-with-ffmpeg/
REM ffmpeg -i "input_audio_file.mp3" -f segment -segment_time 300 -c copy output_audio_file_%%03d.mp3
REM 300= 5min chunk
REM ++++++++++++++++++++++++++
REM set working directory
Pushd %~d1%~p1
REM to let the windows open cmd /k ffmpeg -i "%~n1%~x1" -f segment -segment_time 300 -c copy "%~n1"_%%03d.mp3
cmd /k ffmpeg -i "%~n1%~x1" -f segment -segment_time 300 -c copy "%~n1"_%%03d.mp3
for fileOne in *.mp4
do
baseName=$(basename "$fileOne" .mp4) # "$fileOne" quotes are necessary because of special chars in it
echo "input: " $fileOne
echo "var: " $baseName
echo "target: " $baseName".mp3"
cp "$fileOne" "tmp.mp4"
# ffmpeg problem with specialchars like whitespaces and '-'
# ffmpeg -i \"$fileOne\" "$baseName..mp3"
ffmpeg -i "tmp.mp4" "tmp.mp3"
mv "tmp.mp3" "$baseName".mp3""
done
rm "tmp-mp4"
`just rename the file for the conversion :)
As many have pointed out, the best option is to quote the string. It works for all other special characters.Here are some examples I found of the ffmpeg documentation page. I am attaching a screen shot just in in case it is unavailable in the future.
I solved it by "enquoting" the arg that contain the file path. In my case, the path was stored in the %1 argument (which was written in the registry under quote that are escaped: \"%1\" ). I retrieve it (with a PowerShell script), simply using $arg (inbuilt argument). I then used it get some file information such as:
# Get the File path:
$FilePath = $args
# Get the complete file name:
$file_name_complete = [System.IO.Path]::GetFileName("$FilePath")
# Get File Name Without Extension:
$fileNameOnly = [System.IO.Path]::GetFileNameWithoutExtension("$FilePath")
# Get the Extension:
$fileExtensionOnly = [System.IO.Path]::GetExtension("$FilePath")
Don't forget the quote around $FilePath.
Then you can use it to divide audio filesin 5min parts simply like this:
ffmpeg -i $file_name_complete -f segment -segment_time 300 -c copy $fileNameOnly"_"%03d$fileExtensionOnly #
You are using video URL for the input, so you need to encode that URL, because as I know CURL or WGET also need URL to be encoded, like SPACE become %20, if you use PHP do like this: rawurlencode($video_url)