【问题标题】:FFMPEG M3U8 Download Is Shortened When ProcessedFFMPEG M3U8 下载在处理时被缩短
【发布时间】:2022-12-19 13:46:59
【问题描述】:

我正在使用 FFMPEG 下载 m3u8 流:

timeout 60m ffmpeg -i [feed_url] -movflags isml+frag_keyframe+faststart -bsf:a aac_adtstoasc -vcodec copy -c copy [save_file].mp4
  • 超时将在 60 分钟后自动结束流
  • -movflags isml+frag_keyframe+faststart 确保 moov atom 存在于部分下载以及流是否被切断。

当我在 Quicktime 或 Safari 中播放它时,它工作正常。然后将流上传到另一台服务器,并使用此 ffmpeg 命令对其进行处理:

ffmpeg  -i [input_file] -y  -f mp4 -pix_fmt yuv420p -c:v libx264 -c:a aac -filter_complex "scale='if(gt(iw,1920),1920,-1)':'if(gt(ih,1080),1080,-1)':force_original_aspect_ratio=decrease" -crf 20 -movflags faststart -max_muxing_queue_size 9999 -attempt_recovery 1 -max_recovery_attempts 3 -f mp4 [output_file]

运行上面的命令时,有时会出现这个错误:

[mov,mp4,m4a,3gp,3g2,mj2 @ 0xaaaafcd63b70] Packet corrupt (stream = 0, dts = 53801910).=  64x     
[NULL @ 0xaaaafcd649b0] Invalid NAL unit size (1186 > 532).
[NULL @ 0xaaaafcd649b0] missing picture in access unit with size 542
/code/partners/tmp/video_634d29a2e1f6e.mp4: corrupt input packet in stream 0
[h264 @ 0xaaaafd1211f0] Invalid NAL unit size (1186 > 532).
[h264 @ 0xaaaafd1211f0] Error splitting the input into NAL units.
[mov,mp4,m4a,3gp,3g2,mj2 @ 0xaaaafcd63b70] stream 0, offset 0x3802b2: partial file
[mov,mp4,m4a,3gp,3g2,mj2 @ 0xaaaafcd63b70] stream 0, offset 0x380791: partial file
[mov,mp4,m4a,3gp,3g2,mj2 @ 0xaaaafcd63b70] stream 0, offset 0x380c38: partial file
[mov,mp4,m4a,3gp,3g2,mj2 @ 0xaaaafcd63b70] stream 0, offset 0x380f8d: partial file
[mov,mp4,m4a,3gp,3g2,mj2 @ 0xaaaafcd63b70] stream 0, offset 0x38137a: partial file
Error while decoding stream #0:0: Invalid data found when processing input
[mov,mp4,m4a,3gp,3g2,mj2 @ 0xaaaafcd63b70] stream 0, offset 0x381750: partial file
[mp4 @ 0xaaaafcd743d0] Starting second pass: moving the moov atom to the beginning of the file
frame= 8967 fps=923 q=-1.0 Lsize=    5683kB time=00:09:57.60 bitrate=  77.9kbits/s speed=61.5x    
video:5580kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 1.843884%

发生此错误时,视频会被剪短。如果完整视频是 60 分钟,在 10 分钟标记处出现错误,则转换后的视频将只有 10 分钟。那是什么错误,我怎样才能让 ffmpeg 停止缩短输出视频?

【问题讨论】:

    标签: ffmpeg


    【解决方案1】:

    尝试检查是否发生错误:(来自reddit

    process = subprocess.Popen("ffmpeg ...", encoding='UTF-8', stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
    
    # while process is running
    while not process.poll():
        if process.stdout:
            std_out = process.stdout.readline()
            if std_out:
                log.info(std_out)
                if 'error' in std_out:
                    log.error('**ERROR** Detected error message from ffmpeg:')
                    # log.error(std_err)
                    log.info('Killing ffmpeg process...')
                    process.kill()
                    sys.exit(1)
    
    # process terminated
    if process.returncode and process.returncode != 0:
        log.error('**ERROR** ffmpeg returned error code ' + str(process.returncode))
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-11-21
      • 2017-08-30
      • 1970-01-01
      • 2018-10-03
      • 1970-01-01
      • 2023-03-12
      • 2020-11-06
      • 2020-08-15
      相关资源
      最近更新 更多