magmastonealex / ffproc

A batch transcoding system. Supports multiple remote workers.
Apache License 2.0
46 stars 4 forks source link

ffproc seems to be stripping audio tracks #10

Open nebukazar911 opened 6 years ago

nebukazar911 commented 6 years ago

Hi, This might not be bug but maybe just a config issue...

I'm currently running Plex and have the DVR function enabled (hooked up on a HDHomeRun Extend). I'm recording shows and movies but since most of our devices are iOS based (eg: atv, iphones, ipad, ...), I have to optimize these records to get directplay.

I've been trying to use ffproc to do mass conversion. So far, I'm able to do conversions, but for some odd reason, the audio track seems to be stripped.

The current ffprobe's output on the TS file is:

ffprobe version N-90182-g40102a2 Copyright (c) 2007-2018 the FFmpeg developers
  built with gcc 5.4.0 (Ubuntu 5.4.0-6ubuntu1~16.04.9) 20160609
  configuration: --enable-gpl --enable-libass --enable-libfdk-aac --enable-libfreetype --enable-libmp3lame --enable-libopus --enable-libtheora --enable-libvorbis --enable-libvpx --enable-libx264 --enable-nonfree --enable-shared --enable-openssl
  libavutil      56.  7.101 / 56.  7.101
  libavcodec     58. 13.100 / 58. 13.100
  libavformat    58. 10.100 / 58. 10.100
  libavdevice    58.  2.100 / 58.  2.100
  libavfilter     7. 12.100 /  7. 12.100
  libswscale      5.  0.101 /  5.  0.101
  libswresample   3.  0.101 /  3.  0.101
  libpostproc    55.  0.100 / 55.  0.100
Input #0, mpegts, from '/media/ltellier/Plex Movies/Movies_DVR/21 Jump Street (2012)/21 Jump Street (2012).ts':
  Duration: 02:08:57.80, start: 1.400000, bitrate: 10175 kb/s
  Program 1 
    Metadata:
      service_name    : Service01
      service_provider: FFmpeg
    Stream #0:0[0x100]: Video: h264 (High) ([27][0][0][0] / 0x001B), yuv420p(tv, top first), 1920x1080 [SAR 1:1 DAR 16:9], Closed Captions, 29.97 fps, 29.97 tbr, 90k tbn, 59.94 tbc
    Stream #0:1[0x101](fre): Audio: ac3 ([129][0][0][0] / 0x0081), 48000 Hz, 5.1(side), fltp, 384 kb/s

And the ffproc conversion's output:

# ./ffproc.py --profile default --immediate --showcommand /root/ffproc/21.ts                                                                 [ffpro
c] rq and redis libraries not found. Disabling redis support...
[MediaTransformer] Copying video track
[MediaTransformer] Deinterlacing video track (will cause transcode!)
[ffproc] Enqueing 21.ts for video
[ffproc] ffmpeg command: -map 0:0 -c:v libx264 -level:v 4.1 -preset veryslow -bf 16 -b_strategy 2 -subq 10 -refs 4 -vf yadif=0:-1:0
[ffproc] Running ffmpeg locally.
ffmpeg version N-90182-g40102a2 Copyright (c) 2000-2018 the FFmpeg developers
  built with gcc 5.4.0 (Ubuntu 5.4.0-6ubuntu1~16.04.9) 20160609
  configuration: --enable-gpl --enable-libass --enable-libfdk-aac --enable-libfreetype --enable-libmp3lame --enable-libopus --enable-libtheora --enable-libvorbis --enable-libvpx --e
nable-libx264 --enable-nonfree --enable-shared --enable-openssl
  libavutil      56.  7.101 / 56.  7.101
  libavcodec     58. 13.100 / 58. 13.100
  libavformat    58. 10.100 / 58. 10.100
  libavdevice    58.  2.100 / 58.  2.100
  libavfilter     7. 12.100 /  7. 12.100
  libswscale      5.  0.101 /  5.  0.101
  libswresample   3.  0.101 /  3.  0.101
  libpostproc    55.  0.100 / 55.  0.100
ffmpeg version N-90182-g40102a2 Copyright (c) 2000-2018 the FFmpeg developers
  built with gcc 5.4.0 (Ubuntu 5.4.0-6ubuntu1~16.04.9) 20160609
  configuration: --enable-gpl --enable-libass --enable-libfdk-aac --enable-libfreetype --enable-libmp3lame --enable-libopus --enable-libtheora --enable-libvorbis --enable-libvpx --e
nable-libx264 --enable-nonfree --enable-shared --enable-openssl
  libavutil      56.  7.101 / 56.  7.101
  libavcodec     58. 13.100 / 58. 13.100
  libavformat    58. 10.100 / 58. 10.100
  libavdevice    58.  2.100 / 58.  2.100
  libavfilter     7. 12.100 /  7. 12.100
  libswscale      5.  0.101 /  5.  0.101
  libswresample   3.  0.101 /  3.  0.101
  libpostproc    55.  0.100 / 55.  0.100
Input #0, mpegts, from '/root/ffproc/21.ts':
  Duration: 02:08:57.80, start: 1.400000, bitrate: 10175 kb/s
  Program 1
    Metadata:
      service_name    : Service01   
      service_provider: FFmpeg
    Stream #0:0[0x100]: Video: h264 (High) ([27][0][0][0] / 0x001B), yuv420p(tv, top first), 1920x1080 [SAR 1:1 DAR 16:9], Closed Captions, 29.97 fps, 29.97 tbr, 90k tbn, 59.94 tbc
    Stream #0:1[0x101](fre): Audio: ac3 ([129][0][0][0] / 0x0081), 48000 Hz, 5.1(side), fltp, 384 kb/s
Stream mapping:
  Stream #0:0 -> #0:0 (h264 (native) -> h264 (libx264))
Press [q] to stop, [?] for help
[libx264 @ 0x1829240] using SAR=1/1 
[libx264 @ 0x1829240] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.1 Cache64
[libx264 @ 0x1829240] profile High, level 4.1
[libx264 @ 0x1829240] 264 - core 155 r2901 7d0ff22 - H.264/MPEG-4 AVC codec - Copyleft 2003-2018 - http://www.videolan.org/x264.html - options: cabac=1 ref=4 deblock=1:0:0 analyse=0x3:0x133 me=umh subme=10 psy=1 psy_rd=1.00:0.00 mixed_ref=1 me_range=24 chroma_me=1 trellis=2 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=16 b_pyramid=2 b_adapt=2 b_bias=0 direct=3 weightb=1 open_gop=0 weightp=2 keyint=250 keyint_min=25 scenecut=40 intra_refresh=0 rc_lookahead=60 rc=crf mbtree=1 crf=23.0 qcomp=0.60 qpmin=0 qpmax=69 qpstep=4 ip_ratio=1.40 aq=1:1.00
Output #0, mp4, to 'tmp.mp4':
  Metadata:
    encoder         : Lavf58.10.100 
    Stream #0:0: Video: h264 (libx264) (avc1 / 0x31637661), yuv420p, 1920x1080 [SAR 1:1 DAR 16:9], q=-1--1, 29.97 fps, 30k tbn, 29.97 tbc
    Metadata:
      encoder         : Lavc58.13.100 libx264
    Side data:
      cpb: bitrate max/min/avg: 0/0/0 buffer size: 0 vbv_delay: -1
frame=231868 fps=2.7 q=-1.0 Lsize= 2723450kB time=02:08:56.56 bitrate=2883.8kbits/s dup=57 drop=0 speed=0.0893x
video:2721008kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.089752%
[libx264 @ 0x1829240] frame I:1830  Avg QP:20.18  size: 85967
[libx264 @ 0x1829240] frame P:50343 Avg QP:23.42  size: 28874
[libx264 @ 0x1829240] frame B:179695 Avg QP:26.49  size:  6541
[libx264 @ 0x1829240] consecutive B-frames:  2.1%  2.1% 17.2%  5.8%  5.8% 63.8%  1.8%  0.4%  0.7%  0.1%  0.2%  0.1%  0.0%  0.0%  0.0%  0.0%  0.0%
[libx264 @ 0x1829240] mb I  I16..4: 18.4% 75.2%  6.4%
[libx264 @ 0x1829240] mb P  I16..4:  9.4% 19.6%  0.4%  P16..4: 37.7%  5.0%  5.7%  0.0%  0.0%    skip:22.2%
[libx264 @ 0x1829240] mb B  I16..4:  0.7%  1.2%  0.0%  B16..8: 33.0%  1.9%  0.3%  direct: 1.6%  skip:61.3%  L0:44.7% L1:53.3% BI: 2.0%
[libx264 @ 0x1829240] 8x8 transform intra:66.8% inter:85.5%
[libx264 @ 0x1829240] direct mvs  spatial:100.0% temporal:0.0%
[libx264 @ 0x1829240] coded y,uvDC,uvAC intra: 34.5% 51.2% 6.8% inter: 4.9% 9.2% 0.3%
[libx264 @ 0x1829240] i16 v,h,dc,p: 28% 25% 15% 33%
[libx264 @ 0x1829240] i8 v,h,dc,ddl,ddr,vr,hd,vl,hu: 22% 14% 20%  6%  7%  8%  8%  8%  8%
[libx264 @ 0x1829240] i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 16% 16%  7%  7% 11% 11% 12%  8% 11%
[libx264 @ 0x1829240] i8c dc,h,v,p: 36% 31% 26%  7%
[libx264 @ 0x1829240] Weighted P-Frames: Y:1.6% UV:1.2%
[libx264 @ 0x1829240] ref P L0: 64.6%  9.8% 18.5%  7.0%  0.2%  0.0%
[libx264 @ 0x1829240] ref B L0: 90.0%  8.4%  1.7%
[libx264 @ 0x1829240] ref B L1: 97.1%  2.9%
[libx264 @ 0x1829240] kb/s:2881.15  

And finally the ffprobe's output on the newly created file:

# ffprobe 21.mp4

ffprobe version N-90182-g40102a2 Copyright (c) 2007-2018 the FFmpeg developers
  built with gcc 5.4.0 (Ubuntu 5.4.0-6ubuntu1~16.04.9) 20160609
  configuration: --enable-gpl --enable-libass --enable-libfdk-aac --enable-libfreetype --enable-libmp3lame --enable-libopus --enable-libtheora --enable-libvorbis --enable-libvpx --enable-libx264 --enable-nonfree --enable-shared --enable-openssl
  libavutil      56.  7.101 / 56.  7.101
  libavcodec     58. 13.100 / 58. 13.100
  libavformat    58. 10.100 / 58. 10.100
  libavdevice    58.  2.100 / 58.  2.100
  libavfilter     7. 12.100 /  7. 12.100
  libswscale      5.  0.101 /  5.  0.101
  libswresample   3.  0.101 /  3.  0.101
  libpostproc    55.  0.100 / 55.  0.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '21.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf58.10.100 
  Duration: 02:08:56.66, start: 0.000000, bitrate: 2883 kb/s
    Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 1920x1080 [SAR 1:1 DAR 16:9], Closed Captions, 2881 kb/s, 29.97 fps, 29.97 tbr, 30k tbn, 59.94 tbc (default)
    Metadata:
      handler_name    : VideoHandler

The current profiles.json looks like:

# cat profiles.json
{
"720p":{
        "video": {
                "deinterlace": "yes",
                "allowhevc": true,
                "ignore": false,
                "codec": "h264",
                "force": false,
                "encodepreset": "veryslow",
                "quality": "20",
                "res": "720p"
        },
        "audio": {
                "surround": {
                        "keep": true
                },
                "stereo": {
                        "keep": true,
                        "create": true,
                        "ffproc_filtering": true,
                        "bitrate": "128k",
                        "force_libfdk": true
                }
        },
        "format": {
                "filetype": "mp4"
        }
},
"default":{
        "video": {
                "deinterlace": "yes",
                "allowhevc": true,
                "ignore": false,
                "codec": "h264",
                "force": false,
                "encodepreset": "veryslow",
                "quality": "20",
                "res": "1080p"
        },
        "audio": {
                "surround": {
                        "keep": true
                },
                "stereo": {
                        "keep": true,
                        "create": true,
                        "ffproc_filtering": true,
                        "bitrate": "128k",
                        "force_libfdk": true
                }
        },
        "format": {
                "filetype": "mp4"   
        }
},
"tox265":{
        "video": {
                "deinterlace": "yes",
                "allowhevc": true,  
                "ignore": false,
                "codec": "hevc",
                "force": false,
                "encodepreset": "veryslow",
                "quality": "20",
                "res": "1080p"
        },
        "audio": {
                "surround": {
                        "keep": true
                },
                "stereo": {
                        "keep": true,
                        "create": true,
                        "ffproc_filtering": true,
                        "bitrate": "128k",
                        "force_libfdk": false
                }
        },
        "format": {
                "filetype": "mp4"   
        }
}
}

Are we missing something ? Is there any particular reason why the audio track(s) would get stripped ?

Thanks!

magmastonealex commented 6 years ago

Hello! Thanks for trying out ffproc, and the super well-detailed bug report.

I think I know the issue: the (fre) tag & stream ID on your audio track. ffproc has a line:

if ( track["language"] == "eng" or track["language"] == "und" or track["language"] == None):

which excludes that track from processing.

That dates back from my original use of ripping DVDs, where I did want to bring in only the english track. Maybe my choice was a little short-sighted :smiley:

My proposed fix would be to add a config option somewhere to disable this check, and also add a configurable list of languages that you do want to extract. Does that work for you?

nebukazar911 commented 6 years ago

Indeed, that would definitely work! Most of our shows aired in Quebec are in french, but I would also like to rip other stuff with foreign languages; if we could get that option, that would definitely be awesome. Thanks for the quick turnaround, much appreciated 👍

magmastonealex commented 6 years ago

Alright, I've pushed a commit which should hopefully fix this for you. The "default" profile shows an example of the new feature being configured. You'd just have to set "ignore" to true, or add "fre" as an allowed language.

What I intend to implement a little later on is extracting/transcoding audio tracks per-language, so if you had both English and French, your output would have both as well. I'm tracking that in #13. In Ontario at least, I haven't ever seen a TV broadcaster do that, but I have some DVDs that have this configuration.

Let me know if this works/doesn't work for you.

Also, I'm not sure how much ffmpeg you know, but the output will contain the lines:

Stream mapping:
  Stream #0:0 -> #0:0 (h264 (native) -> h264 (libx264))
Stream mapping:
  Stream #0:0 -> #0:0 (mpeg2video (native) -> h264 (libx264))
  Stream #0:3 -> #0:1 (ac3 (native) -> aac (libfdk_aac))
  Stream #0:1 -> #0:2 (copy)

or similar, which lets you verify it's pulling the right data out of your source, and your output has the right tracks, without letting it transcode all the way through (because 2.7fps movie-length transcodes suck just to find out ffproc did it wrong :disappointed: Sorry about that)

nebukazar911 commented 6 years ago

Awesome! I’ll try this out later this week and let you know how it goes.

Cheers!

Envoyé depuis mon iPhone // Sent from my iPhone

On Mar 3, 2018, at 12:00 AM, Alex Roth notifications@github.com wrote:

Alright, I've pushed a commit which should hopefully fix this for you. The "default" profile shows an example of the new feature being configured. You'd just have to set "ignore" to true, or add "fre" as an allowed language.

What I intend to implement a little later on is extracting/transcoding audio tracks per-language, so if you had both English and French, your output would have both as well. I'm tracking that in #13. In Ontario at least, I haven't ever seen a TV broadcaster do that, but I have some DVDs that have this configuration.

Let me know if this works/doesn't work for you.

Also, I'm not sure how much ffmpeg you know, but the output will contain the lines:

Stream mapping: Stream #0:0 -> #0:0 (h264 (native) -> h264 (libx264)) Stream mapping: Stream #0:0 -> #0:0 (mpeg2video (native) -> h264 (libx264)) Stream #0:3 -> #0:1 (ac3 (native) -> aac (libfdk_aac)) Stream #0:1 -> #0:2 (copy) or similar, which lets you verify it's pulling the right data out of your source, and your output has the right tracks, without letting it transcode all the way through (because 2.7fps movie-length transcodes suck just to find out ffproc did it wrong 😞 Sorry about that)

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or mute the thread.

XenHat commented 5 years ago

Looks like this fellow Quebecois forgot this existed. I'll try to run it on a couple french canadian movies I have laying around, see if I can reproduce the issue :) I also have a metric ton of japanese anime.