ラベル ffmpeg の投稿を表示しています。 すべての投稿を表示
ラベル ffmpeg の投稿を表示しています。 すべての投稿を表示

20260329

m3u8ファイルからTSビデオをダウンローダ(NASAのビデオのダウンロードのへルパ)


m3u8ファイルからTSビデオをダウンローダ(へルパ)

スクリプトのダウンロードはこちら

【スクリプトエディタで開く】 |

m3uダウンロードBasic.scpt
ソース
001#!/usr/bin/env osascript
002----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
003(*
004NASAのビデオのダウンローダー
005ファイルがTSの分割形式で配信されているビデオ用
006m3u8ファイルからTSファイル名を取得してダウンロードします
007mp4ビデオにするには
008ffmpegが必要です
009
010com.cocolog-nifty.quicktimer.icefloe *)
011----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
012use AppleScript version "2.8"
013use framework "Foundation"
014use framework "AppKit"
015use scripting additions
016property refMe : a reference to current application
017########################
018#設定項目 URL
019set strM3Uurl to ("https://nasaplus.akamaized.net/output/10029-7.m3u8")
020(*
02199999-7_00000.ts: 1920 × 1080
02299999-6_00000.ts: 1280 × 720
02399999-5_00000.ts: 1280 × 720
02499999-4_00000.ts: 960 × 540
02599999-3_00000.ts: 640 × 360
02699999-2_00000.ts: 640 × 360
02799999-1_00000.ts: 480 × 270
028*)
029########################
030#設定項目 ffmpeg
031set strBinPath to ("~/Library/Application Support/bin/ffmpeg/ffmpeg") as text
032########################
033#URL組み立て
034set ocidURLString to refMe's NSString's stringWithString:(strM3Uurl)
035set ocidURL to refMe's NSURL's alloc()'s initWithString:(ocidURLString)
036set strURL to ocidURL's absoluteString() as text
037set ocidHostName to ocidURL's |host|() as text
038set ocidScheme to ocidURL's |scheme|() as text
039set ocidBaseURL to ocidURL's URLByDeletingLastPathComponent()
040set ocidLastPath to ocidBaseURL's lastPathComponent()
041########################
042#テンポラリーダウンロードフォルダ
043#起動時に削除される項目内に作成
044set appFileManager to refMe's NSFileManager's defaultManager()
045set ocidTempDirURL to appFileManager's temporaryDirectory()
046set ocidUUID to refMe's NSUUID's alloc()'s init()
047set ocidUUIDString to ocidUUID's UUIDString
048set ocidSaveDirPathURL to ocidTempDirURL's URLByAppendingPathComponent:(ocidUUIDString) isDirectory:(true)
049#
050set ocidAttrDict to refMe's NSMutableDictionary's alloc()'s init()
051ocidAttrDict's setValue:(511) forKey:(refMe's NSFilePosixPermissions)
052set listDone to appFileManager's createDirectoryAtURL:(ocidSaveDirPathURL) withIntermediateDirectories:(true) attributes:(ocidAttrDict) |error|:(reference)
053
054########################
055#M3Uファイル整形
056#   set ocidM3UFilePathStr to refMe's NSString's stringWithString:(strM3uFilePath)
057#   set ocidM3UFilePath to ocidM3UFilePathStr's stringByExpandingTildeInPath()
058#   set ocidM3UFilePathURL to refMe's NSURL's fileURLWithPath:(ocidM3UFilePath)
059#
060set listResponse to refMe's NSString's alloc()'s initWithContentsOfURL:(ocidURL) encoding:(refMe's NSUTF8StringEncoding) |error|:(reference)
061set ocidReadString to (first item of listResponse)
062#
063set strLF to ("" & linefeed & "") as text
064set strCR to ("" & return & "") as text
065set strCRLF to ("" & return & linefeed & "") as text
066set strSpace to ("" & space & "") as text
067set strTab to ("" & tab & "") as text
068#改行をUNIXに強制
069set ocidReadString to (ocidReadString's stringByReplacingOccurrencesOfString:(strCRLF) withString:(strLF))
070set ocidReadString to (ocidReadString's stringByReplacingOccurrencesOfString:(strCR) withString:(strLF))
071set ocidReadString to (ocidReadString's stringByReplacingOccurrencesOfString:(strLF & strLF) withString:(strLF))
072#改行でArrayにしておく
073set ocidLineArray to ocidReadString's componentsSeparatedByString:(strLF)
074#空行 コメント行削除
075set appPredicate to refMe's NSPredicate's predicateWithFormat:("NOT (self BEGINSWITH '#') AND self.length > 0")
076set ocidLineArrayPre to ocidLineArray's filteredArrayUsingPredicate:(appPredicate)
077#ソート
078set ocidLineArray to ocidLineArrayPre's sortedArrayUsingSelector:("localizedStandardCompare:")
079########################
080#URLコンポーネント初期化
081set ocidURLComponents to refMe's NSURLComponents's alloc()'s init()
082ocidURLComponents's setScheme:(ocidScheme)
083ocidURLComponents's setHost:(ocidHostName)
084set strBasePath to ("/" & ocidLastPath & "/") as text
085########################
086#ダウンロード処理
087set numCnter to 0 as integer
088set numCntArray to ocidLineArray's |count|()
089repeat with itemLine in ocidLineArray
090   if (itemLine as text) is "" then
091      exit repeat
092   end if
093   set boolHasPre to (itemLine's hasPrefix:("#")) as boolean
094   if boolHasPre is false then
095      #URL
096      set ocidFileName to itemLine
097      set strSetPath to ("" & strBasePath & ocidFileName & "") as text
098      (ocidURLComponents's setPath:(strSetPath))
099      set ocidURL to ocidURLComponents's |URL|()
100      set strURL to ocidURL's absoluteString() as text
101      log strURL
102      #保存先
103      set ocidSaveFilePathURL to (ocidSaveDirPathURL's URLByAppendingPathComponent:(ocidFileName) isDirectory:(false))
104      #NSDATA
105      set ocidOption to (refMe's NSDataReadingMappedIfSafe)
106      set listResponse to (refMe's NSData's alloc()'s initWithContentsOfURL:(ocidURL) options:(ocidOption) |error|:(reference))
107      set ocidReadData to (first item of listResponse)
108      if ocidReadData = (missing value) then
109         
110         delay 5
111         set listResponse to (refMe's NSData's alloc()'s initWithContentsOfURL:(ocidURL) options:(ocidOption) |error|:(reference))
112         set ocidReadData to (first item of listResponse)
113      end if
114      #NSDATA
115      set ocidOption to (refMe's NSDataWritingAtomic)
116      set listDone to (ocidReadData's writeToURL:(ocidSaveFilePathURL) options:(ocidOption) |error|:(reference))
117   end if
118   log ("Done: " & numCnter & "/" & numCntArray & "") as text
119   set numCnter to (numCnter + 1) as integer
120end repeat
121
122
123########################
124#コンテンツの収集
125set ocidOption to (refMe's NSDirectoryEnumerationSkipsHiddenFiles)
126set ocidKeyArray to refMe's NSMutableArray's alloc()'s init()
127ocidKeyArray's addObject:(refMe's NSURLPathKey)
128set listResponse to (appFileManager's contentsOfDirectoryAtURL:(ocidSaveDirPathURL) includingPropertiesForKeys:(ocidKeyArray) options:(ocidOption) |error|:(reference))
129set ocidSubPathURLArray to (first item of listResponse)
130
131########################
132#マージファイル
133set ocidMergeFilePathURL to ocidSaveDirPathURL's URLByAppendingPathComponent:("merge.ts") isDirectory:(false)
134set ocidMergeFilePath to ocidMergeFilePathURL's |path|()
135set boolDone to appFileManager's createFileAtPath:(ocidMergeFilePath) |contents|:(missing value) attributes:(missing value)
136########################
137#ソート
138set ocidDescriptor to refMe's NSSortDescriptor's sortDescriptorWithKey:("lastPathComponent") ascending:(yes) selector:("localizedStandardCompare:")
139set ocidDescriptorArray to refMe's NSArray's arrayWithObject:(ocidDescriptor)
140set ocidSortedArray to ocidSubPathURLArray's sortedArrayUsingDescriptors:(ocidDescriptorArray)
141########################
142#マージ
143set ocidMergeFilePathURL to ocidSaveDirPathURL's URLByAppendingPathComponent:("merge.ts") isDirectory:(false)
144set ocidMergeFilePath to ocidMergeFilePathURL's |path|()
145set boolDone to appFileManager's createFileAtPath:(ocidMergeFilePath) |contents|:(missing value) attributes:(missing value)
146#
147set appHandleOut to refMe's NSFileHandle's fileHandleForWritingAtPath:(ocidMergeFilePath)
148repeat with itemFileURL in ocidSortedArray
149   set ocidItemFile to itemFileURL's |path|()
150   set appHandleIn to (refMe's NSFileHandle's fileHandleForReadingAtPath:(ocidItemFile))
151   set ocidItemData to appHandleIn's readDataToEndOfFile()
152   (appHandleOut's writeData:(ocidItemData))
153   appHandleIn's closeFile()
154end repeat
155appHandleOut's closeFile()
156########################
157#
158set ocidURLsArray to (appFileManager's URLsForDirectory:(refMe's NSDesktopDirectory) inDomains:(refMe's NSUserDomainMask))
159set ocidDesktopDirPathURL to ocidURLsArray's firstObject()
160set ocidMP4FilePathURL to ocidDesktopDirPathURL's URLByAppendingPathComponent:("merge.mp4") isDirectory:(false)
161set ocidMP4FilePath to ocidMP4FilePathURL's |path|()
162#
163set ocidBinPathStr to refMe's NSString's stringWithString:(strBinPath)
164set ocidBinPath to ocidBinPathStr's stringByStandardizingPath()
165#コマンド整形
166##FIX用 タイムスケール1000だけ調整
167set strCmd to ("\"" & ocidBinPath & "\" -i \"" & ocidMergeFilePath & "\" -codec:v copy -codec:a copy -movflags +faststart -video_track_timescale 1000 \"" & ocidMP4FilePath & "\"") as text
168do shell script strCmd
169########################
170#テンポラリーデータをゴミ箱へ
171set listDone to (appFileManager's trashItemAtURL:(ocidSaveDirPathURL) resultingItemURL:(ocidSaveDirPathURL) |error|:(reference))
172return
AppleScriptで生成しました

 

20260323

【ffmpeg】コマンド実行・ヘルパ(h264_videotoolbox用)


【ffmpeg】コマンド実行・ヘルパ(h264_videotoolbox用)

20260322

【ffmpeg】インストールヘルパ(ffmpeg.martin-riedl.de用)


【ffmpeg】インストールヘルパ(ffmpeg.martin-riedl.de用)