display dialog "Nothing to do!" & return & return & "A non-audio video has already been created:" & return & "\"" & theName & "\"" with icon caution buttons {"OK"} default button "OK"
display dialog "Nothing to do!" & return & return & "\"" & theFile & "\" doesn't contain any audio." with icon caution buttons {"OK"} default button "OK"
# ******* Automator Services script for making a copy of a .MP4 video file and removing its audio track(s) along with a new filename to indicate it doesn't contain any audio *******
# *******
# The original file is left untouched.
# It works with single files or several at once.
# It also checks to see if an MP4 video has already been converted or if the video file is without audio, then alerts accordingly.
#
# ******* This script is dependant on FFmpeg. It won't work without it being installed first
# ******* First, download it from: https://ffmpeg.org/download.html#build-mac
# ******* Then put the ffmpeg binary file into the following folder: /usr/local/bin/
# *******
on run {input, parameters}
repeat with i from 1 to the count of input
set theVideoFile to (item i of input)
set theVideo to quoted form of (POSIX path of (item i of input))
try
set AudioTrack to (do shell script "/usr/local/bin/ffmpeg -i " & theVideo & " 2>&1 | grep -i Audio:" as string)
try
if AudioTrack contains "Audio" then
tell application "Finder"
set extension hidden of theVideoFile to true
set theName to displayed name of theVideoFile
set theOutputFolder to POSIX path of ((container of theVideoFile) as text)
set theNoAudioFile to quoted form of ((theOutputFolder & theName & " (no audio).mp4") as text)
set extension hidden of theVideoFile to false
end tell
tell application "Finder"
if exists (POSIX path of (theOutputFolder & theName & " (no audio).mp4")) as POSIX file then
# ******* dialog options for 'File already processed. Non-audio version already available' *******
# dialog option 1: only dialog, no filename
# "Nothing to do!" & return & "A non-audio video has already been created." with icon caution buttons {"OK"} default button "OK"
#
# dialog option 2: show filename without quote characters
# display dialog "Nothing to do!" & return & "A non-audio video has already been created:" & return & theName with icon caution buttons {"OK"} default button "OK"
#
# dialog option 3: show filename with quote characters
# display dialog "Nothing to do!" & return & "A non-audio video has already been created:" & return "\"" & theName & "\" with icon caution buttons {"OK"} default button "OK"
#
# dialog option 4: show filename with quote characters and line spacing
# display dialog "Nothing to do!" & return & return & "A non-audio video has already been created:" & return & "\"" & theName & "\"" with icon caution buttons {"OK"} default button "OK"
#
# dialog option 5: show filename (including "(no audio)" and file-extension) with quote characters and line spacing
display dialog "Nothing to do!" & return & return & "A non-audio video has already been created:" & return & "\"" & theName & " (no audio).mp4\"" with icon caution buttons {"OK"} default button "OK"
else
do shell script "/usr/local/bin/ffmpeg -i " & theVideo & " -c copy -an " & theNoAudioFile
end if
end tell
end if
--on error errorMessage
--display dialog errorMessage
end try
on error
tell application "Finder"
set theFile to displayed name of theVideoFile
end tell
# ******* dialog options for 'no audio found in file' *******
# dialog option 1: display filename
# display dialog "No audio found in: " & theFile
#
# dialog option 2: display filename with single-quote character
# display dialog "Nothing to do!" & return & "File " & quoted form of theFile & " doesn't contain any audio." with icon caution buttons {"OK"} default button "OK"
#
# dialog option 3: display filename with any other character
# display dialog "Nothing to do!" & return & "File • " & theFile & " • doesn't contain any audio." with icon caution buttons {"OK"} default button "OK"
#
# dialog option 4: display filename with quote character
# display dialog "Nothing to do!" & return & "\"" & theFile & "\" doesn't contain any audio." with icon caution buttons {"OK"} default button "OK"
#
# dialog option 5: display filename with quote character and line spacing
display dialog "Nothing to do!" & return & return & "\"" & theFile & "\" doesn't contain any audio." with icon caution buttons {"OK"} default button "OK"
end try
end repeat
end run
on run {input, parameters}
repeat with i from 1 to the count of input
set theVideo to (item i of input)
set theVideoFile to quoted form of (POSIX path of (item i of input))
try
set AudioTrack to (do shell script "/usr/local/bin/ffmpeg -i " & theVideoFile & " 2>&1 | grep -i Audio:" as string)
try
if AudioTrack contains "Audio" then
tell application "Finder"
set theExt to name extension of (theVideo as alias)
set extension hidden of theVideo to true
set theName to displayed name of theVideo
set theOutputFolder to POSIX path of ((container of theVideo) as text)
set theNoAudio to ((theName & " (no audio)." & theExt) as text)
set theNoAudioFile to (POSIX path of (theOutputFolder & theNoAudio))
set extension hidden of theVideo to false
end tell
tell application "Finder"
if exists theNoAudioFile as POSIX file then
display dialog "Nothing to do!" & return & return & "A non-audio video has already been created:" & return & "\"" & theNoAudio & "\"" with icon caution buttons {"OK"} default button "OK"
else
do shell script "/usr/local/bin/ffmpeg -i " & theVideoFile & " -c copy -an " & quoted form of theNoAudioFile
end if
end tell
end if
end try
on error
tell application "Finder"
set theName to displayed name of theVideo
end tell
display dialog "Nothing to do!" & return & return & "\"" & theName & "\" doesn't contain any audio." with icon caution buttons {"OK"} default button "OK"
end try
end repeat
end run
Take a look here https://support.apple.com/en-gb/HT209029Does "variable extension" mean that it can handle other formats than .MP4?
I tested it with a variety of video file-types downloaded from FileSamples and FreeTestData but was unable to run the script on them successfully.
For most of them I got a "file contains no audio" error while with a .WMV file the script ran but ended up with a zero byte "no sound" file. I tested playback of all the video samples using VLC Media player before running the script and they worked fine. Maybe I've misunderstood.
$ ffmpeg -i videotest.wmv
ffmpeg version N-107731-g5cdf4c0bed-tessus Copyright (c) 2000-2022 the FFmpeg developers
built with Apple clang version 11.0.0 (clang-1100.0.33.17)
configuration: --cc=/usr/bin/clang --prefix=/opt/ffmpeg --extra-version=tessus --enable-avisynth --enable-fontconfig --enable-gpl --enable-libaom --enable-libass --enable-libbluray --enable-libdav1d --enable-libfreetype --enable-libgsm --enable-libmodplug --enable-libmp3lame --enable-libmysofa --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenh264 --enable-libopenjpeg --enable-libopus --enable-librubberband --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libtheora --enable-libtwolame --enable-libvidstab --enable-libvmaf --enable-libvo-amrwbenc --enable-libvorbis --enable-libvpx --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxavs --enable-libxvid --enable-libzimg --enable-libzmq --enable-libzvbi --enable-version3 --pkg-config-flags=--static --disable-ffplay
libavutil 57. 32.101 / 57. 32.101
libavcodec 59. 42.100 / 59. 42.100
libavformat 59. 30.100 / 59. 30.100
libavdevice 59. 8.101 / 59. 8.101
libavfilter 8. 46.101 / 8. 46.101
libswscale 6. 8.102 / 6. 8.102
libswresample 4. 8.100 / 4. 8.100
libpostproc 56. 7.100 / 56. 7.100
[wmv3 @ 0x7fac7af08a40] Extra data: 8 bits left, value: 20
Input #0, asf, from 'videotest.wmv':
Metadata:
VBR Peak : 8000000
DeviceConformanceTemplate: MP@HL
WM/WMADRCPeakReference: 3243
WM/WMADRCPeakTarget: 3243
WM/WMADRCAverageReference: 758
WM/WMADRCAverageTarget: 758
NumberOfFrames : 196
WMFSDKVersion : 12.0.19041.1466
WMFSDKNeeded : 0.0.0.0000
IsVBR : 1
Buffer Average : 200
Duration: 00:00:08.30, start: 0.000000, bitrate: 5061 kb/s
Stream #0:0(eng): Audio: wmapro (b[1][0][0] / 0x0162), 44100 Hz, stereo, fltp, 440 kb/s
Stream #0:1(eng): Video: wmv3 (Main) (WMV3 / 0x33564D57), yuv420p, 1280x720, 5000 kb/s, SAR 1:1 DAR 16:9, 25 fps, 25 tbr, 1k tbn
At least one output file must be specified
$
ffmpeg -i videotest.wmv converted.mp4
$ ffmpeg -i videotest.wmv converted.mp4
ffmpeg version N-107731-g5cdf4c0bed-tessus Copyright (c) 2000-2022 the FFmpeg developers
built with Apple clang version 11.0.0 (clang-1100.0.33.17)
configuration: --cc=/usr/bin/clang --prefix=/opt/ffmpeg --extra-version=tessus --enable-avisynth --enable-fontconfig --enable-gpl --enable-libaom --enable-libass --enable-libbluray --enable-libdav1d --enable-libfreetype --enable-libgsm --enable-libmodplug --enable-libmp3lame --enable-libmysofa --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenh264 --enable-libopenjpeg --enable-libopus --enable-librubberband --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libtheora --enable-libtwolame --enable-libvidstab --enable-libvmaf --enable-libvo-amrwbenc --enable-libvorbis --enable-libvpx --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxavs --enable-libxvid --enable-libzimg --enable-libzmq --enable-libzvbi --enable-version3 --pkg-config-flags=--static --disable-ffplay
libavutil 57. 32.101 / 57. 32.101
libavcodec 59. 42.100 / 59. 42.100
libavformat 59. 30.100 / 59. 30.100
libavdevice 59. 8.101 / 59. 8.101
libavfilter 8. 46.101 / 8. 46.101
libswscale 6. 8.102 / 6. 8.102
libswresample 4. 8.100 / 4. 8.100
libpostproc 56. 7.100 / 56. 7.100
[wmv3 @ 0x7f9e81511680] Extra data: 8 bits left, value: 20
Input #0, asf, from 'videotest.wmv':
Metadata:
VBR Peak : 8000000
DeviceConformanceTemplate: MP@HL
WM/WMADRCPeakReference: 3243
WM/WMADRCPeakTarget: 3243
WM/WMADRCAverageReference: 758
WM/WMADRCAverageTarget: 758
NumberOfFrames : 196
WMFSDKVersion : 12.0.19041.1466
WMFSDKNeeded : 0.0.0.0000
IsVBR : 1
Buffer Average : 200
Duration: 00:00:08.30, start: 0.000000, bitrate: 5061 kb/s
Stream #0:0(eng): Audio: wmapro (b[1][0][0] / 0x0162), 44100 Hz, stereo, fltp, 440 kb/s
Stream #0:1(eng): Video: wmv3 (Main) (WMV3 / 0x33564D57), yuv420p, 1280x720, 5000 kb/s, SAR 1:1 DAR 16:9, 25 fps, 25 tbr, 1k tbn
[wmv3 @ 0x7f9e81512540] Extra data: 8 bits left, value: 20
Stream mapping:
Stream #0:1 -> #0:0 (wmv3 (native) -> h264 (libx264))
Stream #0:0 -> #0:1 (wmapro (native) -> aac (native))
Press [q] to stop, [?] for help
[libx264 @ 0x7f9e81517ac0] using SAR=1/1
[libx264 @ 0x7f9e81517ac0] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2
[libx264 @ 0x7f9e81517ac0] profile High, level 3.1, 4:2:0, 8-bit
[libx264 @ 0x7f9e81517ac0] 264 - core 164 r3095 baee400 - H.264/MPEG-4 AVC codec - Copyleft 2003-2022 - http://www.videolan.org/x264.html - options: cabac=1 ref=3 deblock=1:0:0 analyse=0x3:0x113 me=hex subme=7 psy=1 psy_rd=1.00:0.00 mixed_ref=1 me_range=16 chroma_me=1 trellis=1 8x8dct=1 cqm=0 deadzone=21,11 fast_pskip=1 chroma_qp_offset=-2 threads=18 lookahead_threads=3 sliced_threads=0 nr=0 decimate=1 interlaced=0 bluray_compat=0 constrained_intra=0 bframes=3 b_pyramid=2 b_adapt=1 b_bias=0 direct=1 weightb=1 open_gop=0 weightp=2 keyint=250 keyint_min=25 scenecut=40 intra_refresh=0 rc_lookahead=40 rc=crf mbtree=1 crf=23.0 qcomp=0.60 qpmin=0 qpmax=69 qpstep=4 ip_ratio=1.40 aq=1:1.00
Output #0, mp4, to 'converted.mp4':
Metadata:
VBR Peak : 8000000
DeviceConformanceTemplate: MP@HL
WM/WMADRCPeakReference: 3243
WM/WMADRCPeakTarget: 3243
WM/WMADRCAverageReference: 758
WM/WMADRCAverageTarget: 758
NumberOfFrames : 196
WMFSDKVersion : 12.0.19041.1466
WMFSDKNeeded : 0.0.0.0000
IsVBR : 1
Buffer Average : 200
encoder : Lavf59.30.100
Stream #0:0(eng): Video: h264 (avc1 / 0x31637661), yuv420p(progressive), 1280x720 [SAR 1:1 DAR 16:9], q=2-31, 25 fps, 12800 tbn
Metadata:
encoder : Lavc59.42.100 libx264
Side data:
cpb: bitrate max/min/avg: 0/0/0 buffer size: 0 vbv_delay: N/A
Stream #0:1(eng): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 128 kb/s
Metadata:
encoder : Lavc59.42.100 aac
frame= 196 fps= 74 q=-1.0 Lsize= 1222kB time=00:00:07.91 bitrate=1264.9kbits/s speed=2.99x
video:1115kB audio:99kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.670853%
[libx264 @ 0x7f9e81517ac0] frame I:1 Avg QP:20.08 size: 79000
[libx264 @ 0x7f9e81517ac0] frame P:49 Avg QP:19.40 size: 16852
[libx264 @ 0x7f9e81517ac0] frame B:146 Avg QP:23.57 size: 1619
[libx264 @ 0x7f9e81517ac0] consecutive B-frames: 0.5% 0.0% 1.5% 98.0%
[libx264 @ 0x7f9e81517ac0] mb I I16..4: 12.9% 60.7% 26.4%
[libx264 @ 0x7f9e81517ac0] mb P I16..4: 0.3% 1.0% 0.1% P16..4: 41.6% 14.2% 11.0% 0.0% 0.0% skip:31.8%
[libx264 @ 0x7f9e81517ac0] mb B I16..4: 0.0% 0.0% 0.0% B16..8: 27.5% 1.3% 0.2% direct: 0.5% skip:70.4% L0:34.1% L1:61.7% BI: 4.2%
[libx264 @ 0x7f9e81517ac0] 8x8 transform intra:64.8% inter:70.4%
[libx264 @ 0x7f9e81517ac0] coded y,uvDC,uvAC intra: 65.2% 85.5% 51.5% inter: 6.8% 12.5% 1.4%
[libx264 @ 0x7f9e81517ac0] i16 v,h,dc,p: 30% 27% 11% 32%
[libx264 @ 0x7f9e81517ac0] i8 v,h,dc,ddl,ddr,vr,hd,vl,hu: 30% 26% 24% 3% 3% 2% 3% 3% 5%
[libx264 @ 0x7f9e81517ac0] i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 28% 25% 12% 6% 6% 5% 6% 5% 8%
[libx264 @ 0x7f9e81517ac0] i8c dc,h,v,p: 47% 25% 21% 8%
[libx264 @ 0x7f9e81517ac0] Weighted P-Frames: Y:0.0% UV:0.0%
[libx264 @ 0x7f9e81517ac0] ref P L0: 66.2% 10.7% 17.4% 5.7%
[libx264 @ 0x7f9e81517ac0] ref B L0: 92.3% 6.5% 1.2%
[libx264 @ 0x7f9e81517ac0] ref B L1: 95.4% 4.6%
[libx264 @ 0x7f9e81517ac0] kb/s:1164.45
[aac @ 0x7f9e81518c40] Qavg: 14841.137
$
The only thing abnormal is that videotest.wmv has the audio track as Stream #0:0 and the video track as Stream #0:1. Probably that muxing error somehow confuses ffmpeg.$ ffmpeg -i videotest.wmv
Stream #0:0(eng): Audio: wmapro (b[1][0][0] / 0x0162), 44100 Hz, stereo, fltp, 440 kb/s
Stream #0:1(eng): Video: wmv3 (Main) (WMV3 / 0x33564D57), yuv420p, 1280x720, 5000 kb/s, SAR 1:1 DAR 16:9, 25 fps, 25 tbr, 1k tbn
$ ffmpeg -version
ffmpeg version N-107731-g5cdf4c0bed-tessus Copyright (c) 2000-2022 the FFmpeg developers
built with Apple clang version 11.0.0 (clang-1100.0.33.17)
$
I always use the release version, at the moment ffmpeg-5.1Are you using a different version of ffmpeg than mine?
I'm using the script from post #30 The script from post #29That's the one (the zip file) I've downloaded now (and replaced the old ffmpeg binary with). But I'm getting the exact same error as before, so the problem must be something else.
# ******* OSX Automator Services script for removing audio from video files in a variety of common and more uncommon formats supported by FFmpeg
# more info about this script: https://forums.macrumors.com/threads/unable-to-remove-audio-in-quicktime-player-10-4.2354189/page-2?post=31340895#post-31340895
#
#
# - The original video remains unchanged. A copy with the audio track(s) removed and the name "(no audio)" will be added.
# - The audio-free copy will have the same file-type as the original file.
# - It works with single files or several at once.
# - It works with a variety of file types and codecs which FFmpeg supports. The converted file will be of the same file-type as the original.
# - The script also checks if the video has already been converted and if doesn't have any audio track(s) to begin with. Dialog windows will alert the user about this.
#
# ******* This script is dependant on FFmpeg. It won't work without it being installed first
# ******* First, download it from: https://ffmpeg.org/download.html#build-mac
# ******* Then put the ffmpeg binary file into the following folder: /usr/local/bin/
# *******
on run {input, parameters}
repeat with i from 1 to the count of input
set theVideo to (item i of input)
set theVideoFile to quoted form of (POSIX path of (item i of input))
try
set AudioTrack to (do shell script "/usr/local/bin/ffmpeg -i " & theVideoFile & " 2>&1 | grep -i Audio:" as string)
try
if AudioTrack contains "Audio" then
tell application "Finder"
set theExt to name extension of (theVideo as alias)
set extension hidden of theVideo to true
set theName to displayed name of theVideo
set theOutputFolder to POSIX path of ((container of theVideo) as text)
set theNoAudio to ((theName & " (no audio)." & theExt) as text)
set theNoAudioFile to (POSIX path of (theOutputFolder & theNoAudio))
set extension hidden of theVideo to false
end tell
tell application "Finder"
if exists theNoAudioFile as POSIX file then
# ******* dialog options for 'A non-audio video is already available' *******
#
# Dialog option 1: only dialog, no filename
# display dialog "Nothing to do!" & return & "A non-audio video is already available." with icon caution buttons {"OK"} default button "OK"
# Dialog option 2: display filename WITHOUT any quote characters
# display dialog "Nothing to do!" & return & "A non-audio video is already available:" & return & theNoAudio with icon caution buttons {"OK"} default button "OK"
# Dialog option 3: display filename WITH quote characters
# display dialog "Nothing to do!" & return & "A non-audio video is already available:" & return & "\"" & theNoAudio & "\"" with icon caution buttons {"OK"} default button "OK"
# Dialog option 4: display filename WITH quote characters and line spacing
# display dialog "Nothing to do!" & return & return & "A non-audio video is already available:" & return & "\"" & theNoAudio & "\"" with icon caution buttons {"OK"} default button "OK"
# option 4 selected
display dialog "Nothing to do!" & return & return & "A non-audio video is already available:" & return & "\"" & theNoAudio & "\"" with icon caution buttons {"OK"} default button "OK"
else
do shell script "/usr/local/bin/ffmpeg -i " & theVideoFile & " -c copy -an " & quoted form of theNoAudioFile
end if
end tell
end if
end try
on error
tell application "Finder"
set theName to displayed name of theVideo
end tell
# ******* dialog options for 'no audio found in file' *******
#
# Dialog option 1: only dialog, no filename
# display dialog "No audio found in file!" with icon caution buttons {"OK"} default button "OK"
# Dialog option 2: display filename WITHOUT any quote characters
# display dialog "No audio found in: " & theName with icon caution buttons {"OK"} default button "OK"
# Dialog option 3: display filename WITH single-quote characters
# display dialog "Nothing to do!" & return & "File " & quoted form of theName & " doesn't contain any audio." with icon caution buttons {"OK"} default button "OK"
# Dialog option 4: display filename WITH square (◼︎) characters as quotes (feel free to use other special characters or emojis)
# display dialog "Nothing to do!" & return & "File ◼︎ " & theName & " ◼︎ doesn't contain any audio." with icon caution buttons {"OK"} default button "OK"
# Dialog option 5: display filename WITH multiple angle bracket characters as quotes (feel free to use other special characters or emojis)
# display dialog "Nothing to do!" & return & "File ❮❮❮ " & theName & " ❯❯❯ doesn't contain any audio." with icon caution buttons {"OK"} default button "OK"
# Dialog option 6: display filename WITH emoji characters as quotes (feel free to use other special characters or emojis)
# display dialog "Nothing to do!" & return & "File 😀 " & theName & " 🌸 doesn't contain any audio." with icon caution buttons {"OK"} default button "OK"
# Dialog option 7: display filename WITH quote characters
# display dialog "Nothing to do!" & return & "\"" & theName & "\" doesn't contain any audio." with icon caution buttons {"OK"} default button "OK"
# Dialog option 8: display filename WITH quote characters and line spacing
# display dialog "Nothing to do!" & return & return & "\"" & theName & "\" doesn't contain any audio." with icon caution buttons {"OK"} default button "OK"
# option 8 selected
display dialog "Nothing to do!" & return & return & "\"" & theName & "\" doesn't contain any audio." with icon caution buttons {"OK"} default button "OK"
end try
end repeat
end run
As the script doesn’t re-encode, just removes the audio track, it should work with any file ffmpeg can open.I'm sure there are others as well, but as I understand it the script will take any audio file that FFmpeg supports, correct?
I would advise anyone downloading AppleScripts/macOS services from the Internet, regardless of the source, to check the code before installingTo any new user wondering how to install this OSX Service:
1) download the attached .ZIP file, then double-click on your Mac to decompress it.
2) now double-click the Services file.You'll be asked if you want to install it. Click the "Install" button:
Good advice! Also in case I myself come across Applescripts or Services that I download.As the script doesn’t re-encode, just removes the audio track, it should work with any file ffmpeg can open.
I would advise anyone downloading AppleScripts/macOS services from the Internet, regardless of the source, to check the code before installingIn the case of a service, do not double-click, right-click -» Open with -» Automator (the second one, not the first one that says install).