Re: [gentoo-user] FFmpeg and AVI1'd M-JPEGs
On Mon, Jul 20, 2020 at 10:22:49PM +0100, Neil Bothwick wrote: > On Mon, 20 Jul 2020 19:10:17 +0100, Ashley Dixon wrote: > > > Unfortunately, as per [3], Logitech C-series cameras (among others) > > utilise a proprietary extension to the Motion-JPEG format, in which > > H.264 data is attached to the various JPEG key and delta frames in the > > APP0 field [4], as shown when inspecting the data of any frame > > ("AVI1" [5]): > > > > $ ffmpeg -i video.mp4 -vcodec copy %02d.jpg > > What command are you using to record this file in the first place? `ffmpeg -f v4l2 -r 30 -s hd720 -c:v mjpeg -i /dev/video0 -c:v h264 output.mp4` When recording, ffmpeg litters stderr with the error: "unable to decode APP fields: Invalid data found when processing input". This is from the mjpeg module. VLC (and mpv, among others) will play the resulting video without any complaints, due to the `-c:v h264` option invoking the x264 encoder, although it is played at about 4x its original speed for some reason. The integrated Firefox player now refuses to play the file entirely: "Video can't be played because the file is corrupt.". -- Ashley Dixon suugaku.co.uk 2A9A 4117 DA96 D18A 8A7B B0D2 A30E BF25 F290 A8AA signature.asc Description: PGP signature
Re: [gentoo-user] FFmpeg and AVI1'd M-JPEGs
On Mon, Jul 20, 2020 at 09:18:19PM +0100, Michael wrote: > I don't have this webcam so I don't know if it will or won't play nicely with > Linux, but at least ffmpeg seems to contain the requisite mjpeg codec: > > $ ffmpeg -hide_banner -codecs | grep mjpeg > DEVIL. mjpegMotion JPEG (encoders: mjpeg mjpeg_vaapi ) > D.VIL. mjpegb Apple MJPEG-B > D.A.L. adpcm_ima_smjpeg ADPCM IMA Loki SDL MJPEG MJPEG seems fully supported in FFmpeg; it is the Logitech H.264 "internal" streams in the key and delta frames (APP0 field) that are causing the trouble. FFmpeg has no idea how to interpret them, and thus throws loads of warnings. > Again, I don't know what VLC can do with this. :-/ I have a feeling that the VLC issue is different. As mentioned in my original e-mail, it almost crashes (infinite UI-blocking loop) when trying to load these bloody files. When I record a video with OBS (Open Broadcaster Software) using the separate x264 encoding module, the video is obviously no longer MJPEG, and VLC plays it fine. (Nonetheless, I would like to play native Logi MJPEG files.) VLC is supposed to have an MJPEG-demultiplexing module [1, 2], and it seems to be able to find it: $ vlc --list | grep mjpeg VLC media player 3.0.10 Vetinari (revision 3.0.10-0-g7f145afa84) mjpeg M-JPEG camera demuxer ... But when I specify `--demux=mjpeg` on the command-line, it cannot be found: $ vlc --demux=mjpeg mjpeg-test.mp4 main demux debug: looking for demux module matching "mjpeg": 46 candidates main demux debug: no demux modules matched [1] https://git.videolan.org/?p=vlc.git;a=blob;f=modules/demux/mjpeg.c#l49 [2] https://wiki.videolan.org/Documentation:Modules/mjpeg/#Demux -- Ashley Dixon suugaku.co.uk 2A9A 4117 DA96 D18A 8A7B B0D2 A30E BF25 F290 A8AA signature.asc Description: PGP signature
Re: [gentoo-user] FFmpeg and AVI1'd M-JPEGs
On Mon, 20 Jul 2020 19:10:17 +0100, Ashley Dixon wrote: > Unfortunately, as per [3], Logitech C-series cameras (among others) > utilise a proprietary extension to the Motion-JPEG format, in which > H.264 data is attached to the various JPEG key and delta frames in the > APP0 field [4], as shown when inspecting the data of any frame > ("AVI1" [5]): > > $ ffmpeg -i video.mp4 -vcodec copy %02d.jpg What command are you using to record this file in the first place? -- Neil Bothwick Tell me, and I will forget. Show me, and I will remember. Involve me, and I will learn. pgp9jIAKMbr0s.pgp Description: OpenPGP digital signature
Re: [gentoo-user] FFmpeg and AVI1'd M-JPEGs
On Monday, 20 July 2020 19:10:17 BST Ashley Dixon wrote: > Hi List, > > A while ago, I made the grave mistake of buying a Logitech C270 webcam > [1], which initially seemed to be well-supported under Linux as a U.V.C.\ > camera [2]. As shown by the following (partial) output of `v4l2-ctl > --list-formats-ext` suggests, the full 720p@30fps is only supported when > using MJPG. > > ioctl: VIDIOC_ENUM_FMT > Type: Video Capture > > [0]: 'YUYV' (YUYV 4:2:2) > [...] > Size: Discrete 1280x720 > Interval: Discrete 0.133s (7.500 fps) > Interval: Discrete 0.200s (5.000 fps) > [...] > > [1]: 'MJPG' (Motion-JPEG, compressed) > Size: Discrete 1280x720 > Interval: Discrete 0.033s (30.000 fps) > Interval: Discrete 0.040s (25.000 fps) > Interval: Discrete 0.050s (20.000 fps) > Interval: Discrete 0.067s (15.000 fps) > Interval: Discrete 0.100s (10.000 fps) > Interval: Discrete 0.200s (5.000 fps) > [...] > > Unfortunately, as per [3], Logitech C-series cameras (among others) > utilise a proprietary extension to the Motion-JPEG format, in which H.264 > data is attached to the various JPEG key and delta frames in the APP0 field > [4], as shown when inspecting the data of any frame ("AVI1" [5]): > > $ ffmpeg -i video.mp4 -vcodec copy %02d.jpg > $ xxd 01.jpg | head -n 1 > > : ffd8 ffe0 0021 4156 4931 0001 0101 0078 .!AVI1.x >^^ > > Thus, FFmpeg (and programs using FFmpeg) seem to have trouble trouble > correctly parsing these MJPG videos, and VLC almost crashes when trying > to play one (although the Firefox integrated mp4 player does fine): > > $ vlc output.mp4 > > [7f2eec008aa0] main video output error: video output creation > failed [7f2ee8c0ae50] main decoder error: failed to create video output > > $ ffmpeg -i output.mp4 somethingelse.avi > > [mjpeg @ 0x5611aeee7000] unable to decode APP fields: Invalid data > found when processing input > > Some work was done on libav many years ago, in an effort to provide a > bitstream filter to ffmpeg to properly convert these to JPEG/JFIF images, > however I doubt it's relevant any more [6], especially considering that > Gentoo has removed libav, and the corresponding USE-flag in > `virtual/ffmpeg` is forever-masked [7]. > > To conclude, is there any method of making these Logitech'd MJPG files > play nicely with FFmpeg (and VLC) ? Someone on the aforementioned Stack > Overflow question pointed out that Skype is able to read both the outer > MJPG and inner H.264 streams, however I cannot confirm this myself. So > far, Firefox is the only program which can play these video files, and I do > not want to use that as my primary video-player ! > > I also need to provide these files to some non-technical (Windows) users > at a local College, so I want to make them as portable and > standards-conformant as possible. > > Thanks for any guidance, > Ashley. > > P.S. Other than this, it's an extremely good camera for someone on a budget. > > [1] https://www.argos.co.uk/product/4034924 > [2] https://linux-hardware.org/index.php?id=usb:046d-0825 > [3] https://stackoverflow.com/a/56403628 > [4] > https://en.wikipedia.org/wiki/JPEG_File_Interchange_Format#JFIF_APP0_marker > _segment [5] https://exiftool.org/TagNames/JPEG.html#AVI1 > [6] > https://code.videolan.org/libav/libav/commit/ba83c4bfb55d5c3fc6b3959edb0d3c > da07a70241 [7] > https://gitweb.gentoo.org/repo/gentoo.git/tree/profiles/base/use.mask#n15 I don't have this webcam so I don't know if it will or won't play nicely with Linux, but at least ffmpeg seems to contain the requisite mjpeg codec: $ ffmpeg -hide_banner -codecs | grep mjpeg DEVIL. mjpegMotion JPEG (encoders: mjpeg mjpeg_vaapi ) D.VIL. mjpegb Apple MJPEG-B D.A.L. adpcm_ima_smjpeg ADPCM IMA Loki SDL MJPEG Again, I don't know what VLC can do with this. :-/ signature.asc Description: This is a digitally signed message part.