How do I dump a network stream to a file?

Questions involving a Windows version of FFmpeg.
Post Reply
Videogamer555
Posts: 44
Joined: Sat Nov 09, 2013 1:16 am

How do I dump a network stream to a file?

Post by Videogamer555 » Fri Nov 10, 2017 6:54 am

I've got a stream I'd like to dump to a file. It's like this:
rtsp://someserver/somevideo

I'd like to dump this stream directly to a file without reencoding. I'd like to do it even without remuxing. I'd like to just do a raw dump of the stream as-is.

If I do "ffmpeg.exe -i rtsp://someserver/somevideo -c copy test.mp4" it will take the video and audio streams within the rtsp stream and remux them into an mp4 file. But I want to just blindly dump the content of the network stream into a file (for later remuxing or reencoding). I just want a raw rtsp stream dump as my master-copy.

I was hoping there'd be some command line I could use like "ffmpeg.exe -i rtsp://someserver/somevideo -rawstreamdump output.raw", but in all of the FFMPEG documentation that I've looked through, I can't find anything that seems to support this. I hope I've just been overlooking something, and that maybe one of you guys in this forum would now how to do it. If not, this should definitely be a feature added in a future version of FFMPEG.

navilor
Posts: 51
Joined: Thu May 12, 2011 5:19 pm

Re: How do I dump a network stream to a file?

Post by navilor » Sat Nov 11, 2017 10:17 pm

Video needs to be put into a container such as MP4, MKV, TS or AVI. You can record the raw RTSP stream using Tcpreplay, however playback may be difficult because you would have to replay the stream and have FFmpeg reconnect to it.

http://tcpreplay.appneta.com/

I've been in streaming media since 2008. Recording the live stream to a container is considered not only to be a valid file but can be used as forensic evidence in a court of law as long as the file is unmodified. Make sure to record the content via TCP because you probably don't want UDP packet loss.

ffmpeg -rtsp_transport tcp -i rtsp://someserver/somevideo -codec copy -f mp4 -y out.mp4

Videogamer555
Posts: 44
Joined: Sat Nov 09, 2013 1:16 am

Re: How do I dump a network stream to a file?

Post by Videogamer555 » Sun Nov 12, 2017 3:41 am

navilor wrote:
Sat Nov 11, 2017 10:17 pm
Video needs to be put into a container such as MP4, MKV, TS or AVI. You can record the raw RTSP stream using Tcpreplay, however playback may be difficult because you would have to replay the stream and have FFmpeg reconnect to it.

http://tcpreplay.appneta.com/

I've been in streaming media since 2008. Recording the live stream to a container is considered not only to be a valid file but can be used as forensic evidence in a court of law as long as the file is unmodified. Make sure to record the content via TCP because you probably don't want UDP packet loss.

ffmpeg -rtsp_transport tcp -i rtsp://someserver/somevideo -codec copy -f mp4 -y out.mp4
Actually, my particular source already has a valid container format for file-playback. There are a number of container formats that work both for streaming and for file-playback. In this case, it is an ASF stream. The ASF stream is sent over the RTSP connection. ASF is the same container format used for ASF, WMV, and WMA files. But it also is a valid container for streaming. This means that a raw dump of the stream into a file with the file extension .asf .wmv or .wma should be directly playable in Windows Media Player, without first repackaging it into another container format.

I just need a way to use FFMPEG to take that ASF stream (which is being sent over the RTSP connection), and dump it directly to a file without remuxing it.

If I use "ffmpeg.exe -i rtps://someserver/somevideo -f asf -c copy myvideo.wmv" it will not dump the raw ASF stream. Instead, it will remux it into another ASF stream, which will then be saved to the file. The problem with this is it will likely overwrite timing information (such as original broadcast timestamp, containing the actual time-of-day of the broadcast) with new timing information (starting at time=0). Not only that, it will insert additional metadata like copyright information (it will contain strings like "FFMPEG" or "LAVF"), which were NOT present in the original stream.

I need a simple way of dumping the raw content of the RTSP connection (the actual ASF stream in this case, but from other sources it might be an h264 video stream, or OGG stream, etc). Is there any functionality in FFMPEG to dump the raw content of the network connection (in this case an RTSP connection)?

navilor
Posts: 51
Joined: Thu May 12, 2011 5:19 pm

Re: How do I dump a network stream to a file?

Post by navilor » Sun Nov 12, 2017 6:05 am

I have a cheap RTSP camera and this worked for me once I forced the output container to be asf using the -f option. I had to exclude the audio because the asf container apparently does not like the A-law (also known as G.711pcma_law) codec. The video codec is H.264.

ffmpeg -rtsp_transport -tcp -i rtsp://username:[email protected]:554/11 -codec copy -an -f asf -y out.asf

Note that you will receive the following warning because my build of FFmpeg does not have pthreads.
[udp @ 00000000005ba5c0] 'circular_buffer_size' option was set but it is not supported on this build (pthread support is required)

Videogamer555
Posts: 44
Joined: Sat Nov 09, 2013 1:16 am

Re: How do I dump a network stream to a file?

Post by Videogamer555 » Sun Nov 12, 2017 7:28 am

navilor wrote:
Sun Nov 12, 2017 6:05 am
I have a cheap RTSP camera and this worked for me once I forced the output container to be asf using the -f option. I had to exclude the audio because the asf container apparently does not like the A-law (also known as G.711pcma_law) codec. The video codec is H.264.

ffmpeg -rtsp_transport -tcp -i rtsp://username:[email protected]:554/11 -codec copy -an -f asf -y out.asf

Note that you will receive the following warning because my build of FFmpeg does not have pthreads.
[udp @ 00000000005ba5c0] 'circular_buffer_size' option was set but it is not supported on this build (pthread support is required)
Nope, that's not what I'm looking for. That still REMUXES it. It takes the source ASF stream, splits it into the audio and video streams, and then muxes it into a new ASF stream.

I'm looking for a way to do this

Code: Select all

ffmpeg.exe rtsp://someserver/somevideostream.asf -DumpSourceStreamToFile StreamDump.dat
This should ignore the format (no -f required) and dump whatever the source stream is to the file.

navilor
Posts: 51
Joined: Thu May 12, 2011 5:19 pm

Re: How do I dump a network stream to a file?

Post by navilor » Sun Nov 12, 2017 9:01 am

So basically you want an exact copy of the audio and video stream with the PTS/DTS timestamps kept the same, the metadata kept intact, and no additional data added such as writing application added to the output. A literal binary copy. Too bad FTP, SFTP, and HTTP are not options here.

You might be interested in RTP tools, but it doesn't appear to support ASF for output. In addition it supports RTP streams and not RTSP even though RTSP uses RTP/SDP for track information.

http://www.cs.columbia.edu/irt/software/rtptools/

avconv might be an option but I have not tested it before. It forked from FFmpeg back in 2011 but may add metadata that it was written by avconv.

https://libav.org/avconv.html

I don't think that FFmpeg supports what you want to do.

https://ffmpeg.org/ffmpeg-formats.html

You should request this functionality as a feature.There might be another tool out there, but I do not know what it would be.

GarryBF
Posts: 1
Joined: Fri Nov 17, 2017 4:38 pm

Re: How do I dump a network stream to a file?

Post by GarryBF » Fri Nov 17, 2017 5:06 pm

My advised of this
If you are reencoding in your ffmpeg command line, that may be the reason why it is CPU intensive. You need to simply copy the streams to the single container. Since I do not have your command line I cannot suggest a specific improvement here. Your acodec and vcodec should be set to copy is all I can say.

EDIT: On seeing your command line and given you have already tried it, this is for the benefit of others who come across the same question. The command:
ffmpeg -i rtsp://@192.168.241.1:62156 -acodec copy -vcodec copy c:/abc.mp4

will not do transcoding and dump the file for you in an mp4. Of course this is assuming the streamed contents are compatible with an mp4 (which in all probability they are).

soloism
Posts: 1
Joined: Tue Jan 09, 2018 1:46 am

Re: How do I dump a network stream to a file?

Post by soloism » Tue Jan 09, 2018 1:51 am

The command line

ffmpeg -i rtsp://@192.168.241.1:62156 -acodec copy -vcodec copy c:/abc.mp4


doesn't work for me. What other commands could I use to solve this problem?

gstair
Posts: 1
Joined: Thu Jan 24, 2019 4:00 pm

Re: How do I dump a network stream to a file?

Post by gstair » Thu Jan 24, 2019 4:10 pm

I'm having the same issue you are. Everyone seems to think that using codec copy (-c: copy) will dump the contents to a file, but that's incorrect. ffmpeg will demux then remux the streams identically, but it doesn't retain the base level container information.

My issue is when you pull in a MPEG2-TS stream, ffmpeg won't write the MPEG2-TS container the same as the RTSP source, it ends up having a very low PCR rate. You have to re-mux it to get the rate correct.

Anyway, enough of my problems, on to yours. I found that if you use openRTSP from live555: http://www.live555.com/openRTSP/, it will dump the stream contents to a file. In my case, i'm using this command:

openRTSP -D 1 -c -B 10000000 -b 10000000 -q -Q -d 28800 -P 900 -t rtsp://IP:Port/file.ts

This generates a file without an extension. If you're using a TS stream like me, you can just add the .ts extension and it will be identical to the file you were streaming.

Hope this helps.

Post Reply
'