看影片(支援 *.avi *.wmv)
mp3 我用 CD 轉了不少
影片...沒有
想從 YouTube 上抓一些卡通給他看...
要將 YouTube 影片檔抓下來,google 一下就有很多的教學與網站提供這樣的服務
我找到 http://kej.tw/flvretriever/ 這個網站
將 YouTube 影片網址貼上,就會出現影片真實位址的連結(*.flv格式)
下載後自行改名,並加上 flv 的副檔名,就可以用您的媒體播放軟體播了
(我有裝 codecs: http://opensuse-community.org/Restricted_Formats )
要轉成 avi 格式,我找到 http://www.linux.com/articles/56642 提供的
flv2avi.sh (感謝 Manolis Tzanidakis) 轉貼在此:
#!/bin/sh
if [ -z "$1" ]; then
echo "Usage: $0 {-divx|-xvid} list_of_flv_files"
exit 1
fi
# video encoding bit rate
V_BITRATE=1000
while [ "$1" ]; do
case "$1" in
-divx)
MENC_OPTS="-ovc lavc -lavcopts \
vcodec=mpeg4:vbitrate=$V_BITRATE:mbd=2:v4mv:autoaspect"
;;
-xvid)
MENC_OPTS="-ovc xvid -xvidencopts bitrate=$V_BITRATE:autoaspect"
;;
*)
if file "$1" | grep -q "Macromedia Flash Video"; then
mencoder "$1" $MENC_OPTS -vf pp=lb -oac mp3lame \
-lameopts fast:preset=standard -o \
"`basename $1 .flv`.avi"
else
echo "$1 is not Flash Video. Skipping"
fi
;;
esac
shift
done
將上面的文字檔存成 flv2avi.sh
記得加上執行權限(chmod +x flv2avi.sh)
放在 ~/bin (或 /usr/local/bin)
$ flv2avi.sh -divx VIDEO_FILE.flv
就會將 VIDEO_FILE.flv 轉成 VIDEO_FILE.avi
我花了很長的時間(因為跟程式不熟),從到處的 bash script 範例中抄來抄去(主要是鳥哥的網站)
拼湊出下面的 script
希望將以上步驟簡化,看可不可以教會我兒子自己動手做...
(事實證明他還是只會叫老爸幫他...)
好像是可以用啦,但寫得很難看,希望路過的大哥幫忙提供意見
get_youtube2avi.sh
#!/bin/bash
#抓取 YouTube 影片並利用 flv2avi.sh[1] 轉存為 avi 檔案
if [ -z "$1" ]; then
echo "使用方法: $0 YouTube影片網址"
echo "例如: $0 http://tw.youtube.com/watch?v=yOUR8hlBCOs"
exit 1
fi
#設定參數
#影片預設存檔目錄
VIDEO_DIR=~/影片
#預設暫存目錄
TEMP_DIR="/tmp/get_youtube2avi"
#刪除 flv 檔案
DELETE_FLV="yes"
#flv2avi 參數
FLV2AVI_OPT="-divx"
#檢查(或建立)工作目錄
ls ${VIDEO_DIR} || mkdir -p ${VIDEO_DIR}
ls ${TEMP_DIR} || mkdir -p ${TEMP_DIR}
echo "取得網站原始碼存入暫存目錄..."
rm ${TEMP_DIR}/*
wget -P ${TEMP_DIR} $1
#找尋影片ID及名稱
TempYouTubeFile=`echo $1 | cut -d '/' -f 4 `
TempString=`grep fullscreenUrl ${TEMP_DIR}/${TempYouTubeFile}`
Tempstring=`echo ${TempString} | sed -n 's/ //gp'`
AVI_ID_1=`echo ${TempString#*video_id=} | cut -d \& -f 1`
echo "取得ID_1:"${AVI_ID_1}
AVI_ID_2=`echo ${TempString#*&t=} | cut -d \& -f 1`
echo "取得ID_2:"${AVI_ID_2}
echo "影片ID:"${AVI_ID_1}"&t="${AVI_ID_2}
AVI_NAME=`grep \<title\>YouTube ${TEMP_DIR}/${TempYouTubeFile} | cut -d \> -f 2 | cut -d \< -f 1`
AVI_NAME=`echo ${AVI_NAME} | sed -n 's/ //gp'`
echo "影片名稱:"${AVI_NAME}
#下載flv檔案
echo "開始下載影片..."
wget -P ${TEMP_DIR} http://www.youtube.com/get_video.php?video_id=${AVI_ID_1}"&t="${AVI_ID_2}
echo "影片下載完成!準備進行轉檔..."
rm ${TEMP_DIR}/${TempYouTubeFile}
cp ${TEMP_DIR}/* ${VIDEO_DIR}/${AVI_NAME}.flv
cd ${VIDEO_DIR}
flv2avi.sh ${FLV2AVI_OPT} ${AVI_NAME}.flv
if [ "$?" == 0 ]; then
echo "轉檔完成!"
echo "已經將"${AVI_NAME}".avi 存入"${VIDEO_DIR}"/資料夾中。"
if [ "${DELETE_FLV}" == yes ]; then
rm ${AVI_NAME}.flv
fi
else
echo "吼~出問題了!"
fi
#[1]Thanks Manolis Tzanidakis for flv2avi.sh
#You can get the script flv2avi.sh from http://www.linux.com/articles/56642
#or contact Author : manolis_AT_tzanidakis_DOT_gr
將上面的文字檔存成 get_youtube2avi.sh
一樣 chmod +x get_youtube2avi.sh
放在 ~/bin 或 /usr/local/bin 中
記得 flv2avi.sh 要先裝好
執行
$ get_youtube2avi [YouTube影片網址]
預設使用 YouTube title 相同的名稱,存放在 ~/影片 資料夾中
有興趣可以試試看
下面是執行的過程:
$ get_youtube2avi.sh http://tw.youtube.com/watch?v=p_SsakPOVoQ
get_video?origin=ash-v76.ash.youtube.com&video_id=p_SsakPOVoQ&ip=218.170.117.149®ion=0&signature=B833E3D077C03F3AE115752BA7AEE248A21EA86E.97687192CC6EC27EA365600F5C7CECF241AB3C7F&sver=2&expire=1233187369&key=yt1&ipbits=0&redirect_counter=1
watch?v=p_SsakPOVoQ
取得網站原始碼存入暫存目錄...
--2009-01-29 02:03:51-- http://tw.youtube.com/watch?v=p_SsakPOVoQ
正在查找主機 tw.youtube.com... 208.117.236.74
正在連接 tw.youtube.com|208.117.236.74|:80... 連上了。
已送出 HTTP 要求,正在等候回應... 200 OK
長度: 76528 (75K) [text/html]
Saving to: `/tmp/get_youtube2avi/watch?v=p_SsakPOVoQ'
100%[======================================>] 76,528 18.0K/s in 4.2s
2009-01-29 02:03:56 (18.0 KB/s) -- 已儲存 ‘/tmp/get_youtube2avi/watch?v=p_SsakPOVoQ’ [76528/76528])
取得ID_1:p_SsakPOVoQ
取得ID_2:OEgsToPDskLDLU-EfuSXjNomTpo1TLz7
影片ID:p_SsakPOVoQ&t=OEgsToPDskLDLU-EfuSXjNomTpo1TLz7
影片名稱:YouTube-MrBean豆豆先生~卡通版
開始下載影片...
--2009-01-29 02:03:56-- http://www.youtube.com/get_video.php?video_id=p_SsakPOVoQ&t=OEgsToPDskLDLU-EfuSXjNomTpo1TLz7
正在查找主機 www.youtube.com... 208.65.153.238
正在連接 www.youtube.com|208.65.153.238|:80... 連上了。
已送出 HTTP 要求,正在等候回應... 302 Moved Temporarily
位置: http://tw.youtube.com/get_video.php?video_id=p_SsakPOVoQ&t=OEgsToPDskLDLU-EfuSXjNomTpo1TLz7 [跟隨至新的 URL]
--2009-01-29 02:03:57-- http://tw.youtube.com/get_video.php?video_id=p_SsakPOVoQ&t=OEgsToPDskLDLU-EfuSXjNomTpo1TLz7
正在查找主機 tw.youtube.com... 208.65.153.253
正在連接 tw.youtube.com|208.65.153.253|:80... 連上了。
已送出 HTTP 要求,正在等候回應... 303 See Other
位置: http://v17.cache.googlevideo.com/get_video?origin=ash-v76.ash.youtube.com&video_id=p_SsakPOVoQ&ip=218.170.117.149®ion=0&signature=1AED5FBEA7E4FCA3025A81AAFAA1836E14BFE072.5623A4985C01122656399F791152EF48F0008717&sver=2&expire=1233187422&key=yt1&ipbits=0 [跟隨至新的 URL]
--2009-01-29 02:03:58-- http://v17.cache.googlevideo.com/get_video?origin=ash-v76.ash.youtube.com&video_id=p_SsakPOVoQ&ip=218.170.117.149®ion=0&signature=1AED5FBEA7E4FCA3025A81AAFAA1836E14BFE072.5623A4985C01122656399F791152EF48F0008717&sver=2&expire=1233187422&key=yt1&ipbits=0
正在查找主機 v17.cache.googlevideo.com... 67.69.246.248
正在連接 v17.cache.googlevideo.com|67.69.246.248|:80... 連上了。
已送出 HTTP 要求,正在等候回應... 302 Found
位置: http://tc.cache.googlevideo.com/get_video?origin=ash-v76.ash.youtube.com&video_id=p_SsakPOVoQ&ip=218.170.117.149®ion=0&signature=1AED5FBEA7E4FCA3025A81AAFAA1836E14BFE072.5623A4985C01122656399F791152EF48F0008717&sver=2&expire=1233187422&key=yt1&ipbits=0&redirect_counter=1 [跟隨至新的 URL]
--2009-01-29 02:03:59-- http://tc.cache.googlevideo.com/get_video?origin=ash-v76.ash.youtube.com&video_id=p_SsakPOVoQ&ip=218.170.117.149®ion=0&signature=1AED5FBEA7E4FCA3025A81AAFAA1836E14BFE072.5623A4985C01122656399F791152EF48F0008717&sver=2&expire=1233187422&key=yt1&ipbits=0&redirect_counter=1
正在查找主機 tc.cache.googlevideo.com... 208.117.252.23
正在連接 tc.cache.googlevideo.com|208.117.252.23|:80... 連上了。
已送出 HTTP 要求,正在等候回應... 200 OK
長度: 27052157 (26M) [video/flv]
Saving to: `/tmp/get_youtube2avi/get_video?origin=ash-v76.ash.youtube.com&video_id=p_SsakPOVoQ&ip=218.170.117.149®ion=0&signature=1AED5FBEA7E4FCA3025A81AAFAA1836E14BFE072.5623A4985C01122656399F791152EF48F0008717&sver=2&expire=1233187422&key=yt1&ipbits=0&redirect_counter=1'
100%[======================================>] 27,052,157 84.1K/s in 7m 37s
2009-01-29 02:11:36 (57.8 KB/s) -- 已儲存 ‘/tmp/get_youtube2avi/get_video?origin=ash-v76.ash.youtube.com&video_id=p_SsakPOVoQ&ip=218.170.117.149®ion=0&signature=1AED5FBEA7E4FCA3025A81AAFAA1836E14BFE072.5623A4985C01122656399F791152EF48F0008717&sver=2&expire=1233187422&key=yt1&ipbits=0&redirect_counter=1’ [27052157/27052157])
影片下載完成!準備進行轉檔...
MEncoder 1.0rc2-SUSE Linux 11.0 (i686)-Packman-4.3 (C) 2000-2007 MPlayer Team
CPU: Intel(R) Pentium(R) M processor 1.10GHz (Family: 6, Model: 13, Stepping: 8)
CPUflags: Type: 6 MMX: 1 MMX2: 1 3DNow: 0 3DNow2: 0 SSE: 1 SSE2: 1
Compiled with runtime CPU detection.
success: format: 0 data: 0x0 - 0x19cc87d
libavformat file format detected.
[lavf] Video stream found, -vid 0
[lavf] Audio stream found, -aid 1
VIDEO: [FLV1] 320x239 0bpp 29.970 fps 0.0 kbps ( 0.0 kbyte/s)
[V] filefmt:44 fourcc:0x31564C46 size:320x239 fps:29.97 ftime:=0.0334
==========================================================================
Opening audio decoder: [mp3lib] MPEG layer-2, layer-3
AUDIO: 22050 Hz, 2 ch, s16le, 8.0 kbit/1.13% (ratio: 1000->88200)
Selected audio codec: [mp3] afm: mp3lib (mp3lib MPEG layer-2, layer-3)
==========================================================================
Opening video filter: [expand osd=1]
Expand: -1 x -1, -1 ; -1, osd: 1, aspect: 0.000000, round: 1
Opening video filter: [pp=lb]
==========================================================================
Opening video decoder: [ffmpeg] FFmpeg's libavcodec codec family
Selected video codec: [ffflv] vfm: ffmpeg (FFmpeg Flash video)
==========================================================================
MP3 audio selected.
VDec: vo config request - 320 x 239 (preferred colorspace: Planar YV12)
[PP] Using external postprocessing filter, max q = 6.
VDec: using Planar YV12 as output csp (no 0)
Movie-Aspect is undefined - no prescaling applied.
videocodec: libavcodec (320x239 fourcc=34504d46 [FMP4])
[VE_LAVC] High quality encoding selected (non-realtime)!
New_Face failed. Maybe the font path is wrong.
Please supply the text font file (~/.mplayer/subfont.ttf).
subtitle font: load_sub_face failed.
Writing header...
ODML: vprp aspect is 16384:12236.
Writing header...
ODML: vprp aspect is 16384:12236.
Pos: 0.7s 22f ( 0%) 0.00fps Trem: 5min 25mb A-V:0.070 [0:74]
Skipping frame!
Pos: 1.0s 32f ( 0%) 29.74fps Trem: 4min 27mb A-V:0.070 [660:75]
Skipping frame!
Pos: 1.3s 42f ( 0%) 29.21fps Trem: 6min 37mb A-V:0.070 [724:76]
Skipping frame!
Pos: 1.6s 52f ( 0%) 29.80fps Trem: 7min 44mb A-V:0.068 [708:76]
Skipping frame!
Pos: 2.1s 68f ( 0%) 31.75fps Trem: 7min 40mb A-V:0.070 [654:77]
Skipping frame!
Pos: 577.5s 17312f (87%) 63.72fps Trem: 0min 57mb A-V:0.067 [653:79]
Skipping frame!
Pos: 577.9s 17326f (87%) 63.72fps Trem: 0min 57mb A-V:0.067 [654:79]
Skipping frame!
Pos: 651.5s 19533f (99%) 65.25fps Trem: 0min 58mb A-V:-0.032 [671:79]]
Flushing video frames.
Writing index...
Writing header...
ODML: vprp aspect is 16384:12236.
Video stream: 671.059 kbit/s (83882 B/s) size: 54650829 bytes 651.518 secs 19533 frames
Audio stream: 79.470 kbit/s (9933 B/s) size: 6474642 bytes 651.781 secs
轉檔完成!
已經將YouTube-MrBean豆豆先生~卡通版.avi 存入/home/ray/影片/資料夾中。
$ cd 影片/
$ ls
YouTube-MrBean豆豆先生~卡通版.avi
用 smplayer 播放
寄件者 openSUSE 11.1 |