Opened 8 years ago

Closed 8 years ago

#5152 closed defect (wontfix)

Broken B frames while copying MPEG-2 ibp without recompression from some point

Reported by: Aleksandr Owned by:
Priority: normal Component: undetermined
Version: git-master Keywords:
Cc: Blocked By:
Blocking: Reproduced by developer: no
Analyzed by developer: no

Description

Copying ibp video without recompression from start point to the end point generates video with several broken frames in the start and in the end of the result file.

How to reproduce:

% ffmpeg -i opengop.mov -ss 3 -t 1 -c copy result.mov
(the container does not matter)
% ffmpeg -i result.mov %d.png

opengop.mov is stored here https://yadi.sk/d/z5RvZNremqCxN

ffmpeg version is the last from zeranoe:
ffmpeg-latest-win32-static.7z 10-Jan-2016 01:39

notes:

"Opened GOP" - is MPEG-2 with B-frames, that depend on previous and next key frames. And this B frames are going before I frame in the decoded video stream.

In decoded video stream it is going like b-b-b-I-..
In the file it is layed like I-b-b-b , because it's impossible to decode "b"s without the "next going" I.

So, the problem of "opened gop" begins when you export video from some point, because there is no point (in the file) from where you can start copying frames without leaving first and last frames without the frames they depend on. So you can't just step to the previous or next I frame in the file, because you will get I-b-b-b that's decoding like b-b-b-I , and this b frames depend on the previous key frame.

Maybe you need to force recompression of the "half-of-the-gop" in the beginning and in the end of the file, but I'm not sure this will work, because the next going b-frames after the I-frames will still have their dependencies, but at least they'll have an actual picture before.

Change History (15)

comment:1 by Carl Eugen Hoyos, 8 years ago

Component: ffmpegundetermined
Keywords: Opened Gop keyframes removed

Please provide the command line that allows to reproduce the issue together with the complete, uncut console output to make this a valid ticket.

comment:2 by Aleksandr, 8 years ago

C:\data>ffmpeg -i opengop.mov -ss 3 -t 1 -c copy result.mov
ffmpeg version N-77782-g42c54d4 Copyright (c) 2000-2016 the FFmpeg developers
  built with gcc 5.2.0 (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-libbs2b --enable-libcaca --
enable-libdcadec --enable-libfreetype --enable-libgme --enable-libgsm --enable-l
ibilbc --enable-libmodplug --enable-libmp3lame --enable-libopencore-amrnb --enab
le-libopencore-amrwb --enable-libopenjpeg --enable-libopus --enable-librtmp --en
able-libschroedinger --enable-libsoxr --enable-libspeex --enable-libtheora --ena
ble-libtwolame --enable-libvidstab --enable-libvo-aacenc --enable-libvo-amrwbenc
 --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enabl
e-libx264 --enable-libx265 --enable-libxavs --enable-libxvid --enable-libzimg --
enable-lzma --enable-decklink --enable-zlib
  libavutil      55. 13.100 / 55. 13.100
  libavcodec     57. 22.100 / 57. 22.100
  libavformat    57. 21.101 / 57. 21.101
  libavdevice    57.  0.100 / 57.  0.100
  libavfilter     6. 23.100 /  6. 23.100
  libswscale      4.  0.100 /  4.  0.100
  libswresample   2.  0.101 /  2.  0.101
  libpostproc    54.  0.100 / 54.  0.100
[mov,mp4,m4a,3gp,3g2,mj2 @ 02cc0960] ignoring 'frma' atom of 'in24', stream form
at is 'in24'
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'opengop.mov':
  Metadata:
    major_brand     : qt
    minor_version   : 512
    compatible_brands: qt
    encoder         : Lavf57.21.101
  Duration: 00:00:05.04, start: 0.000000, bitrate: 51487 kb/s
    Stream #0:0(eng): Video: mpeg2video (4:2:2) (xd5c / 0x63356478), yuv422p(tv,
 bt709), 1920x1080 [SAR 1:1 DAR 16:9], 50337 kb/s, 25 fps, 25 tbr, 12800 tbn, 50
 tbc (default)
    Metadata:
      handler_name    : DataHandler
      encoder         : XDCAM HD422 1080i50
      timecode        : 00:00:00:00
    Stream #0:1(eng): Audio: pcm_s24le (in24 / 0x34326E69), 48000 Hz, mono, s32
(24 bit), 1152 kb/s (default)
    Metadata:
      handler_name    : DataHandler
    Stream #0:2(eng): Data: none (tmcd / 0x64636D74), 0 kb/s
    Metadata:
      handler_name    : DataHandler
      timecode        : 00:00:00:00
File 'result.mov' already exists. Overwrite ? [y/N] y
[mov @ 02cc3d00] Codec for stream 0 does not use global headers but container fo
rmat requires global headers
[mov @ 02cc3d00] Codec for stream 1 does not use global headers but container fo
rmat requires global headers
Output #0, mov, to 'result.mov':
  Metadata:
    major_brand     : qt
    minor_version   : 512
    compatible_brands: qt
    encoder         : Lavf57.21.101
    Stream #0:0(eng): Video: mpeg2video (xd5c / 0x63356478), yuv422p, 1920x1080
[SAR 1:1 DAR 16:9], q=2-31, 50337 kb/s, 25 fps, 25 tbr, 12800 tbn, 12800 tbc (de
fault)
    Metadata:
      handler_name    : DataHandler
      encoder         : XDCAM HD422 1080i50
      timecode        : 00:00:00:00
    Stream #0:1(eng): Audio: pcm_s24le (in24 / 0x34326E69), 48000 Hz, mono (24 b
it), 1152 kb/s (default)
    Metadata:
      handler_name    : DataHandler
Stream mapping:
  Stream #0:0 -> #0:0 (copy)
  Stream #0:1 -> #0:1 (copy)
Press [q] to stop, [?] for help
frame=   17 fps=0.0 q=-1.0 Lsize=    3655kB time=00:00:01.00 bitrate=29943.0kbit
s/s speed=83.3x
video:3512kB audio:141kB subtitle:0kB other streams:0kB global headers:0kB muxin
g overhead: 0.065367%

C:\data>ffmpeg -i result.mov %d.png
ffmpeg version N-77782-g42c54d4 Copyright (c) 2000-2016 the FFmpeg developers
  built with gcc 5.2.0 (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-libbs2b --enable-libcaca --
enable-libdcadec --enable-libfreetype --enable-libgme --enable-libgsm --enable-l
ibilbc --enable-libmodplug --enable-libmp3lame --enable-libopencore-amrnb --enab
le-libopencore-amrwb --enable-libopenjpeg --enable-libopus --enable-librtmp --en
able-libschroedinger --enable-libsoxr --enable-libspeex --enable-libtheora --ena
ble-libtwolame --enable-libvidstab --enable-libvo-aacenc --enable-libvo-amrwbenc
 --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enabl
e-libx264 --enable-libx265 --enable-libxavs --enable-libxvid --enable-libzimg --
enable-lzma --enable-decklink --enable-zlib
  libavutil      55. 13.100 / 55. 13.100
  libavcodec     57. 22.100 / 57. 22.100
  libavformat    57. 21.101 / 57. 21.101
  libavdevice    57.  0.100 / 57.  0.100
  libavfilter     6. 23.100 /  6. 23.100
  libswscale      4.  0.100 /  4.  0.100
  libswresample   2.  0.101 /  2.  0.101
  libpostproc    54.  0.100 / 54.  0.100
[mov,mp4,m4a,3gp,3g2,mj2 @ 00a90480] ignoring 'frma' atom of 'in24', stream form
at is 'in24'
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'result.mov':
  Metadata:
    major_brand     : qt
    minor_version   : 512
    compatible_brands: qt
    encoder         : Lavf57.21.101
  Duration: 00:00:01.00, start: 0.000000, bitrate: 29943 kb/s
    Stream #0:0(eng): Video: mpeg2video (4:2:2) (xd5c / 0x63356478), yuv422p(tv,
 bt709), 1920x1080 [SAR 1:1 DAR 16:9], 42311 kb/s, 25 fps, 25 tbr, 12800 tbn, 50
 tbc (default)
    Metadata:
      handler_name    : DataHandler
      encoder         : XDCAM HD422 1080i50
      timecode        : 00:00:00:00
    Stream #0:1(eng): Audio: pcm_s24le (in24 / 0x34326E69), 48000 Hz, mono, s32
(24 bit), 1152 kb/s (default)
    Metadata:
      handler_name    : DataHandler
    Stream #0:2(eng): Data: none (tmcd / 0x64636D74), 0 kb/s
    Metadata:
      handler_name    : DataHandler
      timecode        : 00:00:00:00
Output #0, image2, to '%d.png':
  Metadata:
    major_brand     : qt
    minor_version   : 512
    compatible_brands: qt
    encoder         : Lavf57.21.101
    Stream #0:0(eng): Video: png, rgb24, 1920x1080 [SAR 1:1 DAR 16:9], q=2-31, 2
00 kb/s, 25 fps, 25 tbn, 25 tbc (default)
    Metadata:
      handler_name    : DataHandler
      timecode        : 00:00:00:00
      encoder         : Lavc57.22.100 png
Stream mapping:
  Stream #0:0 -> #0:0 (mpeg2video (native) -> png (native))
Press [q] to stop, [?] for help
frame=   13 fps=0.0 q=-0.0 size=N/A time=00:00:00.36 bitrate=N/A dup=11 drop=0 s
frame=   17 fps= 11 q=-0.0 size=N/A time=00:00:00.52 bitrate=N/A dup=11 drop=0 s
frame=   22 fps=9.1 q=-0.0 size=N/A time=00:00:00.72 bitrate=N/A dup=11 drop=0 s
frame=   27 fps=9.2 q=-0.0 size=N/A time=00:00:00.92 bitrate=N/A dup=12 drop=0 s
frame=   27 fps=7.7 q=-0.0 Lsize=N/A time=00:00:01.08 bitrate=N/A dup=12 drop=0
speed=0.309x
video:58376kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing
 overhead: unknown

in reply to:  2 comment:3 by Carl Eugen Hoyos, 8 years ago

Replying to Aleksandr_Slobodeniuk:

C:\data>ffmpeg -i opengop.mov

Did you provide this input file?

comment:4 by Aleksandr, 8 years ago

yes, it's here:
https://yadi.sk/d/z5RvZNremqCxN

This is the "normal" input file.
by typing

ffmpeg -i opengop.mov -ss 3 -t 1 -c copy result.mov

you can get the "broken" output file result.mov

comment:5 by Carl Eugen Hoyos, 8 years ago

Resolution: needs_more_info
Status: newclosed

Please reopen this ticket if you can provide a command line (including console output) for the input file that you provided.

comment:6 by Aleksandr, 8 years ago

what is wrong with comment 2 ?

comment:7 by Carl Eugen Hoyos, 8 years ago

What's wrong with comment:3?

$ ffmpeg -i opengop.mov
ffmpeg version N-77804-gd64d6ed Copyright (c) 2000-2016 the FFmpeg developers
  built with gcc 4.7 (SUSE Linux)
  configuration: --enable-gpl --enable-libpulse
  libavutil      55. 13.100 / 55. 13.100
  libavcodec     57. 22.100 / 57. 22.100
  libavformat    57. 21.101 / 57. 21.101
  libavdevice    57.  0.100 / 57.  0.100
  libavfilter     6. 23.100 /  6. 23.100
  libswscale      4.  0.100 /  4.  0.100
  libswresample   2.  0.101 /  2.  0.101
  libpostproc    54.  0.100 / 54.  0.100
opengop.mov: No such file or directory

You did not provide this file.

comment:8 by Carl Eugen Hoyos, 8 years ago

Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'opengop.mov':
  Metadata:
    major_brand     : qt
    minor_version   : 512
    compatible_brands: qt
    encoder         : Lavf57.21.101

Please do not upload this input file as it was produced with FFmpeg, instead please provide command line and complete, uncut console output for the file you uploaded.

comment:9 by Aleksandr, 8 years ago

C:\data>ffmpeg -i opengop.mxf -ss 3 -t 1 -c copy result.mov
ffmpeg version N-77782-g42c54d4 Copyright (c) 2000-2016 the FFmpeg developers
  built with gcc 5.2.0 (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-libbs2b --enable-libcaca --
enable-libdcadec --enable-libfreetype --enable-libgme --enable-libgsm --enable-l
ibilbc --enable-libmodplug --enable-libmp3lame --enable-libopencore-amrnb --enab
le-libopencore-amrwb --enable-libopenjpeg --enable-libopus --enable-librtmp --en
able-libschroedinger --enable-libsoxr --enable-libspeex --enable-libtheora --ena
ble-libtwolame --enable-libvidstab --enable-libvo-aacenc --enable-libvo-amrwbenc
 --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enabl
e-libx264 --enable-libx265 --enable-libxavs --enable-libxvid --enable-libzimg --
enable-lzma --enable-decklink --enable-zlib
  libavutil      55. 13.100 / 55. 13.100
  libavcodec     57. 22.100 / 57. 22.100
  libavformat    57. 21.101 / 57. 21.101
  libavdevice    57.  0.100 / 57.  0.100
  libavfilter     6. 23.100 /  6. 23.100
  libswscale      4.  0.100 /  4.  0.100
  libswresample   2.  0.101 /  2.  0.101
  libpostproc    54.  0.100 / 54.  0.100
[mxf @ 00920960] index entry 124 + TemporalOffset 1 = 125, which is out of bound
s
Guessed Channel Layout for  Input Stream #0.1 : mono
Input #0, mxf, from 'opengop.mxf':
  Metadata:
    uid             : adab4424-2f25-4dc7-92ff-29bd000c0000
    generation_uid  : adab4424-2f25-4dc7-92ff-29bd000c0001
    company_name    : FFmpeg
    product_name    : OP1a Muxer
    product_version : 57.21.101
    product_uid     : adab4424-2f25-4dc7-92ff-29bd000c0002
    modification_date: 0000-01-01 00:00:00
    material_package_umid: 0x060A2B340101010501010D00131205F6529471341B1205F6005
29471341B1200
    timecode        : 00:00:00:00
  Duration: 00:00:05.00, start: 0.000000, bitrate: 51910 kb/s
    Stream #0:0: Video: mpeg2video (4:2:2), yuv422p(tv, bt709), 1920x1080 [SAR 1
:1 DAR 16:9], 50000 kb/s, 25 fps, 25 tbr, 25 tbn, 50 tbc
    Metadata:
      file_package_umid: 0x060A2B340101010501010D00131205F6529471341B1205F600529
471341B1201
    Stream #0:1: Audio: pcm_s24le, 48000 Hz, 1 channels, s32 (24 bit), 1152 kb/s

    Metadata:
      file_package_umid: 0x060A2B340101010501010D00131205F6529471341B1205F600529
471341B1201
File 'result.mov' already exists. Overwrite ? [y/N] y
[mov @ 009b3e40] Codec for stream 0 does not use global headers but container fo
rmat requires global headers
[mov @ 009b3e40] Codec for stream 1 does not use global headers but container fo
rmat requires global headers
Output #0, mov, to 'result.mov':
  Metadata:
    uid             : adab4424-2f25-4dc7-92ff-29bd000c0000
    generation_uid  : adab4424-2f25-4dc7-92ff-29bd000c0001
    company_name    : FFmpeg
    product_name    : OP1a Muxer
    product_version : 57.21.101
    product_uid     : adab4424-2f25-4dc7-92ff-29bd000c0002
    modification_date: 0000-01-01 00:00:00
    material_package_umid: 0x060A2B340101010501010D00131205F6529471341B1205F6005
29471341B1200
    timecode        : 00:00:00:00
    encoder         : Lavf57.21.101
    Stream #0:0: Video: mpeg2video (m2v1 / 0x3176326D), yuv422p, 1920x1080 [SAR
1:1 DAR 16:9], q=2-31, 50000 kb/s, 25 fps, 25 tbr, 12800 tbn, 25 tbc
    Metadata:
      file_package_umid: 0x060A2B340101010501010D00131205F6529471341B1205F600529
471341B1201
    Stream #0:1: Audio: pcm_s24le (in24 / 0x34326E69), 48000 Hz, mono (24 bit),
1152 kb/s
    Metadata:
      file_package_umid: 0x060A2B340101010501010D00131205F6529471341B1205F600529
471341B1201
Stream mapping:
  Stream #0:0 -> #0:0 (copy)
  Stream #0:1 -> #0:1 (copy)
Press [q] to stop, [?] for help
frame=   17 fps=0.0 q=-1.0 Lsize=    3655kB time=00:00:01.00 bitrate=29943.0kbit
s/s speed=76.9x
video:3512kB audio:141kB subtitle:0kB other streams:0kB global headers:0kB muxin
g overhead: 0.065367%

comment:10 by Aleksandr, 8 years ago

Resolution: needs_more_info
Status: closedreopened

comment:11 by Carl Eugen Hoyos, 8 years ago

I used your command line to produce result.mov and tested the following:

$ ffmpeg -vsync 0 -i result.mov -vframes 9 out%1d.jpg

The resulting jpg images show "3:11" until "3:19" (nothing missing): What is wrong with the output?

comment:12 by Aleksandr, 8 years ago

1) result must be from 3:00 to 3:24
2) if you type (it's 25 frames)

ffmpeg -i result.mov %d.jpg

you'll see that

  • first 11 frames show 3:11 (because ffmpeg can't decode 11 b frames because they are from the middle of the gop)
  • last 2 frames show 3:24 and 4:01 , 4:00 is missing (because it was not read. 4:01 is a key frame that goes before 4:00 in the file, and it was pulled out with nullptr to avcodec_decode_video)
Last edited 8 years ago by Aleksandr (previous) (diff)

in reply to:  12 comment:13 by Carl Eugen Hoyos, 8 years ago

Replying to Aleksandr_Slobodeniuk:

1) result must be from 3:00 to 3:24

This is impossible for -vcodec copy and the file you provided, and this is not a deficiency of FFmpeg.

2) if you type (it's 25 frames)

No, result.mov only contains 15 frames.

ffmpeg -i result.mov %d.jpg

you'll see that

  • first 11 frames show 3:11 (because ffmpeg can't decode 11 b frames because they are from the middle of the gop)

You have to use -vsync 0 to avoid the command duplicating frames, the ten additional frames are not part of result.mov, the first available frame is "3:11", the second "3:12" and this is not related to FFmpeg but the format of the given input file.

  • last 2 frames show 3:24 and 4:01 , 4:00 is missing (because it was not read. 4:01 is I frame that goes before 4:00 in the file, and it was pulled out with nullptr to avcodec_decode_video)

How should FFmpeg behave in your opinion?

Last edited 8 years ago by Carl Eugen Hoyos (previous) (diff)

comment:14 by Aleksandr, 8 years ago

It's possible to get described errors with the output picture. And there is no "clean" way to fix it.
But the solution exists: force recompression of the first gop and the last gop.

P.S.
Intent of this ticket - is to report on this case, not to expect the solution.

Last edited 8 years ago by Aleksandr (previous) (diff)

in reply to:  14 comment:15 by Carl Eugen Hoyos, 8 years ago

Resolution: wontfix
Status: reopenedclosed

Replying to Aleksandr_Slobodeniuk:

But the solution exists: force recompression of the first gop and the last gop.

This is not how -vcodec copy works.

Note: See TracTickets for help on using tickets.