Learn Rtmpdump by example

Source: Internet
Author: User
Tags prepare iptables server port advantage

Original address: http://pclosmag.com/html/Issues/201104/page19.html

It is strongly recommended to get used to English, CTRL + hold the link above and jump.


RTMP specification:http://www.adobe.com/devnet/rtmp.html

rtmpdump:http://rtmpdump.mplayerhq.hu/


Introduction

Today, technology is innovating and we are getting new possibilities. Television broadcasts are not outdated and are progressing. Today, you can watch TV online and watch TV on demand. But if you can record what they will be. Don't worry, some shows and live broadcasts (not all of them) can be recorded.

If you are old, you will remember the age of the tape recorder (VCR). You can press the "button" key, turn on the video recorder and close it soon, then rewind it and you can play the newly recorded show on TV. What did the computer age bring?


some theories

Today, television is put into many popular streaming formats and protocols, broadcast over the Internet.

* Of course you've heard these streaming formats: FLV,MP4,F4V

*windows media streaming: wmv,asf,asx, and more

There are also a number of different stream formats, for example:

*flash Video: Http,rmtp,rtmpe

*windows Media Videos: Http,rtsp,mms, and others

Let's take a look at the services broadcast with the RMTP protocol. What is it. Wikipedia says: "Real time Messaging Protocol (RTMP: Live messaging protocol) was originally purchased by Macromedia Corporation (acquired by Adobe Corporation in 05) in order to, between flash players and servers, Proprietary protocols developed for the transmission of audio and video and data over the Internet. Now the company is owned by Adobe and it opens up the specification of this set of protocols. ”

So if your favorite online service (TV or video library) relies on the RTMP protocol, then you have a good chance to save its video stream as a local file. There is an excellent tool that can be used to record TV broadcast streams and video on demand, which is "rtmpdump". is what. It is a console toolkit for rtmp streams, based on whether this word (console) console represents an advantage or disadvantage. I think this is a great advantage of the tool, its use of the rules is very simple, you enter the command and parameters, it includes the video server address, and then get a file to meet the needs, including recorded TV programs. You don't see any graphical input on the screen, and you don't have any other useless information. It just connects to the server, consumes only the network traffic, and logs the video to your hard drive. If you are familiar with the "wget" tool, you can imagine its strength.


Prepare

It's time to start. In order for your operating system to be "Rtmpdump", you should get the same name installation package from the corresponding warehouse and install it. This package has other uses, called "Rtmpsuck". This tool can record the video stream, but we only use it as an accessibility tool for the "rtmpdump" query option.

In order to use "Rtmpsuck", we need to prepare a bit. "Rmtpsuck" is an rtmp local proxy server, which itself transmits the network to the Internet to detect the streaming rtmp protocol while it is a parameter. "Rtmpsuck" has no parameters, so if you run "Rtmpsuck" you will get:

RTMP Proxy Server ... Streaming on rtmp://0.0.0.0:1935

That is to say that the server is running and detecting port 1935, it is necessary to realize that this is the default port of the RTMP server. But under such circumstances, "Rtmpsuck" is useless, why. Because to make it work, you need to relocate the rtmp stream to a proxy server, which helps us learn the connection parameters to the media server in turn. To do this, as "root", run the following command:

Iptables-t nat-a output-p tcp--dport 1935-m owner \! --uid-owner root-j REDIRECT

The command means that a new rule is added to the table in the IP table to control your network flow, which will be streamed to a default rtmp external server port (1935) TCP stream, relocated to a local rtmp proxy service side, except for the "root" stream. So, if you open a Web page in the browser to play the media stream, your traffic will flow through that proxy server, and "Rtmpsuck" will provide you with some information that can be used in "Rtmpdump". After you have obtained all the information, you can close "Rtmpsuck" directly by "CTRL + C" and remove the "iptables" rule that you added earlier:

Iptables-t nat-d output-p tcp--dport 1935-m owner \! --uid-owner root-j REDIRECT


Example 1: Online IP TV broadcast "Russia Today" (Russian external 24-hour international news channel)

Step 1: Run a terminal with root privileges:

Iptables-t nat-a output-p tcp--dport 1935-m owner \! --uid-owner root-j REDIRECT

Step 2: ... :

Rtmpsuck

Step 3: Under normal user, open Firefox type address: http://rt.com/on-air/rt-america-air/

Step 4: Switch to the root user and you will see the following:

App:live Flashver:lnx 10,1,82,76
swfurl:http://rt.com/s/swf/player5.4.viral.swf
Tcurl:rtmp://rt.fms.visionip.tv/live
pageurl:http://rt.com/on-air/rt-america-air/
Playpath:rt_us_3

After some time, use "CTRL + C" to close.

Depending on the quality of your connection, you will also get a different "playpath" option.

You can change the video quality options by following the Playpath command:

Rt_us_3–high
Rt_us_2–medium
Rt_us_1–low

Step 5: Root permission Execution command:

Iptables-t nat-d output-p tcp--dport 1935-m owner \! --uid-owner root-j REDIRECT

Step 6: Normal users:

Rtmpdump-r rtmp://rt.fms.visionip.tv/live \
-A live \
-y rt_us_3 \ w http://rt.com/s/swf/player5.4.viral.swf \
-P http://rt.com/on-air/rt-america-air/\
-F "LNX 10,1,82,76" \
-O ~/rt.flv \
-V \
-B 600

After 10 minutes (600 seconds) in the home directory, you will get a video file, "rt.flv".

To run the "rtmpdump" manual command, you will see the meaning of the parameters in the above command:

Mans Rtmpdump

The option "-V" is superfluous and can be removed if your recording succeeds.


Exercise 1: If you live in Eurasia (or both are inconvenient for you), you can also go past the parameters of the main radio program, which is available for this link: http://rt.com/on-air/

Rtmpdump-r rtmp://fms5.visionip.tv/live \
-Y rt_3 \
-O ~/$FILENAME \
-B 1200

Example 2: Online IP TV broadcast "Bloomberg"

Repeat the steps, address: http://www.bloomberg.com/tv/

Step 6: Normal User: (\ For line continuation, don't be confused yo)

Rtmpdump-r rtmpt://cp87869.live.edgefcs.net/live \
-A live \
-Y us_300@21006 \
-W http://player.ooyala.com/static/cacheable/29d28e187072cf05af879e362d57b42d/player_v2.swf \
-P http://www.bloomberg.com/tv/\
-F "LNX 10,1,82,76" \
-O ~/bloomberg.flv \
-V \
-B 600 \
--live

Here we add "--live" to make the function work properly.


Example 3: Live TV "Euronews"

The address for this live stream is: http://www.euronews.net/news/streaming-live/

"Rtmpdump" gave us the following:

App:rtpeuronewslive
Flashver:lnx 10,1,82,76
swfurl:http://www.euronews.net/media/player_live_1_7.swf
Tcurl:rtmp://178.32.100.43:1935/rtpeuronewslive
pageurl:http://www.euronews.net/news/streaming-live/
Playpath:eng_euronews-flash-750.sdp

Then our orders are:

Rtmpdump-r rtmp://178.32.100.43:1935/rtpeuronewslive \
-A rtpeuronewslive \
-Y ENG_EURONEWS-FLASH-750.SDP \
-W http://www.euronews.net/media/player_live_1_7.swf \
-P http://www.euronews.net/news/streaming-live \
-F "LNX 10,1,82,76" \
-O ~/euronews.flv \
-B 600


Example 4: Video on Demand "Deutsche Welle"

There are a lot of good shows on this page: http://www.dw-world.de/dw/0,,4756,00.html

If you try the above techniques, waiting for you will be disappointed, and when you are disappointed, you may not be able to eat. The reason is that the server is broadcasting at this time with a different port. If you review under the "Rtmpsuck" source, you will see "1935" as the default port of the RTMP server is written dead, this is why "Rtmpsuck" will not help us in this case.

And to bring me a new tool is "tcpdump", it is a console network sniffer. One of the tricks of the tool is to be able to display printable symbols in the Web newspaper, which makes it easy to crawl Web pages and this type of stuff. If the tool is not installed in the system, you should do so immediately. The next utility is "grep", which helps to print out a pattern-matching line, and the matching rule can be set.

Let's get a good show of a European way of life, called "Euromaxx". We assume that the RTMP proxy server is off and the relocation stream is not working.

Step 1: Root permissions:

Tcpdump-ieth0-nn-a |grep-e "rtmp"-E "connect"-E "Play" >/euromaxx.txt

This string, which includes the network interface contained in the network stream and flows through (eth0 in my case) mode (RTM, connect or play), the information is recorded in the "Euromaxx.txt" file, located in the root directory "/".

Step 2: Normal user, open Firefox Web page: http://mediacenter.dw-world.de/english/video/#!/93184/euromaxx/Program=7555

And start playing the video. After the video plays for a while, press the "Pause" button in the embedded player and click on Firefox's refresh key. can be repeated 4 times.

Step 3: Root permissions, interrupt the terminal run routine (CTRL + C).

Step 4: Open the file "Euromaxx.txt" to find such a piece of text:

Connect.? ..... app..
a4337/dwwod1/. Flashver ... LNX 10,1,82,76..swfurl.; http://mediacenter.dw-world.de/player/flash/media.player.swf. Tcurl. *rtmpt://tvone.fcod.llnwd.net/a4337/dwwod1/. Fpad....capabilities.@m........audiocodecs.@.........videocodecs. @o ... videofunction.? ..... pageurl. Khttp://mediacenter.dw-world.de/english/video/#!/93184/euromaxx/program=7555..object. H..... P.....play .......; Mp4:dwtv_video/flv/eme/emagen100311-eu Romaxx01ep_sd_avc.mp4

Now you can easily determine the "rtmpdump" option.

Step 5: Normal user run:

Rtmpdump-r rtmpt://tvone.fcod.llnwd.net/a4337/dwwod1/\
-A a4337/dwwod1/\
-Y mp4:dwtv_video/flv/eme/emagen100311-euromaxx01ep_sd_avc.mp4 \
-F "LNX 10,1,82,76" \
-W http://mediacenter.dw-world.de/player/flash/media.player.swf \
-P http://mediacenter.dw-world.de/english/video/#!/93184/euromaxx/Program=7555 \
-O ~/euromaxx.flv

Later you will find that the recorded file already exists in the home directory.

The flaw with this technique is that you encounter dots "." In a place where the strings are inappropriate. The reason is that it is in fact a string of text format is placed in two web newspapers, it should be continuous, and then "tcpdump" the non-printable symbol into a point "." Then, if there is an error, type "-V" in the "rmtpdump" command to view the debugging information. If "Rtmpdump" is not able to connect to the server at all, it is likely that this is a bad URL.


Concluding remarks (original: Finish stroke)

It is a natural hope to record some in a program list. But if you have the same name record file, it will be overwritten by later files. To avoid this situation, it is convenient to include the name of the live server in the file name and to record the time information so that it will not be duplicated. The following script shows this technique, which can be used for the first live TV broadcast example we recorded:

#!/bin/bash
Basename= "RT"
Filename= "$BASENAME" _ ' Date +%y-%m-%d_%h%m%s '. flv
Rtmpdump-r rtmp://rt.fms.visionip.tv/live \
-Y rt_us_3 \
-O ~/$FILENAME \
-B 1200


Exercise 2: Write a script for the dispatch table to record yesterday's show, on the on-demand video example, with this hint:

yesterday=$ (date-d yesterday + "%d%m%y")


#!/bin/bash
yesterday=$ (date-d yesterday + "%d%m%y")
Rtmpdump-r rtmpt://tvone.fcod.llnwd.net/a4337/dwwod1/\
-A a4337/dwwod1/\
-y Mp4:dwtv_video/flv/eme/emagen "$YESTERDAY"-euromaxx01ep_sd_avc.mp4 \
-W http://mediacenter.dw-world.de/player/flash/media.player.swf \
-P "http://mediacenter.dw-world.de/english/video/#!/75622/euromaxx/Program=7555" \
-F "LNX 10,1,82,76" \
-O ~/euromaxx_ "$YESTERDAY". flv


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.