3

When transcoding movies from an AVI to mp4 sometimes FFMPEG sets the "Source Duration" incorrectly.

This messes up playback on IOS devices. Specifically, it causes the video to cut out at "Source duration" while the audio still plays.

enter image description here

FFMPEG output transcode doesn't' show anything odd at all. Looks normal, no errors or warnings.

  • Can I force FFMPEG to never add the "Source Duration" metadata?
  • How do I edit the track metadata shown by mediainfo? I tried Mp4box, and a few others, but I can't seem to figure out how to edit track level metadata.

Thanks.

Log is below.

ffmpeg version N-77455-g4707497 Copyright (c) 2000-2015 the FFmpeg developers   built with gcc 5.2.0 (GCC)   configuration: --enable-gpl
    --enable-version3 --disable-w32threads --enable-avisynth --enable-bzlib --enable-fontconfig --enable-frei0r --enable-gnutls --enable-iconv --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libdcadec --enable-libfreetype --enable-libgme --enable-libgsm --enable-libilbc --enable-libmodplug --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libopus --enable-librtmp --enable-libschroedinger --enable-libsoxr --enable-libspeex --enable-libtheora --enable-libtwolame --enable-libvidstab --enable-libvo-aacenc --enable-libvo-amrwbenc --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxavs --enable-libxvid --enable-libzimg --enable-lzma --enable-decklink --enable-zlib   libavutil      55. 11.100 / 55. 11.100   libavcodec     57. 20.100 / 57. 20.100   libavformat    57. 20.100 / 57. 20.100   libavdevice    57.  0.100 / 57.  0.100   libavfilter     6. 21.101 / 
    6. 21.101   libswscale      4.  0.100 /  4.  0.100   libswresample   2.  0.101 /  2.  0.101   libpostproc    54.  0.100 / 54.  0.100 Input #0, avi, from 'E:\MEDIA\Central.Intelligence.2016.HC.HDRip.XviD.AC3-EVO\Central.Intelligence.2016.HC.HDRip.XviD.AC3-EVO.avi': Metadata:
        encoder         : VirtualDubMod 1.5.10.2 (build 2542/release)   Duration: 01:51:43.27, start: 0.000000, bitrate: 1765 kb/s
        Stream #0:0: Video: mpeg4 (Advanced Simple Profile) (XVID / 0x44495658), yuv420p, 720x304 [SAR 1:1 DAR 45:19], 1563 kb/s, 23.98 fps, 23.98 tbr, 23.98 tbn, 23.98 tbc
        Stream #0:1: Audio: ac3 ([0] [0][0] / 0x2000), 48000 Hz, stereo, fltp, 192 kb/s [libx264 @ 000000f3c80a0a80] using SAR=405/304 [libx264 @ 000000f3c80a0a80] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX FMA3 AVX2 LZCNT BMI2 [libx264 @ 000000f3c80a0a80] profile High, level 3.1 [libx264 @ 000000f3c80a0a80] 264 - core 148 r2638 7599210 - H.264/MPEG-4 AVC codec - Copyleft 2003-2015 - http://www.videolan.org/x264.html - options: cabac=1 ref=3 deblock=1:0:0 analyse=0x3:0x113 me=hex subme=7 psy=1 psy_rd=1.00:0.00 mixed_ref=1 me_range=16 chroma_me=1 trellis=1 8x8dct=1 cqm=0 deadzone=21,11 fast_pskip=1 chroma_qp_offset=-2 threads=6 lookahead_threads=1 sliced_threads=0 nr=0 decimate=1 interlaced=0 bluray_compat=0 constrained_intra=0 bframes=3 b_pyramid=2 b_adapt=1 b_bias=0 direct=1 weightb=1 open_gop=0 weightp=2 keyint=250 keyint_min=23 scenecut=40 intra_refresh=0 rc_lookahead=40 rc=abr mbtree=1 bitrate=1280 ratetol=1.0 qcomp=0.60 qpmin=0 qpmax=69 qpstep=4 ip_ratio=1.40 aq=1:1.00 Output #0, mp4, to 'F:\STREAMS\Central.Intelligence.2016.HC.HDRip.XviD.AC3-EVO.avi.1280x720_1000kbps.TEMP.mp4': Metadata:
        encoder         : Lavf57.20.100
        Stream #0:0: Video: h264 (libx264) ([33][0][0][0] / 0x0021), yuv420p, 1280x720 [SAR 405:304 DAR 45:19], q=-1--1, 1280 kb/s, 23.98 fps, 10000k tbn, 23.98 tbc
        Metadata:
          encoder         : Lavc57.20.100 libx264
        Side data:
          unknown side data type 10 (24 bytes)
        Stream #0:1: Audio: aac ([64][0][0][0] / 0x0040), 44100 Hz, stereo, fltp, 160 kb/s
        Metadata:
          encoder         : Lavc57.20.100 aac Stream mapping:   Stream #0:0 -> #0:0 (mpeg4 (native) -> h264 (libx264))   Stream #0:1 -> #0:1 (ac3 (native) -> aac (native)) Press [q] to stop, [?] for help [mpeg4 @ 000000f3c80ae220] Video uses a non-standard and wasteful way to store B-frames ('packed B-frames'). Consider using the mpeg4_unpack_bframes bitstream filter without encoding but stream copy to fix it. 
frame=   15 fps=0.0 q=0.0 size=       0kB time=00:00:01.18 bitrate=   0.3kbits/s dup=1 drop=0 speed=2.36x   
--SNIP---
frame=160704 fps= 16 q=30.0 size= 1180376kB time=01:51:43.08 bitrate=1442.6kbits/s dup=1 drop=0 speed=0.671x     
[libx264 @ 0000001f60c5d900] frame I:1167  Avg QP:19.08  size: 44465
[libx264 @ 0000001f60c5d900] frame P:63049 Avg QP:22.26  size: 12774
[libx264 @ 0000001f60c5d900] frame B:110691 Avg QP:24.81  size:  2739
[libx264 @ 0000001f60c5d900] consecutive B-frames:  6.0% 22.8% 18.3% 53.0%
[libx264 @ 0000001f60c5d900] mb I  I16..4: 14.0% 76.1%  9.9%
[libx264 @ 0000001f60c5d900] mb P  I16..4:  2.5%  6.6%  0.4%  P16..4: 44.5% 10.8%  5.2%  0.0%  0.0%    skip:30.0%
[libx264 @ 0000001f60c5d900] mb B  I16..4:  0.1%  0.3%  0.0%  B16..8: 32.1%  1.6%  0.2%  direct: 0.9%  skip:64.9%  L0:37.9% L1:58.7% BI: 3.5%
[libx264 @ 0000001f60c5d900] final ratefactor: 23.25
[libx264 @ 0000001f60c5d900] 8x8 transform intra:70.8% inter:85.8%
[libx264 @ 0000001f60c5d900] coded y,uvDC,uvAC intra: 47.1% 56.6% 19.5% inter: 10.7% 14.2% 0.4%
[libx264 @ 0000001f60c5d900] i16 v,h,dc,p: 46% 20%  8% 26%
[libx264 @ 0000001f60c5d900] i8 v,h,dc,ddl,ddr,vr,hd,vl,hu: 21% 17% 25%  5%  7%  7%  7%  6%  6%
[libx264 @ 0000001f60c5d900] i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 27% 20% 12%  5% 10%  9%  8%  5%  4%
[libx264 @ 0000001f60c5d900] i8c dc,h,v,p: 58% 18% 18%  6%
[libx264 @ 0000001f60c5d900] Weighted P-Frames: Y:1.4% UV:0.8%
[libx264 @ 0000001f60c5d900] ref P L0: 62.6% 12.9% 18.9%  5.6%  0.1%
[libx264 @ 0000001f60c5d900] ref B L0: 87.6% 11.0%  1.4%
[libx264 @ 0000001f60c5d900] ref B L1: 94.6%  5.4%
[libx264 @ 0000001f60c5d900] kb/s:1272.59
[aac @ 0000001f60b52180] Qavg: 954.859

Edit

This has something to do with data, when I run this command (cut at 10 minutes)

ffmpeg.exe -i CI.mp4 -ss 00:00:00 -t 00:08:00 -vcodec copy  -map_metadata 0 -acodec copy CI2.mp4

Mediainfo shows

Duration                    : 9mn 49s
Source duration             : 2mn 40s

When I run this one (18 minutes)

ffmpeg.exe -i CI.mp4 -ss 00:00:00 -t 00:18:00 -vcodec copy  -map_metadata 0 -acodec copy CI2.mp4

Mediainfo shows

Duration                    : 17mn 49s
Source duration             : 3mn 30s

How can I edit the metadata directly

Byron Whitlock
  • 49,611
  • 27
  • 114
  • 164
  • 1
    Show the conversion command and its full console output. You can add `-report` to the command and paste the logfile generated. – Gyan Aug 03 '16 at 05:13
  • @Mulvya Thanks, I attached the FFMPEG log. – Byron Whitlock Aug 03 '16 at 05:33
  • 3
    Command not present. – Gyan Aug 03 '16 at 05:52
  • @ByronWhitlock What commands did you use to generate the output? They can be used to recreate your issue & be checked for a fix. Y'know `ffmpeg -i somefile.mp4 -options=showUsed ...etc etc.` – VC.One Aug 03 '16 at 19:35
  • it has something do do with the source data I think. How can i edit the metadata directly? – Byron Whitlock Aug 04 '16 at 02:25
  • 1
    You won't find specifically "source duration" in MP4 metadata, it's not even put there by FFmpeg. It's simply calculated by MediaInfo (but how I don't know). Anyways **CI.mp4** is the result of avi to mp4 conversion, right? So if it came out bad, then why use bad file as input for trimming those 10 & 18 min tests? The result will still be bad... Also was the avi's audio in ac3 format? Did you use `-acodec copy` in the avi to mp4 conversion command? Mp4 expects either mp3 or aac format audio. – VC.One Aug 05 '16 at 03:09
  • I suggest **(1)** try setting Main or Baseline profile for FFmpeg video options (since your issue affects mobile devices. Is it only iOS but Android is fine?), **(2)** leave out `acodec` options (since FFmpeg will auto-set the correct ones for your mp4 format). – VC.One Aug 05 '16 at 03:29
  • Some explanation from the MediaInfo creator is [here](https://sourceforge.net/p/mediainfo/feature-requests/366/). Shortly from it: ***Duration** is the duration from the **track header**, while **Source duration** is the duration from the **media header** (the media header is inside the track header, don't try to understand the reason why are there two durations for the same track).* – MarianD May 04 '21 at 22:49
  • @Gyan, I added a comment about terms in MediaInfo from its creator; maybe it helps you to help OP (and me, too) — if you will be so kind — how to fix such a corrupted MP4 files. Thank you. – MarianD May 04 '21 at 23:06

1 Answers1

1

Recently, I run into a similar problem. I had 3 similar (1080x1920, ie portrait) MP4 videos taken by a mobile phone. I converted them to 1280x720 (landscape) by using to following ffmpeg command:

fmpeg -i input.MP4 -vf "scale=w=1280:h=720:force_original_aspect_ratio=decrease,pad=1280:720:(ow-iw)/2:(oh-ih)/2" -c:a copy -y output.MP4

It resizes the video and adds wide black bars on both sides. Two of the resulting videos were ok, byt the third crashed my video editor. It could be displayed by VLC, however. I checked with MediaInfo its tags, and it had a Source duration video tag (never seen it before). Its value was 9 s 628 ms, while Duration was 48 s 21 ms. The other two videos did not have Source duration tags. Because VLC could display it, I tried to use it to correct the video as follows (I have Advanced Controls checked in the View menu):

  1. Selected Media -> Convert/Save...
  2. Add... -> browsed the input.MP4 -> Open
  3. Convert/Save -> Convert
  4. Selected Profile Video - H.264 + MP3(MP4), clicked Edit selected profile button
  5. Encapsulation tab, MP4/MOV, all Features except Chapters
  6. Video codec tab, checked Video and Keep original video track
  7. Audio codec tab, checked Audio and Keep original audio track
  8. Subtitles tab, unchecked Subtitles because the video did not have them
  9. Save
  10. Browse destination file, browsed output folder, entered tilename of output.MP4
  11. Save
  12. Start

VLC did the "conversion" fast, and voila! According to MediaInfo there was no more a Source duration tag and my video editor willingly accepted the resulting video.