Wie konvertiere ich am besten .avi-Videos (aufgenommen mit Casio Exilim EX-S500) unter Linux?

May 8th, 2008 by matthias

Mit ffmpeg. Zum Beispiel der Export als MPEG-4 Part 2 Dual Pass, Broadband Quality:

  1. ffmpeg -i infile.avi -s 320×240 outfile.mp4

Diese Form des Konvertierens geht deutlich schneller als ein Export aus kino, also der Umweg über
.dv-Dateien. Außerdem sind die (mit obigem Befehl) entstehenden .mp4-Dateien 2-3mal kleiner als die mit kino als »Medium Quality« exportierten.

Posted in Videobearbeitung | No Comments »

Wie bearbeite ich am besten .avi-Videos (aufgenommen mit Casio Exilim EX-S500) unter Linux?

May 8th, 2008 by matthias

  • Software-Empfehlung: kino, außerdem das zum Ubuntu-Paket empfohlene Pakete ffmpeg (sonst funktioniert der .avi-Import nicht) und die weiteren empfohlenen Pakete (u.a. kinoplus für Plugins).
  • alternative Softwareempfehlung: cinelerra; es gibt Debian-Pakete dazu, jedoch ist etwas Konfiguration nötig weil das Programm auf dem vorliegenden System beim Starten abstürzte
  • Man installiere außerdem die avifile-utils. Mit dem darin enthaltenen Programm avitype kann man z.B. den Typ der von der Kamera Casio Exilim EX-S500 produzierten Videos feststellen.
  • Beim Import wandelt kino die .avi-Dateien in .dv-Dateien. Diese brauchen den fünffachen Speicherplatz.
  • xine und gxine können nicht mehr verwendet werden (zumindest nicht wenn sie auf DirectRendering-Support eingestellt waren) solange das Programm kino läuft; außer wenn sie vor kino gestartet werden, dann jedoch spielt kino den Sound nur abgehackt.

Hinweise zu kino:
kino erzeugt einen falsch synchronisierten Audiostream wenn man mit kino die von der Casio Exilim EX-S500 erzeugten .avi-Dateien importiert. Diess Problem umgeht man indem man die .avi-Datein vorher selbst mit ffmpeg transcodiert.

  1. ffmpeg -i input.avi -sameq output.avi

Dadurch wird der bisherige Audio-Stream (adpcm_ima_wav, 44100 Hz, mono, 177 kb/s) umgewandelt in einen Audio-Stream mit dem der Import von kino besser zurecht kommt (mp2, 44100 Hz, mono, 64 kb/s). Dabei wächst leider die Größe der Videodaten um 30-50% an (aus bisher unbekanntem Grund), die der Audiodaten sinkt jedoch deutlich. Insgesamt steigt die Größe damit um etwa 10%.

Um in Kino eine korrekte Darstellung beim Abspielen zu erreichen muss man die Größe des Fensters auf mind. 942×776 Pixel skalieren (im Modus »Schneiden« sogar 839×849 Pixel) und »Ansicht -> Vergrößern bis es passt« einstellen. Am besten stellt man als fensterspezifische Eigenschaft ein dass eine Größe von 1024×849 Pixeln bei Initialisierung angewandt werden soll und dass das Fenster im Vordergrund gehalten werden soll, um über der KDE-Leiste dargestellt zu werden.

Wie kann man beim Export die Auflösung verringern? Indem man bei Export »Other« wählt und ein entsprechendes Profile beim Export als MPEG-4.

Veröffentlichung im Internet: das verbreitetste Format ist MPEG. Dabei gibt es, beginnend mit dem ältesten, verbreitetsten aber auch technisch am wenigsten entwickelten Standard:

  • MPEG-1
  • MPEG-2: ergibt bei Bitraten ab 3MBit/s (also etwa ab einer Auflösung von 400×300 Pixeln) kleinere Dateigrößen als MPEG-1.
  • MPEG-4 Part 2: Siehe en.wikipedia.org/wiki/MPEG-4_Part_2 ; darauf basiert auch DivX. Es kann in kino über den Tab »Other« exportiert werden, wohl am besten »MPEG-4 MP4 Dual Pass (FFMPEG)« und ein passendes Profil.
  • MPEG-4 Part 10: Siehe en.wikipedia.org/wiki/MPEG-4_Part_10 ; auch bezeichnet als H.264/MPEG-4 AVC, u.a. in kino im Tab »Other«. Noch besser als MPEG-4 Part 2 aber evtl. nicht verbreitet genug so dass MPEG-4 Part 2 der beste Kompromiss aus technischen Möglichkeiten und derzeitiger Verbreitung (2007-07) ist. Der technische Vorteil ist gleiche Videoqualität bei halber Größe oder weniger verglichen mit MPEG-2 (nach en.wikipedia.org/wiki/MPEG-4_Part_10#Overview ).

Zur Archivierung ist vermutlich am besten: H.264/MPEG-4 AVC mit einem High Quality Profile. Zur Veröffentlichung im Internet muss eine deutlich geringere Bitrate gewählt werden, man könnte anbieten: H.264/MPEG-4 AVC mit einem Broadband Profile und als technische Alternative MPEG-4 Part 2 mit einem Broadband-Profile. Im direkten Vergleich von MPEG-4 Part 2 und Part 10 (jeweils mit Broadband Profile, also dadurch gleiche Dateigrößen) war subjektiv kein Qualitätsunterschied feststellbar.

Ungelöste Probleme bisher:

  • Welche Deinterlacing-Einstellung beim MPEG-Export ist am besten (»None« funktioniert auf jeden Fall)?
  • Es müsste möglich sein mit ffmpeg die transcodierten (oder sogar die originalen) .avi-Dateien in
    .dv-Dateien zu verarbeiten die von kino verarbeitet werden können. Aber wie bisher entsteht der folgende Fehler:

    [dv @ 0xb7f992d0]Can't initialize DV format!
    Make sure that you supply exactly two streams:
       video: 25fps or 29.97fps, audio: 2ch/48Khz/PCM
       (50Mbps allows an optional second audio stream)
    Could not write header for output file #0 (incorrect codec parameters ?)

    Bisher benutzter Befehl:

    1. ffmpeg -i infile.avi -ac 2 -ar 48000 -acodec pcm_s16le outfile.dv

Posted in Videobearbeitung | No Comments »

What is a recommendable alternative for a program that captures images from a V4L2 UVC webcam that serves JPEG images (here: Creative Live!Cam Optia)?

April 14th, 2008 by matthias

Working alternative

The only working alternative is, for now, to use gstreamer (to show the stream) and a screenshot tool. You cannot use all video sinks, as some are not accessible to the screenshot tools.

Here, the following did show up a green area when the screen was captured:

  • autovideosink
  • dfbvideosink
  • glimagesink
  • xvimagesink

And the following did not work at all:

  • sdlvideosink
  • gconfvideosink

What can be captured by screenshot tools is “ximagesink”, as can be shown thus:

gst-launch videotestsrc ! queue ! ximagesink
# and in another terminal create a screenshot by saying "scrot"

This also works (the “ffmpegcolorspace” is important!):

gst-launch v4l2src ! jpegdec ! ffmpegcolorspace ! ximagesink
# and in another terminal create a screenshot by saying "scrot"

You may now write a script that gets a screenshot and uploads it to a server.

Many very good snippets for all these are here: http://wiki.laptop.org/go/GStreamer

There are many ways how to get a screenshot of a linux screen: http://tips.webdesign10.com/how-to-take-a-screenshot-on-ubuntu-linux

Perhaps working alternatives

fswebcam

It is possible to use fswebcam (http://www.firestorm.cx/fswebcam).

Take screenshots with gstreamer

You may use gstreamer to take the screenshots. A webcam that serves JPEG images just serves JPEG images one after the other. The following worked to view the first captured image from a file that contains JPEG after JPEG:

gst-launch v4l2src ! filesink location=file.jpg
kuickshow file.jpg

This is even a very promising path, as you can combine some JPGs to reduce the noise.

Use gstreamer to pipe to vlc

You may use gstreamer with a filesink and then pipe that to vlc. The following created basic screen output here:

gst-launch v4l2src ! jpegdec ! autovideosink

The following recorded and played an avi video:

gst-launch v4l2src ! avimux ! filesink location=video.avi
xine video.avi

(Perhaps you need instead something like this or similar, but VLC cannot play this, saying: “avi demuxer error: avi module discarded (invalid file)”:)

gst-launch v4l2src device=/dev/video0 ! avimux ! filesink location=video.avi

The following recorded and played an avi video, using forwarding to stdout:

gst-launch v4l2src ! avimux ! fdsink | cat > video.avi
xine video.avi

(This however makes xine not recognize the format.)

And now, piping to vlc media player is possible by:

gst-launch v4l2src ! avimux ! fdsink | vlc -

(But this is not possible yet.) (You may need the “ffmpegcolorspace” element, it’s important.) (See here for the documentation: http://wiki.videolan.org/Uncommon_uses.)

Something comparable should be possible with xine:

gst-launch v4l2src ! avimux ! fdsink | xine stdin://

(However, xine does not recognize the file format and there’s yet a way to find
how to tell it explicitly about that. See here for that:
http://dvd.sourceforge.net/xine-howto/en_GB/html/howto.html#toc10.17 )

Non-working alternatives

ffmpeg to capture and convert

It is also possible to use ffmpeg to capture and transcode the stream from a V4L2 device. The command would be something like:

ffmpeg -v 100 -f video4linux2 -s 320x240 -i /dev/video0 -f audio_device -i /dev/dsp2 -f m4v test.m4v

This however leads to an error:

[video4linux2 @ 0xb7f64610]Cannot find a proper format.

Which might mean that the camera uses a compressed format. See this mailinglist contribution.

See for that and a discussion of alternatives: http://lists.berlios.de/pipermail/linux-uvc-devel/2007-September/002164.html

You may then pipe the ouput to vlc.

transcode to capture and convert

It is possible to use transcode and and pipe it’s output to VLC (as seen here:
http://wiki.videolan.org/Uncommon_uses ) and stream it from there.

On the transcode side something like:

transcode -x v4l2,null -g 640x480 -i /dev/video0 -w 4000 -y ffmpeg -F mjpeg -o test.avi

This leads however to this error:

[import_v4l2.so]: no usable pixel format supported by card

As also documented here: http://lists.berlios.de/pipermail/linux-uvc-devel/2007-September/002164.html

gstreamer

gstreamer is no alternative as it was impossible to create a network stream from it.

uvc-streamer

It is possible to use UVC-Streamer ( naaa.de/uvc_streamer.htm ), which works for V4L2 devices; however there were compilation errors.

mjpeg-streamer

It is possible to use MJPEG-Streamer, which is the successor to UVC-Streamer; however, compile errors happened in both the 35 and 51 revisions.

uvccapture

It is possible to use uvccapture; however, this is rather a hack and has errors when compiling.

MPEG4IP

MPEG4IP might be a possibility, but their tarball is corrupt and their development stopped.

ucview

You may try ucview (an application based on the unicap framework). There are .debs available; however, I wasn’t able to get an image (though it supports MJPEG); it would be the most comfortable software for capturing selected frames.

luvcview

You may try luvcview.

Posted in Graphikbearbeitung, Sprache: Englisch, Videobearbeitung | No Comments »

How can I use gstreamer with a V4L2 UVC webcam that serves JPEG images for video streaming over the network?

April 4th, 2008 by matthias

You can use “gst-inspect | less” to get a list of the current capabilities of gstreamer and it’s plugins.

To start, you should be able to see live video using this:

gst-launch v4l2src device=/dev/video1 ! jpegdec ! autovideosink

The manpage of gst-launch has an example for “network streaming”, but it doesn’t work here.

But you would have to do something similar like this:

gst-launch v4l2src \
  ! jpegdec \
  ! videoscale \
  ! video/x-raw-yuv, width=320, height=240 \
  ! ffmpegcolorspace \
  ! ffenc_h263 \
  ! video/x-h263 \
  ! rtph263ppay pt=96 \
  ! udpsink host=127.0.0.1 port=8800 sync=false

This does not to work yet:

  WARNUNG: Fehlerhafte Leitung: Konnte ffenc_h2630 nicht mit rtph263ppay0 verbinden

The reason seems to be that jpegdec does not serve the format declared as “video/x-raw-yuv”, and this is detected when trying to connect to RTP payloader. We need an additional encoder here.

The following commands show that the camera servers jpgeg:

$ gst-launch v4l2src ! filesink location=Desktop/test.file
$ gst-typefind ~/Desktop/test.file
/home/matthias/Desktop/test.file - image/jpeg

Additional useful things that can be used in the pipelines: r263depayloader, gconfv4l2src

The best solution will than be to combine this with the VLC multimedia player and server, to stream it. See:

  vlc --longhelp --advanced

Posted in Sprache: Englisch, Videobearbeitung, alle Artikel | No Comments »