3

To save space on my NAS, I did compress some of my smartphone videos lately using this command:

ffmpeg -hide_banner -y -i in_filename -map 0 -map_metadata 0 -c copy -c:a libvorbis -q:a 4 -c:v libx264 -crf 23 -preset slow -max_muxing_queue_size 4096 -movflags +faststart out_file.mp4

This worked flawlessly, copying over all data streams and metadata, and compressing video and audio with the specified codecs. Unfortunately, as vorbis is not officially supported in the mp4 container, some player will not play the sound on those files. So I wanted to remux the files, for which I still have the originals available using:

ffmpeg -hide_banner -y -i original.mp4 -i compressed.mp4 -map 1:v -map 0:a -map 0:s? -map 0:d? -map 0:t? -map_metadata 0 -c copy out.mp4

This should

  • take all video streams from the compressed version created by ffmpeg
  • take all audio streams from original
  • take all subtitles, data, and attachment streams from orignal
  • take all metadata from the original

However, the conversion fails with error

Could not find tag for codec none in stream #2

As I already did use this file to create the compressed version, I am puzzled why I now get a codec tag error here. Also using -copy_unknown, or -ignore_unknown does not help. When trying my original command again, I also get this error, so I really wonder, how did I create the "compressed" file in the first place. It must be possible...

Codec information on the "original" and "compressed" file:

Stream #0:2(eng): Data: none (urim / 0x6D697275), 38 kb/s (default)
Stream #0:2(eng): Data: none (stts / 0x73747473), 38 kb/s (default)

FYI: I wanted to remux the existing compressed video and original audio to speed up the process and prevent generation loss. As an alternative I could work on the original file or the compressed and encode only vide or audio respectively. However, as it currently stands I cannot work on either file without losing the "data" stream, which I would like to prevent if possible.

Any inputs?

If it helps, here the complete outputs:

ffmpeg -y -i original.mp4 -map 0 -map_metadata 0 -c copy -c:a libvorbis -aq 4 -c:v libx264 -crf 23 -preset slow -max_muxing_queue_size 4096 -movflags +faststart out.mp4
ffmpeg version git-2020-05-04-5767a2e Copyright (c) 2000-2020 the FFmpeg developers
  built with gcc 9.3.1 (GCC) 20200328
  configuration: --enable-gpl --enable-version3 --enable-sdl2 --enable-fontconfig --enable-gnutls --enable-iconv --enable-libass --enable-libdav1d --enable-libbluray --enable-libfreetype --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libopus --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libsrt --enable-libtheora --enable-libtwolame --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 --enable-libzimg --enable-lzma --enable-zlib --enable-gmp --enable-libvidstab --enable-libvmaf --enable-libvorbis --enable-libvo-amrwbenc --enable-libmysofa --enable-libspeex --enable-libxvid --enable-libaom --disable-w32threads --enable-libmfx --enable-ffnvcodec --enable-cuda-llvm --enable-cuvid --enable-d3d11va --enable-nvenc --enable-nvdec --enable-dxva2 --enable-avisynth --enable-libopenmpt --enable-amf
  libavutil      56. 43.100 / 56. 43.100
  libavcodec     58. 82.100 / 58. 82.100
  libavformat    58. 42.102 / 58. 42.102
  libavdevice    58.  9.103 / 58.  9.103
  libavfilter     7. 80.100 /  7. 80.100
  libswscale      5.  6.101 /  5.  6.101
  libswresample   3.  6.100 /  3.  6.100
  libpostproc    55.  6.100 / 55.  6.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'original.mp4':
  Metadata:
    major_brand     : nvr1
    minor_version   : 65537
    compatible_brands: isommp42nvr1
    creation_time   : 2018-10-06T16:49:58.000000Z
    com.android.version: 8.1.0
  Duration: 00:00:33.81, start: 0.000000, bitrate: 20507 kb/s
    Stream #0:0(eng): Video: h264 (Baseline) (avc1 / 0x31637661), yuvj420p(pc, smpte170m), 1920x1080, 20022 kb/s, SAR 1:1 DAR 16:9, 29.49 fps, 29.50 tbr, 90k tbn, 180k tbc (default)
    Metadata:
      rotate          : 90
      creation_time   : 2018-10-06T16:49:58.000000Z
      handler_name    : VideoHandle
    Side data:
      displaymatrix: rotation of -90.00 degrees
    Stream #0:1(eng): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 255 kb/s (default)
    Metadata:
      creation_time   : 2018-10-06T16:49:58.000000Z
      handler_name    : SoundHandle
    Stream #0:2(eng): Data: none (urim / 0x6D697275), 38 kb/s (default)
    Metadata:
      creation_time   : 2018-10-06T16:49:58.000000Z
      handler_name    : MetaHandler
Multiple -c, -codec, -acodec, -vcodec, -scodec or -dcodec options specified for stream 0, only the last option '-c:v libx264' will be used.
Multiple -c, -codec, -acodec, -vcodec, -scodec or -dcodec options specified for stream 1, only the last option '-c:a libvorbis' will be used.
Stream mapping:
  Stream #0:0 -> #0:0 (h264 (native) -> h264 (libx264))
  Stream #0:1 -> #0:1 (aac (native) -> vorbis (libvorbis))
  Stream #0:2 -> #0:2 (copy)
Press [q] to stop, [?] for help
[libx264 @ 000001dbc892f140] using SAR=1/1
[libx264 @ 000001dbc892f140] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX FMA3 BMI2 AVX2
[libx264 @ 000001dbc892f140] profile High, level 5.0, 4:2:0, 8-bit
[libx264 @ 000001dbc892f140] 264 - core 159 - H.264/MPEG-4 AVC codec - Copyleft 2003-2019 - http://www.videolan.org/x264.html - options: cabac=1 ref=5 deblock=1:0:0 analyse=0x3:0x113 me=hex subme=8 psy=1 psy_rd=1.00:0.00 mixed_ref=1 me_range=16 chroma_me=1 trellis=2 8x8dct=1 cqm=0 deadzone=21,11 fast_pskip=1 chroma_qp_offset=-2 threads=18 lookahead_threads=3 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=3 weightb=1 open_gop=0 weightp=2 keyint=250 keyint_min=25 scenecut=40 intra_refresh=0 rc_lookahead=50 rc=crf mbtree=1 crf=23.0 qcomp=0.60 qpmin=0 qpmax=69 qpstep=4 ip_ratio=1.40 aq=1:1.00
[mp4 @ 000001dbc988f040] Could not find tag for codec none in stream #2, codec not currently supported in container
Could not write header for output file #0 (incorrect codec parameters ?): Invalid argument
Error initializing output stream 0:1 -- 
Conversion failed!



ffmpeg -y -i compressed.mp4 -map 0 -map_metadata 0 -c copy -c:a libvorbis -aq 4 -c:v libx264 -crf 23 -preset slow -max_muxing_queue_size 4096 -movflags +faststart out.mp4
ffmpeg version git-2020-05-04-5767a2e Copyright (c) 2000-2020 the FFmpeg developers
  built with gcc 9.3.1 (GCC) 20200328
  configuration: --enable-gpl --enable-version3 --enable-sdl2 --enable-fontconfig --enable-gnutls --enable-iconv --enable-libass --enable-libdav1d --enable-libbluray --enable-libfreetype --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libopus --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libsrt --enable-libtheora --enable-libtwolame --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 --enable-libzimg --enable-lzma --enable-zlib --enable-gmp --enable-libvidstab --enable-libvmaf --enable-libvorbis --enable-libvo-amrwbenc --enable-libmysofa --enable-libspeex --enable-libxvid --enable-libaom --disable-w32threads --enable-libmfx --enable-ffnvcodec --enable-cuda-llvm --enable-cuvid --enable-d3d11va --enable-nvenc --enable-nvdec --enable-dxva2 --enable-avisynth --enable-libopenmpt --enable-amf
  libavutil      56. 43.100 / 56. 43.100
  libavcodec     58. 82.100 / 58. 82.100
  libavformat    58. 42.102 / 58. 42.102
  libavdevice    58.  9.103 / 58.  9.103
  libavfilter     7. 80.100 /  7. 80.100
  libswscale      5.  6.101 /  5.  6.101
  libswresample   3.  6.100 /  3.  6.100
  libpostproc    55.  6.100 / 55.  6.100
[mov,mp4,m4a,3gp,3g2,mj2 @ 000002c3ca70df00] overread end of atom 'stsd' by 40 bytes
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'compressed.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    creation_time   : 2018-10-06T16:49:58.000000Z
    encoder         : Lavf58.3.100
  Duration: 00:00:33.81, start: 0.000000, bitrate: 10230 kb/s
    Stream #0:0(eng): Video: h264 (High) (avc1 / 0x31637661), yuvj420p(pc), 1080x1920 [SAR 1:1 DAR 9:16], 10098 kb/s, 29.50 fps, 29.50 tbr, 15104 tbn, 59 tbc (default)
    Metadata:
      creation_time   : 2018-10-06T16:49:58.000000Z
      handler_name    : VideoHandler
    Stream #0:1(eng): Audio: vorbis (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 88 kb/s (default)
    Metadata:
      creation_time   : 2018-10-06T16:49:58.000000Z
      handler_name    : SoundHandler
    Stream #0:2(eng): Data: none (stts / 0x73747473), 38 kb/s (default)
    Metadata:
      creation_time   : 2018-10-06T16:49:58.000000Z
      handler_name    : DataHandler
Multiple -c, -codec, -acodec, -vcodec, -scodec or -dcodec options specified for stream 0, only the last option '-c:v libx264' will be used.
Multiple -c, -codec, -acodec, -vcodec, -scodec or -dcodec options specified for stream 1, only the last option '-c:a libvorbis' will be used.
Stream mapping:
  Stream #0:0 -> #0:0 (h264 (native) -> h264 (libx264))
  Stream #0:1 -> #0:1 (vorbis (native) -> vorbis (libvorbis))
  Stream #0:2 -> #0:2 (copy)
Press [q] to stop, [?] for help
[libx264 @ 000002c3ca7b7440] using SAR=1/1
[libx264 @ 000002c3ca7b7440] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX FMA3 BMI2 AVX2
[libx264 @ 000002c3ca7b7440] profile High, level 5.0, 4:2:0, 8-bit
[libx264 @ 000002c3ca7b7440] 264 - core 159 - H.264/MPEG-4 AVC codec - Copyleft 2003-2019 - http://www.videolan.org/x264.html - options: cabac=1 ref=5 deblock=1:0:0 analyse=0x3:0x113 me=hex subme=8 psy=1 psy_rd=1.00:0.00 mixed_ref=1 me_range=16 chroma_me=1 trellis=2 8x8dct=1 cqm=0 deadzone=21,11 fast_pskip=1 chroma_qp_offset=-2 threads=18 lookahead_threads=3 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=3 weightb=1 open_gop=0 weightp=2 keyint=250 keyint_min=25 scenecut=40 intra_refresh=0 rc_lookahead=50 rc=crf mbtree=1 crf=23.0 qcomp=0.60 qpmin=0 qpmax=69 qpstep=4 ip_ratio=1.40 aq=1:1.00
[mp4 @ 000002c3cad94140] Could not find tag for codec none in stream #2, codec not currently supported in container
Could not write header for output file #0 (incorrect codec parameters ?): Invalid argument
Error initializing output stream 0:0 -- 
[libvorbis @ 000002c3ca74adc0] 32 frames left in the queue on closing
Conversion failed!

further reading https://trac.ffmpeg.org/ticket/8338 https://trac.ffmpeg.org/ticket/2928 https://developer.apple.com/library/archive/documentation/QuickTime/QTFF/QTFFChap2/qtff2.html#//apple_ref/doc/uid/TP40000939-CH204-BBCGFJII

2 Answers 2

1

Use:

ffmpeg -i original.mp4 -i compressed.mp4 -map 0 -map -0:v -map 1:v -c copy -movflags +faststart out.mp4

This will copy all streams from original.mp4 except any video and only copy the video from compressed.mp4.

1
  • -map 0 does not work, because this also maps the data stream which cannot be copied due to the unknown tag. I know how to not copy the data stream but wonder why ffmpeg cannot copy an existing stream from one mp4 to a new one.
    – Alexander
    May 6, 2020 at 23:32
1

I had a similar problem with a .mov file, and solved it using this info : https://acassis.wordpress.com/2019/09/28/ffmpeg-conversion-error-could-not-find-tag-for-codec-pcm_s16be/

It's basically : remove the -map 0 -map_metadata 0 -c copy (-codec for my case and also but it's the same as -c and also remove -copy_unknown although in your case you didn't use it) flags, and check after conversion that the video and audio are fine : if they are, it was getting stuck on unwanted data !

I was using :

ffmpeg -I "moviefiletocompress.mov" -copy_unknown -map_metadata 0 -map 0 -codec copy -tag:v hvc1 -codec:v libx265 -x265-params crf="26" -codec:a aac -preset fast "compressedfile-ffmpeg-h265-crf26.mp4"

And then solved it using :

ffmpeg -I "moviefiletocompress.mov" -tag:v hvc1 -codec:v libx265 -x265-params crf="26" -codec:a aac -preset fast "compressedfile-ffmpeg-h265-crf26.mp4"

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .