Learn rtmpdump through examples

Source: Internet
Author: User

Address: http://pclosmag.com/html/Issues/201104/page19.html

It is strongly recommended that you use the English language, CTRL + press the above link to jump.

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

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

Introduction

Today, technology is being innovated, and we have gained new possibilities. Television broadcasting programs are not outdated and are making progress. Today, you can watch online TV and watch TV programs on demand. But what if you can record them? Don't worry, some programs and live broadcasts (not all) can be recorded.

If you are older, you will remember the age of the (VCR) video recorder. You can press the "button" key to turn on the video recorder and close it soon. Then, after the rewind, you can play the recorded program on the TV. What has the computer age brought about?

Some Theories

Today, TV is put into many popular stream formats and protocols, broadcast over the Internet.

* Of course you have heard of these stream formats: FLV, MP4, and f4v.

* Windows Media streams: WMV, ASF, Asx, and others

There are also many different stream formats, for example:

* Flash video: HTTP, rmtp, rtmpe

* Windows Media video: HTTP, RTSP, MMS, and others

Let's take a look at the services broadcast using the rmtp protocol. What is it? "Real Time messaging protocol (rtmp: Real-Time Message Protocol) was initially acquired by Macromedia (which was acquired by Adobe In). To ensure that, between flash players and servers, proprietary protocol developed for transmitting audio and video and data over the Internet. The company is now owned by Adobe and it opens up the specifications of this Protocol ."

Therefore, if your favorite online service (TV or video database) depends on the rtmp protocol, you have a good chance to save the video stream as a local file. There is an excellent tool that can be used to record television broadcasting streams and video on demand. It is "rtmpdump ". What is it? It is a console toolkit. Does the console mean an advantage or disadvantage for rtmp streams? I think this is a great advantage of this tool. Its usage rules are very simple. You enter commands and parameters, including the address of the video server, and then get a file that meets your needs, contains recorded TV programs. You cannot see any graphical input on the screen, and there is no other useless information. It only connects to the server and only consumes network traffic. It records videos to your hard disk. If you are familiar with the "wget" tool, you can imagine its strength.

Preparation

It's time to start. To make the operating system available with "rtmpdump", you should obtain the installation package with the same name from the corresponding warehouse and install it. This package has other purposes, called "rtmpsuck ". This tool can record video streams, but we only use it as an auxiliary tool for the "rtmpdump" query option.

To use "rtmpsuck", we need to prepare it. "Rmtpsuck" is an rtmp local proxy server that transmits its own network to the Internet, detects the flow of rtmp protocol, and is also 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, the server is running and the port 1935 is detected. It is necessary to realize that this is the default port of the rtmp server. But in this case, "rtmpsuck" is useless. Why? To make it work, you need to relocate the rtmp stream to a proxy server, which helps us to know the connection parameters with the Media Server in sequence. For this reason, as "root", run the following command:

Iptables-T Nat-A output-p tcp -- dport 1935-M owner \! -- UID-owner root-J redirect

This command adds a new rule to the IP table in the table to control your network stream and transfers the outbound traffic to the TCP stream of the default rtmp external server port (1935, relocated to a local rtmp proxy server, except for the "root" stream. Therefore, if you open a webpage in your browser to play a media stream, your traffic will flow through the proxy server, and "rtmpsuck" will provide you with information that can be used in "rtmpdump. After obtaining all the information, you can press Ctrl + C to disable rtmpsuck and remove the previously added "iptables" rule:

Iptables-T nat-D Output-p tcp -- dport 1935-M owner \! -- UID-owner root-J redirect


Example 1: Online IP television broadcast "Russia today" (Russian 24-hour international news channel)

Step 1: run a terminal with the root permission:

Iptables-T Nat-A output-p tcp -- dport 1935-M owner \! -- UID-owner root-J redirect

Step 2 :...... :

Rtmpsuck

Step 3: Open Firefox under a common user, 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
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 a while, press Ctrl + C to close it.

Depending on your connection quality, you will also get different "playpath" options.

You can change the video quality options by running the following playpath command:

Rt_us_3-high
Rt_us_2-Medium
Rt_us_1-low

Step 5: run the command with the root permission:

Iptables-T nat-D Output-p tcp -- dport 1935-M owner \! -- UID-owner root-J redirect

Step 6: common 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

Ten minutes (600 seconds) later in the home directory, you will get a video file, "Rt. FLV ".

Run the "rtmpdump" manual command and you will see the meaning of the parameters in the above command:

Man rtmpdump

The option "-V" is redundant. If your recording is successful, you can remove it.

Exercise 1: If you live in Eurasia (or the two are inconvenient for you), you can also go to the parameters of the main broadcast program, available link: http://rt.com/on-air/

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

Example 2: Online IP television broadcast "Bloomberg"

Repeat 1 ~ Step 5 address: http://www.bloomberg.com/ TV/

Step 6: normal user: (\ is the row connection. Don't be confused)

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 normally.

Example 3: TV broadcast "Euronews"

This live stream address: http://www.euronews.net/news/streaming-live/

"Rtmpdump" gave us the following:

APP: rtpeuronewslive
Flashver: lnx
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 command is:

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: apsaravideo for VOD "Deutsche Welle"

On this web page can find a lot of good programs: http://www.dw-world.de/dw/0,,4756,00.html

If you try the above technologies, you will be disappointed. When you are disappointed, you may not be able to eat. The reason is that different ports are used for server broadcast. If you review the source code of "rtmpsuck", you will see that "1935" is written to the default port of the rtmp server, that's why "rtmpsuck" is useless in this case.

The new tool for me is "tcpdump", which is a network sniffer on the console. A trick of this tool is to display printable symbols in the Network reports, which is easy to capture web pages and such items. If this tool is not installed in the system, you should do it immediately. The next utility is "grep", which helps to print the row that matches the pattern. matching rules can be set.

Let's get a good European lifestyle program called "euromaxx". Let's assume that the rtmp proxy server is closed and the redirection stream is not working.

Step 1: Root permission:

Tcpdump-ieth0-nn-A | grep-e "rtmp"-e "Connect"-e "play">/euromaxx.txt

This string contains the network stream and the network interface that flows through (eth0 is in our form (RTM, connected or deleted, the information will be recorded in the euromaxx.txt file, and located in the root directory "/".

Step 2: ordinary user, open Firefox web page: http://mediacenter.dw-world.de/english/video! /93184/euromaxx/program = 7555

And start playing the video. After playing the video for a while, press the "pause" button on the embedded player and click the refresh key of Firefox. It can be repeated four times.

Step 3: Root permission, interrupt the routine running on the terminal (CTRL + C ).

Step 4: open the file ”euromaxx.txt and find the following text:

Connect .?.......... App ..
A4337/dwwod1/... flashver... lnx,. 76..swf URL ...... videofunction .?......... Pageurl .. khttp: // mediacenter.dw-world.de/engish/video /#! /93184/euromaxx/program = 7555... object. encoding .@.........
................ Closestream ..................... H ..... P ..... play ............; MP4: dwtv_video/FLV/EME/emagen100311-eu romaxx01ep_sd_avc.mp4

Now you can easily determine the "rtmpdump" option.

Step 5: run as a common user:

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 disadvantage of this technology is that you encounter dots "." in an inappropriate string ".". The reason is that, in fact, it is a string in text format that is placed in two Network reports. It should have been continuous, and then "tcpdump" turns unprintable symbols into points ".". If an error occurs, type "-V" in the "rmtpdump" command to view the debugging information. If "rtmpdump" cannot connect to the server at all, this may be a wrong URL.

Conclusion(Original article: Finish stroke)

Recording in a program list is a natural hope. However, if you record the file with the same name, it will be overwritten by the subsequent file. To avoid this situation, you can easily include the name of the live video server into the file name and record the time information, so that it will not be repeated. The script below shows this technique, which can be used to record the first live TV broadcast example:

#! /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 scheduling table to record the program of yesterday. In the on-demand video example, use the following prompt:

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.