Showing posts with label mplayer. Show all posts
Showing posts with label mplayer. Show all posts

29 November, 2013

Extracting Video from DVDs

Time and again I find a need to snag video from a DVD and perform some routine video processing.

FFMpeg works nicely with standard video files, less nicely with DVD structures.  While you can certainly extract video directly from the DVD VOB files (ref: http://en.wikibooks.org/wiki/Inside_DVD-Video/Directory_Structure) it's less than desirable since the locating the specific VOB file that contains the segment of video your interested in can be a bit of a setback.

Enter Mplayer;
Mplayer can readily play DVD contents in a user friendly way.  It can also dump the file to a more usable file if you can persuade it to do so.

You can extract the full main title into a single VOB file can be done by playing the DVD somewhat normally, but adding a few arguments;


$ mplayer dvd:// -dumpstream -dumpfile /tmp/video.vob


user@River:~$ 
The above will extract the main title into a single VOB file.  Examining with FFMpeg and you'll find that the output file has a video stream and a single audio stream;



$ ffprobe -i /tmp/video.vob

ffprobe version 1.1.2 Copyright (c) 2007-2013 the FFmpeg developers

  built on Feb 10 2013 17:42:38 with gcc 4.4.5 (Debian 4.4.5-8)

  configuration: --enable-filter=split

  libavutil      52. 13.100 / 52. 13.100

  libavcodec     54. 86.100 / 54. 86.100

  libavformat    54. 59.106 / 54. 59.106

  libavdevice    54.  3.102 / 54.  3.102

  libavfilter     3. 32.100 /  3. 32.100

  libswscale      2.  1.103 /  2.  1.103

  libswresample   0. 17.102 /  0. 17.102

[mpeg @ 0x2cd4c60] max_analyze_duration 5000000 reached at 5004678

Input #0, mpeg, from '/tmp/video.vob':

  Duration: 01:37:58.02, start: 0.280633, bitrate: 5012 kb/s

    Stream #0:0[0x1e0]: Video: mpeg2video (Main), yuv420p, 720x480 [SAR 32:27 DAR 16:9], 26.50 fps, 59.94 tbr, 90k tbn, 59.94 tbc

    Stream #0:1[0x80]: Audio: ac3, 48000 Hz, 5.1(side), fltp, 448 kb/s


You may choose an alternative container rather than a VOB by specifying an alternative extension, such as an AVI container by specifying output file video.avi.

Now, we have something we can readily work with.

Let's snag a 30 sec clip starting at 90 seconds in:




$ ffmpeg -i /tmp/video.vob -qscale 0 -ss 90 -t 30 /tmp/clip.mpg



If you're only interested in the video, you can extract only the video by specifying;


$ mplayer dvd:// -dumpvideo -dumpfile /tmp/video01.avi


Or, if you're only interested in listening to the Big Bang Theory like an audio tape, extract only the audio;




$ mplayer dvd:// -dumpaudio -dumpfile /tmp/video01.aac




Cheers.

24 October, 2013

Create Counting Video


On a couple of occasions, I've had the need to create a source video for video processing and testing video processing commands.  A common need is to create a counting video by generating a series of frames and stitching them together at a pre-defined frame rate.

Below is a mechanism for doing so;


$ cat createVideo 
#!/bin/bash

ws=/var/tmp/cache
rm -rf $ws
mkdir -p $ws

for i in `seq 300`; do
  N=$(printf %03d $i)
  convert -size 640x480 -background white -fill black -pointsize 120 -gravity center label:$i $ws/frame-$N.jpg
done

ffmpeg -y -r 2/1 -i $ws/frame-%03d.jpg -r 30/1 $ws/video.avi
mplayer $ws/video.avi


Cheers.

16 March, 2013

FFMpeg Piping to Mplayer

Far too often I find myself playing with ffmpeg, trying to transcode a video and evaluating the results. The typical manner of doing this is taking the input file, generating an output file, then playing with the equivalent of mplayer. The need for the temporary output file is primarily motivated because I wasn't aware how to properly pipe the transcoded video to standard output and pipe it to the display utility (e.g. mplayer). I did however recently figure this out, and decided to post for those of you struggling with the same issue. The following example takes in the popular open-source video, transcoding to mpeg format and uses only the first audio chanel, using same video quality but resizes to 720x480 and pipes the output to mplayer.

ffmpeg -i Videos/big_buck_bunny_1080p_surround.avi -f mpeg -ac 1 -sameq -s 720x480 - | mplayer -
Enjoy.

04 January, 2010

Mplayer + FFMpeg + /dev/video

I've recently published posts for capturing video from a QuickCam Express using FFMpeg. I also posted how to play live video with MPlayer. That covers storing video or playing live video. Playing or storing video with a camera source seems mutually exclusive.

That said, what if you want to store and play live video simultaneously?

Playing live video while storing the incoming video is do-able using these tools and a first-in-first-out (FIFO).

The trick is to recognize that FFMpeg can support converting a single input file into multiple output files. For instance, you can convert a source video file into two output files as follows:


$ ffmpeg -i source.avi /tmp/output.avi /tmp/output.mpg


This command will take the source file source.avi and generate twin output files /tmp/output.avi and /tmp/output.mpg converting them simultaneously.

Similarly, you can use a video device /dev/video rather than an input video file and generate twin output files by using a similar command:


$ ffmpeg -r 15 -s 352x288 -f video4linux -i /dev/video0 /tmp/output.avi /tmp/output.mpg


While cool and closer, attempting to play the file will eventually reach the file end and terminate. Instead, by using a FIFO as an output file and using this FIFO as the input to Mplayer you've accomplished your goal.


$ mkfifo /tmp/vidPipe
$ ffmpeg -y -f video4linux -r 15 -s 352x288 -i /dev/video0 -f avi -vcodec msmpeg4 /tmp/vidPipe /tmp/output.avi


In another terminal window play the fifo with Mplayer using the following command:

$ mplayer /tmp/vidPipe


I love it when a plan comes together.

03 January, 2010

Playing QuickCam Video Stream with Mplayer

I've been toying with developing a Tk UI for multiple video sources, something like a video surveillance or situational awareness console.

I've made some notable progress embedding mplayer into multiple UI frames using precollected video source files and next needed to integration a 'live' video stream. That required determining the 'secret sauce' of arguments to get mplayer to recognize my QuickCam Express webcam....don't laugh, I've had it for years.

For those of you that are interested, the secret sauce is:

$ mplayer -fps 20 -tv driver=v4l:width=352:height=288:device=/dev/video0:outfmt=bgr24 tv://


Cheers.

27 December, 2009

Embedded MPlayer in Tk

Ok, something a bit more interesting.

I've been using mplayer since 'bout 94 (near as I can recall), it's has been and continues to be my video player of choice. In spite of that, I still learn things now and again. Today was an instance of learning a little something about it I didn't know before.

Mplayer supports a slave mode, this was news to me. In that mode it is geared to receive commands to manipulate the player. The intention is to allow the creation of front-ends which are plentiful for that reason. I found this especially useful in embedding Mplayer into a Tk window and binding Tk controls to the player.

Below is a rough sampling of how it can be done.


#!/usr/bin/tclsh
package require Tk

proc Exit { } {
exit
}

proc Play { } {
upvar #0 playerId playerId
puts $playerId "pause"
}

proc ReadPipe {chan} {
upvar #0 playerId playerId
set d [read $chan]
foreach line [split $d \n] {
set line [string trim $line]
if {[regexp {^\*\*\* screenshot '(.*?)' \*\*\*} $line -> filename]} {
# delay to permit the file to appear
after 250 [list OnScreenshot $filename]
}
}
if {[eof $chan]} {
fileevent $chan readable {}
close $chan
set playerId ""
}
}

proc EmbedPlayer { w } {
upvar #0 fileList fileList
upvar #0 playerId playerId
set cmd mplayer
lappend cmd -slave -vf scale=1540:1050 -wid [winfo id $w] -idle

set pipe [open |$cmd r+]
fconfigure $pipe -blocking 0 -buffering line
fileevent $pipe readable [list ReadPipe $pipe]
set playerId $pipe

puts $playerId "load [lindex $fileList 0]"
set fileList [lrange $fileList 1 end]
}

proc main { { fileList [list]} } {
wm title . "User Interface"
wm protocol . WM_DELETE_WINDOW [list Exit]
wm withdraw .

frame .video -width 1540 -height 800
grid .video -sticky news

frame .controls -width 1540 -height 100
button .play -text "Play" -command Play
grid .play -sticky news

grid rowconfigure . 0 -weight 1
grid columnconfigure . 0 -weight 1


option add *tearOff false
. configure -menu [menu .menu]
.menu add cascade -label File -menu [menu .menu.file]
.menu.file add command -label Exit -command Exit
bind .video {
bind %W
{}
EmbedPlayer %W
}
wm deiconify .
}

#---main---
set fileList $argv
main


I stripped this segment out of a more involved utility I'm working on so it isn't as clean as it could be.

Issue ./mplayerUi and Bobs Your Uncle.

30 June, 2009

Power of the Pipe

For quite some time I've it's been a mystery to me why many Unix-flavored toolsuites offer a command line interface supporting inputting or outputting to stdin/stdout respectively.

For example, ffmpeg can utilize stdin in leu of a input file by specifying -; similarly it can utilize stdout in leu of an output file using the same - specifier.

I've recently become aware of how useful this option can be. In particular it allows you to bypass creating unnecessary temporary files.

For example, using ffmpeg you can redirect the output to stdout and into mplayer to review the impacts of varying codecs and video quality specifiers.


$ ffmpeg -i /var/tmp/foo.mpg -f asf - | mplayer -cache 8192 -


Similarly, you can make use of the similar feature with ImageMagick like so:

$ convert Lenna.jpg - | display -


In each case, redirecting to stdout and piping to a consuming display utility eliminates the need for creating a temporary file.

18 June, 2009

Capturing Radio Broadcast Streams with Mplayer

My wife and I took our honeymoon in Australia and I can admit that there are numerous occasions where I hunger for a bit of Aussie. I recently explored how to capture an audio stream to play back on my MP3 player (since our office frowns on streaming).

This is how I've been capturing Triple-J streams for fun;


$ mplayer http://202.6.74.107:8060/triplej.mp3 -dumpstream -dumpfile /tmp/audio.mp3