Author Topic: avidemux works fine but trying the same with ffmpeg don't  (Read 469 times)

manbau00

  • Newbie
  • *
  • Posts: 9
avidemux works fine but trying the same with ffmpeg don't
« on: September 21, 2018, 08:20:47 AM »
Hello!

I have to resize a lot of  *.ts by repacking them to *.mkv. While everything works fine with avidemux with GUI, when trying to use ffmpeg on the command line because of performance issue, I got errors.

Is it possible to get the settings for ffmpeg that are used in avidemux.

Input *.ts:

Input #0, mpegts, from 'Test.ts':
  Duration: 02:05:36.08, start: 0.028789, bitrate: 8515 kb/s
  Program 1
    Metadata:
      service_name    : Service01
      service_provider: FFmpeg
    Stream #0:0[0x100]: Video: h264 (High) ([27][0][0][0] / 0x001B), yuv420p(progressive), 1280x720 [SAR 1:1 DAR 16:9], 50 fps, 50 tbr, 90k tbn, 100 tbc
    Stream #0:1[0x101](deu): Audio: ac3 ([129][0][0][0] / 0x0081), 48000 Hz, 5.1(side), fltp, 448 kb/s
    Stream #0:2[0x102](mis): Audio: ac3 ([129][0][0][0] / 0x0081), 48000 Hz, 5.1(side), fltp, 448 kb/s

Output:

Should be *.mkv


This is what I am using with avidemux: Works fine :-)

#PY  <- Needed to identify #
#--automatically built--

adm = Avidemux()
adm.loadVideo("D:/video/raw/Test.ts")
adm.clearSegments()
adm.addSegment(0, 0, 7536160000)
adm.markerA = 0
adm.markerB = 7536160000
adm.videoCodec("Copy")
adm.audioClearTracks()
adm.setSourceTrackLanguage(0,"deu")
adm.setSourceTrackLanguage(1,"mis")
adm.audioAddTrack(0)
adm.audioCodec(0, "copy");
adm.audioSetDrc(0, 0)
adm.audioSetShift(0, 0,0)
adm.audioAddTrack(1)
adm.audioCodec(1, "copy");
adm.audioSetDrc(1, 0)
adm.audioSetShift(1, 0,0)
adm.setContainer("MKV", "forceDisplayWidth=False", "displayWidth=1280", "displayAspectRatio=0")


I no, that I am not 100% in the right forum, but avidemux do the right things while ffmpeg direct don't.

Best regards
Manfred

eumagga0x2a

  • Hero Member
  • *****
  • Posts: 2201
Re: avidemux works fine but trying the same with ffmpeg don't
« Reply #1 on: September 21, 2018, 02:07:17 PM »
I have to resize a lot of  *.ts by repacking them to *.mkv. While everything works fine with avidemux with GUI, when trying to use ffmpeg on the command line because of performance issue, I got errors.

Please specify what is the performance issue you experience with Avidemux and what are the error messages from ffmpeg verbatim.

manbau00

  • Newbie
  • *
  • Posts: 9
Re: avidemux works fine but trying the same with ffmpeg don't
« Reply #2 on: September 21, 2018, 02:42:21 PM »
Hi!

Ad performance (network data transfer rate) issue,  I want to do the conversation on the file server on which the files are stored. But on this machine I will do as less package installation as possible. So hopefully I have not to use a remote machine with avidemux installed to do the conversation because that needs a lot of time for transferring data.

Ad ffmpeg error,

# ffmpeg -i Test.mpg -map 0 -c copy Test.mkv                                               

ffmpeg version 3.4.4-0ubuntu0.18.04.1 Copyright (c) 2000-2018 the FFmpeg developers
  built with gcc 7 (Ubuntu 7.3.0-16ubuntu3)
  configuration: --prefix=/usr --extra-version=0ubuntu0.18.04.1 --toolchain=hardened --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-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libflite --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libgme --enable-libgsm --enable-libmp3lame --enable-libmysofa --enable-libopenjpeg --enable-libopenmpt --enable-libopus --enable-libpulse --enable-librubberband --enable-librsvg --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libssh --enable-libtheora --enable-libtwolame --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx265 --enable-libxml2 --enable-libxvid --enable-libzmq --enable-libzvbi --enable-omx --enable-openal --enable-opengl --enable-sdl2 --enable-libdc1394 --enable-libdrm --enable-libiec61883 --enable-chromaprint --enable-frei0r --enable-libopencv --enable-libx264 --enable-shared
  libavutil      55. 78.100 / 55. 78.100
  libavcodec     57.107.100 / 57.107.100
  libavformat    57. 83.100 / 57. 83.100
  libavdevice    57. 10.100 / 57. 10.100
  libavfilter     6.107.100 /  6.107.100
  libavresample   3.  7.  0 /  3.  7.  0
  libswscale      4.  8.100 /  4.  8.100
  libswresample   2.  9.100 /  2.  9.100
  libpostproc    54.  7.100 / 54.  7.100
Input #0, mpegts, from 'Test.mpg':
  Duration: 02:05:36.08, start: 0.028789, bitrate: 8515 kb/s
  Program 1
    Metadata:
      service_name    : Service01
      service_provider: FFmpeg
    Stream #0:0[0x100]: Video: h264 (High) ([27][0][0][0] / 0x001B), yuv420p(progressive), 1280x720 [SAR 1:1 DAR 16:9], 50 fps, 50 tbr, 90k tbn, 100 tbc
    Stream #0:1[0x101](deu): Audio: ac3 ([129][0][0][0] / 0x0081), 48000 Hz, 5.1(side), fltp, 448 kb/s
    Stream #0:2[0x102](mis): Audio: ac3 ([129][0][0][0] / 0x0081), 48000 Hz, 5.1(side), fltp, 448 kb/s
Output #0, matroska, to 'Test.mkv':
  Metadata:
    encoder         : Lavf57.83.100
    Stream #0:0: Video: h264 (High) (H264 / 0x34363248), yuv420p(progressive), 1280x720 [SAR 1:1 DAR 16:9], q=2-31, 50 fps, 50 tbr, 1k tbn, 90k tbc
    Stream #0:1(deu): Audio: ac3 ([0]
  • [0] / 0x2000), 48000 Hz, 5.1(side), fltp, 448 kb/s

    Stream #0:2(mis): Audio: ac3 ([0]
  • [0] / 0x2000), 48000 Hz, 5.1(side), fltp, 448 kb/s

Stream mapping:
  Stream #0:0 -> #0:0 (copy)
  Stream #0:1 -> #0:1 (copy)
  Stream #0:2 -> #0:2 (copy)
Press [q] to stop, [?] for help
[matroska @ 0x5634dbae5cc0] Timestamps are unset in a packet for stream 0. This is deprecated and will stop working in the future. Fix your code to set the timestamps properly
[matroska @ 0x5634dbae5cc0] Can't write packet with unknown timestamp
av_interleaved_write_frame(): Invalid argument
frame=    2 fps=0.0 q=-1.0 Lsize=     165kB time=00:00:00.00 bitrate=450074.7kbits/s speed=0.539x
video:171kB audio:4kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: unknown
Conversion failed!


The same happens with (-fflags +genpts)


# ffmpeg -fflags +genpts -i Test.mpg -map 0 -c copy Test.mkv

ffmpeg version 3.4.4-0ubuntu0.18.04.1 Copyright (c) 2000-2018 the FFmpeg developers
  built with gcc 7 (Ubuntu 7.3.0-16ubuntu3)
  configuration: --prefix=/usr --extra-version=0ubuntu0.18.04.1 --toolchain=hardened --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-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libflite --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libgme --enable-libgsm --enable-libmp3lame --enable-libmysofa --enable-libopenjpeg --enable-libopenmpt --enable-libopus --enable-libpulse --enable-librubberband --enable-librsvg --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libssh --enable-libtheora --enable-libtwolame --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx265 --enable-libxml2 --enable-libxvid --enable-libzmq --enable-libzvbi --enable-omx --enable-openal --enable-opengl --enable-sdl2 --enable-libdc1394 --enable-libdrm --enable-libiec61883 --enable-chromaprint --enable-frei0r --enable-libopencv --enable-libx264 --enable-shared
  libavutil      55. 78.100 / 55. 78.100
  libavcodec     57.107.100 / 57.107.100
  libavformat    57. 83.100 / 57. 83.100
  libavdevice    57. 10.100 / 57. 10.100
  libavfilter     6.107.100 /  6.107.100
  libavresample   3.  7.  0 /  3.  7.  0
  libswscale      4.  8.100 /  4.  8.100
  libswresample   2.  9.100 /  2.  9.100
  libpostproc    54.  7.100 / 54.  7.100
Input #0, mpegts, from 'Test.mpg':
  Duration: 02:05:36.08, start: 0.028789, bitrate: 8515 kb/s
  Program 1
    Metadata:
      service_name    : Service01
      service_provider: FFmpeg
    Stream #0:0[0x100]: Video: h264 (High) ([27][0][0][0] / 0x001B), yuv420p(progressive), 1280x720 [SAR 1:1 DAR 16:9], 50 fps, 50 tbr, 90k tbn, 100 tbc
    Stream #0:1[0x101](deu): Audio: ac3 ([129][0][0][0] / 0x0081), 48000 Hz, 5.1(side), fltp, 448 kb/s
    Stream #0:2[0x102](mis): Audio: ac3 ([129][0][0][0] / 0x0081), 48000 Hz, 5.1(side), fltp, 448 kb/s
File 'Test.mkv' already exists. Overwrite ? [y/N] y
Output #0, matroska, to 'Test.mkv':
  Metadata:
    encoder         : Lavf57.83.100
    Stream #0:0: Video: h264 (High) (H264 / 0x34363248), yuv420p(progressive), 1280x720 [SAR 1:1 DAR 16:9], q=2-31, 50 fps, 50 tbr, 1k tbn, 90k tbc
    Stream #0:1(deu): Audio: ac3 ([0]
  • [0] / 0x2000), 48000 Hz, 5.1(side), fltp, 448 kb/s

    Stream #0:2(mis): Audio: ac3 ([0]
  • [0] / 0x2000), 48000 Hz, 5.1(side), fltp, 448 kb/s

Stream mapping:
  Stream #0:0 -> #0:0 (copy)
  Stream #0:1 -> #0:1 (copy)
  Stream #0:2 -> #0:2 (copy)
Press [q] to stop, [?] for help
[matroska @ 0x5623633b4c60] Timestamps are unset in a packet for stream 0. This is deprecated and will stop working in the future. Fix your code to set the timestamps properly
[matroska @ 0x5623633b4c60] Can't write packet with unknown timestamp
av_interleaved_write_frame(): Invalid argument
frame=    2 fps=0.0 q=-1.0 Lsize=     165kB time=00:00:00.00 bitrate=450074.7kbits/s speed=0.956x
video:171kB audio:4kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: unknown
Conversion failed!

Regards

Manfred

eumagga0x2a

  • Hero Member
  • *****
  • Posts: 2201
Re: avidemux works fine but trying the same with ffmpeg don't
« Reply #3 on: September 21, 2018, 03:46:14 PM »
Which application is responsible for generating a transport stream with a H.264 video without valid PTS? For this specific case, you can't do anything useful with ffmpeg (Avidemux offers a time-consuming workaround which might be able to restore presentation timestamps).

This is true that handling large video files with Avidemux over a slow network connection is no fun.

manbau00

  • Newbie
  • *
  • Posts: 9
Re: avidemux works fine but trying the same with ffmpeg don't
« Reply #4 on: September 21, 2018, 07:41:31 PM »
Mostly often the files are from DVB-S2 streams stored with mythtv.

Is it possible to do the restoration of the presentation timestamps with some bash scripting? Where can I find the code fragment which do the trick in the source code in avidemux?
« Last Edit: September 21, 2018, 07:54:08 PM by manbau00 »

eumagga0x2a

  • Hero Member
  • *****
  • Posts: 2201
Re: avidemux works fine but trying the same with ffmpeg don't
« Reply #5 on: September 21, 2018, 08:19:03 PM »
Could you please provide a sample?

The PTS check and reconstruction is done by ADM_Composer::checkForValidPts, called from ADM_Composer::addFile. I doubt that this matches your experience when loading these streams in Avidemux.

No, bash scripting can't accomplish this task :-)

manbau00

  • Newbie
  • *
  • Posts: 9
Re: avidemux works fine but trying the same with ffmpeg don't
« Reply #6 on: September 21, 2018, 08:43:40 PM »
Here is the sample. It is cut and stream copied into MpegTS container with avidemux.

https://secure.edolos.com/owncloud/public.php?service=files&t=2e80c8a8130b3a97c2b84bffa32155f8

Regards
Manfred

eumagga0x2a

  • Hero Member
  • *****
  • Posts: 2201
Re: avidemux works fine but trying the same with ffmpeg don't
« Reply #7 on: September 22, 2018, 05:47:01 AM »
I'm sorry, please provide a sample of the original source transport stream, not a remuxed one.

Code: [Select]
dd if=/path/to/source of=/path/to/sample bs=1M count=300

manbau00

  • Newbie
  • *
  • Posts: 9
Re: avidemux works fine but trying the same with ffmpeg don't
« Reply #8 on: September 22, 2018, 08:35:25 AM »
Hi,

I am not allowed to post!

An Error Has Occurred!
CleanTalk: *** Forbidden. Please enable JavaScript. Message seems to be spam. ***

Can you help me?

Regards
Manfred

manbau00

  • Newbie
  • *
  • Posts: 9
Re: avidemux works fine but trying the same with ffmpeg don't
« Reply #9 on: September 22, 2018, 08:46:35 AM »
Hi!

I put the Message into a text document. Hopefully this works.

Regards
Manfred

eumagga0x2a

  • Hero Member
  • *****
  • Posts: 2201
Re: avidemux works fine but trying the same with ffmpeg don't
« Reply #10 on: September 22, 2018, 09:26:51 AM »
Thank you, I hope to be able to look at it later today.

eumagga0x2a

  • Hero Member
  • *****
  • Posts: 2201
Re: avidemux works fine but trying the same with ffmpeg don't
« Reply #11 on: September 22, 2018, 06:22:18 PM »
I can reproduce the issue (also with my own captures from DVB-C). The reason is not that PTS were unset but a few frames pretty close to the start of the cut stream get invalid (not monotonically increasing) DTS. Avidemux doesn't see DTS going back (it regards DTS of some frames as unset, which may be correct and harmless).

Interestingly, skipping the start of the stream with say ffmpeg -ss 0.2 -i Sample02_cut_with_avidemux.ts allows to remux it to MKV without errors, but PTS in this MKV are totally broken.

From the practical POV, if you have to use Avidemux anyway to delete portions of the video, why not saving the result to a MKV right away?

manbau00

  • Newbie
  • *
  • Posts: 9
Re: avidemux works fine but trying the same with ffmpeg don't
« Reply #12 on: September 22, 2018, 06:40:56 PM »
Hi,

for the first, many thanks for your analysis of the issue.

Ad practical POV, yes I am willing to do so for the future. But I have already many damaged files.

Do you think skipping the first frames and trying -ss 0.2 -fflags +genpts is a solution? Could this restore the PTS?

Could this also be fixed in Avidemux that it does not happen again?

Regards
Manfred

manbau00

  • Newbie
  • *
  • Posts: 9
Re: avidemux works fine but trying the same with ffmpeg don't
« Reply #13 on: September 22, 2018, 06:52:35 PM »
I'll tried the following:

 ffmpeg  -ss 0.2 -fflags +genpts -i Test.mpg -map 0 -c copy -f matroska -ignore_unknown -sn -y Test.mkv

But now it happens later. After the 300MB.

Input #0, mpegts, from 'Test.mpg':
  Duration: 02:05:36.08, start: 0.028789, bitrate: 8515 kb/s
  Program 1
    Metadata:
      service_name    : Service01
      service_provider: FFmpeg
    Stream #0:0[0x100]: Video: h264 (High) ([27][0][0][0] / 0x001B), yuv420p(progressive), 1280x720 [SAR 1:1 DAR 16:9], 50 fps, 50 tbr, 90k tbn, 100 tbc
    Stream #0:1[0x101](deu): Audio: ac3 ([129][0][0][0] / 0x0081), 48000 Hz, 5.1(side), fltp, 448 kb/s
    Stream #0:2[0x102](mis): Audio: ac3 ([129][0][0][0] / 0x0081), 48000 Hz, 5.1(side), fltp, 448 kb/s
Output #0, matroska, to 'Test.mkv':
  Metadata:
    encoder         : Lavf57.83.100
    Stream #0:0: Video: h264 (High) (H264 / 0x34363248), yuv420p(progressive), 1280x720 [SAR 1:1 DAR 16:9], q=2-31, 50 fps, 50 tbr, 1k tbn, 90k tbc
    Stream #0:1(deu): Audio: ac3 ([0]
  • [0] / 0x2000), 48000 Hz, 5.1(side), fltp, 448 kb/s

    Stream #0:2(mis): Audio: ac3 ([0]
  • [0] / 0x2000), 48000 Hz, 5.1(side), fltp, 448 kb/s

Stream mapping:
  Stream #0:0 -> #0:0 (copy)
  Stream #0:1 -> #0:1 (copy)
  Stream #0:2 -> #0:2 (copy)
Press [q] to stop, [?] for help
[matroska @ 0x5577f9e44f60] Timestamps are unset in a packet for stream 0. This is deprecated and will stop working in the future. Fix your code to set the timestamps properly
[matroska @ 0x5577f9e44f60] Can't write packet with unknown timestamp
av_interleaved_write_frame(): Invalid argument
frame=19272 fps=1223 q=-1.0 Lsize=  411301kB time=00:06:25.85 bitrate=8732.3kbits/s speed=24.5x
video:368744kB audio:42220kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.081901%
Conversion failed!

eumagga0x2a

  • Hero Member
  • *****
  • Posts: 2201
Re: avidemux works fine but trying the same with ffmpeg don't
« Reply #14 on: September 23, 2018, 09:59:41 AM »
Do you think skipping the first frames and trying -ss 0.2 -fflags +genpts is a solution? Could this restore the PTS?

No. BTW, -ss belongs before -i. PTS are broken by ffmpeg when saving after seek.

Quote
Could this also be fixed in Avidemux that it does not happen again?

I'll try to look into it, don't have time ATM though.