AppleScripting QuickTime Pro 7 para exportar arquivos .png


0

Como posso usar o AppleScript para salvar arquivos .png no início e no final dos arquivos .mp4 com o QuickTime? Isso é algo que estou fazendo muito e seria bom automatizá-lo. Tenho alguma experiência em scripts, mas não muito.

Estou usando o QuickTime Pro 7 versão 7.6.6. Estou usando o comando export para obter quadros estáticos do mesmo tamanho do meu arquivo de vídeo.

 (* 
Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple Inc. ("Apple") in consideration of your agreement to the following terms, and your use, installation, modification or redistribution of this Apple software constitutes acceptance of these terms. If you do not agree with these terms, please do not use, install, modify or redistribute this Apple software.

In consideration of your agreement to abide by the following terms, and subject to these terms, Apple grants you a personal, non-exclusive license, under Apple's copyrights in this original Apple software ( the "Apple Software" ), to use, reproduce, modify and redistribute the Apple Software, with or without modifications, in source and / or binary forms; provided that if you redistribute the Apple Software in its entirety and without modifications, you must retain this notice and the following text and disclaimers in all such redistributions of the Apple Software. Neither the name, trademarks, service marks or logos of Apple Inc. may be used to endorse or promote products derived from the Apple Software without specific prior written permission from Apple. Except as expressly stated in this notice, no other rights or licenses, express or implied, are granted by Apple herein, including but not limited to any patent rights that may be infringed by your derivative works or by other works in which the Apple Software may be incorporated.

The Apple Software is provided by Apple on an "AS IS" basis. APPLE MAKES NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION THE IMPLIED WARRANTIES OF NON - INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS.

IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL OR CONSEQUENTIAL DAMAGES ( INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION ) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, MODIFICATION AND / OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED AND WHETHER UNDER THEORY OF CONTRACT, TORT ( INCLUDING NEGLIGENCE ), STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Copyright ( C ) 2011 Apple Inc. All Rights Reserved.
*)

(* INSTRUCTIONS
This droplet is designed to process one or more files, or folders containing files, whose icons are dragged onto the droplet icon.
The droplet processes recursively, and will examine the contents of every dragged-on folder, and every sub-folder within those folders, to find and process any files who kind matches the indicated types.
You can set the droplet to process only files of a specific type, such as images, by adding the appropriate data types, name extensions, and type IDs to the values of the properties listed at the top of this script.
Place your script code for processing the found files, within the process_file() sub-routine at the bottom of this script.
*)


(* TO FILTER FOR SPECIFIC FILES, ENTER THE APPROPRIATE DATA IN THE FOLLOWING LISTS: *)
property type_list : {"M4V ", "mpg4"} -- e.g.: {"PICT", "JPEG", "TIFF", "GIFf"} 
property extension_list : {"mp4", "m4v", "mpg"} -- e.g.: {"txt", "text", "jpg", "jpeg"}, NOT: {".txt", ".text", ".jpg", ".jpeg"}
property typeIDs_list : {"public.mpeg-4"} -- e.g.: {"public.jpeg", "public.tiff", "public.png"}

(* IMAGE FILTERING *)
(*
-- QuickTime supported image formats
property type_list : {"JPEG", "TIFF", "PNGf", "8BPS", "BMPf", "GIFf", "PDF ", "PICT"}
property extension_list : {"jpg", "jpeg", "tif", "tiff", "png", "psd", "bmp", "gif", "jp2", "pdf", "pict", "pct", "sgi", "tga"}
property typeIDs_list : {"public.jpeg", "public.tiff", "public.png", "com.adobe.photoshop-image", "com.microsoft.bmp", "com.compuserve.gif", "public.jpeg-2000", "com.adobe.pdf", "com.apple.pict", "com.sgi.sgi-image", "com.truevision.tga-image"}
*)

(* MOVIE FILTERING *)
(*
-- iDVD supported movie formats
property type_list : {"dvc!", "MooV", "M4V ", "mpg4"}
property extension_list : {"mov", "mp4", "dv", "m4v","mpg"}
property typeIDs_list : {"public.mpeg-4", "com.apple.quicktime-movie"}
*)

-- This droplet processes files dropped onto the applet 
on open these_items
    repeat with i from 1 to the count of these_items
        set this_item to item i of these_items
        set the item_info to info for this_item
        if folder of the item_info is true then
            process_folder(this_item)
        else
            try
                set this_extension to the name extension of item_info
            on error
                set this_extension to ""
            end try
            try
                set this_filetype to the file type of item_info
            on error
                set this_filetype to ""
            end try
            try
                set this_typeID to the type identifier of item_info
            on error
                set this_typeID to ""
            end try
            if (folder of the item_info is false) and (package folder of the item_info is false) and (alias of the item_info is false) and ((this_filetype is in the type_list) or (this_extension is in the extension_list) or (this_typeID is in typeIDs_list)) then
                process_file(this_item)
            end if
        end if
    end repeat
end open

-- this sub-routine processes folders 
on process_folder(this_folder)

    tell application "Finder" to set f to name of this_folder
    log "Processing folder: " & f

    set these_items to list folder this_folder without invisibles
    repeat with i from 1 to the count of these_items
        set this_item to alias ((this_folder as Unicode text) & (item i of these_items))
        set the item_info to info for this_item
        if folder of the item_info is true then
            process_folder(this_item)
        else
            try
                set this_extension to the name extension of item_info
            on error
                set this_extension to ""
            end try
            try
                set this_filetype to the file type of item_info
            on error
                set this_filetype to ""
            end try
            try
                set this_typeID to the type identifier of item_info
            on error
                set this_typeID to ""
            end try
            if (folder of the item_info is false) and (package folder of the item_info is false) and (alias of the item_info is false) and ((this_filetype is in the type_list) or (this_extension is in the extension_list) or (this_typeID is in typeIDs_list)) then
                process_file(this_item)
            end if
        end if
    end repeat
end process_folder

-- this sub-routine processes files 
on process_file(this_item)
    -- NOTE that during execution, the variable this_item contains a file reference in alias format to the item passed into this sub-routine
    -- FILE PROCESSING STATEMENTS GO HERE
    tell application "QuickTime Player 7"
        set play movie from beginning when opened to false

        open this_item

        tell front document

            # Remove extension from filename
            set n to (this_item as string)
            set n to text 1 thru ((offset of "." in n) - 1) of n

            # Use .png since it will be overwritten later on...
            set xFileStart to n & "_start.png"
            set xFileEnd to n & "_end.png"

            # Positions (in seconds) in video to stop and take frames
            set sPos to 0
            set ePos to 0

            # Move for start frame
            set current time to (time scale * sPos)
            export to xFileStart as BMP using default settings with replacing

            # Move for end frame
            set current time to (duration - (time scale * ePos))
            export to xFileEnd as BMP using default settings with replacing

            close
        end tell

        # Do the actual conversion to PNG
        tell application "Image Events"
            set bmpFile to open file xFileStart
            save bmpFile as PNG
            set bmpFileEnd to open file xFileEnd
            save bmpFile as PNG
        end tell

    end tell
end process_file

Qual versão do Quicktime? Estou assumindo o 7.x desde que você disse "pro" no título, mas esclareça. Além disso, você está realmente usando o método Arquivo> Exportar, está fazendo uma captura de tela (Command-Option-4) ou está editando> Copiar e colando na Visualização ou em um editor de imagens?
Tubedogg

Eu incluí meu código na postagem. Estou tentando evitar qualquer interação que não seja soltar o arquivo na gota. Acho que estou perto de onde preciso estar, mas, neste momento, ele ainda não está salvando os arquivos png e não sei por que.
Regenegade

Esse script agora funciona e salva o início e o fim de um arquivo .mp4 como .png, com as palavras início e fim anexadas ao nome do arquivo.
Regenegade

Respostas:


0

Aqui está o meu script para exportar para PNG escrito para o Snow Leopard. Você pode ajustar para atender às suas necessidades com facilidade ...


EDIT: Aqui está o seu código incorporando o código original que eu postei. Isso funciona como você descreveu que queria que o applet funcionasse.

property type_list : {"M4V ", "mpg4"} -- e.g.: {"PICT", "JPEG", "TIFF", "GIFf"} 
property extension_list : {"mp4", "m4v", "mpg"} -- e.g.: {"txt", "text", "jpg", "jpeg"}, NOT: {".txt", ".text", ".jpg", ".jpeg"}
property typeIDs_list : {"public.mpeg-4"} -- e.g.: {"public.jpeg", "public.tiff", "public.png"}

on open these_items
    repeat with i from 1 to the count of these_items
        set this_item to item i of these_items
        set the item_info to info for this_item
        if folder of the item_info is true then
            process_folder(this_item)
        else
            try
                set this_extension to the name extension of item_info
            on error
                set this_extension to ""
            end try
            try
                set this_filetype to the file type of item_info
            on error
                set this_filetype to ""
            end try
            try
                set this_typeID to the type identifier of item_info
            on error
                set this_typeID to ""
            end try

            if (folder of the item_info is false) and (package folder of the item_info is false) and (alias of the item_info is false) and ((this_filetype is in the type_list) or (this_extension is in the extension_list) or (this_typeID is in typeIDs_list)) then
                process_file(this_item)
            end if
        end if
    end repeat
end open

-- this sub-routine processes folders 
on process_folder(this_folder)

    # Debug
    tell application "Finder" to set f to name of this_folder
    log "Processing folder: " & f

    set these_items to list folder this_folder without invisibles
    repeat with i from 1 to the count of these_items
        set this_item to alias ((this_folder as Unicode text) & (item i of these_items))
        set the item_info to info for this_item
        if folder of the item_info is true then
            process_folder(this_item)
        else
            try
                set this_extension to the name extension of item_info
            on error
                set this_extension to ""
            end try
            try
                set this_filetype to the file type of item_info
            on error
                set this_filetype to ""
            end try
            try
                set this_typeID to the type identifier of item_info
            on error
                set this_typeID to ""
            end try

            if (folder of the item_info is false) and (package folder of the item_info is false) and (alias of the item_info is false) and ((this_filetype is in the type_list) or (this_extension is in the extension_list) or (this_typeID is in typeIDs_list)) then
                process_file(this_item)
            end if
        end if
    end repeat
end process_folder

-- this sub-routine processes files 
on process_file(this_item)
    tell application "QuickTime Player 7"
        set play movie from beginning when opened to false

        open this_item

        tell front document

            # Remove extension from filename
            set n to (this_item as string)
            set n to text 1 thru ((offset of "." in n) - 1) of n

            # Use .png since it will be overwritten later on...
            set xFileStart to n & "_start.png"
            set xFileEnd to n & "_end.png"

            # Positions (in seconds) in video to stop and take frames
            set sPos to 1
            set ePos to 1

            # Move for start frame
            set current time to (time scale * sPos)
            export to xFileStart as BMP using default settings with replacing

            # Move for end frame
            set current time to (duration - (time scale * ePos))
            export to xFileEnd as BMP using default settings with replacing

            close
        end tell

        # Do the actual conversion to PNG
        tell application "Image Events"
            set bmpFile to open file xFileStart
            save bmpFile as PNG
            set bmpFileEnd to open file xFileEnd
            save bmpFile as PNG
        end tell

    end tell
end process_file

Obrigado por isso. Eu adicionei seu código ao meu script. Modifiquei para fazer o que acho que deveria estar fazendo, mas ainda não estou obtendo nenhuma saída de arquivo.
Regenegade

Algum erro exibido no painel Eventos / Respostas do Editor de Applescript?
Vic

Ele realmente funciona sem gerar erros, mas também não está gerando nenhum .png de
Regenegade

Bem, você copiou pelo código, mas não fez alterações suficientes. Meu código deveria ser executado enquanto o QT já está sendo reproduzido ... Modifiquei seu código como acho que você deveria alterá-lo e atualizarei minha resposta.
Vic

Obrigado Vic. Eu estava obtendo quadros de 1 segundo desde o início e o fim, então é definida a posição em segundos para 0 e isso me deu os quadros inicial e final. Eu realmente aprecio sua ajuda. Eu atualizei o script na pergunta para refletir as alterações. Estou tentando cada vez mais o script da apple e seus scripts me ajudaram tremendamente a entender melhor enquanto eu trabalhava nisso. Obrigado novamente.
Regenegade

0

O Applescript que você está usando para o Quicktime está incorreto e você está solicitando que ele execute comandos provenientes das adições padrão. Eu caminho para

O QuickTime não entenderá isso e falhará. Similarmente:

set frameOne of this_item to track (beginning)
set frameEnd of this_item to track (end)

QT não saberá o início e final são

Você deve ler o dicionário do Quicktime 7 para entender sua sintaxe.

No Editor de scripts, vá para o menu Janela-> Biblioteca

Isso exibirá a janela Biblioteca de dicionário de aplicativos.

Duvido que o QT7 esteja listado, então vá ao localizador e localize o QT7. Normalmente, está na pasta / Aplicativos / Utilitários .

Arraste-o para a janela Biblioteca de dicionário de aplicativos.

Em seguida, clique duas vezes nele.

Um dicionário será aberto. Leia-o para entender o que o QT7 pode entender.

Agora o script.

Não toquei em nenhum de vocês.

O que mudei é o conteúdo do manipulador process_file () . E adicione algum Objective-C para simplificar a obtenção do caminho e do nome do arquivo.

Não se preocupe muito com o material Objective -c. Você ainda pode usar o Applescript convencional que você entende se quiser substituí-lo.

As partes importantes são:

Definir a posição da cabeça de reprodução e exportar o filme. Como estamos usando o BMP, ele exportará apenas o quadro atual.

Observe que eu defino o início como 0 e o final com a duração total do filme - 20.

Pelo que entendi, as medidas estão em milissegundos. Portanto, ter -20 no final não deve fazer muita diferença para o que você captura. Mas faço isso porque um dos meus vídeos de teste teve um problema ao obter o último quadro durante toda a duração. Ocorreu um erro ao dizer quadro inválido. Alterá-lo para um pouco antes de resolver o problema.

Eu também uso um pouco de linha de comando para converter o bmp em um png.

Novamente, para simplificar as coisas (pelo menos para mim), você pode usar seu próprio método aqui, se quiser.

use scripting additions
use framework "Foundation"



(* TO FILTER FOR SPECIFIC FILES, ENTER THE APPROPRIATE DATA IN THE FOLLOWING LISTS: *)
property type_list : {"M4V ", "mpg4"} -- e.g.: {"PICT", "JPEG", "TIFF", "GIFf"} 
property extension_list : {"mp4", "m4v", "mpg"} -- e.g.: {"txt", "text", "jpg", "jpeg"}, NOT: {".txt", ".text", ".jpg", ".jpeg"}
property typeIDs_list : {"public.mpeg-4"} -- e.g.: {"public.jpeg", "public.tiff", "public.png"}


-- This droplet processes files dropped onto the applet 
on open these_items
    repeat with i from 1 to the count of these_items
        set this_item to item i of these_items
        set the item_info to info for this_item
        if folder of the item_info is true then
            process_folder(this_item)
        else
            try
                set this_extension to the name extension of item_info
            on error
                set this_extension to ""
            end try
            try
                set this_filetype to the file type of item_info
            on error
                set this_filetype to ""
            end try
            try
                set this_typeID to the type identifier of item_info
            on error
                set this_typeID to ""
            end try
            if (folder of the item_info is false) and (package folder of the item_info is false) and (alias of the item_info is false) and ((this_filetype is in the type_list) or (this_extension is in the extension_list) or (this_typeID is in typeIDs_list)) then
                process_file(this_item)
            end if
        end if
    end repeat
end open

-- this sub-routine processes folders 
on process_folder(this_folder)
    set these_items to list folder this_folder without invisibles
    repeat with i from 1 to the count of these_items
        set this_item to alias ((this_folder as Unicode text) & (item i of these_items))
        set the item_info to info for this_item
        if folder of the item_info is true then
            process_folder(this_item)
        else
            try
                set this_extension to the name extension of item_info
            on error
                set this_extension to ""
            end try
            try
                set this_filetype to the file type of item_info
            on error
                set this_filetype to ""
            end try
            try
                set this_typeID to the type identifier of item_info
            on error
                set this_typeID to ""
            end try
            if (folder of the item_info is false) and (package folder of the item_info is false) and (alias of the item_info is false) and ((this_filetype is in the type_list) or (this_extension is in the extension_list) or (this_typeID is in typeIDs_list)) then
                process_file(this_item)
            end if
        end if
    end repeat
end process_folder

-- this sub-routine processes files 
on process_file(this_item)
    tell application "QuickTime Player 7"
        set thisDoc to open this_item -- This will open the file in Quicktime
        tell thisDoc
            set xFolder to its path
            set duro to its duration

        end tell

    end tell

    -->> Objective - c to get the name and file path
    set xFolder to current application's NSString's stringWithString:(xFolder as string)

    set file_path to ((xFolder's stringByDeletingLastPathComponent) as string) & "/"


    set file_name to xFolder's lastPathComponent

    set file_name to (file_name's stringByDeletingPathExtension) as string
    --<<


    tell application "QuickTime Player 7"
        tell thisDoc
            set current time to 0
            set xFileStart to file_path & file_name & "_start.png"

            export track 1 to xFileStart as BMP using default settings with replacing
            delay 1
            do shell script ("sips -s format png " & (quoted form of xFileStart)) -- convert to png
            set current time to (duro - 20)
            set xFileEnd to file_path & file_name & "_end.png"
            export track 1 to xFileEnd as BMP using default settings with replacing
            delay 1
            do shell script ("sips -s format png " & (quoted form of xFileEnd)) -- convert to png
        end tell
        close thisDoc
    end tell
end process_file

Também incorporei esse script porque estou tentando entender os scripts. Por alguma razão, esse script é duas vezes mais lento que o abaixo. Isso ocorre devido às adições de script ou ao objetivo c chamado? Fora isso, funcionou bem e fez o que eu estava tentando fazer. É apreciado.
Regenegade
Ao utilizar nosso site, você reconhece que leu e compreendeu nossa Política de Cookies e nossa Política de Privacidade.
Licensed under cc by-sa 3.0 with attribution required.