leandromoreira / ffmpeg-libav-tutorial

FFmpeg libav tutorial - learn how media works from basic to transmuxing, transcoding and more. Translations: πŸ‡ΊπŸ‡Έ πŸ‡¨πŸ‡³ πŸ‡°πŸ‡· πŸ‡ͺπŸ‡Έ πŸ‡»πŸ‡³ πŸ‡§πŸ‡·
https://github.com/leandromoreira/ffmpeg-libav-tutorial
BSD 3-Clause "New" or "Revised" License
9.82k stars 941 forks source link

`[mp4 @ 000002512f668d80] Invalid packet stream index: 2` #64

Closed Niek-Okido closed 4 years ago

Niek-Okido commented 4 years ago

hi,

first of all awesome tutorial, anyways i get some errors when i run the remuxing sample on my side i use cpp and run the code , and detects the following error , [mp4 @ 000002512f668d80] Invalid packet stream index: 2 i did research it and se that the bunny sample from you only have 2 channels [0, 1] so the 3th and 4th will be NULL , but this cause the error on my side .

you ever get some error like this ? if so can you tell me how i can prevent this error ?

thanks in advance

Niek Tuytel

Niek-Okido commented 4 years ago

sorry if my english is bad :).

leandromoreira commented 4 years ago

Hey @Niek-Okido how are you?

So, the stream index isn't related to the number of audio channels but it's related to the stream index for FFmpeg.

Let's run a simple example:

image

When we run ffprobe it shows that bbb has 3 streams, the format #<INPUT>:<STREAM_INDEX> relates do the input and stream index. (0=h264, 1=mp3, 2=ac3 for input 1).

We can also run it for multiple input files:

$ ffmpeg -hide_banner -i ~/bunny_1080p_60fps.mp4 -i ~/Downloads/video-with-timestamp.mp4
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '/Users/leandro.moreira/bunny_1080p_60fps.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 1
    compatible_brands: isomavc1
    creation_time   : 2013-12-16T17:59:32.000000Z
    title           : Big Buck Bunny, Sunflower version
    artist          : Blender Foundation 2008, Janus Bager Kristensen 2013
    comment         : Creative Commons Attribution 3.0 - http://bbb3d.renderfarming.net
    genre           : Animation
    composer        : Sacha Goedegebure
  Duration: 00:10:34.53, start: 0.000000, bitrate: 4486 kb/s
    Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 1920x1080 [SAR 1:1 DAR 16:9], 4001 kb/s, 60 fps, 60 tbr, 60k tbn, 120 tbc (default)
    Metadata:
      creation_time   : 2013-12-16T17:59:32.000000Z
      handler_name    : GPAC ISO Video Handler
    Stream #0:1(und): Audio: mp3 (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 160 kb/s (default)
    Metadata:
      creation_time   : 2013-12-16T17:59:37.000000Z
      handler_name    : GPAC ISO Audio Handler
    Stream #0:2(und): Audio: ac3 (ac-3 / 0x332D6361), 48000 Hz, 5.1(side), fltp, 320 kb/s (default)
    Metadata:
      creation_time   : 2013-12-16T17:59:37.000000Z
      handler_name    : GPAC ISO Audio Handler
    Side data:
      audio service type: main
Input #1, mov,mp4,m4a,3gp,3g2,mj2, from '/Users/leandro.moreira/Downloads/video-with-timestamp.mp4':
  Metadata:
    major_brand     : mp42
    minor_version   : 0
    compatible_brands: isommp42
    creation_time   : 2019-10-01T11:29:28.000000Z
  Duration: 00:05:00.10, start: 0.000000, bitrate: 321 kb/s
    Stream #1:0(und): Video: h264 (Constrained Baseline) (avc1 / 0x31637661), yuv420p(tv, bt709), 640x360 [SAR 1:1 DAR 16:9], 222 kb/s, 30 fps, 30 tbr, 15360 tbn, 60 tbc (default)
    Metadata:
      creation_time   : 2019-10-01T11:29:28.000000Z
      handler_name    : ISO Media file produced by Google Inc. Created on: 10/01/2019.
    Stream #1:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 95 kb/s (default)
    Metadata:
      creation_time   : 2019-10-01T11:29:28.000000Z
      handler_name    : ISO Media file produced by Google Inc. Created on: 10/01/2019.
At least one output file must be specified

These indexes are the way to specifiy a stream, FFmpeg will assume a lot of defaults for you, Maps has good doc about it.

Niek-Okido commented 4 years ago

hi, yeah i am ok πŸ‘ , how about you?

thanks i just want to mentions this :) ,thanks so i have to define which one to use otherwise he will mess the 2 sounds with each other , (i did a quick test to place a if statement around it)

something not related to this, but when you run the code with the following settings:

    /*
     * H264 -> H264 (fixed gop)
     * Audio -> remuxed (untouched)
     * MP4 - MP4
     */
     StreamingParams sp = {0};
     sp.copy_audio = 1;
     sp.copy_video = 0;
     sp.video_codec = (char*)"libx264";
     sp.codec_priv_key = (char*)"x264-params";
     sp.codec_priv_value = (char*)"keyint=60:min-keyint=60:scenecut=0";

on a mp4[ x264 , aac] file as below , what is here going on ? i guess it have to do something with force-cfr, as well see you get hardtime with this before , you get any wiser on this?

Capture

Niek-Okido commented 4 years ago

ok the solution on this is, that i have to set the codec_priv_value to sp.codec_priv_value = (char*)"keyint=30:min-keyint=30:scenecut=0:force-cfr=1"; when you using a 30fps video and you set the values to 60 (fps) than it will mess upp frames with each other.