Giter Site home page Giter Site logo

Repackaging without transcoding about pyav HOT 12 CLOSED

pyav-org avatar pyav-org commented on August 19, 2024
Repackaging without transcoding

from pyav.

Comments (12)

simora avatar simora commented on August 19, 2024

Thank you for considering my issue.

from pyav.

mikeboers avatar mikeboers commented on August 19, 2024

I've started working on this in the remux branch (https://github.com/mikeboers/PyAV/tree/remux). There is an examples/remux.py which I am testing with.

I'm having issues with local MKVs appearing to have badly ordered packets in the source. Let me know if you have better luck than me.

from pyav.

simora avatar simora commented on August 19, 2024

I must have been using the previous version of pyav from pypi when i reported this issue so i apologize for the confusion. Grabbing the latest from remux branch i am unable to import av with following error. I also have the same error with master and pip install.

ImportError: /usr/local/lib/python2.7/dist-packages/av/_core.so: undefined symbol: avdevice_register_all

Running Ubuntu 14.04, ffmpeg:amd64/trusty 7:1.2.6-1trusty1, libavdevice-dev:amd64/trusty 7:1.2.6-1trusty1

from pyav.

simora avatar simora commented on August 19, 2024

I disabled libavdevice by commenting it out in _core.pxd and include/libav.pxd than i was able to import av. Once i did that i ran the remux.py i get the following error. VLC is able to play the file and read codec information but spits out "no frame!" messages all over the place. A sample output has be included below as well. Also as bonus troubleshooting, I reran remux.py but changed output container to mp4 and it the entire input file with a similar error as outputing in mkv. But the file is all kinds of busted unlike the mkv. That output is also listed below.

--Output Container of mkv--

File "remux.py", line 67, in
output.mux(packet)
File "container.pyx", line 371, in av.container.OutputContainer.mux (PyAV/src/av/container.c:5744)
File "utils.pyx", line 31, in av.utils.err_check (PyAV/src/av/utils.c:1031)
av.AVError: [Errno 22] Invalid argument
ERROR:libav.matroska:Application provided invalid, non monotonically increasing dts to muxer in stream 0: 5202764 >= 0

MediaInfo output:

General
Unique ID : 227301783144717902741594047551258698062 (0xAB00BB268EEB374AB6CF7585D1AB214E)
Complete name : ~/SampleData/Series/Firefly/Season 1/TEST - Firefly - S01E01 - Serenity.mkv
Format : Matroska
Format version : Version 2
File size : 789 MiB
Writing application : Lavf54.63.104
Writing library : Lavf54.63.104

Video
ID : 1
Format : AVC
Format/Info : Advanced Video Codec
Codec ID : V_MPEG4/ISO/AVC
Width : 720 pixels
Height : 480 pixels
Display aspect ratio : 16:9
Frame rate mode : Variable
Standard : NTSC
Default : Yes
Forced : No

Audio
ID : 2
Format : AC-3
Format/Info : Audio Coding 3
Format profile : Dolby Digital
Mode extension : CM (complete main)
Format settings, Endianness : Big
Codec ID : A_AC3
Bit rate mode : Constant
Bit rate : 192 Kbps
Channel(s) : 2 channels
Channel positions : Front: L R
Sampling rate : 48.0 KHz
Bit depth : 16 bits
Compression mode : Lossy
Default : Yes
Forced : No

VLC stdout:

[h264 @ 0x7f29c4c85020] no frame!
[h264 @ 0x7f29c4c820a0] non-existing PPS 2 referenced
[h264 @ 0x7f29c4c820a0] decode_slice_header error

--Output Container of MPEG-4--

MediaInfo Output:

General
Complete name : ~/SampleData/Series/Firefly/Season 1/TEST - Firefly - S01E01 - Serenity.mp4
Format : MPEG-4
Format profile : Base Media
Codec ID : isom
File size : 668 MiB

VLC stdout:

VLC media player 2.1.4 Rincewind (revision 2.1.4-0-g2a072be)
[0x2022118] main libvlc: Running vlc with the default interface. Use 'cvlc' to use vlc without interface.
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x7f1e50c20c00] moov atom not found
[0x7f1e24c01958] mp4 demux error: MP4 plugin discarded (no moov,foov,moof box)
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x7f1e24c09ee0] moov atom not found
[0x7f1e24c01958] avformat demux error: Could not open ~/SampleData/Series/Firefly/Season 1/TEST - Firefly - S01E01 - Serenity.mp4: Unknown error 1094995529

from pyav.

simora avatar simora commented on August 19, 2024

For the sake of simplicity and ease of troubleshooting i will begin using the following video sample as my reference file. I have tested it and produced the same results barring a few caveats. There is an error in your remux.py file at line 53, args.nosubtitle does not exist change it to args.nosubs. i ran the remux.py with --nosubs input.mkv output.mkv. I was able to repoduce all the of the previously mentioned errors. Thank you for your effort in resolving this.

Video sample:
http://www.auby.no/files/video_tests/h264_1080p_hp_4.1_10mbps_dts_unstyled_subs_monsters.mkv

from pyav.

mikeboers avatar mikeboers commented on August 19, 2024

I'm trying to find something nice and compact from the FATE suite as well so that we can include it into the unit tests as well.

from pyav.

simora avatar simora commented on August 19, 2024

Running files through a variation of your remux.py example throws "Invalid argument" on the last packet when muxing. Printing packet shows the following:
av.Packet of #0, dts=0, pts=0 at 0x7f947e521200

Additional error is printed on console from av stating the following:
No handlers could be found for logger "libav.matroska"

from pyav.

mikeboers avatar mikeboers commented on August 19, 2024

Quick link I found via the Googles: http://stackoverflow.com/a/17593502/66502

from pyav.

mikeboers avatar mikeboers commented on August 19, 2024

I think I've solved most of the issues with this. Needed to clear a few flags, and re-scale times. See scratchpad/remux.py on the remux branch.

from pyav.

mikeboers avatar mikeboers commented on August 19, 2024

This is close enough to #143 that we should consider it merged there.

from pyav.

victorhcm avatar victorhcm commented on August 19, 2024

I'm trying to do something similar in my application. I want to intercept the packages, while I also write them to disk (something similar to tee). However, I'm not able to do it. Here is a self-contained example:

import av
import pickle
import numpy as np


def write_packets(filename, packets, video_stream):
    container = av.open(filename, mode='w')
    stream = container.add_stream(
            video_stream.codec_context.name, video_stream.average_rate
    )

    stream.width = video_stream.width
    stream.height = video_stream.height
    stream.pix_fmt = video_stream.codec_context.format.name
    stream.bit_rate = video_stream.codec_context.bit_rate
    stream.options = {}

    for p in packets:
        if p.dts is not None: 
            container.mux(p)
    container.close()


out_filename = 'test.mp4'
in_container = av.open('GOPR6644.MP4')
video_stream = next(s for s in in_container.streams if s.type == 'video')
print(video_stream)

packets = [packet for packet in in_container.demux(video=0)]
write_packets(out_filename, packets, video_stream)

container2 = av.open(out_filename, mode='r')
remuxed_packets = [packet for packet in container2.demux(video=0)]
for p in remuxed_packets:
    print(p)

I tried to write to a .mp4 container, however it's not writing any packets as they are all 1-byte sized:

Could not find codec parameters for stream 0 (Video: h264 (avc1 / 0x31637661), none, 1280x720, 0 kb/s): unspecified pixel format
Consider increasing the value for the 'analyzeduration' and 'probesize' options
<av.Packet of #0, dts=0, pts=0; 1 bytes at 0x7fd09f83b868>
<av.Packet of #0, dts=1001, pts=1001; 1 bytes at 0x7fd09f83b908>
<av.Packet of #0, dts=2002, pts=2002; 1 bytes at 0x7fd09f83b9a8>
<av.Packet of #0, dts=3003, pts=3003; 1 bytes at 0x7fd09f83ba48>
...

The output file is 828 bytes only, while the original (GOPR6644.mp4) is 8,3MB, which I guess it is only the container metadata being written.

Thus, I tried to write to a .h264 file instead just to make sure, which yields a file about the same size of the original video, but it sees the packets as a single 8,2MB packet (which I think is due to some missing metadata or the lack of a container):

Format h264 detected only with low score of 1, misdetection possible!
missing picture in access unit with size 8201183
No start code is found.
Error splitting the input into NAL units.
Stream #0: not enough frames to estimate rate; consider increasing probesize
Could not find codec parameters for stream 0 (Video: h264, none): unspecified size
Consider increasing the value for the 'analyzeduration' and 'probesize' options
<av.Packet of #0, dts=None, pts=None; 8201183 bytes at 0x7f1f5c2fa9a8>
<av.Packet of #0, dts=None, pts=None; 0 bytes at 0x7f1f5c2faae8>

I'm not sure why the packets are not being written when I use .mp4. Am I missing something? I checked the examples, but they look similar. The only difference that comes to mind right now is the packets being decoded before being encoded and then muxed again.

from pyav.

victorhcm avatar victorhcm commented on August 19, 2024

We were able to fix it by changing the add_stream call in write_packets() to stream = container.add_stream(template=video_stream). It now works for any container. Here's the fixed working snippet:

import av
import numpy as np


def write_packets(filename, packets, video_stream):
    container = av.open(filename, mode='w')
    stream = container.add_stream(template=video_stream)
    stream.options = {}
    for p in packets:
        if p.dts is not None: 
            container.mux(p)
    container.close()


out_filename = 'test.mp4'
container = av.open('GOPR6644.MP4')
video_stream = next(s for s in container.streams if s.type == 'video')

packets = [packet for packet in container.demux(video = 0)]
write_packets(out_filename, packets, video_stream)

container2 = av.open(out_filename, mode='r')
remuxed_packets = [packet for packet in container2.demux(video = 0)]
for p in remuxed_packets:
    print(p)

It had nothing to do with the filetype, whether it was .ts (transport stream) or .mp4.

from pyav.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.