Skip to content

Crash on muxing MP4 with ADTS AAC audio ("Malformed AAC bitstream detected") #367

Description

@allensakura

Describe the bug

When processing an MP4 file containing AAC audio with ADTS headers, the encoding/muxing step crashes with a PermissionError and stops the pipeline.

Last error log from FFmpeg: [mp4] Malformed AAC bitstream detected: use the audio bitstream filter 'aac_adtstoasc' to fix it ('-bsf:a aac_adtstoasc' option with ffmpeg)

To Reproduce

GUI processor running a video job with an AAC/ADTS audio stream.

Console/Log output

Click to expand full console output
10:03:59 AM INFO    Processing started by user

10:03:59 AM INFO    Output folder: 

10:03:59 AM INFO    Output pattern: {original}_restored.mp4

10:03:59 AM INFO    Files queued: 1

10:03:59 AM INFO    Processing started

10:03:59 AM INFO    Started processing a.mp4

10:03:59 AM INFO    Loads checkpoint by local backend from path: E:\jasna-windows-0.10.0\model_weights\lada_mosaic_restoration_model_generic_v1.2.pth

10:04:00 AM INFO    BasicVSR++ using TRT sub-engines (fp16=True)

10:04:00 AM INFO    RestorationPipeline: secondary=tvai denoise=NONE denoise_step=AFTER_PRIMARY

10:04:00 AM INFO    Restoration models loaded (reused across video jobs)

10:04:00 AM INFO    RF-DETR detection model loaded: E:\jasna-windows-0.10.0\model_weights\rfdetr-v6.bs1-4.fp16.win.engine (batch_size=4)

10:04:00 AM INFO    VR mode: requested=auto resolved=off projection=none reason=display aspect 1.778 is outside the SBS gate

10:04:00 AM INFO    VramOffloader: threshold=15525 MiB (total=16275 MiB, safetynet=750 MiB)

10:04:00 AM INFO    Using VALI NVDEC decoder for a.mp4

10:04:00 AM INFO    Processing a.mp4: 262300 frames @ 29.97002997002997 fps, 1280x720

10:04:00 AM INFO    Using VALI NVDEC decoder for a.mp4

10:04:00 AM ERROR   Malformed AAC bitstream detected: use the audio bitstream filter 'aac_adtstoasc' to fix it ('-bsf:a aac_adtstoasc' option with ffmpeg)

10:04:00 AM ERROR   [encoder-worker] crashed

Traceback (most recent call last):

  File "E:\jasna-windows-0.10.0\jasna\media\video_encoder.py", line 813, in _encode_worker

  File "E:\jasna-windows-0.10.0\jasna\media\video_encoder.py", line 840, in _handle_encode_item

  File "E:\jasna-windows-0.10.0\jasna\media\video_encoder.py", line 1058, in _encode_frame

  File "E:\jasna-windows-0.10.0\jasna\media\video_encoder.py", line 865, in _mux_video

  File "E:\jasna-windows-0.10.0\jasna\media\video_encoder.py", line 922, in _pump_source_streams

  File "av/container/output.py", line 604, in av.container.output.OutputContainer.mux

  File "av/container/output.py", line 613, in av.container.output.OutputContainer.mux_one

  File "av/container/output.py", line 635, in av.container.output.OutputContainer._mux_one

  File "av/container/core.py", line 369, in av.container.core.Container.err_check

  File "av/error.py", line 354, in av.error.err_check

av.error.PermissionError: [Errno 1] Operation not permitted: 'E:\a_restore.mp4'; last error log: [mp4] Malformed AAC bitstream detected: use the audio bitstream filter 'aac_adtstoasc' to fix it ('-bsf:a aac_adtstoasc' option with ffmpeg)

10:04:00 AM ERROR   [blend-encode] thread crashed

Traceback (most recent call last):

  File "E:\jasna-windows-0.10.0\jasna\pipeline_threads.py", line 435, in blend_encode_loop

  File "E:\jasna-windows-0.10.0\jasna\pipeline.py", line 62, in write

  File "E:\jasna-windows-0.10.0\jasna\media\video_encoder.py", line 1062, in encode

  File "E:\jasna-windows-0.10.0\jasna\media\video_encoder.py", line 813, in _encode_worker

  File "E:\jasna-windows-0.10.0\jasna\media\video_encoder.py", line 840, in _handle_encode_item

  File "E:\jasna-windows-0.10.0\jasna\media\video_encoder.py", line 1058, in _encode_frame

  File "E:\jasna-windows-0.10.0\jasna\media\video_encoder.py", line 865, in _mux_video

  File "E:\jasna-windows-0.10.0\jasna\media\video_encoder.py", line 922, in _pump_source_streams

  File "av/container/output.py", line 604, in av.container.output.OutputContainer.mux

  File "av/container/output.py", line 613, in av.container.output.OutputContainer.mux_one

  File "av/container/output.py", line 635, in av.container.output.OutputContainer._mux_one

  File "av/container/core.py", line 369, in av.container.core.Container.err_check

  File "av/error.py", line 354, in av.error.err_check

av.error.PermissionError: [Errno 1] Operation not permitted: 'E:\a_restore.mp4'; last error log: [mp4] Malformed AAC bitstream detected: use the audio bitstream filter 'aac_adtstoasc' to fix it ('-bsf:a aac_adtstoasc' option with ffmpeg)

10:04:00 AM INFO    [timing] blend-encode: queue-wait=0.2s, decode=0.0s, result-wait=0.0s, blend=0.0s, write=0.0s (tracked 0.2s)

10:04:01 AM ERROR   [decode] thread crashed

Traceback (most recent call last):

  File "E:\jasna-windows-0.10.0\jasna\pipeline_threads.py", line 152, in decode_detect_loop

  File "E:\jasna-windows-0.10.0\jasna\pipeline_threads.py", line 435, in blend_encode_loop

  File "E:\jasna-windows-0.10.0\jasna\pipeline.py", line 62, in write

  File "E:\jasna-windows-0.10.0\jasna\media\video_encoder.py", line 1062, in encode

  File "E:\jasna-windows-0.10.0\jasna\media\video_encoder.py", line 813, in _encode_worker

  File "E:\jasna-windows-0.10.0\jasna\media\video_encoder.py", line 840, in _handle_encode_item

  File "E:\jasna-windows-0.10.0\jasna\media\video_encoder.py", line 1058, in _encode_frame

  File "E:\jasna-windows-0.10.0\jasna\media\video_encoder.py", line 865, in _mux_video

  File "E:\jasna-windows-0.10.0\jasna\media\video_encoder.py", line 922, in _pump_source_streams

  File "av/container/output.py", line 604, in av.container.output.OutputContainer.mux

  File "av/container/output.py", line 613, in av.container.output.OutputContainer.mux_one

  File "av/container/output.py", line 635, in av.container.output.OutputContainer._mux_one

  File "av/container/core.py", line 369, in av.container.core.Container.err_check

  File "av/error.py", line 354, in av.error.err_check

  File "av/error.py", line 354, in av.error.err_check

av.error.PermissionError: [Errno 1] Operation not permitted: 'E:\a_restore.mp4'; last error log: [mp4] Malformed AAC bitstream detected: use the audio bitstream filter 'aac_adtstoasc' to fix it ('-bsf:a aac_adtstoasc' option with ffmpeg)

10:04:01 AM INFO    [timing] decode-detect: decode=0.0s, detect-track=0.2s (tracked 0.3s)

10:04:01 AM INFO    [timing] primary: queue-wait=0.3s (tracked 0.3s)

10:04:01 AM INFO    VRAM — min: 3139 MiB, max: 3239 MiB, avg: 3189 MiB | offloads: 0, total offloaded: 0 MiB

10:04:01 AM ERROR   Failed to process a.mp4: [Errno 1] Operation not permitted: 'E:\a_restore.mp4'; last error log: [mp4] Malformed AAC bitstream detected: use the audio bitstream filter 'aac_adtstoasc' to fix it ('-bsf:a aac_adtstoasc' option with ffmpeg)

Traceback (most recent call last):

  File "E:\jasna-windows-0.10.0\jasna\gui\processor.py", line 254, in _process_job

  File "E:\jasna-windows-0.10.0\jasna\gui\processor.py", line 350, in _run_pipeline

  File "E:\jasna-windows-0.10.0\jasna\gui\processor.py", line 481, in _run_video_job

  File "E:\jasna-windows-0.10.0\jasna\pipeline.py", line 716, in run

  File "E:\jasna-windows-0.10.0\jasna\pipeline.py", line 594, in _run_full

  File "E:\jasna-windows-0.10.0\jasna\pipeline.py", line 495, in _run_pass

  File "E:\jasna-windows-0.10.0\jasna\pipeline.py", line 70, in close

  File "E:\jasna-windows-0.10.0\jasna\media\video_encoder.py", line 797, in __exit__

  File "E:\jasna-windows-0.10.0\jasna\pipeline_threads.py", line 152, in decode_detect_loop

  File "E:\jasna-windows-0.10.0\jasna\pipeline_threads.py", line 435, in blend_encode_loop

  File "E:\jasna-windows-0.10.0\jasna\pipeline.py", line 62, in write

  File "E:\jasna-windows-0.10.0\jasna\media\video_encoder.py", line 1062, in encode

  File "E:\jasna-windows-0.10.0\jasna\media\video_encoder.py", line 813, in _encode_worker

  File "E:\jasna-windows-0.10.0\jasna\media\video_encoder.py", line 840, in _handle_encode_item

  File "E:\jasna-windows-0.10.0\jasna\media\video_encoder.py", line 1058, in _encode_frame

  File "E:\jasna-windows-0.10.0\jasna\media\video_encoder.py", line 865, in _mux_video

  File "E:\jasna-windows-0.10.0\jasna\media\video_encoder.py", line 922, in _pump_source_streams

  File "av/container/output.py", line 604, in av.container.output.OutputContainer.mux

  File "av/container/output.py", line 613, in av.container.output.OutputContainer.mux_one

  File "av/container/output.py", line 635, in av.container.output.OutputContainer._mux_one

  File "av/container/core.py", line 369, in av.container.core.Container.err_check

  File "av/error.py", line 354, in av.error.err_check

  File "av/error.py", line 354, in av.error.err_check

av.error.PermissionError: [Errno 1] Operation not permitted: 'E:\a_restore.mp4'; last error log: [mp4] Malformed AAC bitstream detected: use the audio bitstream filter 'aac_adtstoasc' to fix it ('-bsf:a aac_adtstoasc' option with ffmpeg)

10:04:01 AM INFO    Restoration models unloaded

10:04:01 AM INFO    Processing completed

10:04:01 AM INFO    All jobs completed

JAV Code with timestamp: @ 00:00:00

Desktop (please complete the following information)

OS: Windows 11 25H2

Jasna Version: 0.10.0

GUI or CLI? GUI

GPU: NVIDIA GeForce RTX 5080

Nvidia Driver version: 615.56

CPU: 9800X3D

Suggested improvement

I suggest adding an automatic detection and conversion step for this case.

When Jasna detects an AAC audio stream with ADTS headers and the target container is MP4/MOV, it could automatically apply the aac_adtstoasc bitstream filter before muxing.

This should allow the AAC stream to be converted to the format required by the MP4 container without re-encoding the audio, avoiding both quality loss and unnecessary processing overhead.

Ideally, this could be handled during a preflight/media analysis stage so the incompatible AAC bitstream is detected and corrected before the encoding/muxing stage, rather than causing the encoder worker to crash.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions