Log in

View Full Version : ffmpeg ignoring audio track during mp4 -> mt2s with PCM


osgZach
27th January 2017, 01:47
I'm really confused.

The M2TS container supports PCM audio as far as I know. But no matter what I do if I use


ffmpeg -i <file> -c:v copy -c:a pcm_s16be <output.m2ts>


I get a file with no audio track. ffmpeg doesn't even try to encode.

It doesn't matter whether I use little endian or big endian either.

I can take the same source file and save the audio out as ".wav" (s16be) and the video out as a separate track as well, and I can mux those into a valid working M2TS via megui. So clearly it's not an issue of the container not supporting it.

Can anyone clue me in as to what I'm doing wrong. I've got files with HE-AAC audio that needs to be converted to PCM for editing.

The same command used above will work fine and you get an audio track in the produced M2TS if you specify c:a copy, or AC3, etc.
Doesn't seem to matter whether the source is MP4 or MKV, etc.

osgZach
27th January 2017, 02:17
I ran the conversion on a shorter file I had laying around just to capture an output log.

This was the command line


ffmpeg -i "2017-01-09 21-52-42.mp4" -c:v copy -c:a pcm_s16le "Dirt Rally.m2ts" >output.txt 2>&1


This is the log file

ffmpeg version N-83243-g2080bc3 Copyright (c) 2000-2017 the FFmpeg developers
built with gcc 5.4.0 (GCC)
configuration: --enable-gpl --enable-version3 --enable-cuda --enable-cuvid --enable-d3d11va --enable-dxva2
--enable-libmfx --enable-nvenc --enable-avisynth --enable-bzlib --enable-fontconfig --enable-frei0r --enable-gnutls
--enable-iconv --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libfreetype --enable-libgme
--enable-libgsm --enable-libilbc --enable-libmodplug --enable-libmp3lame --enable-libopencore-amrnb
--enable-libopencore-amrwb --enable-libopenh264 --enable-libopenjpeg --enable-libopus --enable-librtmp
--enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libtheora --enable-libtwolame --enable-libvidstab
--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. 45.100 / 55. 45.100
libavcodec 57. 75.100 / 57. 75.100
libavformat 57. 63.100 / 57. 63.100
libavdevice 57. 2.100 / 57. 2.100
libavfilter 6. 70.100 / 6. 70.100
libswscale 4. 3.101 / 4. 3.101
libswresample 2. 4.100 / 2. 4.100
libpostproc 54. 2.100 / 54. 2.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '2017-01-09 21-52-42.mp4':
Metadata:
major_brand : isom
minor_version : 512
compatible_brands: isomiso2avc1mp41
encoder : Lavf57.41.100
Duration: 00:00:09.46, start: 0.000000, bitrate: 25591 kb/s
Stream #0:0(und): Video: h264 (Constrained Baseline) (avc1 / 0x31637661), yuv420p, 1920x1080, 25448 kb/s, 59.94 fps, 59.94 tbr, 60k tbn, 119.88 tbc (default)
Metadata:
handler_name : VideoHandler
Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 132 kb/s (default)
Metadata:
handler_name : SoundHandler
Output #0, mpegts, to 'Dirt Rally.m2ts':
Metadata:
major_brand : isom
minor_version : 512
compatible_brands: isomiso2avc1mp41
encoder : Lavf57.63.100
Stream #0:0(und): Video: h264 (Constrained Baseline) (avc1 / 0x31637661), yuv420p, 1920x1080, q=2-31, 25448 kb/s, 59.94 fps, 59.94 tbr, 90k tbn, 60k tbc (default)
Metadata:
handler_name : VideoHandler
Stream #0:1(und): Audio: pcm_s16le, 44100 Hz, stereo, s16, 1411 kb/s (default)
Metadata:
handler_name : SoundHandler
encoder : Lavc57.75.100 pcm_s16le
Stream mapping:
Stream #0:0 -> #0:0 (copy)
Stream #0:1 -> #0:1 (aac (native) -> pcm_s16le (native))
Press [q] to stop, [?] for help
frame= 567 fps=0.0 q=-1.0 Lsize= 34276kB time=00:00:09.47 bitrate=29643.4kbits/s speed= 139x
video:29386kB audio:1632kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 10.502914%




Which produces a file no media player, or editor will pick up an audio track from. Media info reports video track only

hello_hello
27th January 2017, 04:03
Out of curiosity I tried the same thing and ended up with a m2ts with no audio (apparently). I tried an older ffmpeg too and the result was the same. When I opened the m2ts file with TSMuxer it complained about not recognising one of the tracks and only remuxed the video.

I ran out of motivation at that point but maybe as a workaround you could output an MKV and if there's audio within, remux that as an m2ts with TSMuxer. I didn't try it myself.

microchip8
27th January 2017, 05:00
sounds like worth of a bug report ;)

osgZach
27th January 2017, 05:40
I'll get around to it eventually, unless someone beats me to it

edit: filed a report this morning

osgZach
4th February 2017, 17:54
I Appear to have started an arguement with someone on the ffmpeg trac about whether or not an M2TS can legally carry a PCM stream

hello_hello
4th February 2017, 20:53
I wondered about that myself for a second, but isn't m2ts the format used on Blu-ray and isn't PCM legal for Bluray? Plus I figured if PCM wasn't legal for m2ts, ffmpeg would offer an error rather than only appear to have achieved what was asked. Maybe not......

hello_hello
4th February 2017, 22:19
TSMuxer has no issue with putting PCM audio in an m2ts container.

I just realised..... the thread heading mentions mt2s while your post says m2ts. Is there a difference?

For mt2s I'm getting an error from ffmpeg about being unable to find a suitable output format when I try to remux an MKV containing PCM audio, although I get the same error even without the audio as though it doesn't know what mt2s is, while for m2ts it remuxes and the resulting file appears to have no audio.
Same when remuxing as a TS file. The output seems to have no audio.

nevcairiel
4th February 2017, 22:49
Muxing PCM into m2ts requires use of a special codec, which is called "pcm_bluray" in ffmpeg - it includes the required headers to properly identify the properties of the pcm content. Pure "raw" pcm cannot be muxed into mpegts, because it lacks format identification headers, so you would not know the number of channels, sample rate, and whatnot.
I'm not aware of a way to mux PCM ouside of the Blu-ray way into mpegts, but I can't say I tried to find out if there is more ways, either.

All that said, ffmpeg doesn't have an "encoder" for the pcm bluray format, so it cannot do this currently. mpegts usually requires special handling for every codec you want to put into it, since it doesn't have generic codec headers like many other formats. Hence the list of supported codecs is rather short, and every codec needs to be manually implemented.

tebasuna51
5th February 2017, 00:53
Seems than is related with a little tool than I make in 2008 to be used for tsMuxeR (when still don't support w64 input) Pcm2Tsmu (https://forum.doom9.org/showthread.php?p=1137225#post1137225) to convert pcm to the "pcm_bluray" with short headers.

I think that is easy for the ffmpeg team.

osgZach
5th February 2017, 02:06
That was going to be my next question. I was wondering if there were special flags or something I was unaware of to put a PCM stream into appro. container with headers, etc.

To clarify I did mean M2TS, dyslexic typer and all that.

So just to be clear.

I need to find an encoder that will output a pcm_bluray spec PCM file, and then I need to use that flag to mux it with ffmpeg?

I'm wondering if I can just select a BDAV or whatever Mpeg2 profile out of Vegas and find one that'll let me spit out PCM.

nevcairiel
5th February 2017, 09:40
Without modifying ffmpeg to make it support this, its impossible to mux such content right now, no matter what input you give it.

tebasuna51
5th February 2017, 10:49
Yep, we can make a feature request to ffmpeg: support PCM to mux in m2ts
Until that we can't use ffmpeg for this at all.

You don't need Pcm2Tsmu at all, it was only necesary when tsMuxeR don't support w64 input, for wav greater than 4 GB.

You know the workaround, extract the wav (or w64), edit it, and mux with MeGUI or tsMuxeR.