How to specify output video width and height?
myme5261314 opened this issue · 9 comments
This tracker is for defects only! For feature requests, you can submit a pull
request with the changes.
If you’re reporting a defect, make it as detailed as possible, and include both your operating system and MLT versions (e.g. macOS 13.6.7; MLT v7.24.0).
running melt command like below
melt blank in=0 out=1 -consumer avformat:trial.mp4 width=1920 height=1080The generated video file has resolution of 2048x1080 which is unexpected.
Why does this happen and how to solve it?
You need to specify a profile. See the documentation here:
https://mltframework.org/docs/melt/
Closing this issue because you are not reporting a defect. See our support page here:
https://mltframework.org/support/
Brian, an explicit -profile is not required. Melt generates an automatic profile, and then the base mlt_consumer updates the profile from the consumer properties.
However, the reporter's command line does not reproduce for me. What is "blank"? When I run the command I get a 1920x1080 as expected (default profile when nothing can be probed) as proven by ffprobe:
ffprobe version n7.0-7-gd38bf5e08e Copyright (c) 2007-2024 the FFmpeg developers
built with gcc 11 (Ubuntu 11.4.0-1ubuntu1~22.04)
configuration: --prefix=/home/ddennedy/opt --disable-static --disable-doc --enable-gpl --enable-version3 --enable-shared --enable-runtime-cpudetect --enable-libtheora --enable-libvorbis --enable-libmp3lame --enable-libx264 --enable-libx265 --enable-libvpx --enable-libopus --enable-libzimg --enable-libdav1d --enable-libaom --disable-decoder=libaom_av1 --enable-libwebp --enable-libvmaf --enable-libjack --enable-libxcb --enable-libpulse --enable-openssl
libavutil 59. 8.100 / 59. 8.100
libavcodec 61. 3.100 / 61. 3.100
libavformat 61. 1.100 / 61. 1.100
libavdevice 61. 1.100 / 61. 1.100
libavfilter 10. 1.100 / 10. 1.100
libswscale 8. 1.100 / 8. 1.100
libswresample 5. 1.100 / 5. 1.100
libpostproc 58. 1.100 / 58. 1.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'trial.mp4':
Metadata:
major_brand : isom
minor_version : 512
compatible_brands: isomiso2avc1mp41
encoder : Lavf61.1.100
Duration: 00:00:00.09, start: 0.000000, bitrate: 262 kb/s
Stream #0:0[0x1](und): Video: h264 (High) (avc1 / 0x31637661), yuv420p(tv, smpte170m, top first), 1920x1080 [SAR 16:15 DAR 256:135], 124 kb/s, 25 fps, 25 tbr, 12800 tbn (default)
Metadata:
handler_name : VideoHandler
vendor_id : [0][0][0][0]
Stream #0:1[0x2](und): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 3 kb/s (default)
Metadata:
handler_name : SoundHandler
vendor_id : [0][0][0][0]
Now, I just did some testing with a 4K60 input file, and while width and height are changing, it is not working as expected.
melt GX010071.MP4 -consumer avformat:trial.mp4 width=1920 height=1080
ffprobe trial.mp4
...
Stream #0:0[0x1](und): Video: h264 (High) (avc1 / 0x31637661), yuv420p(tv, smpte170m, top first), 1920x1080 [SAR 16:15DAR 256:135], 969 kb/s, 25 fps, 25 tbr, 12800 tbn (default)
aspect ratio and frame rate are wrong.
OK, I figured out what is wrong. If you do not specify a profile, the profile initializes with the default dv_pal (SD PAL) and then the consumer properties updates that. That explains both ffprobe results above.
The workaround is to also set the aspect ratio properties because SD is neither 16:9 display aspect ratio nor is it square pixels:
... display_aspect_num=16 display_aspect_den=9 sample_aspect_num=1 sample_aspect_den=1
However, I do think would be better behavior if the consumer properties update the automatic profile instead of the default.
I do think would be better behavior if the consumer properties update the automatic profile instead of the default.
This is heavily complicated by the behavior that MLT XML may contain a profile and when that combines with the melt -profile option the loader producer must inject the consumer producer. MLT XML processing has a higher priority than simple melt command lines since those are usually better accomplished with ffmpeg. And non-simple melt command lines really ought to specify -profile instead of leaving it rather non-deterministic (i.e. upon which of the multiple input files should I base the output?).
This change works with some light testing. The case it does not cover (and neither does current version) is when a MLT XML contains profile information and you want to override some of the consumer properties (like it does here with avformat);
--- src/melt/melt.c
+++ src/melt/melt.c
@@ -751,7 +751,7 @@ int main(int argc, char **argv)
int is_abort = 0;
int is_getc = 0;
int error = 0;
- mlt_profile backup_profile;
+ mlt_profile backup_profile = NULL;
mlt_repository repo = NULL;
const char *repo_path = NULL;
int is_consumer_explicit = 0;
@@ -922,8 +922,6 @@ int main(int argc, char **argv)
|| profile->frame_rate_num != backup_profile->frame_rate_num
|| profile->colorspace != backup_profile->colorspace))
profile->is_explicit = 1;
- mlt_profile_close(backup_profile);
- backup_profile = NULL;
// Get melt producer
if (argc > 1)
@@ -931,7 +929,7 @@ int main(int argc, char **argv)
if (melt) {
// Generate an automatic profile if needed.
- if (!profile->is_explicit) {
+ if (backup_profile && !backup_profile->is_explicit) {
mlt_producer first_producer = mlt_properties_get_data(MLT_PRODUCER_PROPERTIES(melt),
"first_producer",
NULL);
@@ -946,6 +944,7 @@ int main(int argc, char **argv)
double scale = mlt_properties_get_double(MLT_CONSUMER_PROPERTIES(consumer), "scale");
if (scale > 0.0) {
+ mlt_profile_close(backup_profile);
set_preview_scale(&profile, &backup_profile, scale);
}
Thanks.
Another weird thing I find out is that the portable release for Windows OS (shotcut-win64-240626.zip, from github release) produce 1920x1080 blank (white background) video.
Actually, I find out the 2048 only comes from the file description dialog of OSX system and the Quicktime file info dialog except ffprobe output.
I don't know the 2048 represents which indicator and 1920 indicate which other indicator.
-> % ffprobe trial.mp4
ffprobe version 7.0.2 Copyright (c) 2007-2024 the FFmpeg developers
built with Apple clang version 15.0.0 (clang-1500.1.0.2.5)
configuration: --prefix=/usr/local/Cellar/ffmpeg/7.0.2 --enable-shared --enable-pthreads --enable-version3 --cc=clang --host-cflags= --host-ldflags='-Wl,-ld_classic' --enable-ffplay --enable-gnutls --enable-gpl --enable-libaom --enable-libaribb24 --enable-libbluray --enable-libdav1d --enable-libharfbuzz --enable-libjxl --enable-libmp3lame --enable-libopus --enable-librav1e --enable-librist --enable-librubberband --enable-libsnappy --enable-libsrt --enable-libssh --enable-libsvtav1 --enable-libtesseract --enable-libtheora --enable-libvidstab --enable-libvmaf --enable-libvorbis --enable-libvpx --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 --enable-libxvid --enable-lzma --enable-libfontconfig --enable-libfreetype --enable-frei0r --enable-libass --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libspeex --enable-libsoxr --enable-libzmq --enable-libzimg --disable-libjack --disable-indev=jack --enable-videotoolbox --enable-audiotoolbox
libavutil 59. 8.100 / 59. 8.100
libavcodec 61. 3.100 / 61. 3.100
libavformat 61. 1.100 / 61. 1.100
libavdevice 61. 1.100 / 61. 1.100
libavfilter 10. 1.100 / 10. 1.100
libswscale 8. 1.100 / 8. 1.100
libswresample 5. 1.100 / 5. 1.100
libpostproc 58. 1.100 / 58. 1.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'trial.mp4':
Metadata:
major_brand : isom
minor_version : 512
compatible_brands: isomiso2avc1mp41
encoder : Lavf60.16.100
Duration: 00:00:05.06, start: 0.000000, bitrate: 27 kb/s
Stream #0:0[0x1](und): Video: h264 (High) (avc1 / 0x31637661), yuv420p(tv, smpte170m, top first), 1920x1080 [SAR 16:15 DAR 256:135], 16 kb/s, 25 fps, 25 tbr, 12800 tbn (default)
Metadata:
handler_name : VideoHandler
vendor_id : [0][0][0][0]
Stream #0:1[0x2](und): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 2 kb/s (default)
Metadata:
handler_name : SoundHandler
vendor_id : [0][0][0][0]This change works with some light testing. The case it does not cover (and neither does current version) is when a MLT XML contains profile information and you want to override some of the consumer properties (like it does here with avformat);
--- src/melt/melt.c +++ src/melt/melt.c @@ -751,7 +751,7 @@ int main(int argc, char **argv) int is_abort = 0; int is_getc = 0; int error = 0; - mlt_profile backup_profile; + mlt_profile backup_profile = NULL; mlt_repository repo = NULL; const char *repo_path = NULL; int is_consumer_explicit = 0; @@ -922,8 +922,6 @@ int main(int argc, char **argv) || profile->frame_rate_num != backup_profile->frame_rate_num || profile->colorspace != backup_profile->colorspace)) profile->is_explicit = 1; - mlt_profile_close(backup_profile); - backup_profile = NULL; // Get melt producer if (argc > 1) @@ -931,7 +929,7 @@ int main(int argc, char **argv) if (melt) { // Generate an automatic profile if needed. - if (!profile->is_explicit) { + if (backup_profile && !backup_profile->is_explicit) { mlt_producer first_producer = mlt_properties_get_data(MLT_PRODUCER_PROPERTIES(melt), "first_producer", NULL); @@ -946,6 +944,7 @@ int main(int argc, char **argv) double scale = mlt_properties_get_double(MLT_CONSUMER_PROPERTIES(consumer), "scale"); if (scale > 0.0) { + mlt_profile_close(backup_profile); set_preview_scale(&profile, &backup_profile, scale); }
I've just confirmed some cases you described.
Use melt command like this, you will get a background image fully filled in the 720x720 video file.
melt -track color:#000000 out=0 -track Pictures/background.jpeg in=":0.000000" out=":10.000000" width="720" height="720" -attach-track rescale -transition composite distort=0 a_track=0 b_track=1 -transition mix a_track=0 b_track=1 -consumer avformat:trial.mp4 display_aspect_num=720 display_aspect_den=720 sample_aspect_num=1 sample_aspect_den=1trial.mp4
But, what's the difference between 720 and "720", since the next command produce a video with weird aspect ratio.
melt -track color:#000000 out=0 -track Pictures/background.jpeg in=":0.000000" out=":10.000000" width=720 height=720 -attach-track rescale -transition composite distort=0 a_track=0 b_track=1 -transition mix a_track=0 b_track=1 -consumer avformat:trial.mp4 display_aspect_num=720 display_aspect_den=720 sample_aspect_num=1trial.mp4
If you first generate xml, and then use xml to generate video, you will get a 720x720 video file with non-fully filled background image. I don't know why my brew installed mlt package can't use xml consumer. But I confirmed this on my Windows OS.
melt -track color:#000000 out=0 -track Pictures/background.jpeg in=":0.000000" out=":10.000000" width=720 height=720 -attach-track rescale -transition composite distort=0 a_track=0 b_track=1 -transition mix a_track=0 b_track=1 -consumer xml:trial.xml
melt trial.xml -consumer avformat:trial.mp4 display_aspect_num=720 display_aspect_den=720 sample_aspect_num=1
Below is the error message of my brew installed mlt.
-> % melt -track color:#000000 out=0 -track Pictures/background.jpeg in=":0.000000" out=":10.000000" width=720 height=720 -attach-track rescale -transition composite distort=0 a_track=0 b_track=1 -transition mix a_track=0 b_track=1 --consumer xml
Failed to load "xml"
Failed to load "xml"
+-----+ +-----+ +-----+ +-----+ +-----+ +-----+ +-----+ +-----+ +-----+
|1=-10| |2= -5| |3= -2| |4= -1| |5= 0| |6= 1| |7= 2| |8= 5| |9= 10|
+-----+ +-----+ +-----+ +-----+ +-----+ +-----+ +-----+ +-----+ +-----+
+---------------------------------------------------------------------+
| H = back 1 minute, L = forward 1 minute |
| h = previous frame, l = next frame |
| g = start of clip, j = next clip, k = previous clip |
| 0 = restart, q = quit, space = play |
+---------------------------------------------------------------------+
[consumer sdl2] Failed to create SDL renderer: Parameter 'window' is invalid
[consumer sdl2] Failed to create SDL renderer: Parameter 'window' is invalidBut, what's the difference between 720 and "720", since the next command produce a video with weird aspect ratio.
This is expected since the default profile dv_pal, which has sample_aspect_den=15, and you did not change it,. You are making assumptions about some different behavior, but that is not how it works. Do you understand sample/pixel ratio is different than display aspect ratio and that pixels are not always square?
If you first generate xml, and then use xml to generate video, you will get a 720x720 video file with non-fully filled background image.
This is expected since the XML specifies a profile and that must be respected to maintain the spatial arrangement of the composition--maybe in this example, but in the general.
--consumer xml
Do not use 2 dashes.
Thanks for your kind reminder about PAR/DAR/typo/missing parameter.
Let me concentrate my current unresolved issue like below:
melt Pictures/background.jpeg out=125 -filter rescale -consumer avformat:trial4.mp4 \
display_aspect_num=720 display_aspect_den=720 sample_aspect_num=1 sample_aspect_den=1 height=720 width=720melt Pictures/background.jpeg out=125 -filter rescale -consumer xml:trial1.xml \
&& melt trial1.xml -consumer avformat:trial3.mp4 \
display_aspect_num=720 display_aspect_den=720 sample_aspect_num=1 sample_aspect_den=1 height=720 width=720These two commands produce different background image portions in the videos.
I'm newbie in video editing. Is this because of this?
MLT XML processing has a higher priority than simple melt command lines since those are usually better accomplished with ffmpeg.
But both videos are 720x720 resolution.
Does this mean that rescale filter acts differently by different profile properties while the avformat consumer utilizes same profile properties?
What's the workaround to make the background image to have a 100% coverage in xml approach?
