This forum has been archived. All content is frozen. Please use KDE Discuss instead.

HD Motion-JPEG Rec601 ??

Tags: None
(comma "," separated)
Inapickle
Registered Member
Posts
157
Karma
3

HD Motion-JPEG Rec601 ??

Wed Dec 28, 2016 5:06 pm
I've just been testing some raw HD video clips from several DSLR cameras (Nikon, Panasonic) that were recorded in Motion-JPEG format. Loading the clips into KDenLive 16.12.0 (on Kubuntu 16.04 AMD64) I was surprised to see that Clip Properties reported the colorspace as ITU-R-601, which seemed a bit odd given that this is HD material, not Standard Definition

Analysing the clips with FFProbe also the color primaries are reported to be bt470bg (i.e. smpte170m=Rec.601). Example:

Code: Select all
ffprobe version N-82664-g801b5c1 Copyright (c) 2007-2016 the FFmpeg developers
  built with gcc 5.4.0 (GCC)
  configuration: --enable-gpl --enable-version3 --disable-w32threads --enable-d
va2 --enable-libmfx --enable-nvenc --enable-avisynth --enable-bzlib --enable-fo
tconfig --enable-frei0r --enable-gnutls --enable-iconv --enable-libass --enable
libbluray --enable-libbs2b --enable-libcaca --enable-libfreetype --enable-libgm
 --enable-libgsm --enable-libilbc --enable-libmodplug --enable-libmp3lame --ena
le-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenh264 --enable-l
bopenjpeg --enable-libopus --enable-librtmp --enable-libschroedinger --enable-l
bsnappy --enable-libsoxr --enable-libspeex --enable-libtheora --enable-libtwola
e --enable-libvidstab --enable-libvo-amrwbenc --enable-libvorbis --enable-libvp
 --enable-libwavpack --enable-libwebp --enable-libx264 --enable-libx265 --enabl
-libxavs --enable-libxvid --enable-lzma --enable-decklink --enable-zlib
  libavutil      55. 41.101 / 55. 41.101
  libavcodec     57. 66.108 / 57. 66.108
  libavformat    57. 58.101 / 57. 58.101
  libavdevice    57.  2.100 / 57.  2.100
  libavfilter     6. 67.100 /  6. 67.100
  libswscale      4.  3.101 /  4.  3.101
  libswresample   2.  4.100 /  2.  4.100
  libpostproc    54.  2.100 / 54.  2.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'X:/22485969.mov':
  Metadata:
    major_brand     : qt
    minor_version   : 537331972
    compatible_brands: qt  pana
    creation_time   : 2010-06-10T16:50:54.000000Z
  Duration: 00:00:12.00, start: 0.000000, bitrate: 52100 kb/s
    Stream #0:0(eng): Video: mjpeg (jpeg / 0x6765706A), yuvj420p(pc,bt470bg/un
nown/unknown), 1920x1080, 51586 kb/s, 30 fps, 30 tbr, 30 tbn, 30 tbc (default)
    Metadata:
      creation_time   : 2010-06-10T16:50:54.000000Z
      encoder         : Photo - JPEG
    Stream #0:1(eng): Audio: pcm_s16be (twos / 0x736F7774), 16000 Hz, 2 channel
, s16, 512 kb/s (default)
    Metadata:
      creation_time   : 2010-06-10T16:50:54.000000Z
[FORMAT]
filename=X:/22485969.mov
nb_streams=2
nb_programs=0
format_name=mov,mp4,m4a,3gp,3g2,mj2
format_long_name=QuickTime / MOV
start_time=0.000000
duration=12.000000
size=78150730
bit_rate=52100486
probe_score=100
TAG:major_brand=qt
TAG:minor_version=537331972
TAG:compatible_brands=qt  pana
TAG:creation_time=2010-06-10T16:50:54.000000Z
[/FORMAT]


If that really is the case, does it mean that KDenLive will be acting on that information and applying Rec.601 coefficients when converting to and back from RGB and deriving luma and RGB values for the Videoscopes ? Also when using Curves, does it mean that Rec.601 should be selected for the 'Luma Formula' instead of Rec.709?
It just seems strange that one would use Rec.601 co-efficients for HD material.

To see if it made any difference, I also tried transcoding another HD-AVC.mp4 DSLR clip (with full range luma) to MJPEG, setting the encode colorspace to BT709:

Code: Select all
ffmpeg -i X:\EOSM3FS.mp4 -vcodec mjpeg -q:v 2 -colorspace bt709 X:\EOSM3FS_MJPEG.mov

The encode completed without any errors/warnings:
Code: Select all
ffmpeg version N-82664-g801b5c1 Copyright (c) 2000-2016 the FFmpeg developers
  built with gcc 5.4.0 (GCC)
  configuration: --enable-gpl --enable-version3 --disable-w32threads --enable-dx
va2 --enable-libmfx --enable-nvenc --enable-avisynth --enable-bzlib --enable-fon
tconfig --enable-frei0r --enable-gnutls --enable-iconv --enable-libass --enable-
libbluray --enable-libbs2b --enable-libcaca --enable-libfreetype --enable-libgme
 --enable-libgsm --enable-libilbc --enable-libmodplug --enable-libmp3lame --enab
le-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenh264 --enable-li
bopenjpeg --enable-libopus --enable-librtmp --enable-libschroedinger --enable-li
bsnappy --enable-libsoxr --enable-libspeex --enable-libtheora --enable-libtwolam
e --enable-libvidstab --enable-libvo-amrwbenc --enable-libvorbis --enable-libvpx
 --enable-libwavpack --enable-libwebp --enable-libx264 --enable-libx265 --enable
-libxavs --enable-libxvid --enable-lzma --enable-decklink --enable-zlib
  libavutil      55. 41.101 / 55. 41.101
  libavcodec     57. 66.108 / 57. 66.108
  libavformat    57. 58.101 / 57. 58.101
  libavdevice    57.  2.100 / 57.  2.100
  libavfilter     6. 67.100 /  6. 67.100
  libswscale      4.  3.101 /  4.  3.101
  libswresample   2.  4.100 /  2.  4.100
  libpostproc    54.  2.100 / 54.  2.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'X:\EOSM3FS.mp4':
  Metadata:
    major_brand     : mp42
    minor_version   : 1
    compatible_brands: mp42avc1CAEP
    copyright       :
    copyright-eng   :
    creation_time   : 2015-04-19T13:07:02.000000Z
  Duration: 00:00:46.88, start: 0.000000, bitrate: 22232 kb/s
    Stream #0:0(eng): Video: h264 (High) (avc1 / 0x31637661), yuvj420p(pc, bt709
), 1920x1080, 22088 kb/s, 25 fps, 25 tbr, 25k tbn, 50k tbc (default)
    Metadata:
      creation_time   : 2015-04-19T13:07:02.000000Z
    Stream #0:1(eng): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, flt
p, 127 kb/s (default)
    Metadata:
      creation_time   : 2015-04-19T13:07:02.000000Z
Output #0, mov, to 'X:\EOSM3FS_MJPEG.mov':
  Metadata:
    major_brand     : mp42
    minor_version   : 1
    compatible_brands: mp42avc1CAEP
    copyright       :
    copyright-eng   :
    encoder         : Lavf57.58.101
    Stream #0:0(eng): Video: mjpeg (jpeg / 0x6765706A), yuvj420p(pc,bt709/unkno
wn/unknown), 1920x1080, q=2-31, 200 kb/s, 25 fps, 12800 tbn, 25 tbc (default)
    Metadata:
      creation_time   : 2015-04-19T13:07:02.000000Z
      encoder         : Lavc57.66.108 mjpeg
    Side data:
      cpb: bitrate max/min/avg: 0/0/200000 buffer size: 0 vbv_delay: -1
    Stream #0:1(eng): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, flt
p, 128 kb/s (default)
    Metadata:
      creation_time   : 2015-04-19T13:07:02.000000Z
      encoder         : Lavc57.66.108 aac
Stream mapping:
  Stream #0:0 -> #0:0 (h264 (native) -> mjpeg (native))
  Stream #0:1 -> #0:1 (aac (native) -> aac (native))
Press [q] to stop, [?] for help
frame=   47 fps=0.0 q=2.0 size=    6400kB time=00:00:02.34 bitrate=22341.4kbits/...
....frame= 1170 fps=121 q=2.0 Lsize=  199255kB time=00:00:46.86 bitrate=34826.6kbits
/s speed=4.84x
video:198483kB audio:745kB subtitle:0kB other streams:0kB global headers:0kB mux
ing overhead: 0.013574%
[aac @ 00000000004e7020] Qavg: 464.457

But when I examined the MJPEG encode with FFProbe the Color Primary was again reported as being BT470bg.
Inapickle
Registered Member
Posts
157
Karma
3

Re: HD Motion-JPEG Rec601 ??

Thu Jan 12, 2017 3:52 am
Well I've reached my own conclusions on this.

Transcoding a Rec709 source directly to MJPEG with ffmpeg does not in itself effect a change in the color matrix to Rec601. That is to say, when encoded like so....

Code: Select all
ffmpeg -i {Path}\Test_Rec709.mp4 -vcodec mjpeg -q:v 2 {Path}\Test_MJPEG.mov

....the color-matrix of the MJPEG encode is still Rec709.

To do so requires assertive conversion of the color matrix of the decode output from Rec709 to Rec601:
Code: Select all
ffmpeg -i {Path}\Test_Rec709.mp4 -vf colormatrix=bt709:bt601 -vcodec mjpeg -q:v 2 {Path}\Test_MJPEG_Rec601.mov

However, for some reason FFProbe always reports the Color Primary of MJPEG files as being bt470bg. Just why, I don't know. Unless someone can offer a better explanation, my best guess is that it is some legacy from the standard definition days when MJPEG was in vogue i.e. it is an assumptive association - "recognized as MJPEG - so assumed to be Rec601". MediaInfo doesn't report any Color Primary/Matrix Coefficient information for MJPEG files, so the 'bt470bg' designation is surely an FFProbe thing.

And unfortunately this does have implications when importing 'direct' Rec709 > MJPEG transcodes into KDenLive. They get treated as if they are Rec601 when they are not, and as a result Rec601 coefficients are incorrectly applied in the internal color-space conversions that take place, resulting in color inaccuracies.

How I can I be certain of all of this?

Using metric difference analyses, I first examined the YUV characteristics of MJPEG files encoded with and without Rec709>Rec601 color-matrix conversion and compared them with lossless encodes (of the same Rec709 source), where the Rec709 color-matrix had likewise been retained or converted to Rec601. That confirmed without any doubt that MJPEG transcodes retained a Rec709 color-matrix, unless assertively converted to Rec601.

I then used these files for input into KDenLive (noting the respective color-space reported in Clip Properties), rendered out to UTVideo and in the same manner compared the YUV characteristics of the test input and rendered files using metric analyses. In addition, I compared the RGB Histograms obtained when the input and rendered files were converted to RGB (with AVISynth) using Rec709 and Rec601 coefficients. From the pattern of results obtained, it was clear that KdenLive does indeed treat all MJPEG encodes as being Rec601, and it is reasonable to assume that this results from FFProbe reporting the color primary as being bt470bg.

As such, I would not at all recommend using MJPEG as an intra-frame edit intermediate for Rec709 sources, at least with KDenLive.

When I went on to carry out similar tests with Cinelerra CV 2.3 and HV (6), both of which use Quicktime, I did not see this behavior. MJPEG transcodes were only interpreted as being Rec601 when the color-matrix was assertively converted from Rec709 to Rec601 on encoding. And strangely enough, so did Cinelerra 5.1 (Good Guy), which does use ffmpeg for import and export. That said, the latest Cinelerra 5.1 update has a major issue with all input formats, so it's not exactly a yard stick to compare with. Enough said.

Anyhow, I'm sure most people would not consider using MJPEG as an edit intermediate with KDenLive when there are better alternatives, but it's something to bear in mind.

Edit: Actually what's more interesting, and potentially significant, is that I've now gone back to examine the native 1080p DSLR clips that were recorded in MJPEG format:

Inapickle wrote:I've just been testing some raw HD video clips from several DSLR cameras (Nikon, Panasonic) that were recorded in Motion-JPEG format. Loading the clips into KDenLive 16.12.0 (on Kubuntu 16.04 AMD64) I was surprised to see that Clip Properties reported the colorspace as ITU-R-601, which seemed a bit odd given that this is HD material, not Standard Definition


And using the same difference metrics to compare the YUV characteristics of original files with lossless ffmpeg transcodes (with and without color-matrix conversion) I find that the native files are also Rec709, and not 'bt470bg' as reported by FFProbe and ITU-R-601 as reported by KDenLive Clip Properties.

I also tried changing the color-space from ITU-R 601 to ITU-R 709 in the 'Force Properties' section of Clip Properties and it made no difference to the outcome.


Bookmarks



Who is online

Registered users: Bing [Bot], Google [Bot], kde-naveen, Sogou [Bot], Yahoo [Bot]