Opened 3 years ago

Closed 3 years ago

#2875 closed defect (invalid)

ffmpeg changes stream order from input to output

Reported by: kadmandux Owned by:
Priority: normal Component: avformat
Version: git-master Keywords: stream order
Cc: Blocked By:
Blocking: Reproduced by developer: no
Analyzed by developer: no

Description

Summary of the bug:

I'm extracting some fragments from an mpeg file, to join them afterwards.

The problem is that ffmpeg sometimes changes the order of the audio and video streams (video was the first stream and, sometimes, the file produced by ffmeg has audio as the first stream), and this makes more difficult to join the files, because of this:

http://trac.ffmpeg.org/ticket/2873

ffprobe M2U00135.mpg
Input #0, mpeg, from 'M2U00135.mpg':
  Duration: 00:03:44.61, start: 0.108467, bitrate: 7840 kb/s
    Stream #0:0[0x1e0]: Video: mpeg2video (Main), yuv420p, 720x576 [SAR 64:45 DAR 16:9], max. 9100 kb/s, 25 fps, 25 tbr, 90k tbn, 50 tbc
    Stream #0:1[0x80]: Audio: ac3, 48000 Hz, stereo, fltp, 256 kb/s

How to reproduce:

% ffmpeg -ss 10 -i M2U00135.mpg -c:v copy -c:a copy -t 40 v1.mpg
ffmpeg version N-55393-g3b2e99f Copyright (c) 2000-2013 the FFmpeg developers
  built on Aug  8 2013 21:32:57 with gcc 4.7.3 (GCC)
  configuration: --enable-gpl --enable-version3 --disable-w32threads --enable-av
isynth --enable-bzlib --enable-fontconfig --enable-frei0r --enable-gnutls --enab
le-iconv --enable-libass --enable-libbluray --enable-libcaca --enable-libfreetyp
e --enable-libgsm --enable-libilbc --enable-libmodplug --enable-libmp3lame --ena
ble-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-l
ibopus --enable-librtmp --enable-libschroedinger --enable-libsoxr --enable-libsp
eex --enable-libtheora --enable-libtwolame --enable-libvo-aacenc --enable-libvo-
amrwbenc --enable-libvorbis --enable-libvpx --enable-libx264 --enable-libxavs --
enable-libxvid --enable-zlib
  libavutil      52. 41.100 / 52. 41.100
  libavcodec     55. 24.100 / 55. 24.100
  libavformat    55. 13.102 / 55. 13.102
  libavdevice    55.  3.100 / 55.  3.100
  libavfilter     3. 82.100 /  3. 82.100
  libswscale      2.  4.100 /  2.  4.100
  libswresample   0. 17.103 /  0. 17.103
  libpostproc    52.  3.100 / 52.  3.100
Input #0, mpeg, from 'M2U00135.mpg':
  Duration: 00:03:44.61, start: 0.108467, bitrate: 7840 kb/s
    Stream #0:0[0x1e0]: Video: mpeg2video (Main), yuv420p, 720x576 [SAR 64:45 DAR 16:9], max. 9100 kb/s, 25 fps, 25 tbr, 90k tbn, 50 tbc
    Stream #0:1[0x80]: Audio: ac3, 48000 Hz, stereo, fltp, 256 kb/s
Output #0, mpeg, to 'v1.mpg':
  Metadata:
    encoder         : Lavf55.13.102
    Stream #0:0: Video: mpeg2video, yuv420p, 720x576 [SAR 64:45 DAR 16:9], q=2-31, max. 9100 kb/s, 25 fps, 90k tbn, 25 tbc
    Stream #0:1: Audio: ac3, 48000 Hz, stereo, 256 kb/s
Stream mapping:
  Stream #0:0 -> #0:0 (copy)
  Stream #0:1 -> #0:1 (copy)
Press [q] to stop, [?] for help
frame=   23 fps=0.0 q=-1.0 size=     794kB time=00:00:00.96 bitrate=6775.5kbits/
frame=   60 fps= 59 q=-1.0 size=    2126kB time=00:00:02.44 bitrate=7137.8kbits/

.....

% ffmpeg -ss 00:01:35 -i M2U00135.mpg -c:v copy -c:a copy -to 00:03:45 -nostats v2.mpg
ffmpeg version N-55393-g3b2e99f Copyright (c) 2000-2013 the FFmpeg developers
  built on Aug  8 2013 21:32:57 with gcc 4.7.3 (GCC)
  configuration: --enable-gpl --enable-version3 --disable-w32threads --enable-av
isynth --enable-bzlib --enable-fontconfig --enable-frei0r --enable-gnutls --enab
le-iconv --enable-libass --enable-libbluray --enable-libcaca --enable-libfreetyp
e --enable-libgsm --enable-libilbc --enable-libmodplug --enable-libmp3lame --ena
ble-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-l
ibopus --enable-librtmp --enable-libschroedinger --enable-libsoxr --enable-libsp
eex --enable-libtheora --enable-libtwolame --enable-libvo-aacenc --enable-libvo-
amrwbenc --enable-libvorbis --enable-libvpx --enable-libx264 --enable-libxavs --
enable-libxvid --enable-zlib
  libavutil      52. 41.100 / 52. 41.100
  libavcodec     55. 24.100 / 55. 24.100
  libavformat    55. 13.102 / 55. 13.102
  libavdevice    55.  3.100 / 55.  3.100
  libavfilter     3. 82.100 /  3. 82.100
  libswscale      2.  4.100 /  2.  4.100
  libswresample   0. 17.103 /  0. 17.103
  libpostproc    52.  3.100 / 52.  3.100
Input #0, mpeg, from 'M2U00135.mpg':
  Duration: 00:03:44.61, start: 0.108467, bitrate: 7840 kb/s
    Stream #0:0[0x1e0]: Video: mpeg2video (Main), yuv420p, 720x576 [SAR 64:45 DAR 16:9], max. 9100 kb/s, 25 fps, 25 tbr, 90k tbn, 50 tbc
    Stream #0:1[0x80]: Audio: ac3, 48000 Hz, stereo, fltp, 256 kb/s
Output #0, mpeg, to 'v2.mpg':
  Metadata:
    encoder         : Lavf55.13.102
    Stream #0:0: Video: mpeg2video, yuv420p, 720x576 [SAR 64:45 DAR 16:9], q=2-31, max. 9100 kb/s, 25 fps, 90k tbn, 25 tbc
    Stream #0:1: Audio: ac3, 48000 Hz, stereo, 256 kb/s
Stream mapping:
  Stream #0:0 -> #0:0 (copy)
  Stream #0:1 -> #0:1 (copy)
Press [q] to stop, [?] for help
frame= 3240 fps=155 q=-1.0 Lsize=  120176kB time=00:02:09.64 bitrate=7594.0kbits/s
video:115639kB audio:4058kB subtitle:0 global headers:0kB muxing overhead 0.399988%


% ffprobe v1.mpg
Input #0, mpeg, from 'v1.mpg':
  Duration: 00:00:40.14, start: 0.500000, bitrate: 7713 kb/s
    Stream #0:0[0x1e0]: Video: mpeg2video (Main), yuv420p, 720x576 [SAR 64:45 DAR 16:9], max. 9100 kb/s, 25 fps, 25 tbr, 90k tbn, 50 tbc
    Stream #0:1[0x80]: Audio: ac3, 48000 Hz, stereo, fltp, 256 kb/s

% ffprobe v2.mpg
Input #0, mpeg, from 'v2.mpg':
  Duration: 00:02:09.82, start: 0.500000, bitrate: 7583 kb/s
    Stream #0:0[0x80]: Audio: ac3, 48000 Hz, stereo, fltp, 256 kb/s
    Stream #0:1[0x1e0]: Video: mpeg2video (Main), yuv420p, 720x576 [SAR 64:45 DAR 16:9], max. 9100 kb/s, 25 fps, 25 tbr, 90k tbn, 50 tbc

The file v1.mpg has the same stream order than the original file, but v2.mpg has the stream orden changed.

And it is interesting to see that the ffmpeg console output said that the stream order for this file was the same that had the original file:

Input #0, mpeg, from 'M2U00135.mpg':
  Duration: 00:03:44.61, start: 0.108467, bitrate: 7840 kb/s
    Stream #0:0[0x1e0]: Video: mpeg2video (Main), yuv420p, 720x576 [SAR 64:45 DAR 16:9], max. 9100 kb/s, 25 fps, 25 tbr, 90k tbn, 50 tbc
    Stream #0:1[0x80]: Audio: ac3, 48000 Hz, stereo, fltp, 256 kb/s
Output #0, mpeg, to 'v2.mpg':
  Metadata:
    encoder         : Lavf55.13.102
    Stream #0:0: Video: mpeg2video, yuv420p, 720x576 [SAR 64:45 DAR 16:9], q=2-31, max. 9100 kb/s, 25 fps, 90k tbn, 25 tbc
    Stream #0:1: Audio: ac3, 48000 Hz, stereo, 256 kb/s
Stream mapping:
  Stream #0:0 -> #0:0 (copy)
  Stream #0:1 -> #0:1 (copy)

Change History (1)

comment:1 Changed 3 years ago by michael

  • Resolution set to invalid
  • Status changed from new to closed

There is no stream order in mpeg-ps.
what you see from ffmpeg output order is likely just if a audio or video packet comes first

Note: See TracTickets for help on using tickets.