OpenShot / openshot-qt

OpenShot Video Editor is an award-winning free and open-source video editor for Linux, Mac, and Windows, and is dedicated to delivering high quality video editing and animation solutions to the world.
http://www.openshot.org
Other
4.32k stars 537 forks source link

(Still) Beyond completely messed up video bitrate settings #1680

Closed TheLEGObrick closed 3 years ago

TheLEGObrick commented 6 years ago

There are significant inconsistencies with how OpenSoft makes use of video bitrates when exporting videos, at least with videos that are made of pictures and not other videos

System Details:

To Reproduce Steps to reproduce the behaviour:

  1. Add roughly a dozen pictures
  2. Export as video with 5 Mb/s, 192 kb/s and 1 b/s bitrates
  3. See that the resulting video bitrates are virtually nowhere close to the set ones

Expected behavior I expected it to... well... actually work, in that the bitrate used would be exactly what I set it to use

Screenshots Export with 192 kb/s video bitrate image Export with 1 b/s video bitrate image

peanutbutterandcrackers commented 6 years ago

@gary9872 - Perhaps you'd have some idea regarding this, good sir?

DylanC commented 6 years ago

@TheLEGObrick Can you try v2.4.2 and let us know if you have any success?

Valouleloup commented 6 years ago

@DylanC I just tried to export a 4K video (MP4 h264) with 1MB/s, 15MB/s, 40MB/s and 60MB/s bitrate settings and I'm always getting a ~80-90MB/s bitrate video. Win 7 Openshot 2.4.2

DylanC commented 6 years ago

@Valouleloup - Thanks for the response. I'll open this up again.

TheLEGObrick commented 6 years ago

Uh, sorry about the ridiculously late response, but I'll try see that when I get the time to

PetteriAimonen commented 5 years ago

I'm getting the same behaviour on Linux (Ubuntu 18.04, OpenShot 2.4.1). Video is HD 720p 30FPS profile. Tried MP4 h264 and WebM (libvpx), both seem to give very high bitrates even though I've set it to 2 Mbps.

PetteriAimonen commented 5 years ago

Hmm, I'm trying to debug this a bit. At least for my system, the bitrate (384000 in this test) is getting passed to libopenshot and also to libav:

#4  0x00007f243adec2d5 in openshot::FFmpegWriter::WriteFrame (this=0x6c1a110, frame=std::shared_ptr (use count 6, weak count 0) = {...})
    at /build/libopenshot-2OFXY3/libopenshot-0.1.9+dfsg1/src/FFmpegWriter.cpp:369
369 /build/libopenshot-2OFXY3/libopenshot-0.1.9+dfsg1/src/FFmpegWriter.cpp: No such file or directory.
(gdb) p *this
$1 = { = {_vptr.WriterBase = 0x7f243b071b20 , info = {has_video = true, has_audio = true, has_single_image = false, 
      duration = 0, file_size = 0, height = 720, width = 1280, pixel_format = -1, fps = {num = 30, den = 1}, video_bit_rate = 384000, pixel_ratio = {num = 1, den = 1}, 
      display_ratio = {num = 16, den = 9}, vcodec = "libvpx", video_length = 0, video_stream_index = -1, video_timebase = {num = 1, den = 30}, interlaced_frame = false, 
      top_field_first = false, acodec = "libvorbis", audio_bit_rate = 96000, sample_rate = 44100, channels = 2, channel_layout = openshot::LAYOUT_STEREO, audio_stream_index = -1, 
      audio_timebase = {num = 1, den = 1}}}

(gdb) p *video_st->codec
$7 = {av_class = 0x7f243957f920 , log_level_offset = 0, codec_type = AVMEDIA_TYPE_VIDEO, codec = 0x7f24395b0680 , 
  codec_name = '\000' , codec_id = AV_CODEC_ID_VP8, codec_tag = 0, stream_codec_tag = 0, priv_data = 0x39050c0, internal = 0x5812c20, opaque = 0x0, 
  bit_rate = 384000, bit_rate_tolerance = 4000000, global_quality = 0, compression_level = -1, flags = 4194304, flags2 = 0, extradata = 0x0, extradata_size = 0, time_base = {num = 1, 
    den = 30}, ticks_per_frame = 1, delay = 0, width = 1280, height = 720, coded_width = 1280, coded_height = 720, gop_size = 12, pix_fmt = AV_PIX_FMT_YUV420P, me_method = 5, 
  draw_horiz_band = 0x0, get_format = 0x7f24388baa80 , max_b_frames = 0, b_quant_factor = 1.25, rc_strategy = 0, b_frame_strategy = 0, 
  b_quant_offset = 1.25, has_b_frames = 0, mpeg_quant = 0, i_quant_factor = -0.800000012, i_quant_offset = 0, lumi_masking = 0, temporal_cplx_masking = 0, spatial_cplx_masking = 0, 
  p_masking = 0, dark_masking = 0, slice_count = 0, prediction_method = 0, slice_offset = 0x0, sample_aspect_ratio = {num = 0, den = 1}, me_cmp = 0, me_sub_cmp = 0, mb_cmp = 0, 
  ildct_cmp = 8, dia_size = 0, last_predictor_count = 0, pre_me = 0, me_pre_cmp = 0, pre_dia_size = 0, me_subpel_quality = 8, dtg_active_format = 0, me_range = 0, 
  intra_quant_bias = 999999, inter_quant_bias = 999999, slice_flags = 0, xvmc_acceleration = 0, mb_decision = 0, intra_matrix = 0x0, inter_matrix = 0x0, scenechange_threshold = 0, 
  noise_reduction = 0, me_threshold = 0, mb_threshold = 0, intra_dc_precision = 0, skip_top = 0, skip_bottom = 0, border_masking = 0, mb_lmin = 236, mb_lmax = 3658, 
  me_penalty_compensation = 256, bidir_refine = 1, brd_scale = 0, keyint_min = -1, refs = 1, chromaoffset = 0, scenechange_factor = 6, mv0_threshold = 256, b_sensitivity = 40, 
  color_primaries = AVCOL_PRI_UNSPECIFIED, color_trc = AVCOL_TRC_UNSPECIFIED, colorspace = AVCOL_SPC_UNSPECIFIED, color_range = AVCOL_RANGE_UNSPECIFIED, 
  chroma_sample_location = AVCHROMA_LOC_UNSPECIFIED, slices = 0, field_order = AV_FIELD_UNKNOWN, sample_rate = 0, channels = 0, sample_fmt = AV_SAMPLE_FMT_NONE, frame_size = 0, 
  frame_number = 4155, block_align = 0, cutoff = 0, channel_layout = 0, request_channel_layout = 0, audio_service_type = AV_AUDIO_SERVICE_TYPE_MAIN, 
  request_sample_fmt = AV_SAMPLE_FMT_U8, get_buffer2 = 0x7f24388bae20 , refcounted_frames = 0, qcompress = 0.5, qblur = 0.5, qmin = 2, qmax = 30, 
  max_qdiff = 3, rc_qsquish = 0, rc_qmod_amp = 0, rc_qmod_freq = 0, rc_buffer_size = 0, rc_override_count = 0, rc_override = 0x0, rc_eq = 0x0, rc_max_rate = 0, rc_min_rate = 0, 
  rc_buffer_aggressivity = 1, rc_initial_cplx = 0, rc_max_available_vbv_use = 0, rc_min_vbv_overflow_use = 3, rc_initial_buffer_occupancy = 0, coder_type = 0, context_model = 0, 
  lmin = 0, lmax = 0, frame_skip_threshold = 0, frame_skip_factor = 0, frame_skip_exp = 0, frame_skip_cmp = 13, trellis = 0, min_prediction_order = 0, max_prediction_order = 0, 
  timecode_frame_start = -1, rtp_callback = 0x0, rtp_payload_size = 0, mv_bits = 0, header_bits = 0, i_tex_bits = 0, p_tex_bits = 0, i_count = 0, p_count = 0, skip_count = 0, 
  misc_bits = 0, frame_bits = 0, stats_out = 0x0, stats_in = 0x0, workaround_bugs = 1, strict_std_compliance = 0, error_concealment = 3, debug = 0, debug_mv = 0, err_recognition = 0, 
  reordered_opaque = -9223372036854775808, hwaccel = 0x0, hwaccel_context = 0x0, error = {0, 0, 0, 0, 0, 0, 0, 0}, dct_algo = 0, idct_algo = 0, bits_per_coded_sample = 0, 
  bits_per_raw_sample = 0, lowres = 0, coded_frame = 0x4beeca0, thread_count = 4, thread_type = 3, active_thread_type = 0, thread_safe_callbacks = 0, execute = 
    0x7f2438d47c30 , execute2 = 0x7f2438d47cf0 , nsse_weight = 8, profile = -99, level = -99, skip_loop_filter = AVDISCARD_DEFAULT, 
  skip_idct = AVDISCARD_DEFAULT, skip_frame = AVDISCARD_DEFAULT, subtitle_header = 0x0, subtitle_header_size = 0, error_rate = 0, vbv_delay = 0, side_data_only_packets = 1, 
  initial_padding = 0, framerate = {num = 0, den = 1}, sw_pix_fmt = AV_PIX_FMT_NONE, pkt_timebase = {num = 1, den = 1000}, codec_descriptor = 0x7f2439593f00 , 
  pts_correction_num_faulty_pts = 0, pts_correction_num_faulty_dts = 0, pts_correction_last_pts = -9223372036854775808, pts_correction_last_dts = -9223372036854775808, 
  sub_charenc = 0x0, sub_charenc_mode = 0, skip_alpha = 0, seek_preroll = 0, chroma_intra_matrix = 0x0, dump_separator = 0x0, codec_whitelist = 0x0, properties = 0, 
  coded_side_data = 0x6c3b640, nb_coded_side_data = 1, hw_frames_ctx = 0x0, sub_text_format = 0, trailing_padding = 0, max_pixels = 2147483647, hw_device_ctx = 0x0, hwaccel_flags = 1, 
  apply_cropping = 1}

I'm suspecting that one of the other settings there might cause libav to ignore the bitrate; perhaps the bitrate tolerance is too high? I'll have to do some tests.

PetteriAimonen commented 5 years ago

Hmm, looks like the problem is caused by this line that sets qmax to 30: https://github.com/OpenShot/libopenshot/blob/develop/src/FFmpegWriter.cpp#L947

This maximum quantizer seems to be too low to achieve small bitrates on high resolution videos. Also it seems questionable whether one could specify any default value that could work for all codecs, I think it will be better to let ffmpeg and codec libraries decide the values. I just commented the two lines qmin and qmax out and recompiled libopenshot, and now it hits exactly the bitrate I specify on the advanced tab.

Possibly related issues: #1994, #2300.

TheLEGObrick commented 5 years ago

Hmm, looks like the problem is caused by this line that sets qmax to 30: https://github.com/OpenShot/libopenshot/blob/develop/src/FFmpegWriter.cpp#L947

This maximum quantizer seems to be too low to achieve small bitrates on high resolution videos. Also it seems questionable whether one could specify any default value that could work for all codecs, I think it will be better to let ffmpeg and codec libraries decide the values. I just commented the two lines qmin and qmax out and recompiled libopenshot, and now it hits exactly the bitrate I specify on the advanced tab.

Possibly related issues: #1994, #2300.

Oooh that's... pretty neat I guess, hopefully it'll be able to be fixed at some point... If it hasn't already been, I haven't gotten around to check the thing in quite some while.

peanutbutterandcrackers commented 5 years ago

@PetteriAimonen - Hey there! Perhaps you could open up an issue over at libopenshot repo regarding this? With the deductions that you have made so far? And by linking all the possibly related issues? That way, the contributors who wanted to fix it would have an easier time. Perhaps you yourself might be able to gain some more insight into the issue from the discussions that might happen and then make a PR to fix this?

We could really really really use some more contributors.

PetteriAimonen commented 5 years ago

@peanutbutterandcrackers Well, I can pull request the removal of those two lines. But perhaps there is some purpose to them. The commit message suggests it might have something to do with Windows support, but I've only tested on Linux so far.

@jonoomph The qmax and qmin settings were added by your commit back in 2015 ( https://github.com/OpenShot/libopenshot/commit/fbc719b11fa0d68f3f89c9db51e8c5bebe7a93ab ). Do you remember if there was some specific need for them?

peanutbutterandcrackers commented 5 years ago

@PetteriAimonen - It might be a few weeks before we get any answers. Please do stand by, though. We do need new volunteers. Working for OpenShot is often exhausting as we are just normal users who want to help out but the issues are overwhelming. We wouldn't want to lose any potential contributor. :)

PetteriAimonen commented 5 years ago

@peanutbutterandcrackers Yeah, sure; I've been using openshot for years and this is the first time some problem was big enough that I felt like fixing it :)

Otherwise I'm quite overwhelmed with my own projects also so not sure if I can put much time towards openshot.

peanutbutterandcrackers commented 5 years ago

@PetteriAimonen - I understand. Still, any help we can get is great. There aren't enough programmer-contributors around. Hope you can squirrel some time away every now and then to make some drive-by contributions. :)

DylanC commented 5 years ago

@peanutbutterandcrackers - Indeed. We could definitely do with some more of those random contributions even if we don't see that contributor for another 6 months. 😄 I have my hands full with my own project right now, so unfortunately I just don't have the time required for more Openshot contributions yet.

stale[bot] commented 3 years ago

Thank you so much for submitting an issue to help improve OpenShot Video Editor. We are sorry about this, but this particular issue has gone unnoticed for quite some time. To help keep the OpenShot GitHub Issue Tracker organized and focused, we must ensure that every issue is correctly labelled and triaged, to get the proper attention. This issue will be closed, as it meets the following criteria: - No activity in the past 180 days - No one is assigned to this issue We'd like to ask you to help us out and determine whether this issue should be reopened. - If this issue is reporting a bug, please can you attempt to reproduce on the latest daily build to help us to understand whether the bug still needs our attention. - If this issue is proposing a new feature, please can you verify whether the feature proposal is still relevant. Thanks again for your help!