Last active
March 24, 2017 09:25
-
-
Save unstabler/48465592be876cfd06b2 to your computer and use it in GitHub Desktop.
ffserver streaming
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
stream.m3u8은 iOS / Mac OS X에서 재생하기 위해서 필요합니다. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
for file in *.avi | |
do | |
file_without_ext=$(echo "$file" | sed -e 's/\.avi//') | |
subtitle="$file_without_ext.smi" | |
outfile="$file_without_ext.ts" | |
if ! [ -f "$subtitle" ] | |
then | |
echo "자막 파일 $subtitle 이 존재하지 않습니다! 다음으로 넘어갑니다.." | tee -a encode.log | |
continue | |
fi | |
sami2ass "$subtitle" > "out.ass" | |
ffmpeg -y -i "$file" -bsf h264_mp4toannexb -vcodec libx264 -vf "scale=640:480, ass=out.ass" -r 24 -b:v 550K -tune animation -preset fast -acodec libmp3lame -b:a 112K -af "aresample=44100" "$outfile" | |
echo "$file를 $outfile로 인코드 하였습니다." | tee -a encode.log | |
rm out.ass | |
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env perl | |
# ffmpeg로 파이프를 엽니다. | |
my $endpoint = "http://localhost:8090/feed1.ffm"; | |
open my $ffmpeg, '|-', "ffmpeg -re -f mpegts -i - -codec copy $endpoint"; | |
binmode $ffmpeg; | |
# 동영상 위치를 적절히 수정해 주세요. | |
my @videos = glob '~/streaming/*.ts'; | |
while (1) { | |
my $videoname = $videos[int(rand(scalar @videos))]; | |
# 파일을 읽기 전용 모드로 엽니다. | |
open my $video, '<', $videoname; | |
binmode $video; | |
# 스트림을 조금씩 ffmpeg로 흘려줍니다 | |
while (<$video>) { | |
print $ffmpeg $_; | |
} | |
# 끝났으면 파일을 닫습니다. | |
close $video; | |
} | |
# 죽어버렷!! | |
close $ffmpeg; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Port 8090 | |
BindAddress 0.0.0.0 | |
MaxHTTPConnections 100 | |
MaxClients 100 | |
MaxBandwidth 100000 | |
CustomLog - | |
<Feed feed1.ffm> | |
File ./feed1.ffm | |
FileMaxSize 40M | |
ACL allow 127.0.0.1 | |
</feed> | |
<Stream stream.mkv> | |
Feed feed1.ffm | |
Format matroska | |
AudioCodec libmp3lame | |
StartSendOnKey | |
AVOptionVideo flags +global_header | |
AVOptionAudio flags +global_header | |
Preroll 10 | |
</Stream> | |
<Stream stream.ts> | |
Feed feed1.ffm | |
Format mpegts | |
StartSendOnKey | |
AVOptionVideo flags +global_header | |
AVOptionAudio flags +global_header | |
PreRoll 10 | |
</Stream> | |
<Stream status.html> | |
Format status | |
</Stream> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8"/> | |
<meta name="viewport" content="width=640px" /> | |
<title>Hello, Pi!</title> | |
<link href="./style.css" rel="stylesheet"> | |
<script> | |
window.onload = function() { | |
var video = document.getElementById('video'); | |
if (!( video.canPlayType('video/x-matroska') || video.canPlayType('video/mp2t') || video.canPlayType('application/x-mpegurl'))) { | |
alert("현재 접속하신 브라우저에서는 Matroska(.mkv), MPEG2-TS (.ts) 파일의 재생이 제대로 지원되지 않습니다.\n재생이 불가능할 수도 있습니다."); | |
} | |
} | |
</script> | |
</head> | |
<body> | |
<video id="video" width="640" height="480" controls poster="/thumb.jpg"> | |
<source src="http://pi.unstabler.pl:8090/stream.mkv"> | |
<source src="http://pi.unstabler.pl:8090/stream.ts"> | |
<source src="./stream.m3u8"> | |
</video> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env perl | |
#FIXME : 코드가 개판이라 조금 정리하고 올리겠습니다. 죄송합니다 ㅠㅠ.. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# ffserver를 시작합니다. | |
ffserver -f ~/streaming/ffserver.conf & | |
# BUG: ffserver의 버그로 인해 feed 전에 mkv 헤더를 받아놔야 합니다. | |
# 상당히 멍청한 해결법입니다. | |
sleep 5 | |
wget -O- http://localhost:8090/stream.mkv & | |
sleep 5 | |
kill $! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#EXTM3U | |
http://pi.unstabler.pl:8090/stream.ts |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment