Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

bogdanw

macrumors 603
Mar 10, 2009
5,712
2,749
Yes, use \"
Code:
display dialog "Nothing to do!" & return & "File \"" & theFile & "\" doesn't contain any audio." with icon caution buttons {"OK"} default button "OK"
 

macstatic

macrumors 68020
Original poster
Oct 21, 2005
2,010
163
Norway
Yes! This looks a whole lot better IMHO as it distiguishes the filename from the rest of the text. I've also added a space between the text for increased legibility.

Regarding the first error message (a non-audio video has already been created), the string "theName" shows the source file (instead of the non-audio created file) and doesn't include the file extension. This could cause some confusion:
Screen Shot 2022-08-16 at 11.14.46.png

Screen Shot 2022-08-16 at 11.14.53.png


AppleScript:
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"

What do I need to change in order to make "theName" display the target file (i.e. "Videotest (no audio).mp4") and include the file-extension? I tried replacing "theName" with "theFile" but it didn't work.

Applying the Service to an non-audio video file displays the filename correctly:
Screen Shot 2022-08-16 at 11.20.11.png

Screen Shot 2022-08-16 at 11.20.21.png

AppleScript:
display dialog "Nothing to do!" & return & return & "\"" & theFile & "\" doesn't contain any audio." with icon caution buttons {"OK"} default button "OK"
 
Last edited:

bogdanw

macrumors 603
Mar 10, 2009
5,712
2,749
Add (no audio).mp4\" to the message
Code:
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"
 

macstatic

macrumors 68020
Original poster
Oct 21, 2005
2,010
163
Norway
Thanks, Bogdanw.
I believe it works more or less perfectly now! 👍
I've tested it with single and multiple files, and as far as I can see appears "bomb-proof".
Here's the final script with comments and multiple dialog options which the user can un-comment to select the ones they prefer:
AppleScript:
# ******* 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

For me it now does exactly what I want, but would it be useful for others to have it convert any type video file? In that case, should it convert the other file formats to non-audio MP4 video files, or keep the same format as before? In my experience, MP4 appears to be the most common format on the Mac platform, but I'm just wondering if this is something necessary or not. Opinions?
 
Last edited:

bogdanw

macrumors 603
Mar 10, 2009
5,712
2,749
Some cleanup and added variable extension
Code:
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
 

macstatic

macrumors 68020
Original poster
Oct 21, 2005
2,010
163
Norway
Does "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.
 

bogdanw

macrumors 603
Mar 10, 2009
5,712
2,749
Does "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.
Take a look here https://support.apple.com/en-gb/HT209029
The same container (MP4) can incorporate video and audio tracks with different codecs.
The error is not about the container/extension, but about the codec.
I’m surprised that ffmpeg doesn’t recognize some audio codecs.
Try to run /usr/local/bin/ffmpeg -i /path/to/file.mkv in Terminal to see the error or get media info from VLC.
 

macstatic

macrumors 68020
Original poster
Oct 21, 2005
2,010
163
Norway
I see.
Here's what Terminal tells me when using "-i" on the WMV file that ended with a zero byte output file, but with an error message at the end (At least one output file must be specified):

Code:
$ 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
$

But here's something interesting. With the above error message in mind I tried the same command but with an output file specified:

Code:
ffmpeg -i videotest.wmv converted.mp4

This indeed resulted in the creation of "converted.mp4" and was fully playable!
So this must mean FFmpeg can read the codec of this file. Maybe it'll work with some changes to the Applescript?

Here's all the information shown in Terminal when issued the above command (I couldn't remember the options for removing the audio, so this is just a quick test to see if it can handle any conversion with such a filtype (WMV) at all):
Code:
$ 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
$
 
Last edited:

bogdanw

macrumors 603
Mar 10, 2009
5,712
2,749
$ 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
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.

The script works perfectly with sample_960x400_ocean_with_audio.wmv from https://filesamples.com/formats/wmv

Anyway, I wouldn’t worry too much about converting wmv files. These days they are most likely used to spread malware, rather than to distribute video content :)
 

macstatic

macrumors 68020
Original poster
Oct 21, 2005
2,010
163
Norway
That's strange; I downloaded that video (https://filesamples.com/samples/video/wmv/sample_960x400_ocean_with_audio.wmv) but it didn't convert here. I got the same problem as before (a "no audio" MP4 was created, but sized at 0 bytes). Are you using a different version of ffmpeg than mine? Mine is this:

Code:
$ 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)
$
 

macstatic

macrumors 68020
Original poster
Oct 21, 2005
2,010
163
Norway
The ffmpeg page is a little confusing when you'd expect a single "download" button instead of all those options.
Is it the one on the upper right side (circled in red)?
Screen Shot 2022-08-23 at 18.44.32.png


That'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.
 

bogdanw

macrumors 603
Mar 10, 2009
5,712
2,749
That'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.
I'm using the script from post #30 The script from post #29
adds the extension .mp4 instead of wmv, and AviDemux explains why the .mp4 file is empty:
“Unsupported
Video track is incompatible
Only MPEG-1/2/4, H264, H265 and AV1 supported for video”
 

macstatic

macrumors 68020
Original poster
Oct 21, 2005
2,010
163
Norway
You're right! The script from post #30 works fine with the WMV files, and I used the one in post #29 which doesn't.
Below is your post #30 script along with the various various dialog options I've made in the previous script and some updated comments.
I've also thoroughly tested it with a lot of video filetypes, and it seems very robust now.
The filetypes which I've tried have these extensions:

.VOB
.OGV
.MOV
.MKV
.FLV
.AVI
.3GP
.WEBM
.RM
.WMV
.MP4
.MPG
.M2TS

I'm sure there are others as well, but as I understand it the script will take any audio file that FFmpeg supports, correct?

Below is the updated (and tested) Applescript along with the actual Automator file (the script contains some special characters in the dialog options which might come out messed up in the code listing here).
AppleScript:
# ******* 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

To 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.
Screen Shot 2022-08-26 at 16.20.50.png

2) now double-click the Services file.You'll be asked if you want to install it. Click the "Install" button:
Screen Shot 2022-08-26 at 16.18.39.png

3) The Service is now ready for use. Right-click on the video file (or select several files first, then right-click on those) and select the Service for converting this/these videos to audio-free videos.
Screen Shot 2022-08-26 at 16.26.56.png
 

Attachments

  • Convert VIDEO to VIDEO (with NO SOUND).zip
    248.3 KB · Views: 101

bogdanw

macrumors 603
Mar 10, 2009
5,712
2,749
I'm sure there are others as well, but as I understand it the script will take any audio file that FFmpeg supports, correct?
As the script doesn’t re-encode, just removes the audio track, it should work with any file ffmpeg can open.
To 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:
I would advise anyone downloading AppleScripts/macOS services from the Internet, regardless of the source, to check the code before installing :) In the case of a service, do not double-click, right-click -» Open with -» Automator (the second one, not the first one that says install).
 

macstatic

macrumors 68020
Original poster
Oct 21, 2005
2,010
163
Norway
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 installing :) In the case of a service, do not double-click, right-click -» Open with -» Automator (the second one, not the first one that says install).
Good advice! Also in case I myself come across Applescripts or Services that I download.
You mean in case someone creates malicous/harmful code, right?
Actually it seems the special characters did come through correctly here anyway, so people can just as well copy and paste it directly into their Automator app to make the Service themselves.

Thanks for confirming that it can handle any video file FFmpeg can take. I like that your script doesn't re-encode. It makes things faster and doesn't degrade the quality. It now works as intended (or even better actually) so it looks like we can say the project is completed :)
Thanks again for all your help in this 👍 👍 👍
 
Last edited:
  • Like
Reactions: bogdanw
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.