7

Why doesn't this work?

cat /dev/video1 | mplayer -

If I could get that to work, then I could play & record video at the same time using 'tee' to feed mplayer and mencoder.

I want to play live video (from /dev/video1:input=1:norm=NTSC) and record it at the same time without introducing lag.

mplayer plays the video fine (no noticeable lag).

mencoder records it fine.

But I can't figure out how to "tee" the output from /dev/video so that I can feed it to both at the same time. (I know ways to encode it, then immediately play the encoded video, but that introduces too much lag).

If mplayer and mencoder would read from stdin, then I could use 'tee' to solve this.

How can I do it?

[BTW, I'd be happy with ANY solution that plays & records at the same time, as long as it doesn't add lag - I'm not wedded to mplayer. But encoding first and then playing adds lag.]

  • Where's the the /dev/video0 input coming from? A web camera? – slm Oct 22 '13 at 1:14
  • /dev/video0 is the built-in webcam (it's a netbook). /dev/video1 is the input I'm trying to read (a USB video adapter; it's connected to a receiver for a wireless camera) – nerdfever.com Oct 22 '13 at 2:36
8

You need to give it some cache when playing from stdin

cat /dev/video1 | mplayer -cache 1024 -

Without that cache option you'll get the error "Seek failed Cannot seek backward in linear streams"

  • 1
    If you found this on some website could you add the reference to it here? Otherwise it's difficult to understand why this solves the OP's issue. – slm Aug 29 '14 at 12:02
  • I compensated the downvote but only because you are a beginner here. Next time please give at least a minimal elaboration (references, explanation, anything), please. – peterh Aug 29 '14 at 12:48
  • I've edited in a clarification - mplayer needs the cache option in order to playback many streams from stdin. – Mike Redrobe Sep 2 '14 at 15:20
  • This also solves the same problem ("Seek failed Cannot seek backward in linear streams") for http audio steams. – Rudy Matela Oct 18 '16 at 17:03
3

According to the mplayer man page mplayer - should read from stdin, but you also need to specify -noconsolecontrols to prevent mplayer from trying to read keyboard control events from stdin.

  • Thanks, but that doesn't seem to help - see here: pastebin.com/ai78v5W1 <br /> also, if I try it with /dev/video1 I get "Cannot seek backward in linear streams! Seek failed" (this is a live video stream) – nerdfever.com Oct 21 '13 at 23:31
2

I don't think what you want to do is possible using a single mplayer. I found this exact question asked and apparently answer thusly:

excerpt :[MPlayer-users] Display and record a camera ip stream at the same time ?

This work, but I really want to do it in the same mplayer process. Any idea how to write a stream in a file in slave mode ? I haven't find yet the right command in the documentation.

I think it can't be done. MPlayer can play or dump a stream, not both at the same time.

You can, however, dump a stream with one task, and play thar recording stream with another task. At least you wouldn't have twice the network traffic then.

The original question to that answer was this:

I need, at the same time, to display the stream, and the possibility to write it in a file (so, record it). My point is: I would like to do this is the same process.

Actually, I have a process for mplayer in slave mode:

    $ mplayer -slave -wid id_window  camera_address/

And each time I need to record, I start a new process, not in slave this time:

    $ mplayer -dumpvideo camera_address -dumpfile stream.mp4/

This work, but I really want to do it in the same mplayer process. Any idea how to write a stream in a file in slave mode ? I haven't find yet the right command in the documentation.

Using ffmpeg?

Just an idea but I found this wiki post on the ffmpeg website which discusses creating multiple outputs. Perhaps you could split /dev/video1 and then make use of the duplicate streams in mplayer?

  • I don't understand - that'll just play the stream, not record it. I have no problem either playing or recording - I just can't do both at the same time. – nerdfever.com Oct 22 '13 at 2:39
  • @nerdfever.com - whoops I didn't realize you wanted to record it, let me update this. – slm Oct 22 '13 at 3:04
  • Thanks; I know mplayer can't record and play at the same time. That's why I want to run 2 instances (one mplayer, one mencoder) at the same time, both reading from the same /dev/video1 device. If I could get them both (mplayer & mencoder) to read from stdin, then I could use 'tee' to feed them both. But how to get them to take input from stdin in the first place?? [BTW, I'd be happy with ANY solution that plays & records at the same time, as long as it doesn't add lag.] – nerdfever.com Oct 22 '13 at 3:51
  • @nerdfever.com - added additional info about ffmpeg, let me know what you think. – slm Oct 22 '13 at 4:22
  • Thanks again, I'll give it a try. I'm running Mint (Ubuntu) so I'll have to compile ffmpeg myself (they switched to avconv). If ffmpeg can do a video passthru (without encoding) then this might work - if it insists on encoding first, that'll add lag and it won't work for me... but I'll try it. – nerdfever.com Oct 22 '13 at 15:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.