Пример #1
0
import av
from tests.common import asset, sandboxed

arg_parser = argparse.ArgumentParser()
arg_parser.add_argument('-v', '--verbose', action='store_true')
arg_parser.add_argument('input', nargs=1)
args = arg_parser.parse_args()

input_file = av.open(args.input[0])
input_video_stream = None  # next((s for s in input_file.streams if s.type == 'video'), None)
input_audio_stream = next((s for s in input_file.streams if s.type == 'audio'),
                          None)

# open output file
output_file_path = sandboxed('encoded-' + os.path.basename(args.input[0]))
output_file = av.open(output_file_path, 'w')
output_video_stream = output_file.add_stream(
    "mpeg4", 24) if input_video_stream else None
output_audio_stream = output_file.add_stream(
    "mp3") if input_audio_stream else None

frame_count = 0

for packet in input_file.demux(
    [s for s in (input_video_stream, input_audio_stream) if s]):

    if args.verbose:
        print('in ', packet)

    for frame in packet.decode():
Пример #2
0
from __future__ import division

import math

import av
from av.video.frame import VideoFrame
from PIL import Image
from tests.common import sandboxed

width = 320
height = 240
duration = 96

path = sandboxed('rgb_rotate.mov')
output = av.open(path, 'w')

stream = output.add_stream("mpeg4", 24)
stream.width = width
stream.height = height
stream.pix_fmt = "yuv420p"

for frame_i in range(duration):

    frame = VideoFrame(width, height, 'rgb24')
    image = Image.new('RGB', (width, height), (
        int(255 * (0.5 + 0.5 * math.sin(frame_i / duration * 2 * math.pi))),
        int(255 *
            (0.5 + 0.5 *
             math.sin(frame_i / duration * 2 * math.pi + 2 / 3 * math.pi))),
        int(255 *
            (0.5 + 0.5 *
Пример #3
0
import av
from tests.common import asset, sandboxed


arg_parser = argparse.ArgumentParser()
arg_parser.add_argument('-v', '--verbose', action='store_true')
arg_parser.add_argument('input', nargs=1)
args = arg_parser.parse_args()

input_file = av.open(args.input[0])
input_video_stream = None # next((s for s in input_file.streams if s.type == 'video'), None)
input_audio_stream = next((s for s in input_file.streams if s.type == 'audio'), None)

# open output file
output_file_path = sandboxed('encoded-' + os.path.basename(args.input[0]))
output_file = av.open(output_file_path, 'w')
output_video_stream = output_file.add_stream("mpeg4", 24) if input_video_stream else None
output_audio_stream = output_file.add_stream("mp3") if input_audio_stream else None


frame_count = 0


for packet in input_file.demux([s for s in (input_video_stream, input_audio_stream) if s]):


    if args.verbose:
        print('in ', packet)

    for frame in packet.decode():
Пример #4
0
from __future__ import division

import math

import av
from av.video.frame import VideoFrame
from PIL import Image
from tests.common import sandboxed


width = 320
height = 240
duration = 96

path = sandboxed('rgb_rotate.mov')
output = av.open(path, 'w')


stream = output.add_stream("mpeg4", 24)
stream.width = width
stream.height = height
stream.pix_fmt = "yuv420p"

for frame_i in xrange(duration):

    frame = VideoFrame(width, height, 'rgb24')
    image = Image.new('RGB', (width, height), (
        int(255 * (0.5 + 0.5 * math.sin(frame_i / duration * 2 * math.pi))),
        int(255 * (0.5 + 0.5 * math.sin(frame_i / duration * 2 * math.pi + 2 / 3 * math.pi))),
        int(255 * (0.5 + 0.5 * math.sin(frame_i / duration * 2 * math.pi + 4 / 3 * math.pi))),
    ))