encoding H264 from pictures, encoding values manipulation

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

encoding H264 from pictures, encoding values manipulation

Jorge Mas
Hello.

Im new using ffmpeg and mostly in the video field.

im trying to generate a video with the same h264 encoding parameters as a
video that was given to me.

im generating a h264 video parting from pictures, the commands that im
using are the following:

  ./ffmpeg.exe -framerate 25 -i $picture%04d.jpg -g 1 -c:v libx264
-profile:v baseline -level 4.0 -crf 20 -pix_fmt yuv420p $picture.mp4
  ./ffmpeg.exe -i $picture.mp4 -vcodec copy -vbsf h264_mp4toannexb -an
$picture.mp4.h264

after analyzing both of videos with a tool named  SpecialVH264, several
parameters differ between both videos, i.e:
constraint_set0_flag in the original video is 0, but in the one that im
generating the value is 1.

is there a way that i can manipulate that constraint_set0_flag parameter?

thanks
_______________________________________________
ffmpeg-user mailing list
[hidden email]
https://ffmpeg.org/mailman/listinfo/ffmpeg-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".
Reply | Threaded
Open this post in threaded view
|

Re: encoding H264 from pictures, encoding values manipulation

Moritz Barsnick
On Wed, Nov 20, 2019 at 16:38:49 +0100, Jorge Mas wrote:
>   ./ffmpeg.exe -framerate 25 -i $picture%04d.jpg -g 1 -c:v libx264
> -profile:v baseline -level 4.0 -crf 20 -pix_fmt yuv420p $picture.mp4
>   ./ffmpeg.exe -i $picture.mp4 -vcodec copy -vbsf h264_mp4toannexb -an
> $picture.mp4.h264

You don't need to do this in two steps.

> after analyzing both of videos with a tool named  SpecialVH264, several
> parameters differ between both videos, i.e:
> constraint_set0_flag in the original video is 0, but in the one that im
> generating the value is 1.

You should also show us the difference of the console outputs of
$ ffmpeg -i inputvideo
$ ffmpeg -i outputvideo

You should also show us the complete, uncut console output of your
conversion.

> is there a way that i can manipulate that constraint_set0_flag parameter?

If I understand correctly, the flag says something about the profile.
Indeed, libx264 has these code lines:
https://github.com/mirror/x264/blob/d4099dd4c722f52c4f3c14575d7d39eb8fadb97f/encoder/set.c#L129

> sps->b_constraint_set0  = sps->i_profile_idc == PROFILE_BASELINE;
> sps->b_constraint_set1  = sps->i_profile_idc <= PROFILE_MAIN;

So it seems your video is created with the Baseline profile. (We would
be able to see if you provided those outputs.)

Basically, choose a higher profile, e.g. by adding the encoder option
  -profile:v Main
or
  -profile:v High

(It depends what you want constraint_set1_flag to be.)

Cheers,
Moritz
_______________________________________________
ffmpeg-user mailing list
[hidden email]
https://ffmpeg.org/mailman/listinfo/ffmpeg-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".
Reply | Threaded
Open this post in threaded view
|

Re: encoding H264 from pictures, encoding values manipulation

Carl Eugen Hoyos-2
In reply to this post by Jorge Mas
Am Mi., 20. Nov. 2019 um 16:39 Uhr schrieb Jorge Mas <[hidden email]>:

> im trying to generate a video with the same h264 encoding parameters
> as a video that was given to me.

In addition to what Moritz wrote, I'd like to add that this may not be
possible depending on the used encoders.

Carl Eugen
_______________________________________________
ffmpeg-user mailing list
[hidden email]
https://ffmpeg.org/mailman/listinfo/ffmpeg-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".
Reply | Threaded
Open this post in threaded view
|

Re: encoding H264 from pictures, encoding values manipulation

Jorge Mas
Hello Moritz.

i changed the profile to Main

the profile_idc change to 77, i need it to be 66 which it is profile =
baseline


this is the difference using ffmpeg -i

original video
  libavutil      56. 25.100 / 56. 25.100
  libavcodec     58. 43.100 / 58. 43.100
  libavformat    58. 25.100 / 58. 25.100
  libavdevice    58.  6.101 / 58.  6.101
  libavfilter     7. 46.101 /  7. 46.101
  libswscale      5.  4.100 /  5.  4.100
  libswresample   3.  4.100 /  3.  4.100
  libpostproc    55.  4.100 / 55.  4.100
[h264 @ 000001c19ceda580] Stream #0: not enough frames to estimate rate;
consider increasing probesize
Input #0, h264, from 'original.h264':
  Duration: N/A, bitrate: N/A
    Stream #0:0: Video: h264 (Constrained Baseline), yuv420p(progressive),
1344x968, 25 fps, 25 tbr, 1200k tbn, 50.01 tbc

created:

  libavutil      56. 25.100 / 56. 25.100
  libavcodec     58. 43.100 / 58. 43.100
  libavformat    58. 25.100 / 58. 25.100
  libavdevice    58.  6.101 / 58.  6.101
  libavfilter     7. 46.101 /  7. 46.101
  libswscale      5.  4.100 /  5.  4.100
  libswresample   3.  4.100 /  3.  4.100
  libpostproc    55.  4.100 / 55.  4.100
[h264 @ 00000118abc6a680] Stream #0: not enough frames to estimate rate;
consider increasing probesize
Input #0, h264, from
'McLaren-P16-ExtrinsicCalibration-Front_AT102A_1344x968.jpg.mp4.h264no_head':
  Duration: N/A, bitrate: N/A
    Stream #0:0: Video: h264 (Constrained Baseline), yuv420p(progressive),
1344x968 [SAR 1:1 DAR 168:121], 25 fps, 25 tbr, 1200k tbn, 50 tbc


This is the output of the conversion:
ffmpeg version N-92899-g1dcb5b7dca Copyright (c) 2000-2019 the FFmpeg
developers
  built with gcc 8.2.1 (GCC) 20181201
  configuration: --enable-gpl --enable-version3 --enable-sdl2
--enable-fontconfig --enable-gnutls --enable-iconv --enable-libass
--enable-libbluray --enable-libfreetype --enable-libmp3lame
--enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg
--enable-libopus --enable-libshine --enable-libsnappy --enable-libsoxr
--enable-libtheora --enable-libtwolame --enable-libvpx --enable-libwavpack
--enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2
--enable-libzimg --enable-lzma --enable-zlib --enable-gmp
--enable-libvidstab --enable-libvorbis --enable-libvo-amrwbenc
--enable-libmysofa --enable-libspeex --enable-libxvid --enable-libaom
--enable-libmfx --enable-amf --enable-ffnvcodec --enable-cuvid
--enable-d3d11va --enable-nvenc --enable-nvdec --enable-dxva2
--enable-avisynth --enable-libopenmpt
  libavutil      56. 25.100 / 56. 25.100
  libavcodec     58. 43.100 / 58. 43.100
  libavformat    58. 25.100 / 58. 25.100
  libavdevice    58.  6.101 / 58.  6.101
  libavfilter     7. 46.101 /  7. 46.101
  libswscale      5.  4.100 /  5.  4.100
  libswresample   3.  4.100 /  3.  4.100
  libpostproc    55.  4.100 / 55.  4.100
Input #0, image2, from '1344x968.jpg%04d.jpg':
  Duration: 00:00:05.00, start: 0.000000, bitrate: N/A
    Stream #0:0: Video: mjpeg (Baseline), yuvj420p(pc,
bt470bg/unknown/unknown), 1344x968 [SAR 120:120 DAR 168:121], 25 fps, 25
tbr, 25 tbn, 25 tbc
File '1344x968.jpg.mp4' already exists. Overwrite ? [y/N] y
Stream mapping:
  Stream #0:0 -> #0:0 (mjpeg (native) -> h264 (libx264))
Press [q] to stop, [?] for help
[swscaler @ 0000029263bb8340] deprecated pixel format used, make sure you
did set range correctly
[libx264 @ 0000029263673800] using SAR=1/1
[libx264 @ 0000029263673800] using cpu capabilities: MMX2 SSE2Fast SSSE3
SSE4.2 AVX FMA3 BMI2 AVX2
[libx264 @ 0000029263673800] profile Constrained Baseline, level 4.0,
4:2:0, 8-bit
[libx264 @ 0000029263673800] 264 - core 157 r2935 545de2f - H.264/MPEG-4
AVC codec - Copyleft 2003-2018 - http://www.videolan.org/x264.html -
options: cabac=0 ref=1 deblock=1:0:0 analyse=0x1:0x111 me=hex subme=7 psy=1
psy_rd=1.00:0.00 mixed_ref=0 me_range=16 chroma_me=1 trellis=1 8x8dct=0
cqm=0 deadzone=21,11 fast_pskip=1 chroma_qp_offset=-2 threads=6
lookahead_threads=1 sliced_threads=0 nr=0 decimate=1 interlaced=0
bluray_compat=0 constrained_intra=0 bframes=0 weightp=0 keyint=1
keyint_min=1 scenecut=40 intra_refresh=0 rc=crf mbtree=0 crf=20.0
qcomp=0.60 qpmin=0 qpmax=69 qpstep=4 ip_ratio=1.40 aq=1:1.00
Output #0, mp4, to '1344x968.jpg.mp4':
  Metadata:
    encoder         : Lavf58.25.100
    Stream #0:0: Video: h264 (libx264) (avc1 / 0x31637661), yuv420p,
1344x968 [SAR 1:1 DAR 168:121], q=-1--1, 20000 kb/s, 25 fps, 12800 tbn, 25
tbc
    Metadata:
      encoder         : Lavc58.43.100 libx264
    Side data:
      cpb: bitrate max/min/avg: 0/0/20000000 buffer size: 0 vbv_delay: -1
frame=  125 fps= 60 q=-1.0 Lsize=    6028kB time=00:00:04.96
bitrate=9955.0kbits/s speed= 2.4x
video:6026kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB
muxing overhead: 0.021828%
[libx264 @ 0000029263673800] frame I:125   Avg QP:15.53  size: 49362
[libx264 @ 0000029263673800] mb I  I16..4: 59.3%  0.0% 40.7%
[libx264 @ 0000029263673800] coded y,uvDC,uvAC intra: 40.2% 38.9% 21.1%
[libx264 @ 0000029263673800] i16 v,h,dc,p: 64% 20% 10%  7%
[libx264 @ 0000029263673800] i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 32% 22% 25%  3%
 4%  2%  5%  2%  5%
[libx264 @ 0000029263673800] i8c dc,h,v,p: 61% 23% 13%  3%
[libx264 @ 0000029263673800] kb/s:9872.42
ffmpeg version N-92899-g1dcb5b7dca Copyright (c) 2000-2019 the FFmpeg
developers
  built with gcc 8.2.1 (GCC) 20181201
  configuration: --enable-gpl --enable-version3 --enable-sdl2
--enable-fontconfig --enable-gnutls --enable-iconv --enable-libass
--enable-libbluray --enable-libfreetype --enable-libmp3lame
--enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg
--enable-libopus --enable-libshine --enable-libsnappy --enable-libsoxr
--enable-libtheora --enable-libtwolame --enable-libvpx --enable-libwavpack
--enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2
--enable-libzimg --enable-lzma --enable-zlib --enable-gmp
--enable-libvidstab --enable-libvorbis --enable-libvo-amrwbenc
--enable-libmysofa --enable-libspeex --enable-libxvid --enable-libaom
--enable-libmfx --enable-amf --enable-ffnvcodec --enable-cuvid
--enable-d3d11va --enable-nvenc --enable-nvdec --enable-dxva2
--enable-avisynth --enable-libopenmpt
  libavutil      56. 25.100 / 56. 25.100
  libavcodec     58. 43.100 / 58. 43.100
  libavformat    58. 25.100 / 58. 25.100
  libavdevice    58.  6.101 / 58.  6.101
  libavfilter     7. 46.101 /  7. 46.101
  libswscale      5.  4.100 /  5.  4.100
  libswresample   3.  4.100 /  3.  4.100
  libpostproc    55.  4.100 / 55.  4.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '1344x968.jpg.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf58.25.100
  Duration: 00:00:05.00, start: 0.000000, bitrate: 9875 kb/s
    Stream #0:0(und): Video: h264 (Constrained Baseline) (avc1 /
0x31637661), yuv420p, 1344x968 [SAR 1:1 DAR 168:121], 9873 kb/s, 25 fps, 25
tbr, 12800 tbn, 50 tbc (default)
    Metadata:
      handler_name    : VideoHandler
File '1344x968.jpg.mp4.h264' already exists. Overwrite ? [y/N] y
Output #0, h264, to '1344x968.jpg.mp4.h264':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf58.25.100
    Stream #0:0(und): Video: h264 (Constrained Baseline) (avc1 /
0x31637661), yuv420p, 1344x968 [SAR 1:1 DAR 168:121], q=2-31, 9873 kb/s, 25
fps, 25 tbr, 25 tbn, 25 tbc (default)
    Metadata:
      handler_name    : VideoHandler
Stream mapping:
  Stream #0:0 -> #0:0 (copy)
Press [q] to stop, [?] for help
frame=  125 fps=0.0 q=-1.0 Lsize=    6031kB time=00:00:05.00
bitrate=9881.0kbits/s speed= 384x
video:6031kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB
muxing overhead: 0.000000%



El mié., 20 nov. 2019 a las 18:44, Carl Eugen Hoyos (<[hidden email]>)
escribió:

> Am Mi., 20. Nov. 2019 um 16:39 Uhr schrieb Jorge Mas <[hidden email]
> >:
>
> > im trying to generate a video with the same h264 encoding parameters
> > as a video that was given to me.
>
> In addition to what Moritz wrote, I'd like to add that this may not be
> possible depending on the used encoders.
>
> Carl Eugen
> _______________________________________________
> ffmpeg-user mailing list
> [hidden email]
> https://ffmpeg.org/mailman/listinfo/ffmpeg-user
>
> To unsubscribe, visit link above, or email
> [hidden email] with subject "unsubscribe".
_______________________________________________
ffmpeg-user mailing list
[hidden email]
https://ffmpeg.org/mailman/listinfo/ffmpeg-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".
Reply | Threaded
Open this post in threaded view
|

Re: encoding H264 from pictures, encoding values manipulation

Carl Eugen Hoyos-2
Am Do., 21. Nov. 2019 um 10:55 Uhr schrieb Jorge Mas <[hidden email]>:

> i changed the profile to Main
>
> the profile_idc change to 77, i need it to be 66 which it is
> profile = baseline

There is neither a known encoder nor a known decoder that
supports the "baseline" profile, 77 is "constrained baseline"
which is supported by all encoders and decoders.
(constrained baseline is a strict subset of baseline, so 66
is not a wrong value, just a useless one. You can patch
x264 if you need 66, short googling did not reveal an
option to force this value.)

This is what I tried to explain yesterday.

Please find out what top-posting means and avoid it here,
Carl Eugen
_______________________________________________
ffmpeg-user mailing list
[hidden email]
https://ffmpeg.org/mailman/listinfo/ffmpeg-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".
Reply | Threaded
Open this post in threaded view
|

Re: encoding H264 from pictures, encoding values manipulation

Carl Eugen Hoyos-2
Am Do., 21. Nov. 2019 um 11:03 Uhr schrieb Carl Eugen Hoyos
<[hidden email]>:
>
> Am Do., 21. Nov. 2019 um 10:55 Uhr schrieb Jorge Mas <[hidden email]>:
>
> > i changed the profile to Main
> >
> > the profile_idc change to 77, i need it to be 66 which it is
> > profile = baseline
>
> There is neither a known encoder nor a known decoder that

> supports the "baseline" profile, 77 is "constrained baseline"

Sorry, "constrained baseline" is a large number (66 plus
a constant), 77 is "main":

> which is supported by all encoders and decoders.
> (constrained baseline is a strict subset of baseline, so 66
> is not a wrong value, just a useless one. You can patch
> x264 if you need 66, short googling did not reveal an
> option to force this value.)

Carl Eugen
_______________________________________________
ffmpeg-user mailing list
[hidden email]
https://ffmpeg.org/mailman/listinfo/ffmpeg-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".
Reply | Threaded
Open this post in threaded view
|

Re: encoding H264 from pictures, encoding values manipulation

Moritz Barsnick
In reply to this post by Jorge Mas
On Thu, Nov 21, 2019 at 10:54:49 +0100, Jorge Mas wrote:
> i changed the profile to Main
>
> the profile_idc change to 77, i need it to be 66 which it is profile =
> baseline

What are you actually trying to achieve? Do you really need everything
to be identical? Even if you achieve that, the video may still be
different regarding some characteristics, as it's (likely) a different
encoder.

You are going in to quite deep details, so it might be necessary for
you to get an understanding of these values, and what you need them
for.

> This is the output of the conversion:
> Input #0, image2, from '1344x968.jpg%04d.jpg':
>   Duration: 00:00:05.00, start: 0.000000, bitrate: N/A
>     Stream #0:0: Video: mjpeg (Baseline), yuvj420p(pc, bt470bg/unknown/unknown), 1344x968 [SAR 120:120 DAR 168:121], 25 fps, 25

Ah, so you're trying to create a similar video from JPEG files?

> [libx264 @ 0000029263673800] profile Constrained Baseline, level 4.0, 4:2:0, 8-bit

I don't see why libx264 would create a "Constrained Baseline" profile
video if you tell it to use "-profile Main".

> [libx264 @ 0000029263673800] 264 - core 157 r2935 545de2f - H.264/MPEG-4
> AVC codec - Copyleft 2003-2018 - http://www.videolan.org/x264.html -
> options: cabac=0 ref=1 deblock=1:0:0 analyse=0x1:0x111 me=hex subme=7 psy=1
> psy_rd=1.00:0.00 mixed_ref=0 me_range=16 chroma_me=1 trellis=1 8x8dct=0
> cqm=0 deadzone=21,11 fast_pskip=1 chroma_qp_offset=-2 threads=6
> lookahead_threads=1 sliced_threads=0 nr=0 decimate=1 interlaced=0
> bluray_compat=0 constrained_intra=0 bframes=0 weightp=0 keyint=1
> keyint_min=1 scenecut=40 intra_refresh=0 rc=crf mbtree=0 crf=20.0
> qcomp=0.60 qpmin=0 qpmax=69 qpstep=4 ip_ratio=1.40 aq=1:1.00

BTW, these are some of the parameters which may differ from the
original encoder. (Some affect the encoding strategies, some affect the
resulting video.) Do you really understand them all? Do you know which
you want to reproduce?

That said, I don't see how your "original" video has
constraint_set0_flag = 0 while being "Contrained Baseline". As far as
x264 is concerned, this seems like a contradiction.

Cheers,
Moritz
_______________________________________________
ffmpeg-user mailing list
[hidden email]
https://ffmpeg.org/mailman/listinfo/ffmpeg-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".