ammen99 / wf-recorder

MIT License
859 stars 63 forks source link

Examples for passing codec parameters #79

Closed apiraino closed 4 years ago

apiraino commented 4 years ago

Hi, I'm trying to increase the quality of the libvpx codec when I create a .webm file.

I tried:

but I could not see any difference.

I'm confused on how in general parameters should be passed to the codec. The man page correctly a generic indication but no specifics. Perhaps some real world examples in wiki? Examples:

Thanks

ammen99 commented 4 years ago

Your examples look good. wf-recorder will print a line to stdout for each codec param passed. Something like

Setting codec option: minrate=500K

Do you see these lines? They should be somewhere in the beginning.

apiraino commented 4 years ago

sorry, yes, I forgot to mention that the parameters are "recognized" by wf-recorder, I see them in the stdout.

But the generated file does not reflect the parameters I use (unless I'm reading wrong the results). Examples:

$ recorder -c libvpx -p minrate=500K -p maxrate=500K -f ~/tmp/recording.webm
...
$ mediainfo ~/tmp/recording.webm
General
Complete name                            : recording.webm
Format                                   : WebM
Format version                           : Version 2
File size                                : 51.6 KiB
Duration                                 : 1 s 799 ms
Overall bit rate                         : 235 kb/s
Writing application                      : Lavf58.20.100
Writing library                          : Lavf58.20.100

Video
ID                                       : 1
Format                                   : VP8
Codec ID                                 : V_VP8
Duration                                 : 1 s 799 ms
Bit rate                                 : 219 kb/s
Width                                    : 1 920 pixels
Height                                   : 1 080 pixels
Display aspect ratio                     : 16:9
Frame rate mode                          : Variable
Compression mode                         : Lossy
Stream size                              : 48.1 KiB (93%)
Default                                  : Yes
Forced                                   : No
$ wf-recorder -c libvpx -p target-bitrate=300 -f ~/tmp/recording.webm
...
$ mediainfo ~/tmp/recording.webm
General
Complete name                            : recording.webm
Format                                   : WebM
Format version                           : Version 2
File size                                : 44.3 KiB
Duration                                 : 883 ms
Overall bit rate                         : 411 kb/s
Writing application                      : Lavf58.20.100
Writing library                          : Lavf58.20.100

Video
ID                                       : 1
Format                                   : VP8
Codec ID                                 : V_VP8
Duration                                 : 883 ms
Width                                    : 1 920 pixels
Height                                   : 1 080 pixels
Display aspect ratio                     : 16:9
Frame rate mode                          : Variable
Compression mode                         : Lossy
Default                                  : Yes
Forced                                   : No
ammen99 commented 4 years ago

Unfortunately, I can't say what is going wrong here. Do the exact same options work as you expect if you pass them to ffmpeg ?

apiraino commented 4 years ago

I tried but I couldn't figure out how to record from any source (desktop or webcam) under Wayland using ffmpeg, so I cannot provide any useful comparison. Do you have an example command line to do that?

Example: ffmpeg -i ??? -f webm out.webm. What should I use there?

If you think there's nothing useful to investigate, I can close this issue (no problem)

soreau commented 4 years ago

Hi, I'm trying to increase the quality of the libvpx codec when I create a .webm file.

I tried:

* wf-recorder -c libvpx -p minrate=500K -p maxrate=500K -f ~/tmp/recording.webm

* wf-recorder -c libvpx -p target-bitrate=300 -f ~/tmp/recording.webm

I suspect you don't see messages like these for your options.

but I could not see any difference.

It is probably the same as https://github.com/ammen99/wf-recorder/issues/39

Try specifying --codec-param="target-bitrate=300" or -ptarget-bitrate=300.

apiraino commented 4 years ago

Thanks @soreau for the suggestion, I did some more tests.

Unfortunately I cannot have consistent results when changing parameters. Parameters are indeed parsed by wf-recorder (tested by adding `--log``) and (I assume) passed on to ffmpeg as shown by the following tests:

Running wf-recorder with different bitrate params:

$ diff bitrate200m.txt bitrate500m.txt
1c1
< $ wf-recorder --log -c libvpx --codec-param="minrate=200M" --codec-param="maxrate=200M" --codec-param="b:v=200M" -f ~/tmp/recording-200m.webm 
---
> $ wf-recorder --log -c libvpx --codec-param="minrate=500M" --codec-param="maxrate=500M" --codec-param="b:v=500M" -f ~/tmp/recording-500m.webm 
3,5c3,5
< Setting codec option: b:v=200M
< Setting codec option: maxrate=200M
< Setting codec option: minrate=200M
---
> Setting codec option: b:v=500M
> Setting codec option: maxrate=500M
> Setting codec option: minrate=500M
83,84c83,84
<   rc_2pass_vbr_minsection_pct:  100000
<   rc_2pass_vbr_maxsection_pct:  100000
---
>   rc_2pass_vbr_minsection_pct:  250000
>   rc_2pass_vbr_maxsection_pct:  250000
100c100

Next, file info for both provided by mediainfo. Resulting bitrate is confusing and does not reflect the above params.

$ diff ~/tmp/diff-200m.txt ~/tmp/diff-500m.txt 
2c2
< Complete name                            : recording-200m.webm
---
> Complete name                            : recording-500m.webm
5,7c5,7
< File size                                : 147 KiB
< Duration                                 : 9 s 714 ms
< Overall bit rate                         : 124 kb/s
---
> File size                                : 146 KiB
> Duration                                 : 9 s 347 ms
> Overall bit rate                         : 128 kb/s
15,16c15,16
< Duration                                 : 9 s 714 ms
< Bit rate                                 : 113 kb/s
---
> Duration                                 : 9 s 347 ms
> Bit rate                                 : 116 kb/s
22c22
< Stream size                              : 133 KiB (90%)
---
> Stream size                              : 132 KiB (91%)

So, end of the line is that either I don't understand how to bend ffmpeg to my will :-) or I don't understand how to use wf-recorder beside generating gif files. A bit more documentation about uses would help, perhaps.

Anyway, I'm closing this as there seems to be no actionable outcome (and I prefer to keep the issue list clean). But feel free to add comments or suggestions.

thanks again

ammen99 commented 4 years ago

@apiraino Did you try with ffmpeg on Xorg? It may very well be that these options do not work as you think they do.

apiraino commented 4 years ago

Yes and I could verify that results differ.

Here's my (final) test runs. In all cases the parameters are "understood" by wf-recorder and ffmpeg:

1) ffmpeg -video_size 1920x1080 -f x11grab -i :0.0+0x0 -c libvpx -crf 4 -b:v 1M output-vp8-crf4-bitrate1M.webm
2) wf-recorder -c libvpx -pcrf=4 -pb:v=1M -f output-vp8-crf4-bitrate1M-wayland.webm
3) wf-recorder -c libvpx --codec-param="crf=4" --codec-param="b:v=1M" -f output-vp8-crf4-bitrate1M-wayland-1.webm

Commands 2 and 3 produce almost the same results so it seems that parameters parsing is equally understood (or equally discarded...).

I expect the above commands to output almost the same file. The reality is that wf-recorder outputs a file of way worse quality:

General
Complete name                            : output-vp8-crf4-bitrate1M.webm
Format                                   : WebM
Format version                           : Version 2
File size                                : 1.49 MiB
Duration                                 : 13 s 380 ms
Overall bit rate                         : 932 kb/s
Writing application                      : Lavf58.20.100
Writing library                          : Lavf58.20.100

Video
ID                                       : 1
Format                                   : VP8
Codec ID                                 : V_VP8
Duration                                 : 13 s 380 ms
Bit rate                                 : 889 kb/s
Width                                    : 1 920 pixels
Height                                   : 1 080 pixels
Display aspect ratio                     : 16:9
Frame rate mode                          : Variable
Compression mode                         : Lossy
Stream size                              : 1.42 MiB (95%)
Writing library                          : Lavc58.35.100 libvpx
Default                                  : Yes
Forced                                   : No

General
Complete name                            : output-vp8-crf4-bitrate1M-wayland.webm
Format                                   : WebM
Format version                           : Version 2
File size                                : 64.4 KiB
Duration                                 : 10 s 713 ms
Overall bit rate                         : 49.2 kb/s
Writing application                      : Lavf58.20.100
Writing library                          : Lavf58.20.100

Video
ID                                       : 1
Format                                   : VP8
Codec ID                                 : V_VP8
Duration                                 : 10 s 713 ms
Bit rate                                 : 40.4 kb/s
Width                                    : 1 920 pixels
Height                                   : 1 080 pixels
Display aspect ratio                     : 16:9
Frame rate mode                          : Variable
Compression mode                         : Lossy
Stream size                              : 52.8 KiB (82%)
Default                                  : Yes
Forced                                   : No
ammen99 commented 4 years ago

This lools like a problem with wf-recorder then, the issue should remain open because it is not solved.

soreau commented 4 years ago

@apiraino I played around with the options here and found that setting only qmin=0 qmax=25 helped while nothing else seemed to.

apiraino commented 4 years ago

@soreau very good finding, impressive results, thanks! I can now generate tiny .webm files with great quality (which was my whole point for replacing the GIF format)