Get media file length in Mac Terminal - macos

Is there a way to get any media file (.avi, .mp4, .mp3, etc.) length using Mac's Terminal?
I there is a need to install a package or a library can you please specify which, and how to install them?

Mac built in:
mdls *.mp4
Tested in MacOSX 10.6.8

You can use ffmpeg or ffprobe to get the duration. You can install ffmpeg easily using Homebrew:
brew install ffmpeg
And then you can get the duration using this command:
ffmpeg -i input 2>&1 | grep "Duration"| cut -d ' ' -f 4 | sed s/,//
See the answers here for more details: How to get length of video file from console?

Related

Including Youtube-dl in FFMPEG not working in Bash (OSX)

I am trying to download 5 second samples for a list of youtube video. The traditional approach is to download the entire file with "youtube-dl" and then use "ffmpeg" to split it however you want it.
I am trying to use the following method: https://github.com/ytdl-org/youtube-dl/issues/622#issuecomment-162337869
It does work when I include the variables in the command, for example:
ffmpeg -ss 0 -i $(youtube-dl -f best --get-url https://www.youtube.com/watch?v=ySVi-0RS5vI&t=5s) -t 10 -c:v copy -c:a copy title2.mp4
However, I am having issues trying to automate the system. Specifically, I would like ffmpeg and youtube-dl to read a file and use the values. I created the file "youtube.txt" which includes the following codes:
440.8,https://www.youtube.com/watch?v=0-4wOE_DNeA,661.2,881.6,0-4wOE_DNeA
330,https://www.youtube.com/watch?v=0-AMWW6tHzw,495,660,0-AMWW6tHzw
509.2,https://www.youtube.com/watch?v=0-Rmto2rgMw,763.8,1018.4,0-Rmto2rgMw
427.6,https://www.youtube.com/watch?v=0-U53qm45cA,641.4,855.2,0-U53qm45cA
320.4,https://www.youtube.com/watch?v=0-dja9Ys4Sg,480.6,640.8,0-dja9Ys4Sg
343.6,https://www.youtube.com/watch?v=0-g_PulsqtM,515.4,687.2,0-g_PulsqtM
415.6,https://www.youtube.com/watch?v=0-nniRyn7dU,623.4,831.2,0-nniRyn7dU
431.2,https://www.youtube.com/watch?v=006BQU3BFxw,646.8,862.4,006BQU3BFxw
I am using the following command:
parallel -j 6 --colsep ',' ffmpeg -ss {1} -i $(youtube-dl -f best --get-url {2}) --t 5 -c:v copy -c:a copy {5} :::: youtube.txt
However, I get the following errors:
ERROR: '{2}' is not a valid URL. Set --default-search "ytsearch" (or run youtube-dl "ytsearch:{2}" ) to search YouTube
--t: No such file or directory
Would you mind helping me?
Thanks!
Here's a solution using python2, so this should work on the python version shipped with MacOS. My original bash script was choking on the csv line reading for some reason. Add this script to getvids.py in the same directory as your youtube.txt, then run chmod +x getvids.py and when you're ready to turn it loose ./getvids.py
#!/usr/bin/python
import csv, os
with open('youtube.txt') as csv_file:
csv_reader = csv.reader(csv_file, delimiter=',')
for row in csv_reader:
starttimes = [row[0], row[2], row[3]]
yturl = os.popen('youtube-dl -f best --get-url '+row[1]).read().strip()
for thistime in starttimes:
print(row[1] + ' #time='+thistime)
os.system('ffmpeg -hide_banner -loglevel panic -ss '
+thistime+' -i "'+yturl+'" -t 5 -c copy '+row[4]+'['+thistime+'s].mp4')

Named Pipe file on Windows 7

At the moment I'm successfully running the following tshark command on Windows 10 and Windows server 2012:
tshark -l -n -r "\\.\pipe\tsharkpipe2"
but when I run it on Windows 7 and Windows server 2012, tshark gives me File does not exist error. However I can use the pipe with -i like:
tshark -i "\\.\pipe\tsharkpipe2"
but I need to run -Y filter and -T pdml which seems cannot be done using -i.
I'm using tshark 2.0.5 and C# Example from Wireshark wiki and both tshark and my client are running as Administrator.
Am I missing something here?

/usr/local/share/timidity/timidity.cfg: No such file or directory

Timidity version is TiMidity++-2.14.0, and here is my install commond:
./configure && make && make install
Then I run the commond
timidity song.mid -Ow -o | ffmpeg -i - -acodec libmp3lame -ab 64k song.mp3
and it returns error:
/usr/local/share/timidity/timidity.cfg: No such file or directory timidity: Can't read any configuration file. Please check /usr/local/share/timidity/timidity.cfg
"find / -name timidity.cfg", but there is no such file.
I am confused about the error.
Thanks for your reply in advance.
The documentation says:
TiMidity++ uses Either GUS/patch, or SoundFont (,or both) as the voice data to play. You must get a SoundFont or GUS/patch files, and make the configuration file. You must make the configuration file (*.cfg). By default, timidity.cfg is /usr/local/share/timidity/timidity.cfg.
Also see the Arch documentation.

ffmpeg socks4 proxy parameter with rtmp

I am unable to capture some livestreams because of the proxy issues. So in rtmpdump i can use:
rtmpdump -v -r rtmp://a_rtmp_address -p http://a_http_address -S 85.185.244.101:1080 -B 10 -o aaa.flv
But I need to use ffmpeg or avconv. But I can not find a parameter corresponds to that -S 85.185.244.101:1080 parameter.
Can anyone please give me an ffmpeg command corresponding to this rtmpdump command.
You should place socks option in quotes with rtmp:// address.
Options must be in the form KEY=VALUE after rtmp://. Like this:
ffmpeg ... -f flv "rtmp://a_rtmp_address socks=85.185.244.101:1080"

Convert MIDI file to WAV using fluidsynth on OS X

I'm trying to convert a MIDI file to a WAV file, on OS X.
So far, I have this:
fluidsynth -F output_sound soundfont.sf2 note.mid
This creates an output_sound file, however, that file is not WAV, it seems to be in sint16 format given that I get this output:
~ $ fluidsynth -O help
FluidSynth version 1.1.6
Copyright (C) 2000-2012 Peter Hanappe and others.
Distributed under the LGPL license.
SoundFont(R) is a registered trademark of E-mu Systems, Inc.
-O options (audio file format):
's16'
Is there an easy way to convert the output_sound to a WAV file in Terminal (or in any scriptable fashion)?
There is a simpler way than using SoX: when FluidSynth is installed with libsndfile support, it outputs WAV by default. This is how Homebrew installs FluidSynth by default:
$ brew install fluid-synth
...
$ fluidsynth -T help
FluidSynth runtime version 2.0.8
Copyright (C) 2000-2019 Peter Hanappe and others.
Distributed under the LGPL license.
SoundFont(R) is a registered trademark of E-mu Systems, Inc.
-T options (audio file type):
'aiff','au','auto','avr','caf','flac','htk','iff','mat','mpc','oga','paf','pvf','raw','rf64','sd2','sds','sf','voc','w64','wav','wve','xi'
auto: Determine type from file name extension, defaults to "wav"
I found the easiest solution to be timidity:
timidity input.mid -Ow -o out.wav
If you use homebrew it's also trivial to install:
brew install timidity
Thanks to CL.'s comment I came up with this:
sox -t raw -r 44100 -e signed -b 16 -c 1 raw_audio audio.wav

Resources