filter_complex and map. Am i confused or bug?

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

filter_complex and map. Am i confused or bug?

alexdjca
Hi guys,



What I'm trying to do, in theory, should be very simple but it seems that I miss to understand about how ffmpeg routes different tracks.



Basically I have a file with a single video track and a single audio track.

What I want to achieve is:



a) Scale the video track to 720x576 and encode it in H264 @ 2M with 2M minrate and 2M maxrate

b) Scale the video track to 640x480 and encode it in H264 @ 1M with 1M minrate and 1M maxrate

c) Pick the audio track and encode it in aac

d) Mux all the tracks together in this order: first Video 640x480, second Video 720x576, third Audio



So I though to run this command (I will separate section by section commenting with my thoughs)



ffmpeg -i INPUTFILE \    <- this is quite clear :)

-filter_complex "[0:v]scale=720:576[vidout1];[0:v]scale=640:480[vidout2]" \ <- here I pickup the video, I scale it to 720x576 and I route it to [vidout1], and I scale it again to 640x480 and I route it to [vidout2]

-c:v libx264 -c:a aac \ <- here I specify that all video tracks have to be encoded in x264, all audio tracks in aac

-b:v:vidout1 2M -minrate:v:vidout1 2M -maxrate:v:vidout1 2M \ <- I specify that [vidout1] has to be encoded in 2M/2M/2M

-b:v:vidout2 1M -minrate:v:vidout2 1M -maxrate:v:vidout2 1M \ <- I specify that [vidout2] has to be encoded in 1M/1M/1M

-map [vidout2] -map [vidout1] -map 0:a \ <- here I specify that the order has to be 640x480, 720x576, Audio

-f mpegts test.ts



So the final command is the following:



ffmpeg -i INPUTFILE -filter_complex "[0:v]scale=720:576[vidout1];[0:v]scale=640:480[vidout2]" -c:v libx264 -c:a aac -b:v:vidout1 2M -minrate:v:vidout1 2M -maxrate:v:vidout1 2M -b:v:vidout2 1M -minrate:v:vidout2 1M -maxrate:v:vidout2 1M -map [vidout2] -map [vidout1] -map 0:a -f mpegts test.ts



but the output, is definitely different that what I expected:



Output #0, mpegts, to 'test.ts':

  Metadata:

    encoder         : Lavf58.20.100

    Stream #0:0: Video: h264 (libx264), yuv420p(top coded first (swapped)), 640x480 [SAR 4:3 DAR 16:9], q=-1--1, 1000 kb/s, 25 fps, 90k tbn, 25 tbc

    Metadata:

      encoder         : Lavc58.35.100 libx264

    Side data:

      cpb: bitrate max/min/avg: 1000000/0/1000000 buffer size: 0 vbv_delay: -1

    Stream #0:1: Video: h264 (libx264), yuv420p, 720x576 [SAR 64:45 DAR 16:9], q=-1--1, 25 fps, 90k tbn, 25 tbc

    Metadata:

      encoder         : Lavc58.35.100 libx264

    Side data:

      cpb: bitrate max/min/avg: 0/0/0 buffer size: 0 vbv_delay: -1

    Stream #0:2: Audio: aac (LC), 48000 Hz, stereo, fltp, 128 kb/s

    Metadata:

      encoder         : Lavc58.35.100 aac



The order of the streams is correct (first 640x480, then 720x576, then audio) but the encoding settings were passed correctly only to the first track, and totally ignored for the second  track.



So, I've tried to change the order of the video tracks to see what happened:



-map [vidout1] -map [vidout2] -map 0:a



And the result is:



Output #0, mpegts, to 'test.ts':

  Metadata:

    encoder         : Lavf58.20.100

    Stream #0:0: Video: h264 (libx264), 1 reference frame, yuv420p(top coded first (swapped)), 720x576 [SAR 64:45 DAR 16:9], q=-1--1, 1000 kb/s, 25 fps, 90k tbn, 25 tbc

    Metadata:

      encoder         : Lavc58.35.100 libx264

    Side data:

      cpb: bitrate max/min/avg: 1000000/0/1000000 buffer size: 0 vbv_delay: -1

    Stream #0:1: Video: h264 (libx264), 1 reference frame, yuv420p, 640x480 [SAR 4:3 DAR 16:9], q=-1--1, 25 fps, 90k tbn, 25 tbc

    Metadata:

      encoder         : Lavc58.35.100 libx264

    Side data:

      cpb: bitrate max/min/avg: 0/0/0 buffer size: 0 vbv_delay: -1

    Stream #0:2: Audio: aac (LC), 48000 Hz, stereo, fltp, delay 1024, 128 kb/s

    Metadata:

      encoder         : Lavc58.35.100 aac



As before, the tracks are in the order expected, but not only one of the two tracks were not encoded as expected, now surprisingly the first track was encoded with the charateristics I expected to be used for the second track!!!! So basically vout1 was encoded with the parameters I expected to be applied to vout2, and vout2 just ignored the settings at all.



But even more surprisingly, if I remove "-b:v:vidout2 1M -minrate:v:vidout2 1M -maxrate:v:vidout2" the result is this:



Output #0, mpegts, to 'test.ts':

  Metadata:

    encoder         : Lavf58.20.100

    Stream #0:0: Video: h264 (libx264), 1 reference frame, yuv420p(top coded first (swapped)), 720x576 [SAR 64:45 DAR 16:9], q=-1--1, 2000 kb/s, 25 fps, 90k tbn, 25 tbc

    Metadata:

      encoder         : Lavc58.35.100 libx264

    Side data:

      cpb: bitrate max/min/avg: 2000000/0/2000000 buffer size: 0 vbv_delay: -1

    Stream #0:1: Video: h264 (libx264), 1 reference frame, yuv420p, 640x480 [SAR 4:3 DAR 16:9], q=-1--1, 25 fps, 90k tbn, 25 tbc

    Metadata:

      encoder         : Lavc58.35.100 libx264

    Side data:

      cpb: bitrate max/min/avg: 0/0/0 buffer size: 0 vbv_delay: -1

    Stream #0:2: Audio: aac (LC), 48000 Hz, stereo, fltp, delay 1024, 128 kb/s

    Metadata:

      encoder         : Lavc58.35.100 aac



Basically now vout1 is encoded "almost" as expected....except for the minrate....



What am I doing wrong?



Did I totally misunderstood how to use filter_complex and map, or is there any possible bug preventing the mechanism to work properly?



Thanks in advance,



Alex Molon


_______________________________________________
ffmpeg-user mailing list
[hidden email]
http://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: filter_complex and map. Am i confused or bug?

Carl Eugen Hoyos-2
2019-01-31 13:41 GMT+01:00, Alex Molon <[hidden email]>:

> Basically I have a file with a single video track and a single audio track.
>
> What I want to achieve is:
>
>
>
> a) Scale the video track to 720x576 and encode it in H264 @ 2M with 2M
> minrate and 2M maxrate
>
> b) Scale the video track to 640x480 and encode it in H264 @ 1M with 1M
> minrate and 1M maxrate
>
> c) Pick the audio track and encode it in aac

> d) Mux all the tracks together in this order: first Video 640x480, second
> Video 720x576, third Audio

Transport streams do not know about "order", this concept simply
doesn't apply.

If this does not answer your question, please provide your actual
command line (no variables) including the complete, uncut console
output if you need support here.

Carl Eugen
_______________________________________________
ffmpeg-user mailing list
[hidden email]
http://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: filter_complex and map. Am i confused or bug?

alexdjca
Hi Carl,

My problem actually is not the order itself, but how the single tracks are actually encoded....

The complete command is:

ffmpeg -i INPUTFILE -filter_complex "[0:v]scale=720:576[vidout1];[0:v]scale=640:480[vidout2]" -c:v libx264 -c:a aac -b:v:vidout1 2M -minrate:v:vidout1 2M -maxrate:v:vidout1 2M -b:v:vidout2 1M -minrate:v:vidout2 1M -maxrate:v:vidout2 1M -map [vidout2] -map [vidout1] -map 0:a -f mpegts test.ts

And the result is that:
instead to have a stream with one video track 720x576@2M/2M/2M, one video track 640x480@1M/1M/1m and one audio track
as a result I have a stream with one video track with one video track 640x480@1M/1M/1M, one video track 720x576 with no specific encoding settings and one audio track.
Or, in alternative (if I change the order of the map commands) one video track 720x576@1M/1M/1M, one video track 640x480 with no specific encoding settings and one audio track.

Output #0, mpegts, to 'test.ts':
  Metadata:
    encoder         : Lavf58.20.100
    Stream #0:0: Video: h264 (libx264), yuv420p(top coded first (swapped)), 640x480 [SAR 4:3 DAR 16:9], q=-1--1, 1000 kb/s, 25 fps, 90k tbn, 25 tbc
    Metadata:
      encoder         : Lavc58.35.100 libx264
    Side data:
      cpb: bitrate max/min/avg: 1000000/0/1000000 buffer size: 0 vbv_delay: -1
    Stream #0:1: Video: h264 (libx264), yuv420p, 720x576 [SAR 64:45 DAR 16:9], q=-1--1, 25 fps, 90k tbn, 25 tbc
    Metadata:
      encoder         : Lavc58.35.100 libx264
    Side data:
      cpb: bitrate max/min/avg: 0/0/0 buffer size: 0 vbv_delay: -1
    Stream #0:2: Audio: aac (LC), 48000 Hz, stereo, fltp, 128 kb/s
    Metadata:

Thanks in advance,
Alex

-----Original Message-----
From: ffmpeg-user [mailto:[hidden email]] On Behalf Of Carl Eugen Hoyos
Sent: 31 January 2019 12:45
To: FFmpeg user questions
Subject: Re: [FFmpeg-user] filter_complex and map. Am i confused or bug?

2019-01-31 13:41 GMT+01:00, Alex Molon <[hidden email]>:

> Basically I have a file with a single video track and a single audio track.
>
> What I want to achieve is:
>
>
>
> a) Scale the video track to 720x576 and encode it in H264 @ 2M with 2M
> minrate and 2M maxrate
>
> b) Scale the video track to 640x480 and encode it in H264 @ 1M with 1M
> minrate and 1M maxrate
>
> c) Pick the audio track and encode it in aac

> d) Mux all the tracks together in this order: first Video 640x480, second
> Video 720x576, third Audio

Transport streams do not know about "order", this concept simply
doesn't apply.

If this does not answer your question, please provide your actual
command line (no variables) including the complete, uncut console
output if you need support here.

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

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".
_______________________________________________
ffmpeg-user mailing list
[hidden email]
http://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: filter_complex and map. Am i confused or bug?

Gyan
In reply to this post by alexdjca


On 31-01-2019 06:11 PM, Alex Molon wrote:
> -b:v:vidout1 2M -minrate:v:vidout1 2M -maxrate:v:vidout1 2M \ <- I specify that [vidout1] has to be encoded in 2M/2M/2M
>
> -b:v:vidout2 1M -minrate:v:vidout2 1M -maxrate:v:vidout2 1M \ <- I specify that [vidout2] has to be encoded in 1M/1M/1M

Stream specifiers for output stream codec options s  e.g. v:vidout1 can
refer to ordinal index only, so

     -b:v:vidout1

becomes

     -b:v:1

assuming vidout1 is mapped after vidout2.


Gyan

_______________________________________________
ffmpeg-user mailing list
[hidden email]
http://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: filter_complex and map. Am i confused or bug?

alexdjca
In reply to this post by alexdjca
In this case I used a "real life" scenario, picking up a live stream. The result is the same:



Command executed:



ffmpeg  -i udp://226.45.23.147:2001?fifo_size=1000000 -filter_complex "[0:v]scale=720:576[vidout1];[0:v]scale=640:480[vidout2]" -c:v libx264 -c:a aac -b:v:vidout1 2M -minrate:v:vidout1 2M -maxrate:v:vidout1 2M -b:v:vidout2 1M -minrate:v:vidout2 1M -maxrate:v:vidout2 1M -map [vidout1] -map [vidout2] -map 0:a -t 10 -y -f mpegts test.ts



Expectation:



A file called test.ts containing 3 elementary streams:

One video stream 720x576 encoded at 2M with minimum and maximum bitrate 2M

One video stream 640x480 encoded at 1M with minimum and maximum bitrate 1M

One audio stream AAC



Result:

A file called test ts containing 3 elementary streams:

One video stream at 720x576 unexpectedly encoded at 1M

One video stream at 640x480 unexpectedly encoded with no specific settings

One audio stream AAC



Suspected cause:

I think the following section of the command is parsed wrongly or I’m totally confused

b:v:vidout1 2M -minrate:v:vidout1 2M -maxrate:v:vidout1 2M -b:v:vidout2 1M -minrate:v:vidout2 1M -maxrate:v:vidout2 1M



Output:

ffmpeg version 4.1 Copyright (c) 2000-2018 the FFmpeg developers

  built with gcc 7 (Ubuntu 7.3.0-27ubuntu1~18.04)

  configuration: --libdir=/usr/lib/x86_64-linux-gnu --incdir=/usr/include/x86_64-linux-gnu --enable-gpl --disable-stripping --enable-avresample --enable-avisynth --enable-gnutls --enable-ladspa --enable-libass --enable-libbs2b --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libmp3lame --enable-libopenjpeg --enable-libopenmpt --enable-libssh --enable-libtheora --enable-libtwolame --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx265 --enable-libxml2 --enable-libzvbi --enable-opengl --enable-sdl2 --enable-libdrm --enable-chromaprint --enable-frei0r --enable-libx264 --disable-shared --enable-static --enable-libnpp --enable-nonfree --enable-nvenc --enable-cuvid --enable-libfdk-aac

  libavutil      56. 22.100 / 56. 22.100

  libavcodec     58. 35.100 / 58. 35.100

  libavformat    58. 20.100 / 58. 20.100

  libavdevice    58.  5.100 / 58.  5.100

  libavfilter     7. 40.101 /  7. 40.101

  libavresample   4.  0.  0 /  4.  0.  0

  libswscale      5.  3.100 /  5.  3.100

  libswresample   3.  3.100 /  3.  3.100

  libpostproc    55.  3.100 / 55.  3.100

Input #0, mpegts, from 'udp://226.45.23.147:2001?fifo_size=1000000':

  Duration: N/A, start: 17355.533200, bitrate: N/A

  Program 1408

    Metadata:

      service_name    : BTV HD

      service_provider:

    Stream #0:0[0x1959]: Video: h264 (High) ([27][0][0][0] / 0x001B), yuv420p(tv, bt709, top first), 1920x1080 [SAR 1:1 DAR 16:9], 25 fps, 50 tbr, 90k tbn, 50 tbc

    Stream #0:1[0x195a]: Audio: mp2 ([4][0][0][0] / 0x0004), 48000 Hz, stereo, s16p, 128 kb/s

Stream mapping:

  Stream #0:0 (h264) -> scale (graph 0)

  Stream #0:0 (h264) -> scale (graph 0)

  scale (graph 0) -> Stream #0:0 (libx264)

  scale (graph 0) -> Stream #0:1 (libx264)

  Stream #0:1 -> #0:2 (mp2 (native) -> aac (native))

Press [q] to stop, [?] for help

Output #0, mpegts, to 'test.ts':

  Metadata:

    encoder         : Lavf58.20.100

    Stream #0:0: Video: h264 (libx264), yuv420p(top coded first (swapped)), 720x576 [SAR 64:45 DAR 16:9], q=-1--1, 1000 kb/s, 25 fps, 90k tbn, 25 tbc

    Metadata:

      encoder         : Lavc58.35.100 libx264

    Side data:

      cpb: bitrate max/min/avg: 1000000/0/1000000 buffer size: 0 vbv_delay: -1

    Stream #0:1: Video: h264 (libx264), yuv420p, 640x480 [SAR 4:3 DAR 16:9], q=-1--1, 25 fps, 90k tbn, 25 tbc

    Metadata:

      encoder         : Lavc58.35.100 libx264

    Side data:

      cpb: bitrate max/min/avg: 0/0/0 buffer size: 0 vbv_delay: -1

    Stream #0:2: Audio: aac (LC), 48000 Hz, stereo, fltp, 128 kb/s

    Metadata:

      encoder         : Lavc58.35.100 aac

frame=  228 fps= 39 q=-1.0 Lq=-1.0 size=    1832kB time=00:00:10.00 bitrate=1500.3kbits/s speed=1.69x



Thanks in advance,



Alex Molon



-----Original Message-----
From: ffmpeg-user [mailto:[hidden email]] On Behalf Of Alex Molon
Sent: 31 January 2019 12:52
To: FFmpeg user questions
Subject: Re: [FFmpeg-user] filter_complex and map. Am i confused or bug?



Hi Carl,



My problem actually is not the order itself, but how the single tracks are actually encoded....



The complete command is:



ffmpeg -i INPUTFILE -filter_complex "[0:v]scale=720:576[vidout1];[0:v]scale=640:480[vidout2]" -c:v libx264 -c:a aac -b:v:vidout1 2M -minrate:v:vidout1 2M -maxrate:v:vidout1 2M -b:v:vidout2 1M -minrate:v:vidout2 1M -maxrate:v:vidout2 1M -map [vidout2] -map [vidout1] -map 0:a -f mpegts test.ts



And the result is that:

instead to have a stream with one video track 720x576@2M/2M/2M, one video track 640x480@1M/1M/1m and one audio track

as a result I have a stream with one video track with one video track 640x480@1M/1M/1M, one video track 720x576 with no specific encoding settings and one audio track.

Or, in alternative (if I change the order of the map commands) one video track 720x576@1M/1M/1M, one video track 640x480 with no specific encoding settings and one audio track.



Output #0, mpegts, to 'test.ts':

  Metadata:

    encoder         : Lavf58.20.100

    Stream #0:0: Video: h264 (libx264), yuv420p(top coded first (swapped)), 640x480 [SAR 4:3 DAR 16:9], q=-1--1, 1000 kb/s, 25 fps, 90k tbn, 25 tbc

    Metadata:

      encoder         : Lavc58.35.100 libx264

    Side data:

      cpb: bitrate max/min/avg: 1000000/0/1000000 buffer size: 0 vbv_delay: -1

    Stream #0:1: Video: h264 (libx264), yuv420p, 720x576 [SAR 64:45 DAR 16:9], q=-1--1, 25 fps, 90k tbn, 25 tbc

    Metadata:

      encoder         : Lavc58.35.100 libx264

    Side data:

      cpb: bitrate max/min/avg: 0/0/0 buffer size: 0 vbv_delay: -1

    Stream #0:2: Audio: aac (LC), 48000 Hz, stereo, fltp, 128 kb/s

    Metadata:



Thanks in advance,

Alex



-----Original Message-----

From: ffmpeg-user [mailto:[hidden email]] On Behalf Of Carl Eugen Hoyos

Sent: 31 January 2019 12:45

To: FFmpeg user questions

Subject: Re: [FFmpeg-user] filter_complex and map. Am i confused or bug?



2019-01-31 13:41 GMT+01:00, Alex Molon <[hidden email]>:



> Basically I have a file with a single video track and a single audio track.

>

> What I want to achieve is:

>

>

>

> a) Scale the video track to 720x576 and encode it in H264 @ 2M with 2M

> minrate and 2M maxrate

>

> b) Scale the video track to 640x480 and encode it in H264 @ 1M with 1M

> minrate and 1M maxrate

>

> c) Pick the audio track and encode it in aac



> d) Mux all the tracks together in this order: first Video 640x480, second

> Video 720x576, third Audio



Transport streams do not know about "order", this concept simply

doesn't apply.



If this does not answer your question, please provide your actual

command line (no variables) including the complete, uncut console

output if you need support here.



Carl Eugen

_______________________________________________

ffmpeg-user mailing list

[hidden email]

http://ffmpeg.org/mailman/listinfo/ffmpeg-user



To unsubscribe, visit link above, or email

[hidden email] with subject "unsubscribe".

_______________________________________________

ffmpeg-user mailing list

[hidden email]

http://ffmpeg.org/mailman/listinfo/ffmpeg-user



To unsubscribe, visit link above, or email

[hidden email] with subject "unsubscribe".
_______________________________________________
ffmpeg-user mailing list
[hidden email]
http://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: filter_complex and map. Am i confused or bug?

alexdjca
In reply to this post by Gyan
Hi Gyan,

Thanks a lot,
Seems to work as expected now :)

Alex Molon



-----Original Message-----
From: ffmpeg-user [mailto:[hidden email]] On Behalf Of Gyan
Sent: 31 January 2019 12:59
To: [hidden email]
Subject: Re: [FFmpeg-user] filter_complex and map. Am i confused or bug?



On 31-01-2019 06:11 PM, Alex Molon wrote:
> -b:v:vidout1 2M -minrate:v:vidout1 2M -maxrate:v:vidout1 2M \ <- I specify that [vidout1] has to be encoded in 2M/2M/2M
>
> -b:v:vidout2 1M -minrate:v:vidout2 1M -maxrate:v:vidout2 1M \ <- I specify that [vidout2] has to be encoded in 1M/1M/1M

Stream specifiers for output stream codec options s  e.g. v:vidout1 can
refer to ordinal index only, so

     -b:v:vidout1

becomes

     -b:v:1

assuming vidout1 is mapped after vidout2.


Gyan

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

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".
_______________________________________________
ffmpeg-user mailing list
[hidden email]
http://ffmpeg.org/mailman/listinfo/ffmpeg-user

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